From 1f5f2a9eeb2e48fe90c5dc1eb694f2825587deb9 Mon Sep 17 00:00:00 2001 From: Andrea Franz Date: Wed, 27 Mar 2019 15:16:02 +0100 Subject: [PATCH] add change PUK and Pairing Secret commands --- command_set.go | 15 +++++++++++++++ commands.go | 20 ++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/command_set.go b/command_set.go index cf322f4..70ab302 100644 --- a/command_set.go +++ b/command_set.go @@ -195,6 +195,21 @@ func (cs *CommandSet) ChangePIN(pin string) error { return cs.checkOK(resp, err) } +func (cs *CommandSet) ChangePUK(puk string) error { + cmd := NewCommandChangePUK(puk) + resp, err := cs.sc.Send(cmd) + + return cs.checkOK(resp, err) +} + +func (cs *CommandSet) ChangePairingSecret(password string) error { + secret := generatePairingToken(password) + cmd := NewCommandChangePairingSecret(secret) + resp, err := cs.sc.Send(cmd) + + return cs.checkOK(resp, err) +} + func (cs *CommandSet) GenerateKey() ([]byte, error) { cmd := NewCommandGenerateKey() resp, err := cs.sc.Send(cmd) diff --git a/commands.go b/commands.go index b47435e..7118000 100644 --- a/commands.go +++ b/commands.go @@ -149,6 +149,26 @@ func NewCommandChangePIN(pin string) *apdu.Command { ) } +func NewCommandChangePUK(puk string) *apdu.Command { + return apdu.NewCommand( + globalplatform.ClaGp, + InsChangePIN, + P1ChangePinPUK, + uint8(0), + []byte(puk), + ) +} + +func NewCommandChangePairingSecret(secret []byte) *apdu.Command { + return apdu.NewCommand( + globalplatform.ClaGp, + InsChangePIN, + P1ChangePinPairingSecret, + uint8(0), + secret, + ) +} + func NewCommandDeriveKey(pathStr string) (*apdu.Command, error) { startingPoint, path, err := derivationpath.Decode(pathStr) if err != nil {