Skip to content

Commit

Permalink
fix: Data object passed to PUT DATA command is an unstructured byte s…
Browse files Browse the repository at this point in the history
…equence not a constructed object

Signed-off-by: Steffen Vogel <[email protected]>
  • Loading branch information
stv0g committed Dec 9, 2024
1 parent 4021198 commit b4a3ca1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
17 changes: 11 additions & 6 deletions cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,19 @@ func (c *Card) SetCertificate(key ManagementKey, slot Slot, cert *x509.Certifica
return fmt.Errorf("failed to authenticate with management key: %w", err)
}

// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-73-4.pdf#page=40
certData, err := tlv.EncodeBER(
tlv.New(tagCertificate, cert.Raw),
tlv.New(tagCertInfo, 0x00), // "for a certificate encoded in uncompressed form CertInfo shall be 0x00"
tlv.New(tagErrorDetectionCode),
)
if err != nil {
return err
}

if _, err := sendTLV(c.tx, insPutData, 0x3f, 0xff,
slot.Object.TagValue(),
tlv.New(0x53,
// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-73-4.pdf#page=40
tlv.New(tagCertificate, cert.Raw),
tlv.New(tagCertInfo, 0x00), // "for a certificate encoded in uncompressed form CertInfo shall be 0x00"
tlv.New(tagErrorDetectionCode),
),
tlv.New(0x53, certData),
); err != nil {
return fmt.Errorf("failed to execute command: %w", err)
}
Expand Down
7 changes: 6 additions & 1 deletion pin_protected.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,14 @@ func (c *Card) SetPinProtectedData(key ManagementKey, ppd *PinProtectedData) err
return fmt.Errorf("failed to authenticate with key: %w", err)
}

ppdData, err := tlv.EncodeBER(ppd.TagValues...)
if err != nil {
return err
}

if _, err := sendTLV(c.tx, insPutData, 0x3f, 0xff,
doPrinted.TagValue(),
tlv.New(0x53, ppd.TagValues),
tlv.New(0x53, ppdData),
); err != nil {
return fmt.Errorf("failed to execute command: %w", err)
}
Expand Down

0 comments on commit b4a3ca1

Please sign in to comment.