exportKey always parse both pub and priv keys

This commit is contained in:
Andrea Franz 2021-10-07 15:10:14 +02:00
parent 557c4c58b3
commit b3978ba458
No known key found for this signature in database
GPG Key ID: 4F0D2F2D9DE7F29D
1 changed files with 21 additions and 9 deletions

View File

@ -18,15 +18,27 @@ func ParseExportKeyResponse(data []byte) ([]byte, []byte, error) {
return nil, nil, err
}
privKey, err := apdu.FindTag(tpl, apdu.Tag{0x81})
if err != nil {
return nil, nil, err
pubKey := tryFindTag(tpl, apdu.Tag{0x80})
privKey := tryFindTag(tpl, apdu.Tag{0x81})
if len(pubKey) == 0 && len(privKey) > 0 {
ecdsaKey, err := ethcrypto.HexToECDSA(fmt.Sprintf("%x", privKey))
if err != nil {
return nil, nil, err
}
pubKey = ethcrypto.FromECDSAPub(&ecdsaKey.PublicKey)
}
ecdsaKey, err := ethcrypto.HexToECDSA(fmt.Sprintf("%x", privKey))
if err != nil {
return nil, nil, err
}
return privKey, ethcrypto.FromECDSAPub(&ecdsaKey.PublicKey), nil
return privKey, pubKey, nil
}
func tryFindTag(tpl []byte, tags ...apdu.Tag) []byte {
data, err := apdu.FindTag(tpl, tags...)
if err != nil {
fmt.Printf("returning nil %+v\n", tags)
return nil
}
return data
}