adding get device info command
This commit is contained in:
parent
43f6e607f2
commit
3f0395de8f
|
@ -9,6 +9,15 @@ import (
|
||||||
"github.com/certusone/yubihsm-go/authkey"
|
"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) {
|
func CreateCreateSessionCommand(keySetID uint16, hostChallenge []byte) (*CommandMessage, error) {
|
||||||
command := &CommandMessage{
|
command := &CommandMessage{
|
||||||
CommandType: CommandTypeCreateSession,
|
CommandType: CommandTypeCreateSession,
|
||||||
|
|
|
@ -15,6 +15,13 @@ type (
|
||||||
Code ErrorCode
|
Code ErrorCode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DeviceInfoResponse struct {
|
||||||
|
MajorVersion uint8
|
||||||
|
MinorVersion uint8
|
||||||
|
BuildVersion uint8
|
||||||
|
SerialNumber uint32
|
||||||
|
}
|
||||||
|
|
||||||
CreateSessionResponse struct {
|
CreateSessionResponse struct {
|
||||||
SessionID uint8
|
SessionID uint8
|
||||||
CardChallenge []byte
|
CardChallenge []byte
|
||||||
|
@ -141,6 +148,8 @@ func ParseResponse(data []byte) (Response, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
switch transactionType {
|
switch transactionType {
|
||||||
|
case CommandTypeDeviceInfo:
|
||||||
|
return parseDeviceInfoResponse(payload)
|
||||||
case CommandTypeCreateSession:
|
case CommandTypeCreateSession:
|
||||||
return parseCreateSessionResponse(payload)
|
return parseCreateSessionResponse(payload)
|
||||||
case CommandTypeAuthenticateSession:
|
case CommandTypeAuthenticateSession:
|
||||||
|
@ -214,6 +223,20 @@ func parseSessionMessage(payload []byte) (Response, error) {
|
||||||
}, nil
|
}, 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) {
|
func parseCreateSessionResponse(payload []byte) (Response, error) {
|
||||||
if len(payload) != 17 {
|
if len(payload) != 17 {
|
||||||
return nil, errors.New("invalid response payload length")
|
return nil, errors.New("invalid response payload length")
|
||||||
|
|
Loading…
Reference in New Issue