add verify in and generate key methods

This commit is contained in:
Andrea Franz 2019-03-14 16:31:30 +01:00
parent fa2a5514a2
commit 19e1a9ade1
No known key found for this signature in database
GPG Key ID: 4F0D2F2D9DE7F29D
2 changed files with 39 additions and 0 deletions

View File

@ -161,6 +161,23 @@ func (cs *CommandSet) GetStatus() (*types.ApplicationStatus, error) {
return types.ParseApplicationStatus(resp.Data)
}
func (cs *CommandSet) VerifyPIN(pin string) error {
cmd := NewCommandVerifyPIN(pin)
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)
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

@ -11,6 +11,8 @@ const (
InsMutuallyAuthenticate = uint8(0x11)
InsPair = uint8(0x12)
InsGetStatus = uint8(0xF2)
InsGenerateKey = uint8(0xD4)
InsVerifyPIN = uint8(0x20)
P1PairingFirstStep = uint8(0x00)
P1PairingFinalStep = uint8(0x01)
@ -85,3 +87,23 @@ func NewCommandGetStatusApplication() *apdu.Command {
func NewCommandGetStatusKeyPath() *apdu.Command {
return NewCommandGetStatus(P1GetStatusKeyPath)
}
func NewCommandGenerateKey() *apdu.Command {
return apdu.NewCommand(
globalplatform.ClaGp,
InsGenerateKey,
uint8(0),
uint8(0),
[]byte{},
)
}
func NewCommandVerifyPIN(pin string) *apdu.Command {
return apdu.NewCommand(
globalplatform.ClaGp,
InsVerifyPIN,
uint8(0),
uint8(0),
[]byte(pin),
)
}