adding get device info command

This commit is contained in:
Rohan Meringenti 2022-06-15 17:54:59 -06:00
parent 43f6e607f2
commit 3f0395de8f
No known key found for this signature in database
GPG Key ID: 403927C99FC911A4
2 changed files with 32 additions and 0 deletions

View File

@ -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,

View File

@ -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")