Documentation
¶
Index ¶
- Variables
- func IsKeyringKey(key string) bool
- type AutoLockOptions
- type AutoUnlockOptions
- type BeginStorageTransactionFunc
- type InitializeOptions
- type InitializeResult
- type Keyring
- func (kr *Keyring) AddEncryptionKey(ctx context.Context, engine string) error
- func (kr *Keyring) CancelUnlock()
- func (kr *Keyring) Decrypt(ciphertext []byte) ([]byte, error)
- func (kr *Keyring) Destroy()
- func (kr *Keyring) Encrypt(plaintext []byte) ([]byte, error)
- func (kr *Keyring) Initialize(ctx context.Context, opts InitializeOptions) (InitializeResult, error)
- func (kr *Keyring) IsLocked() bool
- func (kr *Keyring) Lock()
- func (kr *Keyring) RotateRootKey(ctx context.Context, opts RotateRootKeyOptions) (RotateRootKeyResult, error)
- func (kr *Keyring) Status(ctx context.Context) error
- func (kr *Keyring) Unlock(ctx context.Context, opts UnlockOptions) error
- type ManualLockOptions
- type ManualLockResult
- type ManualUnlockOptions
- type Options
- type RotateRootKeyOptions
- type RotateRootKeyResult
- type StorageTx
- type UnlockOptions
Constants ¶
This section is empty.
Variables ¶
var ( // ErrAlreadyInitialized should be considered as non-fatal. It is returned in the call to `Initialize` // when the keyring is already initialized. ErrAlreadyInitialized = errors.New("already initialized") // ErrMoreKeysRequired is returned by `Unlock` when the keyring is locked and the user needs to provide // more keys to unlock it. ErrMoreKeysRequired = errors.New("more keys required") // ErrAlreadyUnlocked is returned by `Unlock` when the keyring is already unlocked. ErrAlreadyUnlocked = errors.New("already unlocked") ErrNotInitialized = errors.New("not initialized") ErrLocked = errors.New("locked") ErrEncryptionKeyNotFound = errors.New("encryption key not found") ErrInvalidStoredData = errors.New("invalid stored data") ErrNotFound = errors.New("not found") ErrUnlockFailed = errors.New("unlock failed") ErrKeyringDataHasChanged = errors.New("keyring data has changed") )
Functions ¶
func IsKeyringKey ¶ added in v0.2.0
IsKeyringKey returns true if the given key is a keyring key.
Types ¶
type AutoLockOptions ¶ added in v0.2.0
type AutoLockOptions struct {
// Encrypt function to call when the keyring manager needs to encrypt the root key using the
// external secure encryption engine like AWS CloudHSM or Azure Dedicated HSM.
Encrypt func(ctx context.Context, plaintext []byte) ([]byte, error)
}
AutoLockOptions defines the keyring auto-lock feature options.
type AutoUnlockOptions ¶ added in v0.2.0
type AutoUnlockOptions struct {
// Function to call when the keyring manager needs to decrypt the root key.
Decrypt func(ctx context.Context, ciphertext []byte) ([]byte, error)
}
AutoUnlockOptions establishes the options to use when the auto-locking feature is used.
type BeginStorageTransactionFunc ¶
BeginStorageTransactionFunc defines a function that creates a transaction in the underlying storage.
type InitializeOptions ¶ added in v0.2.0
type InitializeOptions struct {
// Encryption engine to use for the initial encryption key.
Engine string
// Encryption engine to use for the root key. If not defined, the same engine for encryption keys will be used.
RootKeyEngine string
ManualLock *ManualLockOptions
AutoLock *AutoLockOptions
}
InitializeOptions is a set of options to use to initialize the keyring.
type InitializeResult ¶ added in v0.2.0
type InitializeResult struct {
ManualLock ManualLockResult
}
InitializeResult is returned as a result of the keyring initialization process.
type Keyring ¶
type Keyring struct {
// contains filtered or unexported fields
}
Keyring implements a secure store and management of encryption keys.
func (*Keyring) AddEncryptionKey ¶
AddEncryptionKey adds a new encryption key to the keyring. Later encryption will use this new key.
func (*Keyring) CancelUnlock ¶
func (kr *Keyring) CancelUnlock()
CancelUnlock cancels an active keyring unlock process.
func (*Keyring) Decrypt ¶
Decrypt decrypts the given cipher text with the available encryption keys.
func (*Keyring) Destroy ¶
func (kr *Keyring) Destroy()
Destroy destroys (not physically a keyring). All memory is zeroed.
func (*Keyring) Encrypt ¶
Encrypt encrypts the given plain text with the current active encryption key.
func (*Keyring) Initialize ¶
func (kr *Keyring) Initialize(ctx context.Context, opts InitializeOptions) (InitializeResult, error)
Initialize initializes an uninitialized keyring. NOTE: If initialization succeeds, the keyring remains unlocked.
func (*Keyring) Lock ¶
func (kr *Keyring) Lock()
Lock locks access until unlocked again. NOTE: If you lock an auto-unlock keyring, you will need to create a new keyring object based on the same
storage and auto-unlock interface to unlock it.
func (*Keyring) RotateRootKey ¶
func (kr *Keyring) RotateRootKey(ctx context.Context, opts RotateRootKeyOptions) (RotateRootKeyResult, error)
RotateRootKey changes the root key. It also allows to change from manual to auto-locking and vice versa.
func (*Keyring) Status ¶ added in v0.2.0
Status returns the current status of the keyring. It can be used to check if the keyring is initialized, unlocked or if another instance using the same database changed any keyring configuration.
ErrLocked is returned if the keyring is locked.
ErrKeyringDataHasChanged is returned if an encryption key was added or the root key or a parameter was changed.
type ManualLockOptions ¶ added in v0.2.0
type ManualLockOptions struct {
// Threshold defines the minimum number of keys required to unlock the keyring.
Threshold int
Shares int
}
ManualLockOptions defines the keyring manual-lock feature options.
type ManualLockResult ¶ added in v0.2.0
type ManualLockResult struct {
// SplitRootKey will hold the split shamir root key.
SplitRootKey [][]byte
}
ManualLockResult contains the result of a manual-lock keyring.
type ManualUnlockOptions ¶ added in v0.2.0
type ManualUnlockOptions struct {
// One of the split keys to unlock the keyring.
Key []byte
}
ManualUnlockOptions establishes the options to use when manual-locking is used.
type Options ¶
type Options struct {
// A transactional-enabled storage that holds keyring data.
BeginStorageTX BeginStorageTransactionFunc
// An optional random number generator reader. If nil, the keyring will use crypto/rand.Reader.
RandomGeneratorReader io.Reader
}
Options configure the keyring base options.
type RotateRootKeyOptions ¶ added in v0.2.0
type RotateRootKeyOptions struct {
// Encryption engine to use for the root key.
Engine string
ManualLock *ManualLockOptions
AutoLock *AutoLockOptions
}
RotateRootKeyOptions is a set of options to use to rotate the root key of the keyring.
type RotateRootKeyResult ¶ added in v0.2.0
type RotateRootKeyResult struct {
ManualLock ManualLockResult
}
RotateRootKeyResult is returned as a result of the root key rotation process.
type StorageTx ¶
type StorageTx interface {
// Get retrieves the value of the given key. Returns nil and no error if the key is not found.
// Also, the implementation must return a copy of the value if the underlying implementation
// overwrites its contents.
Get(ctx context.Context, key string) ([]byte, error)
// Put saves the given value under the provided key. The implementation MUST make a copy of the
// value parameter if it needs to keep it until the commit call.
Put(ctx context.Context, key string, value []byte) error
// Delete removes the given key from the database. Don't return an error if the key is not found.
Delete(ctx context.Context, key string) error
// Commit saves all changes into the storage.
Commit(ctx context.Context) error
// Rollback discards pending changes.
Rollback(ctx context.Context)
}
StorageTx is an interface that represents a storage transaction.
type UnlockOptions ¶ added in v0.2.0
type UnlockOptions struct {
ManualUnlock *ManualUnlockOptions
AutoUnlock *AutoUnlockOptions
}
UnlockOptions is a set of options used to unlock the keyring.