From 3f0395de8fd1c540e5e6602f22238633d74849ce Mon Sep 17 00:00:00 2001 From: Rohan Meringenti Date: Wed, 15 Jun 2022 17:54:59 -0600 Subject: [PATCH] adding get device info command --- commands/constructors.go | 9 +++++++++ commands/response.go | 23 +++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/commands/constructors.go b/commands/constructors.go index c303b06..9b95a4f 100644 --- a/commands/constructors.go +++ b/commands/constructors.go @@ -9,6 +9,15 @@ import ( "github.com/certusone/yubihsm-go/authkey" ) + +func CreateDeviceInfoCommand() (*CommandMessage, error) { + command := &CommandMessage{ + CommandType: CommandTypeDeviceInfo, + } + + return command, nil +} + func CreateCreateSessionCommand(keySetID uint16, hostChallenge []byte) (*CommandMessage, error) { command := &CommandMessage{ CommandType: CommandTypeCreateSession, diff --git a/commands/response.go b/commands/response.go index bd34727..2bdc1b1 100644 --- a/commands/response.go +++ b/commands/response.go @@ -15,6 +15,13 @@ type ( Code ErrorCode } + DeviceInfoResponse struct { + MajorVersion uint8 + MinorVersion uint8 + BuildVersion uint8 + SerialNumber uint32 + } + CreateSessionResponse struct { SessionID uint8 CardChallenge []byte @@ -141,6 +148,8 @@ func ParseResponse(data []byte) (Response, error) { } switch transactionType { + case CommandTypeDeviceInfo: + return parseDeviceInfoResponse(payload) case CommandTypeCreateSession: return parseCreateSessionResponse(payload) case CommandTypeAuthenticateSession: @@ -214,6 +223,20 @@ func parseSessionMessage(payload []byte) (Response, error) { }, nil } +func parseDeviceInfoResponse(payload []byte) (Response, error) { + var serialNumber uint32 + err := binary.Read(bytes.NewReader(payload[3:7]), binary.BigEndian, &serialNumber) + if err != nil { + return nil, err + } + + return &DeviceInfoResponse{ + MajorVersion: payload[0], + MinorVersion: payload[1], + BuildVersion: payload[2], + SerialNumber: serialNumber, + }, nil +} func parseCreateSessionResponse(payload []byte) (Response, error) { if len(payload) != 17 { return nil, errors.New("invalid response payload length")