-
Notifications
You must be signed in to change notification settings - Fork 713
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Starcos 3.2 #1347
Starcos 3.2 #1347
Conversation
Well, the current (and past) approach seems very hacky. Though we could continue with it until we hit a starcos version that's used in multiple configurations, it is also possible to try and be more generic, at least with Starcos 3.X. For example, which operation is allowed with what key, is specified in EF.KEYD. If parsed, it indicates which exact operation and mechanism to use for signature and encryption... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although I'd better like to see the real card versions integrated instead of more and more card profiles (which by accident are based on different card versions), I'm aware that it's hard to perform a full restart with the given code base. Hence, I would accept your hack, but please have a look at the inline comments...
src/libopensc/card-starcos.c
Outdated
sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "Found alg ref id%02x\n",env->algorithm_ref & 0xFF ); | ||
*p++ = 0x80; | ||
*p++ = 0x01; | ||
*p++ = env->algorithm_ref & 0xFF; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing length check
src/libopensc/card-starcos.c
Outdated
} | ||
if(env->algorithm == SC_ALGORITHM_DES){ | ||
return -1; //for now, not supported | ||
/**p++= 0x89; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please remove dead code
src/libopensc/card-starcos.c
Outdated
*p++= 0x13;//signature | ||
*p++= 0x23;//PKCS RSA (standard) | ||
if (env->algorithm_flags & SC_ALGORITHM_RSA_HASH_SHA1){ | ||
//TODO: not tested yet |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please remove untested code
src/libopensc/card-starcos.c
Outdated
@@ -268,7 +406,7 @@ static int process_fci(sc_context_t *ctx, sc_file_t *file, | |||
return SC_SUCCESS; | |||
} | |||
|
|||
static int process_fci_v3_4(sc_context_t *ctx, sc_file_t *file, | |||
static int process_fci_v3_2_v3_4_v3_5(sc_context_t *ctx, sc_file_t *file, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe renaming this to process_fci_v3
would be useful
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Starcos 3.1 and 3.6 are not included, that's the reason for this naming scheme. Maybe process_fci_v3_2-5 ? Or solely put this information in a comment above the function and name it process_fci_v3?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is no 3.1 or 3.6 at the moment, hence there is only 3.x and everything else. just change the naming.
src/libopensc/card-starcos.c
Outdated
@@ -304,7 +442,7 @@ static int process_fci_v3_4(sc_context_t *ctx, sc_file_t *file, | |||
return SC_SUCCESS; | |||
} | |||
|
|||
static int process_fcp_v3_4(sc_context_t *ctx, sc_file_t *file, | |||
static int process_fcp_v3_2_v3_4_v3_5(sc_context_t *ctx, sc_file_t *file, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see above comment on the naming
src/libopensc/card-starcos.c
Outdated
@@ -1857,7 +2165,8 @@ static struct sc_card_driver * sc_get_driver(void) | |||
starcos_ops.card_ctl = starcos_card_ctl; | |||
starcos_ops.logout = starcos_logout; | |||
starcos_ops.pin_cmd = starcos_pin_cmd; | |||
|
|||
starcos_ops.list_files = NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not needed
src/pkcs11/framework-pkcs15.c
Outdated
@@ -1071,7 +1071,7 @@ pkcs15_init_slot(struct sc_pkcs15_card *p15card, struct sc_pkcs11_slot *slot, | |||
pin_info = NULL; | |||
} | |||
else { | |||
if (auth->label[0] && strncmp(auth->label, "PIN", 4) != 0) | |||
if (auth->label[0] && strncmp(auth->label, "PIN", 4) != 0 && strncmp(auth->label, "User Pin", 9) != 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what do you need this change for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The term User PIN is normally used to differentiate from SO PIN or Signature PIN.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without this string compare, the label is copied into the tokeninfo label, which causes the inserted card to be displayed as "User Pin()" instead of "". At the same time, the closing bracket is often cut off. With the additional clause, the string is not copied and hence not shown.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's intended to be shown as PIN LABEL (CARD LABEL). It seems your card doesn't have set p15card->tokeninfo->label
. A better approach would be to only append (CARD LABEL) if p15card->tokeninfo->label
is not empty.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both auth->label and p15card->tokeninfo->label are not empty, Github just removed the strings surrounded by angle brackets from my example. What the output shows is "User Pin(Example card" -where the closing bracket is oftentimes missing- instead of the desired "Example card".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As explained above, I don't think this should be done for all cards. Either do this specifically for your card in something like pkcs15-starcos.c
or create a configuration option that allows setting the pkcs#11 slot labels.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not as well-versed in the code structure and order of execution of certain functions: Is either one of the pkcs15-starcos.c::starcos_init_card( )
or pkcs15-starcos.c::starcos_finalize_card( )
functions definitely going to be called After the above function pkcs15_init_slot( )
? In that case, one could change the card label in pkcs15-starcos.c
, otherwise it might be overwritten again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please remove this change. We'll think about configuring the slot naming seperately.
If you look at the inline comments, we can merge this for the next release... |
e2001b3
to
6edb4ec
Compare
I undid changes concerning the renaming of the card lable in |
There's some error handling missing with |
As far as I could see, after each malloc, a pointer check is performed (Though this is not shown here, it is visible in the file)? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the result of malloc was checked, indeed. But there is still some dead code lying around, for which I don't see a good reason.
sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x22, 0x81, | ||
0xb8); | ||
// adapt last byte : FIXME DIRTY HACK (somehow works?) | ||
p += env->key_ref_len -1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what are you trying to achieve? As a general rule, don't use hacks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a discrepancy between provided key reference number by the card and reference number expected by it. This was tested on multiple cards and compared to other drivers which also receive the same numbers by the card. Even though e.g. a 0x84 is given as a key reference number when the card is read out, it produces an error when later specifying this exact key reference number for an operation. For an unknown reason, it always expects a number which is smaller by three, 0x81 in the example. The reason for this could not be found after a thorough in depth search, so we left it at that. I see that there needs to be an additional check concerning a zero length key reference number, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the exact key reference and the exact value you need to code in the MSE? What's the content of EF_KEYD?
I think understanding EF_KEYD is key in avoiding hacks like this. Please read the documentation and try to find some hints.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am fairly sure I tried the following, but I will look this up to confirm it:
I was not able to access any EF_KEYD file as an additional source of information. Neither was this file accessed by any other driver, implementation or program which could be used as a reference. The documentation did not provide any further helpful information. Additionally, OpenSC chooses a key with the appropriate usage flags (see e.g. pkcs15-framework.c:pkcs15_prkey_sign
, line 3773), whose reference number is written into the key-ref-pointer. This number is the exact same as the one which was initially read out from the Starcos Smart-Card. It is later not accepted as a valid ref-number anymore, the reported error code deeming the key not suitable or the number invalid. No information in the documentation suggests a change in or an adaption of the key reference number.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you read the starcos reference manual? Did you search for EF_KEYD?
Sorry for being picky, but this hack is a little too problematic. Unfortunately, I currently don't have more time to implement this myself...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I completely understand. I spent an extensive amount of time myself trying to find the reason for this. This also lead to the fact that I compared the complete communication process between driver and card for different implementations, none was making use of this EF_KEYD file or gaining any further relevant information. I am certain that the information found in the manual was not sufficient, but I am going to check that again tomorrow and come back to you.
src/libopensc/card-starcos.c
Outdated
* Not supported yet | ||
* TODO: check one-sided symmetric | ||
* double-sided symmetric */ | ||
return 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is more dead code
"not supported for STARCOS 3.2 cards"); \ | ||
return SC_ERROR_NOT_SUPPORTED; \ | ||
} \ | ||
} while (0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be merged with CHECK_NOT_SUPPORTED_V3_4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is one additional operation which was not tested on Starcos 3.4. Apart from this, one could merge both checks and implement a manual error check at that point.
src/libopensc/card-starcos.c
Outdated
} else if(card->type == SC_CARD_TYPE_STARCOS_V3_2) { | ||
//TODO: for now: not supported (Internal authenticate used instead) | ||
return SC_ERROR_NOT_SUPPORTED; | ||
#if 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove dead code
if(env->flags & SC_SEC_ENV_KEY_REF_SYMMETRIC){ | ||
/* For now, signature sometimes runs into this case -> return 0, not -1 to continue signature procedures | ||
* Not supported yet. */ | ||
return 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be an error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll update the comment, thanks.
} while (0); | ||
|
||
/*Finds appropriate alg based on sec environment and writes these into the ptr | ||
* returns number of bytes which were added, 0 if no alg specified. -1 if not supported |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-1
or an error code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error code, thank you.
Closing this issue due to inactivity. Please re-open the ticket if more input is available. |
Added support for Starcos 3.2. cards.
Encryption, signature and decryption functionalities were implemented.
GetSerialnumber and PIN-info are supported.
Superfluous "User Pin" removed from card label.
Starcos 3.2. cards were used during testing.