add LoadKey command

This commit is contained in:
Andrea Franz 2020-01-07 12:56:50 +01:00
parent 6dd40a46ba
commit f38e9a1995
No known key found for this signature in database
GPG Key ID: 4F0D2F2D9DE7F29D
2 changed files with 27 additions and 6 deletions

View File

@ -310,6 +310,16 @@ func (cs *CommandSet) SignPinless(data []byte) (*types.Signature, error) {
return types.ParseSignature(data, resp.Data)
}
func (cs *CommandSet) LoadSeed(seed []byte) ([]byte, error) {
cmd := NewCommandLoadSeed(seed)
resp, err := cs.sc.Send(cmd)
if err = cs.checkOK(resp, err); err != nil {
return nil, err
}
return resp.Data, nil
}
func (cs *CommandSet) mutualAuthenticate() error {
data := make([]byte, 32)
if _, err := rand.Read(data); err != nil {

View File

@ -25,6 +25,7 @@ const (
InsExportKey = 0xC2
InsSign = 0xC0
InsSetPinlessPath = 0xC1
InsLoadKey = 0xD0
P1PairingFirstStep = 0x00
P1PairingFinalStep = 0x01
@ -40,12 +41,12 @@ const (
P1SignDerive = 0x01
P1SignDeriveAndMakeCurrent = 0x02
P1SignPinless = 0x03
P1ExportKeyCurrent = uint8(0x00)
P1ExportKeyDerive = uint8(0x01)
P1ExportKeyDeriveAndMakeCurrent = uint8(0x02)
P2ExportKeyPrivateAndPublic = uint8(0x00)
P2ExportKeyPublicOnly = uint8(0x01)
P1ExportKeyCurrent = 0x00
P1ExportKeyDerive = 0x01
P1ExportKeyDeriveAndMakeCurrent = 0x02
P2ExportKeyPrivateAndPublic = 0x00
P2ExportKeyPublicOnly = 0x01
P1LoadKeySeed = 0x03
SwNoAvailablePairingSlots = 0x6A84
)
@ -180,6 +181,16 @@ func NewCommandChangePairingSecret(secret []byte) *apdu.Command {
)
}
func NewCommandLoadSeed(seed []byte) *apdu.Command {
return apdu.NewCommand(
globalplatform.ClaGp,
InsLoadKey,
P1LoadKeySeed,
0,
seed,
)
}
func NewCommandDeriveKey(pathStr string) (*apdu.Command, error) {
startingPoint, path, err := derivationpath.Decode(pathStr)
if err != nil {