-
Notifications
You must be signed in to change notification settings - Fork 711
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
Solve handling of wrong length status codes with SM card bug and Add ECC support in Feitian ePass2003 #1127
Solve handling of wrong length status codes with SM card bug and Add ECC support in Feitian ePass2003 #1127
Conversation
Check the communication #1110 The issue is related SM card, when got response 6CXX, case sc_set_le_and_transmit API retries the command and only changing apdu->resplen and apdu->le, then call sc_single_transmit, at this time, the SM authenticated message won't work, because it still contains the orginal LE. modify sm.c file solve the issue.
Add ePass2003 ECC support, the related feedback check #1073
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 way you could have tested this successfully, your code doesn't even compile! Please review your checklist!
On first glance, however, the code looks OK.
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've marked and fixed compilation errors reported by Travis. I hope it will help you to submit good code.
diff --git a/src/libopensc/card-epass2003.c b/src/libopensc/card-epass2003.c
index 33b77601..8f582b13 100644
--- a/src/libopensc/card-epass2003.c
+++ b/src/libopensc/card-epass2003.c
@@ -172,7 +172,7 @@ static const struct sc_card_error epass2003_errors[] = {
static int epass2003_transmit_apdu(struct sc_card *card, struct sc_apdu *apdu);
static int epass2003_select_file(struct sc_card *card, const sc_path_t * in_path, sc_file_t ** file_out);
int epass2003_refresh(struct sc_card *card);
-static int hash_data(unsigned char *data, size_t datalen, unsigned char *hash, unsigned int mechanismType);
+static int hash_data(const unsigned char *data, size_t datalen, unsigned char *hash, unsigned int mechanismType);
static int
epass2003_check_sw(struct sc_card *card, unsigned int sw1, unsigned int sw2)
@@ -1204,7 +1204,7 @@ epass2003_init(struct sc_card *card)
//set EC Alg Flags
flags = SC_ALGORITHM_ONBOARD_KEY_GEN|SC_ALGORITHM_ECDSA_HASH_SHA1|SC_ALGORITHM_ECDSA_HASH_SHA256|SC_ALGORITHM_ECDSA_HASH_NONE|SC_ALGORITHM_ECDSA_RAW;
- //ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE | SC_ALGORITHM_EXT_EC_UNCOMPRESES;
+ ext_flags = 0;//ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE | SC_ALGORITHM_EXT_EC_UNCOMPRESES;
_sc_card_add_ec_alg(card, 256, flags, ext_flags, NULL);
card->caps = SC_CARD_CAP_RNG | SC_CARD_CAP_APDU_EXT;
@@ -2235,7 +2235,7 @@ internal_write_rsa_key(struct sc_card *card, unsigned short fid, struct sc_pkcs1
static int
-hash_data(unsigned char *data, size_t datalen, unsigned char *hash, unsigned int mechanismType)
+hash_data(const unsigned char *data, size_t datalen, unsigned char *hash, unsigned int mechanismType)
{
if ((NULL == data) || (NULL == hash))
@@ -2483,7 +2483,7 @@ epass2003_card_ctl(struct sc_card *card, unsigned long cmd, void *ptr)
{
LOG_FUNC_CALLED(card->ctx);
- sc_log(card->ctx, "cmd is %0x", cmd);
+ sc_log(card->ctx, "cmd is %0lx", cmd);
switch (cmd) {
case SC_CARDCTL_ENTERSAFE_WRITE_KEY:
return epass2003_write_key(card, (sc_epass2003_wkey_data *) ptr);
src/libopensc/card-epass2003.c
Outdated
@@ -1192,6 +1202,11 @@ epass2003_init(struct sc_card *card) | |||
_sc_card_add_rsa_alg(card, 1024, flags, 0); | |||
_sc_card_add_rsa_alg(card, 2048, flags, 0); | |||
|
|||
//set EC Alg Flags | |||
flags = SC_ALGORITHM_ONBOARD_KEY_GEN|SC_ALGORITHM_ECDSA_HASH_SHA1|SC_ALGORITHM_ECDSA_HASH_SHA256|SC_ALGORITHM_ECDSA_HASH_NONE|SC_ALGORITHM_ECDSA_RAW; | |||
//ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE | SC_ALGORITHM_EXT_EC_UNCOMPRESES; |
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.
Initialize ext_flags
to zero or to this commented flags.
src/libopensc/card-epass2003.c
Outdated
@@ -170,6 +172,7 @@ static const struct sc_card_error epass2003_errors[] = { | |||
static int epass2003_transmit_apdu(struct sc_card *card, struct sc_apdu *apdu); | |||
static int epass2003_select_file(struct sc_card *card, const sc_path_t * in_path, sc_file_t ** file_out); | |||
int epass2003_refresh(struct sc_card *card); | |||
static int hash_data(unsigned char *data, size_t datalen, unsigned char *hash, unsigned int mechanismType); |
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.
Add a const
specifier to data
param.
src/libopensc/card-epass2003.c
Outdated
@@ -2349,6 +2483,7 @@ epass2003_card_ctl(struct sc_card *card, unsigned long cmd, void *ptr) | |||
{ | |||
LOG_FUNC_CALLED(card->ctx); | |||
|
|||
sc_log(card->ctx, "cmd is %0x", cmd); |
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.
Replace format specifier with %0lx
.
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.
that works
To make it clearly, close this PR, will open another PR, thanks |
Fixes #1073
Fixes #1115
Checklist