Skip to content

Commit 705e97c

Browse files
committed
card-piv.c cards.h - Support Nitrokey PIV as new card type
Nitrokey 3A with firmware 1.8.0 now supports PIV applet. It is considered experimental at this time: https://github.com/Nitrokey/piv-authenticator It does not have complete support for algorithms required by NIST but it does follow Yubikey in many respects. On branch Nitrokey-PIV Changes to be committed: modified: card-piv.c modified: cards.h
1 parent 9b0313d commit 705e97c

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/libopensc/card-piv.c

+16-2
Original file line numberDiff line numberDiff line change
@@ -2903,7 +2903,7 @@ static int piv_find_aid(sc_card_t * card)
29032903
priv->init_flags |= PIV_INIT_AID_PARSED;
29042904
/* look for 800-73-4 0xAC for Cipher Suite Algorithm Identifier Table 14 */
29052905
/* There may be more than one 0xAC tag, loop to find all */
2906-
2906+
/* TODO do we need to look for "Nitrokey PIVP" in tag 0x50 length 12 */
29072907
nextac = tag;
29082908
while((actag = sc_asn1_find_tag(card->ctx, nextac, taglen - (nextac - tag),
29092909
0xAC, &actaglen)) != NULL) {
@@ -5396,6 +5396,7 @@ static int piv_match_card_continued(sc_card_t *card)
53965396
case SC_CARD_TYPE_PIV_II_PIVKEY:
53975397
case SC_CARD_TYPE_PIV_II_SWISSBIT:
53985398
case SC_CARD_TYPE_PIV_II_800_73_4:
5399+
case SC_CARD_TYPE_PIV_II_NITROKEY:
53995400
type = card->type;
54005401
break;
54015402
default:
@@ -5431,7 +5432,9 @@ static int piv_match_card_continued(sc_card_t *card)
54315432

54325433
if ((data = sc_compacttlv_find_tag(card->reader->atr_info.hist_bytes + 1,
54335434
card->reader->atr_info.hist_bytes_len - 1, 0x50, &datalen))) {
5434-
if (datalen == 7 && !(memcmp(data, "YubiKey", 7))) {
5435+
if (datalen >= 8 && !(memcmp(data, "Nitrokey", 8))) { /* first 8 are Nitrokey */
5436+
type = SC_CARD_TYPE_PIV_II_NITROKEY;
5437+
} else if (datalen == 7 && !(memcmp(data, "YubiKey", 7))) {
54355438
type = SC_CARD_TYPE_PIV_II_YUBIKEY4; /* reader says 4 really 5 */
54365439
}
54375440
/* Yubikey 5 NFC ATR using ACR122 contactless reader does not match
@@ -5560,6 +5563,10 @@ static int piv_match_card_continued(sc_card_t *card)
55605563
priv->yubico_version = (yubico_version_buf[0]<<16) | (yubico_version_buf[1] <<8) | yubico_version_buf[2];
55615564
sc_log(card->ctx, "Yubico card->type=%d, r=0x%08x version=0x%08x", card->type, r, priv->yubico_version);
55625565
}
5566+
break;
5567+
case SC_CARD_TYPE_PIV_II_NITROKEY:
5568+
/* TODO get Nitrokey version number */
5569+
break;
55635570
}
55645571
sc_debug(card->ctx,SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d\n", card->type, r2, priv->card_issues, r);
55655572

@@ -5612,6 +5619,7 @@ static int piv_match_card_continued(sc_card_t *card)
56125619
priv->card_issues |= CI_DISCOVERY_USELESS;
56135620
priv->obj_cache[PIV_OBJ_DISCOVERY].flags |= PIV_OBJ_CACHE_NOT_PRESENT;
56145621
break;
5622+
/* TODO SC_CARD_TYPE_PIV_II_NITROKEY: nothing to do for now */
56155623
}
56165624
sc_debug(card->ctx,SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d\n", card->type, r2, priv->card_issues, r);
56175625

@@ -5620,6 +5628,7 @@ static int piv_match_card_continued(sc_card_t *card)
56205628
switch(card->type) {
56215629
case SC_CARD_TYPE_PIV_II_BASE:
56225630
case SC_CARD_TYPE_PIV_II_800_73_4:
5631+
case SC_CARD_TYPE_PIV_II_NITROKEY:
56235632
r2 = piv_find_aid(card);
56245633
}
56255634
}
@@ -5713,6 +5722,11 @@ static int piv_match_card_continued(sc_card_t *card)
57135722
/* TODO may need more research */
57145723
break;
57155724

5725+
case SC_CARD_TYPE_PIV_II_NITROKEY:
5726+
priv->card_issues |= CI_PIV_AID_LOSE_STATE;
5727+
/* TODO may need to add others */
5728+
break;
5729+
57165730
default:
57175731
priv->card_issues |= CI_VERIFY_LC0_FAIL
57185732
| CI_OTHER_AID_LOSE_STATE;

src/libopensc/cards.h

+2
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ enum {
122122
SC_CARD_TYPE_PIV_II_PIVKEY,
123123
SC_CARD_TYPE_PIV_II_SWISSBIT,
124124
SC_CARD_TYPE_PIV_II_800_73_4,
125+
SC_CARD_TYPE_PIV_II_NITROKEY,
126+
125127

126128
/* MuscleApplet */
127129
SC_CARD_TYPE_MUSCLE_BASE = 15000,

0 commit comments

Comments
 (0)