3
3
* card-default.c: Support for cards with no driver
4
4
*
5
5
* Copyright (C) 2001, 2002 Juha Yrjölä <juha.yrjola@iki.fi>
6
- * Copyright (C) 2005-2024 Douglas E. Engert <deengert@gmail.com>
6
+ * Copyright (C) 2005-2025 Douglas E. Engert <deengert@gmail.com>
7
7
* Copyright (C) 2006, Identity Alliance, Thomas Harning <thomas.harning@identityalliance.com>
8
8
* Copyright (C) 2007, EMC, Russell Larner <rlarner@rsa.com>
9
9
*
@@ -2902,8 +2902,10 @@ static int piv_find_aid(sc_card_t * card)
2902
2902
if (tag != NULL ) {
2903
2903
priv -> init_flags |= PIV_INIT_AID_PARSED ;
2904
2904
/* look for 800-73-4 0xAC for Cipher Suite Algorithm Identifier Table 14 */
2905
- /* There may be more than one 0xAC tag, loop to find all */
2906
- /* TODO do we need to look for "Nitrokey PIVP" in tag 0x50 length 12 */
2905
+ /* 800-73-4 only expects 1 0xAC tag len 6 with a 80 01 xx 06 01 00
2906
+ * where xx is the SM csID either 27 or 2E.
2907
+ * Some vendors may include entries for supported Algorithms even when
2908
+ * not required */
2907
2909
nextac = tag ;
2908
2910
while ((actag = sc_asn1_find_tag (card -> ctx , nextac , taglen - (nextac - tag ),
2909
2911
0xAC , & actaglen )) != NULL ) {
@@ -2912,7 +2914,7 @@ static int piv_find_aid(sc_card_t * card)
2912
2914
csai = sc_asn1_find_tag (card -> ctx , actag , actaglen , 0x80 , & csailen );
2913
2915
if (csai != NULL ) {
2914
2916
if (csailen == 1 ) {
2915
- sc_log (card -> ctx ,"found csID= 0x%2.2x" ,* csai );
2917
+ sc_log (card -> ctx ,"found 0xAC 0x80 entry: 0x%2.2x" ,* csai );
2916
2918
#ifdef ENABLE_PIV_SM
2917
2919
for (i = 0 ; i < PIV_CSS_SIZE ; i ++ ) {
2918
2920
if (* csai != css [i ].id )
@@ -5345,6 +5347,7 @@ static int piv_match_card(sc_card_t *card)
5345
5347
case SC_CARD_TYPE_PIV_II_PIVKEY :
5346
5348
case SC_CARD_TYPE_PIV_II_SWISSBIT :
5347
5349
case SC_CARD_TYPE_PIV_II_800_73_4 :
5350
+ case SC_CARD_TYPE_PIV_II_NITROKEY :
5348
5351
break ;
5349
5352
default :
5350
5353
return 0 ; /* can not handle the card */
@@ -5547,10 +5550,11 @@ static int piv_match_card_continued(sc_card_t *card)
5547
5550
goto err ;
5548
5551
}
5549
5552
5550
- /* Assumes all Yubikey cards are identified via ATR Historic bytes */
5553
+ /* Assumes all Yubikey/Nitrokey cards are identified via ATR Historic bytes */
5551
5554
switch (card -> type ) {
5552
5555
case SC_CARD_TYPE_PIV_II_NEO :
5553
5556
case SC_CARD_TYPE_PIV_II_YUBIKEY4 :
5557
+ case SC_CARD_TYPE_PIV_II_NITROKEY : /* Nitrokey PIV iuses same APDU as Yubikey */
5554
5558
sc_format_apdu (card , & apdu , SC_APDU_CASE_2_SHORT , 0xFD , 0x00 , 0x00 );
5555
5559
apdu .lc = 0 ;
5556
5560
apdu .data = NULL ;
@@ -5561,12 +5565,9 @@ static int piv_match_card_continued(sc_card_t *card)
5561
5565
r2 = sc_transmit_apdu (card , & apdu ); /* on error yubico_version == 0 */
5562
5566
if (apdu .resplen == 3 ) {
5563
5567
priv -> yubico_version = (yubico_version_buf [0 ]<<16 ) | (yubico_version_buf [1 ] <<8 ) | yubico_version_buf [2 ];
5564
- sc_log (card -> ctx , "Yubico card->type=%d, r=0x%08x version=0x%08x" , card -> type , r , priv -> yubico_version );
5568
+ sc_log (card -> ctx , "Yubico/Nitrokey card->type=%d, r=0x%08x version=0x%08x" , card -> type , r , priv -> yubico_version );
5565
5569
}
5566
5570
break ;
5567
- case SC_CARD_TYPE_PIV_II_NITROKEY :
5568
- /* TODO get Nitrokey version number */
5569
- break ;
5570
5571
}
5571
5572
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 );
5572
5573
@@ -5619,7 +5620,6 @@ static int piv_match_card_continued(sc_card_t *card)
5619
5620
priv -> card_issues |= CI_DISCOVERY_USELESS ;
5620
5621
priv -> obj_cache [PIV_OBJ_DISCOVERY ].flags |= PIV_OBJ_CACHE_NOT_PRESENT ;
5621
5622
break ;
5622
- /* TODO SC_CARD_TYPE_PIV_II_NITROKEY: nothing to do for now */
5623
5623
}
5624
5624
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 );
5625
5625
@@ -5633,19 +5633,23 @@ static int piv_match_card_continued(sc_card_t *card)
5633
5633
}
5634
5634
}
5635
5635
5636
- /* If SM is supported, set SC_CARD_TYPE_PIV_II_800_73_4 */
5637
- if (priv -> init_flags & PIV_INIT_AID_AC ) {
5638
- card -> type = SC_CARD_TYPE_PIV_II_800_73_4 ;
5639
- }
5640
-
5641
- 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 );
5636
+ /* If unknown card has 800-73-4 features, it must be based on 800-73-4 or above */
5637
+ /* SC_CARD_TYPE_PIV_II_NITROKEY is already known to be based on 800-73-4 */
5638
+ switch (card -> type ) {
5639
+ case SC_CARD_TYPE_PIV_II_BASE :
5640
+ if (priv -> init_flags & PIV_INIT_AID_AC ) {
5641
+ card -> type = SC_CARD_TYPE_PIV_II_800_73_4 ;
5642
+ }
5642
5643
5643
5644
#ifdef ENABLE_PIV_SM
5644
- /* Discovery object has pin policy. 800-74-4 bits, its at least SC_CARD_TYPE_PIV_II_800_73_4 */
5645
- if ((priv -> pin_policy & (PIV_PP_OCC | PIV_PP_VCI_IMPL | PIV_PP_VCI_WITHOUT_PC )) != 0 ) {
5646
- card -> type = SC_CARD_TYPE_PIV_II_800_73_4 ;
5647
- }
5645
+ /* Discovery object has pin policy. 800-74-4 bits, its at least SC_CARD_TYPE_PIV_II_800_73_4 */
5646
+ if ((priv -> pin_policy & (PIV_PP_OCC | PIV_PP_VCI_IMPL | PIV_PP_VCI_WITHOUT_PC )) != 0 ) {
5647
+ card -> type = SC_CARD_TYPE_PIV_II_800_73_4 ;
5648
+ }
5648
5649
#endif
5650
+ break ;
5651
+ }
5652
+
5649
5653
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 );
5650
5654
5651
5655
/*
@@ -5685,6 +5689,10 @@ static int piv_match_card_continued(sc_card_t *card)
5685
5689
priv -> card_issues |= CI_RSA_4096 | CI_25519 ;
5686
5690
break ;
5687
5691
5692
+ case SC_CARD_TYPE_PIV_II_NITROKEY :
5693
+ priv -> card_issues |= CI_OTHER_AID_LOSE_STATE ;
5694
+ break ;
5695
+
5688
5696
case SC_CARD_TYPE_PIV_II_GI_DE :
5689
5697
case SC_CARD_TYPE_PIV_II_OBERTHUR :
5690
5698
case SC_CARD_TYPE_PIV_II_GEMALTO :
@@ -5722,11 +5730,6 @@ static int piv_match_card_continued(sc_card_t *card)
5722
5730
/* TODO may need more research */
5723
5731
break ;
5724
5732
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
-
5730
5733
default :
5731
5734
priv -> card_issues |= CI_VERIFY_LC0_FAIL
5732
5735
| CI_OTHER_AID_LOSE_STATE ;
0 commit comments