Skip to content

Commit 76725db

Browse files
author
JC Martin
committed
Initial CHUID reading
1 parent be4d86e commit 76725db

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

piv/piv.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,3 +846,38 @@ func ykSetProtectedMetadata(tx *scTx, key [24]byte, m *Metadata) error {
846846
}
847847
return nil
848848
}
849+
850+
// Card Holder Unique Identifier
851+
type CardId []byte
852+
853+
func (yk *YubiKey) CardId() (CardId, error) {
854+
return ykGetCardId(yk.tx)
855+
856+
}
857+
func ykGetCardId(tx *scTx) (CardId, error) {
858+
// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-73-4.pdf#page=17
859+
// OID for CardId is 5FC102
860+
861+
cmd := apdu{
862+
instruction: insGetData,
863+
param1: 0x3f,
864+
param2: 0xff,
865+
data: []byte{
866+
0x5c, // Tag list
867+
0x03,
868+
0x5f,
869+
0xc1,
870+
0x02,
871+
},
872+
}
873+
resp, err := tx.Transmit(cmd)
874+
if err != nil {
875+
return nil, fmt.Errorf("command failed: %w", err)
876+
}
877+
// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-73-4.pdf#page=85
878+
obj, _, err := unmarshalASN1(resp, 1, 0x13) // tag 0x53
879+
if err != nil {
880+
return nil, fmt.Errorf("unmarshaling response: %v", err)
881+
}
882+
return obj, nil
883+
}

0 commit comments

Comments
 (0)