Skip to content
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

Closed
wants to merge 3 commits into from

Conversation

FeitianSmartcardReader
Copy link
Contributor

@FeitianSmartcardReader FeitianSmartcardReader commented Aug 8, 2017

Fixes #1073
Fixes #1115

Checklist
  • Documentation is added or updated
  • New files have a LGPL 2.1 license statement
  • Tested with the following card:
    • tested PKCS#11
    • tested Windows Minidriver
    • tested macOS Tokend

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
Copy link
Member

@frankmorgner frankmorgner left a 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.

Copy link
Contributor

@majkrzak majkrzak left a 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);

@@ -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;
Copy link
Contributor

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.

@@ -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);
Copy link
Contributor

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.

@@ -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);
Copy link
Contributor

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.

Copy link
Contributor Author

@FeitianSmartcardReader FeitianSmartcardReader left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that works

@FeitianSmartcardReader
Copy link
Contributor Author

To make it clearly, close this PR, will open another PR, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants