[go: up one dir, main page]

Skip to content

A Go client for the yubihsm2 binary protocol and connector service

License

Notifications You must be signed in to change notification settings

Indoff/yubihsm-go

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

82 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

yubihsm-go

Yubihsm-go is a minimal implementation of the securechannel and connector protocol of the YubiHSM2.

It also implements a simple SessionManager which keeps connections alive and swaps them if the maximum number of messages is depleted.

Currently the following commands are implemented:

  • DeviceInfo
  • Reset
  • GenerateAsymmetricKey
  • SignDataEddsa
  • SignDataPkcs1
  • PutAsymmetricKey
  • GetPubKey
  • DeriveEcdh
  • Echo
  • ChangeAuthenticationKey
  • PutAuthenticationKey
  • GetOpaque
  • PutOpaque
  • SignAttestationCertificate
  • Authentication & Session related commands
  • GetPseudoRandom
  • GetLogs
  • SetLogIndex
  • EncryptAesCbc
  • DecryptAesCbc

Implementing new commands is really easy. Please consult commands/constructors.go and commands/response.go for reference.

Please submit a PR if you have implemented new commands or extended existing constructors.

Example of usage

c := connector.NewHTTPConnector("localhost:1234")
sm, err := yubihsm.NewSessionManager(c, 1, "password", 2)
if err != nil {
	panic(err)
}

echoMessage := []byte("test")

command, err := commands.CreateEchoCommand(echoMessage)
if err != nil {
	panic(err)
}

resp, err := sm.SendEncryptedCommand(command)
if err != nil {
	panic(err)
}

parsedResp, matched := resp.(*commands.EchoResponse)
if !matched {
	panic("invalid response type")
}

if bytes.Equal(parsedResp.Data, echoMessage) {
	println("successfully echoed data")
} else {
	panic(errors.New("echoed message did not equal requested message"))
}

About

A Go client for the yubihsm2 binary protocol and connector service

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%