hsm

package
v0.0.0-...-d1cd67c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 9, 2018 License: MIT Imports: 8 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Full path to the PKCS#11 object on the filesystem. The exact value
	// of this depends on the host, but should usually end in a .so
	Module string

	// Label of the x.509 Certificate stored on the PKCS#11 token,
	// for PIV devices, one option for this might be
	// "Certificate for PIV Authentication"
	CertificateLabel string

	// Private key material backing the x.509 Certificate indicated by
	// CertificateLabel, one option for this might be "PIV AUTH key"
	PrivateKeyLabel string

	// Optional PIN for the PKCS#11 token. If this is nil, no PIN will be
	// sent to the device.
	PIN *string

	TokenLabel string
}

HSM Configuration object, to define which PKCS#11 .so module to use, Certificate and Private Key strings, a PIN (if needed), and the label of the token.

func (Config) GetCertificateTemplate

func (c Config) GetCertificateTemplate() []*pkcs11.Attribute

Create a pkcs11.Attribute array containing constraints that should uniquely identify the PKCS#11 Certificate we're interested in

func (Config) GetPrivateKeyTemplate

func (c Config) GetPrivateKeyTemplate() []*pkcs11.Attribute

Create a pkcs11.Attribute array containing constraints that should uniquely identify the PKCS#11 private key we're interested in

func (Config) SelectSlot

func (c Config) SelectSlot(context *pkcs11.Ctx, slots []uint) (uint, error)

Given a pkcs11.Ctx, and a list of slots, figure out which slot is the slot we're interested in, returning an error if there's nothing we should be using.

type Store

type Store struct {
	// contains filtered or unexported fields
}

internal hsm.Store encaupsulating state. This implements the store.Store interface, as well as crypto.Signer, and crypto.Decryptor.

func New

func New(config Config) (*Store, error)

Create a new hsm.Store defined by the hsm.Config. If no slot can be found, or the underlying infrastructure throws a problem at us, we will return an error.

func (Store) Certificate

func (s Store) Certificate() (*x509.Certificate, error)

Query the underlying HSM Store for the x509 Certificate we're interested in, and return a Go x509.Certificate.

func (Store) Close

func (s Store) Close() error

Method to log out of the Token, and close any open sessions we might have open. This method ought to be defer'd after creating a new hsm.Store.

func (Store) Decrypt

func (s Store) Decrypt(rand io.Reader, msg []byte, opts crypto.DecrypterOpts) ([]byte, error)

implement crypto.Decryptor. This will have the HSM Decrypt the encrypted data given, ignoring `rand`, and using on chip entropy sources. This will returned the data in cleartext.

func (Store) Public

func (s Store) Public() crypto.PublicKey

Return the cached PublicKey, because uh, the interface we're implementing doesn't want us to return errors, so, we'll force errors during startup.

This has a downside of not being able to read the PublicKey if it changes during our session (womp), but maybe that's not a problem? Who can know. If that's a problem you hit, maybe we should do something smarter here.

func (Store) Sign

func (s Store) Sign(rand io.Reader, digest []byte, opts crypto.SignerOpts) ([]byte, error)

implement crypto.Signer. This will have the HSM sign the hash given, ignoring the entropy source `rand` on chip, and return the signature blob.

func (Store) Update

func (s Store) Update(certificate x509.Certificate) error

XXX: UNIMPLEMENTED AND WHAT WAIT DID HOW DID I WHAT THE

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL