Merge pull request #19 from rmeringe/add_get_device_info_command
Adding get device info command
This commit is contained in:
commit
61ec9248b3
|
@ -6,6 +6,7 @@ messages is depleted.
|
|||
|
||||
Currently the following commands are implemented:
|
||||
|
||||
* DeviceInfo
|
||||
* Reset
|
||||
* GenerateAsymmetricKey
|
||||
* SignDataEddsa
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -15,6 +15,16 @@ type (
|
|||
Code ErrorCode
|
||||
}
|
||||
|
||||
DeviceInfoResponse struct {
|
||||
MajorVersion uint8
|
||||
MinorVersion uint8
|
||||
BuildVersion uint8
|
||||
SerialNumber uint32
|
||||
LogTotal uint8
|
||||
LogUsed uint8
|
||||
SupportedAlgorithms []Algorithm
|
||||
}
|
||||
|
||||
CreateSessionResponse struct {
|
||||
SessionID uint8
|
||||
CardChallenge []byte
|
||||
|
@ -141,6 +151,8 @@ func ParseResponse(data []byte) (Response, error) {
|
|||
}
|
||||
|
||||
switch transactionType {
|
||||
case CommandTypeDeviceInfo:
|
||||
return parseDeviceInfoResponse(payload)
|
||||
case CommandTypeCreateSession:
|
||||
return parseCreateSessionResponse(payload)
|
||||
case CommandTypeAuthenticateSession:
|
||||
|
@ -214,6 +226,28 @@ 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
|
||||
}
|
||||
|
||||
var supportedAlgorithms []Algorithm
|
||||
for _, alg := range payload[9:] {
|
||||
supportedAlgorithms = append(supportedAlgorithms, Algorithm(alg))
|
||||
}
|
||||
|
||||
return &DeviceInfoResponse{
|
||||
MajorVersion: payload[0],
|
||||
MinorVersion: payload[1],
|
||||
BuildVersion: payload[2],
|
||||
SerialNumber: serialNumber,
|
||||
LogTotal: payload[7],
|
||||
LogUsed: payload[8],
|
||||
SupportedAlgorithms: supportedAlgorithms,
|
||||
}, nil
|
||||
}
|
||||
func parseCreateSessionResponse(payload []byte) (Response, error) {
|
||||
if len(payload) != 17 {
|
||||
return nil, errors.New("invalid response payload length")
|
||||
|
|
Loading…
Reference in New Issue