2016-01-14 22:01:04 +00:00
|
|
|
package vault
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2018-01-19 06:44:44 +00:00
|
|
|
"context"
|
2016-01-14 22:01:04 +00:00
|
|
|
"encoding/hex"
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
|
2018-04-05 15:49:21 +00:00
|
|
|
"github.com/hashicorp/errwrap"
|
2016-01-14 22:01:04 +00:00
|
|
|
"github.com/hashicorp/go-uuid"
|
2017-02-16 20:15:02 +00:00
|
|
|
"github.com/hashicorp/vault/helper/consts"
|
2016-07-06 16:25:40 +00:00
|
|
|
"github.com/hashicorp/vault/helper/jsonutil"
|
2016-01-14 22:01:04 +00:00
|
|
|
"github.com/hashicorp/vault/helper/pgpkeys"
|
|
|
|
"github.com/hashicorp/vault/physical"
|
|
|
|
"github.com/hashicorp/vault/shamir"
|
|
|
|
)
|
|
|
|
|
2016-04-04 14:44:22 +00:00
|
|
|
const (
|
2018-03-20 18:54:10 +00:00
|
|
|
// coreUnsealKeysBackupPath is the path used to backup encrypted unseal
|
2016-04-04 14:44:22 +00:00
|
|
|
// keys if specified during a rekey operation. This is outside of the
|
|
|
|
// barrier.
|
|
|
|
coreBarrierUnsealKeysBackupPath = "core/unseal-keys-backup"
|
|
|
|
|
2018-03-20 18:54:10 +00:00
|
|
|
// coreRecoveryUnsealKeysBackupPath is the path used to backup encrypted
|
2016-04-04 14:44:22 +00:00
|
|
|
// recovery keys if specified during a rekey operation. This is outside of
|
|
|
|
// the barrier.
|
|
|
|
coreRecoveryUnsealKeysBackupPath = "core/recovery-keys-backup"
|
|
|
|
)
|
|
|
|
|
2016-01-14 22:01:04 +00:00
|
|
|
// RekeyResult is used to provide the key parts back after
|
|
|
|
// they are generated as part of the rekey.
|
|
|
|
type RekeyResult struct {
|
|
|
|
SecretShares [][]byte
|
|
|
|
PGPFingerprints []string
|
|
|
|
Backup bool
|
2016-04-04 14:44:22 +00:00
|
|
|
RecoveryKey bool
|
2016-01-14 22:01:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// RekeyBackup stores the backup copy of PGP-encrypted keys
|
|
|
|
type RekeyBackup struct {
|
|
|
|
Nonce string
|
|
|
|
Keys map[string][]string
|
|
|
|
}
|
|
|
|
|
2017-10-23 18:59:37 +00:00
|
|
|
// RekeyThreshold returns the secret threshold for the current seal
|
|
|
|
// config. This threshold can either be the barrier key threshold or
|
|
|
|
// the recovery key threshold, depending on whether rekey is being
|
|
|
|
// performed on the recovery key, or whether the seal supports
|
|
|
|
// recovery keys.
|
2018-01-19 06:44:44 +00:00
|
|
|
func (c *Core) RekeyThreshold(ctx context.Context, recovery bool) (int, error) {
|
2016-04-04 14:44:22 +00:00
|
|
|
c.stateLock.RLock()
|
|
|
|
defer c.stateLock.RUnlock()
|
|
|
|
if c.sealed {
|
2017-02-16 20:15:02 +00:00
|
|
|
return 0, consts.ErrSealed
|
2016-04-04 14:44:22 +00:00
|
|
|
}
|
|
|
|
if c.standby {
|
2017-02-16 20:15:02 +00:00
|
|
|
return 0, consts.ErrStandby
|
2016-04-04 14:44:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
c.rekeyLock.RLock()
|
|
|
|
defer c.rekeyLock.RUnlock()
|
|
|
|
|
|
|
|
var config *SealConfig
|
|
|
|
var err error
|
2017-10-23 18:59:37 +00:00
|
|
|
// If we are rekeying the recovery key, or if the seal supports
|
|
|
|
// recovery keys and we are rekeying the barrier key, we use the
|
|
|
|
// recovery config as the threshold instead.
|
2018-01-19 08:44:06 +00:00
|
|
|
if recovery || c.seal.RecoveryKeySupported() {
|
2018-01-19 06:44:44 +00:00
|
|
|
config, err = c.seal.RecoveryConfig(ctx)
|
2016-04-04 14:44:22 +00:00
|
|
|
} else {
|
2018-01-19 06:44:44 +00:00
|
|
|
config, err = c.seal.BarrierConfig(ctx)
|
2016-04-04 14:44:22 +00:00
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return config.SecretThreshold, nil
|
|
|
|
}
|
|
|
|
|
2017-10-23 18:59:37 +00:00
|
|
|
// RekeyProgress is used to return the rekey progress (num shares).
|
2016-04-04 14:44:22 +00:00
|
|
|
func (c *Core) RekeyProgress(recovery bool) (int, error) {
|
2016-01-14 22:01:04 +00:00
|
|
|
c.stateLock.RLock()
|
|
|
|
defer c.stateLock.RUnlock()
|
|
|
|
if c.sealed {
|
2017-02-16 20:15:02 +00:00
|
|
|
return 0, consts.ErrSealed
|
2016-01-14 22:01:04 +00:00
|
|
|
}
|
|
|
|
if c.standby {
|
2017-02-16 20:15:02 +00:00
|
|
|
return 0, consts.ErrStandby
|
2016-01-14 22:01:04 +00:00
|
|
|
}
|
|
|
|
|
2016-04-04 14:44:22 +00:00
|
|
|
c.rekeyLock.RLock()
|
|
|
|
defer c.rekeyLock.RUnlock()
|
|
|
|
|
|
|
|
if recovery {
|
|
|
|
return len(c.recoveryRekeyProgress), nil
|
|
|
|
}
|
|
|
|
return len(c.barrierRekeyProgress), nil
|
2016-01-14 22:01:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// RekeyConfig is used to read the rekey configuration
|
2016-04-04 14:44:22 +00:00
|
|
|
func (c *Core) RekeyConfig(recovery bool) (*SealConfig, error) {
|
2016-01-14 22:01:04 +00:00
|
|
|
c.stateLock.RLock()
|
|
|
|
defer c.stateLock.RUnlock()
|
|
|
|
if c.sealed {
|
2017-02-16 20:15:02 +00:00
|
|
|
return nil, consts.ErrSealed
|
2016-01-14 22:01:04 +00:00
|
|
|
}
|
|
|
|
if c.standby {
|
2017-02-16 20:15:02 +00:00
|
|
|
return nil, consts.ErrStandby
|
2016-01-14 22:01:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
c.rekeyLock.Lock()
|
|
|
|
defer c.rekeyLock.Unlock()
|
|
|
|
|
|
|
|
// Copy the seal config if any
|
|
|
|
var conf *SealConfig
|
2016-04-04 14:44:22 +00:00
|
|
|
if recovery {
|
|
|
|
if c.recoveryRekeyConfig != nil {
|
|
|
|
conf = c.recoveryRekeyConfig.Clone()
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if c.barrierRekeyConfig != nil {
|
|
|
|
conf = c.barrierRekeyConfig.Clone()
|
|
|
|
}
|
2016-01-14 22:01:04 +00:00
|
|
|
}
|
2016-04-04 14:44:22 +00:00
|
|
|
|
2016-01-14 22:01:04 +00:00
|
|
|
return conf, nil
|
|
|
|
}
|
|
|
|
|
2017-10-23 18:59:37 +00:00
|
|
|
// RekeyInit will either initialize the rekey of barrier or recovery key.
|
|
|
|
// recovery determines whether this is a rekey on the barrier or recovery key.
|
2018-01-19 08:44:06 +00:00
|
|
|
func (c *Core) RekeyInit(config *SealConfig, recovery bool) error {
|
2016-04-04 14:44:22 +00:00
|
|
|
if recovery {
|
2018-01-19 08:44:06 +00:00
|
|
|
return c.RecoveryRekeyInit(config)
|
2016-04-04 14:44:22 +00:00
|
|
|
}
|
2018-01-19 08:44:06 +00:00
|
|
|
return c.BarrierRekeyInit(config)
|
2016-04-04 14:44:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// BarrierRekeyInit is used to initialize the rekey settings for the barrier key
|
2018-01-19 08:44:06 +00:00
|
|
|
func (c *Core) BarrierRekeyInit(config *SealConfig) error {
|
2016-04-04 14:44:22 +00:00
|
|
|
if config.StoredShares > 0 {
|
2018-01-19 08:44:06 +00:00
|
|
|
if !c.seal.StoredKeysSupported() {
|
2016-04-04 14:44:22 +00:00
|
|
|
return fmt.Errorf("storing keys not supported by barrier seal")
|
|
|
|
}
|
|
|
|
if len(config.PGPKeys) > 0 {
|
|
|
|
return fmt.Errorf("PGP key encryption not supported when using stored keys")
|
|
|
|
}
|
|
|
|
if config.Backup {
|
|
|
|
return fmt.Errorf("key backup not supported when using stored keys")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-19 08:44:06 +00:00
|
|
|
if c.seal.RecoveryKeySupported() && c.seal.RecoveryType() == config.Type {
|
2018-04-03 00:46:59 +00:00
|
|
|
c.logger.Debug("using recovery seal configuration to rekey barrier key")
|
2017-10-23 18:59:37 +00:00
|
|
|
}
|
|
|
|
|
2016-05-15 16:58:36 +00:00
|
|
|
// Check if the seal configuration is valid
|
2016-01-14 22:01:04 +00:00
|
|
|
if err := config.Validate(); err != nil {
|
2018-04-03 00:46:59 +00:00
|
|
|
c.logger.Error("invalid rekey seal configuration", "error", err)
|
2018-04-05 15:49:21 +00:00
|
|
|
return errwrap.Wrapf("invalid rekey seal configuration: {{err}}", err)
|
2016-01-14 22:01:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
c.stateLock.RLock()
|
|
|
|
defer c.stateLock.RUnlock()
|
|
|
|
if c.sealed {
|
2017-02-16 20:15:02 +00:00
|
|
|
return consts.ErrSealed
|
2016-01-14 22:01:04 +00:00
|
|
|
}
|
|
|
|
if c.standby {
|
2017-02-16 20:15:02 +00:00
|
|
|
return consts.ErrStandby
|
2016-01-14 22:01:04 +00:00
|
|
|
}
|
|
|
|
|
2016-04-04 14:44:22 +00:00
|
|
|
c.rekeyLock.Lock()
|
|
|
|
defer c.rekeyLock.Unlock()
|
|
|
|
|
2016-01-14 22:01:04 +00:00
|
|
|
// Prevent multiple concurrent re-keys
|
2016-04-04 14:44:22 +00:00
|
|
|
if c.barrierRekeyConfig != nil {
|
2016-01-14 22:01:04 +00:00
|
|
|
return fmt.Errorf("rekey already in progress")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy the configuration
|
2016-04-04 14:44:22 +00:00
|
|
|
c.barrierRekeyConfig = config.Clone()
|
2016-01-14 22:01:04 +00:00
|
|
|
|
|
|
|
// Initialize the nonce
|
|
|
|
nonce, err := uuid.GenerateUUID()
|
|
|
|
if err != nil {
|
2016-04-04 14:44:22 +00:00
|
|
|
c.barrierRekeyConfig = nil
|
2016-01-14 22:01:04 +00:00
|
|
|
return err
|
|
|
|
}
|
2016-04-04 14:44:22 +00:00
|
|
|
c.barrierRekeyConfig.Nonce = nonce
|
2016-01-14 22:01:04 +00:00
|
|
|
|
2016-08-19 20:45:17 +00:00
|
|
|
if c.logger.IsInfo() {
|
2018-04-03 00:46:59 +00:00
|
|
|
c.logger.Info("rekey initialized", "nonce", c.barrierRekeyConfig.Nonce, "shares", c.barrierRekeyConfig.SecretShares, "threshold", c.barrierRekeyConfig.SecretThreshold)
|
2016-08-19 20:45:17 +00:00
|
|
|
}
|
2016-01-14 22:01:04 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-04-04 14:44:22 +00:00
|
|
|
// RecoveryRekeyInit is used to initialize the rekey settings for the recovery key
|
2018-01-19 08:44:06 +00:00
|
|
|
func (c *Core) RecoveryRekeyInit(config *SealConfig) error {
|
2016-04-04 14:44:22 +00:00
|
|
|
if config.StoredShares > 0 {
|
|
|
|
return fmt.Errorf("stored shares not supported by recovery key")
|
2016-01-14 22:01:04 +00:00
|
|
|
}
|
2016-04-04 14:44:22 +00:00
|
|
|
|
2016-05-15 16:58:36 +00:00
|
|
|
// Check if the seal configuration is valid
|
2016-04-04 14:44:22 +00:00
|
|
|
if err := config.Validate(); err != nil {
|
2018-04-03 00:46:59 +00:00
|
|
|
c.logger.Error("invalid recovery configuration", "error", err)
|
2018-04-05 15:49:21 +00:00
|
|
|
return errwrap.Wrapf("invalid recovery configuration: {{err}}", err)
|
2016-01-14 22:01:04 +00:00
|
|
|
}
|
|
|
|
|
2018-01-19 08:44:06 +00:00
|
|
|
if !c.seal.RecoveryKeySupported() {
|
2016-04-04 14:44:22 +00:00
|
|
|
return fmt.Errorf("recovery keys not supported")
|
|
|
|
}
|
|
|
|
|
|
|
|
c.stateLock.RLock()
|
|
|
|
defer c.stateLock.RUnlock()
|
|
|
|
if c.sealed {
|
2017-02-16 20:15:02 +00:00
|
|
|
return consts.ErrSealed
|
2016-04-04 14:44:22 +00:00
|
|
|
}
|
|
|
|
if c.standby {
|
2017-02-16 20:15:02 +00:00
|
|
|
return consts.ErrStandby
|
2016-04-04 14:44:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
c.rekeyLock.Lock()
|
|
|
|
defer c.rekeyLock.Unlock()
|
|
|
|
|
|
|
|
// Prevent multiple concurrent re-keys
|
|
|
|
if c.recoveryRekeyConfig != nil {
|
|
|
|
return fmt.Errorf("rekey already in progress")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy the configuration
|
|
|
|
c.recoveryRekeyConfig = config.Clone()
|
|
|
|
|
|
|
|
// Initialize the nonce
|
|
|
|
nonce, err := uuid.GenerateUUID()
|
2016-01-14 22:01:04 +00:00
|
|
|
if err != nil {
|
2016-04-04 14:44:22 +00:00
|
|
|
c.recoveryRekeyConfig = nil
|
|
|
|
return err
|
2016-01-14 22:01:04 +00:00
|
|
|
}
|
2016-04-04 14:44:22 +00:00
|
|
|
c.recoveryRekeyConfig.Nonce = nonce
|
2016-01-14 22:01:04 +00:00
|
|
|
|
2016-08-19 20:45:17 +00:00
|
|
|
if c.logger.IsInfo() {
|
2018-04-03 00:46:59 +00:00
|
|
|
c.logger.Info("rekey initialized", "nonce", c.recoveryRekeyConfig.Nonce, "shares", c.recoveryRekeyConfig.SecretShares, "threshold", c.recoveryRekeyConfig.SecretThreshold)
|
2016-08-19 20:45:17 +00:00
|
|
|
}
|
2016-04-04 14:44:22 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-10-23 18:59:37 +00:00
|
|
|
// RekeyUpdate is used to provide a new key part for the barrier or recovery key.
|
2018-01-19 06:44:44 +00:00
|
|
|
func (c *Core) RekeyUpdate(ctx context.Context, key []byte, nonce string, recovery bool) (*RekeyResult, error) {
|
2016-04-04 14:44:22 +00:00
|
|
|
if recovery {
|
2018-01-19 06:44:44 +00:00
|
|
|
return c.RecoveryRekeyUpdate(ctx, key, nonce)
|
2016-01-14 22:01:04 +00:00
|
|
|
}
|
2018-01-19 06:44:44 +00:00
|
|
|
return c.BarrierRekeyUpdate(ctx, key, nonce)
|
2016-04-04 14:44:22 +00:00
|
|
|
}
|
2016-01-14 22:01:04 +00:00
|
|
|
|
2017-10-23 18:59:37 +00:00
|
|
|
// BarrierRekeyUpdate is used to provide a new key part. Barrier rekey can be done
|
|
|
|
// with unseal keys, or recovery keys if that's supported and we are storing the barrier
|
|
|
|
// key.
|
|
|
|
//
|
|
|
|
// N.B.: If recovery keys are used to rekey, the new barrier key shares are not returned.
|
2018-01-19 06:44:44 +00:00
|
|
|
func (c *Core) BarrierRekeyUpdate(ctx context.Context, key []byte, nonce string) (*RekeyResult, error) {
|
2016-01-14 22:01:04 +00:00
|
|
|
// Ensure we are already unsealed
|
|
|
|
c.stateLock.RLock()
|
|
|
|
defer c.stateLock.RUnlock()
|
|
|
|
if c.sealed {
|
2017-02-16 20:15:02 +00:00
|
|
|
return nil, consts.ErrSealed
|
2016-01-14 22:01:04 +00:00
|
|
|
}
|
|
|
|
if c.standby {
|
2017-02-16 20:15:02 +00:00
|
|
|
return nil, consts.ErrStandby
|
2016-01-14 22:01:04 +00:00
|
|
|
}
|
|
|
|
|
2016-04-04 14:44:22 +00:00
|
|
|
// Verify the key length
|
|
|
|
min, max := c.barrier.KeyLength()
|
|
|
|
max += shamir.ShareOverhead
|
|
|
|
if len(key) < min {
|
|
|
|
return nil, &ErrInvalidKey{fmt.Sprintf("key is shorter than minimum %d bytes", min)}
|
|
|
|
}
|
|
|
|
if len(key) > max {
|
|
|
|
return nil, &ErrInvalidKey{fmt.Sprintf("key is longer than maximum %d bytes", max)}
|
|
|
|
}
|
|
|
|
|
2016-01-14 22:01:04 +00:00
|
|
|
c.rekeyLock.Lock()
|
|
|
|
defer c.rekeyLock.Unlock()
|
|
|
|
|
2016-04-04 14:44:22 +00:00
|
|
|
// Get the seal configuration
|
2017-10-23 18:59:37 +00:00
|
|
|
var existingConfig *SealConfig
|
|
|
|
var err error
|
|
|
|
var useRecovery bool // Determines whether recovery key is being used to rekey the master key
|
2018-01-19 08:44:06 +00:00
|
|
|
if c.seal.StoredKeysSupported() && c.seal.RecoveryKeySupported() {
|
2018-01-19 06:44:44 +00:00
|
|
|
existingConfig, err = c.seal.RecoveryConfig(ctx)
|
2017-10-23 18:59:37 +00:00
|
|
|
useRecovery = true
|
|
|
|
} else {
|
2018-01-19 06:44:44 +00:00
|
|
|
existingConfig, err = c.seal.BarrierConfig(ctx)
|
2017-10-23 18:59:37 +00:00
|
|
|
}
|
2016-04-04 14:44:22 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure the barrier is initialized
|
|
|
|
if existingConfig == nil {
|
|
|
|
return nil, ErrNotInit
|
|
|
|
}
|
|
|
|
|
2016-01-14 22:01:04 +00:00
|
|
|
// Ensure a rekey is in progress
|
2016-04-04 14:44:22 +00:00
|
|
|
if c.barrierRekeyConfig == nil {
|
2016-01-14 22:01:04 +00:00
|
|
|
return nil, fmt.Errorf("no rekey in progress")
|
|
|
|
}
|
|
|
|
|
2016-04-04 14:44:22 +00:00
|
|
|
if nonce != c.barrierRekeyConfig.Nonce {
|
2018-04-05 15:49:21 +00:00
|
|
|
return nil, fmt.Errorf("incorrect nonce supplied; nonce for this rekey operation is %q", c.barrierRekeyConfig.Nonce)
|
2016-01-14 22:01:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check if we already have this piece
|
2016-04-04 14:44:22 +00:00
|
|
|
for _, existing := range c.barrierRekeyProgress {
|
2016-01-14 22:01:04 +00:00
|
|
|
if bytes.Equal(existing, key) {
|
2016-09-01 21:42:28 +00:00
|
|
|
return nil, fmt.Errorf("given key has already been provided during this generation operation")
|
2016-01-14 22:01:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Store this key
|
2016-04-04 14:44:22 +00:00
|
|
|
c.barrierRekeyProgress = append(c.barrierRekeyProgress, key)
|
2016-01-14 22:01:04 +00:00
|
|
|
|
|
|
|
// Check if we don't have enough keys to unlock
|
2016-04-04 14:44:22 +00:00
|
|
|
if len(c.barrierRekeyProgress) < existingConfig.SecretThreshold {
|
2016-08-19 20:45:17 +00:00
|
|
|
if c.logger.IsDebug() {
|
2018-04-03 00:46:59 +00:00
|
|
|
c.logger.Debug("cannot rekey yet, not enough keys", "keys", len(c.barrierRekeyProgress), "threshold", existingConfig.SecretThreshold)
|
2016-08-19 20:45:17 +00:00
|
|
|
}
|
2016-01-14 22:01:04 +00:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2017-10-23 18:59:37 +00:00
|
|
|
// Recover the master key or recovery key
|
|
|
|
var recoveredKey []byte
|
2016-04-04 14:44:22 +00:00
|
|
|
if existingConfig.SecretThreshold == 1 {
|
2017-10-23 18:59:37 +00:00
|
|
|
recoveredKey = c.barrierRekeyProgress[0]
|
2016-04-04 14:44:22 +00:00
|
|
|
c.barrierRekeyProgress = nil
|
2016-01-14 22:01:04 +00:00
|
|
|
} else {
|
2017-10-23 18:59:37 +00:00
|
|
|
recoveredKey, err = shamir.Combine(c.barrierRekeyProgress)
|
2016-04-04 14:44:22 +00:00
|
|
|
c.barrierRekeyProgress = nil
|
2016-01-14 22:01:04 +00:00
|
|
|
if err != nil {
|
2018-04-05 15:49:21 +00:00
|
|
|
return nil, errwrap.Wrapf("failed to compute master key: {{err}}", err)
|
2016-01-14 22:01:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-23 18:59:37 +00:00
|
|
|
if useRecovery {
|
2018-01-19 06:44:44 +00:00
|
|
|
if err := c.seal.VerifyRecoveryKey(ctx, recoveredKey); err != nil {
|
2018-04-03 00:46:59 +00:00
|
|
|
c.logger.Error("rekey aborted, recovery key verification failed", "error", err)
|
2017-10-23 18:59:37 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if err := c.barrier.VerifyMaster(recoveredKey); err != nil {
|
2018-04-03 00:46:59 +00:00
|
|
|
c.logger.Error("rekey aborted, master key verification failed", "error", err)
|
2017-10-23 18:59:37 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
2016-01-14 22:01:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Generate a new master key
|
|
|
|
newMasterKey, err := c.barrier.GenerateKey()
|
|
|
|
if err != nil {
|
2018-04-03 00:46:59 +00:00
|
|
|
c.logger.Error("failed to generate master key", "error", err)
|
2018-04-05 15:49:21 +00:00
|
|
|
return nil, errwrap.Wrapf("master key generation failed: {{err}}", err)
|
2016-01-14 22:01:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
results := &RekeyResult{
|
2016-04-04 14:44:22 +00:00
|
|
|
Backup: c.barrierRekeyConfig.Backup,
|
2016-01-14 22:01:04 +00:00
|
|
|
}
|
2017-10-23 18:59:37 +00:00
|
|
|
// Set result.SecretShares to the master key if only a single key
|
|
|
|
// part is used -- no Shamir split required.
|
2016-04-04 14:44:22 +00:00
|
|
|
if c.barrierRekeyConfig.SecretShares == 1 {
|
2016-01-14 22:01:04 +00:00
|
|
|
results.SecretShares = append(results.SecretShares, newMasterKey)
|
|
|
|
} else {
|
|
|
|
// Split the master key using the Shamir algorithm
|
2016-04-04 14:44:22 +00:00
|
|
|
shares, err := shamir.Split(newMasterKey, c.barrierRekeyConfig.SecretShares, c.barrierRekeyConfig.SecretThreshold)
|
2016-01-14 22:01:04 +00:00
|
|
|
if err != nil {
|
2018-04-03 00:46:59 +00:00
|
|
|
c.logger.Error("failed to generate shares", "error", err)
|
2018-04-05 15:49:21 +00:00
|
|
|
return nil, errwrap.Wrapf("failed to generate shares: {{err}}", err)
|
2016-01-14 22:01:04 +00:00
|
|
|
}
|
|
|
|
results.SecretShares = shares
|
|
|
|
}
|
|
|
|
|
2016-04-04 14:44:22 +00:00
|
|
|
// If we are storing any shares, add them to the shares to store and remove
|
|
|
|
// from the returned keys
|
|
|
|
var keysToStore [][]byte
|
2018-01-19 08:44:06 +00:00
|
|
|
if c.seal.StoredKeysSupported() && c.barrierRekeyConfig.StoredShares > 0 {
|
2016-04-04 14:44:22 +00:00
|
|
|
for i := 0; i < c.barrierRekeyConfig.StoredShares; i++ {
|
|
|
|
keysToStore = append(keysToStore, results.SecretShares[0])
|
|
|
|
results.SecretShares = results.SecretShares[1:]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-23 18:59:37 +00:00
|
|
|
// If PGP keys are passed in, encrypt shares with corresponding PGP keys.
|
2016-04-04 14:44:22 +00:00
|
|
|
if len(c.barrierRekeyConfig.PGPKeys) > 0 {
|
2016-01-20 00:19:07 +00:00
|
|
|
hexEncodedShares := make([][]byte, len(results.SecretShares))
|
|
|
|
for i, _ := range results.SecretShares {
|
|
|
|
hexEncodedShares[i] = []byte(hex.EncodeToString(results.SecretShares[i]))
|
|
|
|
}
|
2016-04-04 14:44:22 +00:00
|
|
|
results.PGPFingerprints, results.SecretShares, err = pgpkeys.EncryptShares(hexEncodedShares, c.barrierRekeyConfig.PGPKeys)
|
2016-01-14 22:01:04 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2017-10-23 18:59:37 +00:00
|
|
|
// If backup is enabled, store backup info in vault.coreBarrierUnsealKeysBackupPath
|
2016-04-04 14:44:22 +00:00
|
|
|
if c.barrierRekeyConfig.Backup {
|
2016-01-14 22:01:04 +00:00
|
|
|
backupInfo := map[string][]string{}
|
|
|
|
for i := 0; i < len(results.PGPFingerprints); i++ {
|
|
|
|
encShare := bytes.NewBuffer(results.SecretShares[i])
|
|
|
|
if backupInfo[results.PGPFingerprints[i]] == nil {
|
|
|
|
backupInfo[results.PGPFingerprints[i]] = []string{hex.EncodeToString(encShare.Bytes())}
|
|
|
|
} else {
|
|
|
|
backupInfo[results.PGPFingerprints[i]] = append(backupInfo[results.PGPFingerprints[i]], hex.EncodeToString(encShare.Bytes()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
backupVals := &RekeyBackup{
|
2016-04-04 14:44:22 +00:00
|
|
|
Nonce: c.barrierRekeyConfig.Nonce,
|
2016-01-14 22:01:04 +00:00
|
|
|
Keys: backupInfo,
|
|
|
|
}
|
|
|
|
buf, err := json.Marshal(backupVals)
|
|
|
|
if err != nil {
|
2018-04-03 00:46:59 +00:00
|
|
|
c.logger.Error("failed to marshal unseal key backup", "error", err)
|
2018-04-05 15:49:21 +00:00
|
|
|
return nil, errwrap.Wrapf("failed to marshal unseal key backup: {{err}}", err)
|
2016-01-14 22:01:04 +00:00
|
|
|
}
|
|
|
|
pe := &physical.Entry{
|
2016-04-04 14:44:22 +00:00
|
|
|
Key: coreBarrierUnsealKeysBackupPath,
|
2016-01-14 22:01:04 +00:00
|
|
|
Value: buf,
|
|
|
|
}
|
2018-01-19 06:44:44 +00:00
|
|
|
if err = c.physical.Put(ctx, pe); err != nil {
|
2018-04-03 00:46:59 +00:00
|
|
|
c.logger.Error("failed to save unseal key backup", "error", err)
|
2018-04-05 15:49:21 +00:00
|
|
|
return nil, errwrap.Wrapf("failed to save unseal key backup: {{err}}", err)
|
2016-01-14 22:01:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-04 14:44:22 +00:00
|
|
|
if keysToStore != nil {
|
2018-01-19 06:44:44 +00:00
|
|
|
if err := c.seal.SetStoredKeys(ctx, keysToStore); err != nil {
|
2018-04-03 00:46:59 +00:00
|
|
|
c.logger.Error("failed to store keys", "error", err)
|
2018-04-05 15:49:21 +00:00
|
|
|
return nil, errwrap.Wrapf("failed to store keys: {{err}}", err)
|
2016-04-04 14:44:22 +00:00
|
|
|
}
|
2016-01-14 22:01:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Rekey the barrier
|
2018-01-19 06:44:44 +00:00
|
|
|
if err := c.barrier.Rekey(ctx, newMasterKey); err != nil {
|
2018-04-03 00:46:59 +00:00
|
|
|
c.logger.Error("failed to rekey barrier", "error", err)
|
2018-04-05 15:49:21 +00:00
|
|
|
return nil, errwrap.Wrapf("failed to rekey barrier: {{err}}", err)
|
2016-01-14 22:01:04 +00:00
|
|
|
}
|
2016-08-19 20:45:17 +00:00
|
|
|
if c.logger.IsInfo() {
|
2018-04-03 00:46:59 +00:00
|
|
|
c.logger.Info("security barrier rekeyed", "shares", c.barrierRekeyConfig.SecretShares, "threshold", c.barrierRekeyConfig.SecretThreshold)
|
2016-08-19 20:45:17 +00:00
|
|
|
}
|
2018-01-19 06:44:44 +00:00
|
|
|
if err := c.seal.SetBarrierConfig(ctx, c.barrierRekeyConfig); err != nil {
|
2018-04-03 00:46:59 +00:00
|
|
|
c.logger.Error("error saving rekey seal configuration", "error", err)
|
2018-04-05 15:49:21 +00:00
|
|
|
return nil, errwrap.Wrapf("failed to save rekey seal configuration: {{err}}", err)
|
2016-04-04 14:44:22 +00:00
|
|
|
}
|
|
|
|
|
2017-02-24 15:45:29 +00:00
|
|
|
// Write to the canary path, which will force a synchronous truing during
|
|
|
|
// replication
|
2018-01-19 06:44:44 +00:00
|
|
|
if err := c.barrier.Put(ctx, &Entry{
|
2017-02-24 15:45:29 +00:00
|
|
|
Key: coreKeyringCanaryPath,
|
|
|
|
Value: []byte(c.barrierRekeyConfig.Nonce),
|
|
|
|
}); err != nil {
|
2018-04-03 00:46:59 +00:00
|
|
|
c.logger.Error("error saving keyring canary", "error", err)
|
2018-04-05 15:49:21 +00:00
|
|
|
return nil, errwrap.Wrapf("failed to save keyring canary: {{err}}", err)
|
2017-02-24 15:45:29 +00:00
|
|
|
}
|
|
|
|
|
2016-04-04 14:44:22 +00:00
|
|
|
// Done!
|
|
|
|
c.barrierRekeyProgress = nil
|
|
|
|
c.barrierRekeyConfig = nil
|
|
|
|
return results, nil
|
|
|
|
}
|
2016-01-14 22:01:04 +00:00
|
|
|
|
2016-04-04 14:44:22 +00:00
|
|
|
// RecoveryRekeyUpdate is used to provide a new key part
|
2018-01-19 06:44:44 +00:00
|
|
|
func (c *Core) RecoveryRekeyUpdate(ctx context.Context, key []byte, nonce string) (*RekeyResult, error) {
|
2016-04-04 14:44:22 +00:00
|
|
|
// Ensure we are already unsealed
|
|
|
|
c.stateLock.RLock()
|
|
|
|
defer c.stateLock.RUnlock()
|
|
|
|
if c.sealed {
|
2017-02-16 20:15:02 +00:00
|
|
|
return nil, consts.ErrSealed
|
2016-01-14 22:01:04 +00:00
|
|
|
}
|
2016-04-04 14:44:22 +00:00
|
|
|
if c.standby {
|
2017-02-16 20:15:02 +00:00
|
|
|
return nil, consts.ErrStandby
|
2016-04-04 14:44:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Verify the key length
|
|
|
|
min, max := c.barrier.KeyLength()
|
|
|
|
max += shamir.ShareOverhead
|
|
|
|
if len(key) < min {
|
|
|
|
return nil, &ErrInvalidKey{fmt.Sprintf("key is shorter than minimum %d bytes", min)}
|
|
|
|
}
|
|
|
|
if len(key) > max {
|
|
|
|
return nil, &ErrInvalidKey{fmt.Sprintf("key is longer than maximum %d bytes", max)}
|
|
|
|
}
|
|
|
|
|
|
|
|
c.rekeyLock.Lock()
|
|
|
|
defer c.rekeyLock.Unlock()
|
|
|
|
|
|
|
|
// Get the seal configuration
|
2018-01-19 06:44:44 +00:00
|
|
|
existingConfig, err := c.seal.RecoveryConfig(ctx)
|
2016-04-04 14:44:22 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2017-10-23 18:59:37 +00:00
|
|
|
// Ensure the seal is initialized
|
|
|
|
if existingConfig == nil {
|
2016-04-04 14:44:22 +00:00
|
|
|
return nil, ErrNotInit
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure a rekey is in progress
|
|
|
|
if c.recoveryRekeyConfig == nil {
|
|
|
|
return nil, fmt.Errorf("no rekey in progress")
|
|
|
|
}
|
|
|
|
|
|
|
|
if nonce != c.recoveryRekeyConfig.Nonce {
|
2018-04-05 15:49:21 +00:00
|
|
|
return nil, fmt.Errorf("incorrect nonce supplied; nonce for this rekey operation is %q", c.recoveryRekeyConfig.Nonce)
|
2016-04-04 14:44:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check if we already have this piece
|
|
|
|
for _, existing := range c.recoveryRekeyProgress {
|
|
|
|
if bytes.Equal(existing, key) {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Store this key
|
|
|
|
c.recoveryRekeyProgress = append(c.recoveryRekeyProgress, key)
|
|
|
|
|
|
|
|
// Check if we don't have enough keys to unlock
|
|
|
|
if len(c.recoveryRekeyProgress) < existingConfig.SecretThreshold {
|
2016-08-19 20:45:17 +00:00
|
|
|
if c.logger.IsDebug() {
|
2018-04-03 00:46:59 +00:00
|
|
|
c.logger.Debug("cannot rekey yet, not enough keys", "keys", len(c.recoveryRekeyProgress), "threshold", existingConfig.SecretThreshold)
|
2016-08-19 20:45:17 +00:00
|
|
|
}
|
2016-04-04 14:44:22 +00:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Recover the master key
|
2017-10-23 18:59:37 +00:00
|
|
|
var recoveryKey []byte
|
2016-04-04 14:44:22 +00:00
|
|
|
if existingConfig.SecretThreshold == 1 {
|
2017-10-23 18:59:37 +00:00
|
|
|
recoveryKey = c.recoveryRekeyProgress[0]
|
2016-04-04 14:44:22 +00:00
|
|
|
c.recoveryRekeyProgress = nil
|
|
|
|
} else {
|
2017-10-23 18:59:37 +00:00
|
|
|
recoveryKey, err = shamir.Combine(c.recoveryRekeyProgress)
|
2016-04-04 14:44:22 +00:00
|
|
|
c.recoveryRekeyProgress = nil
|
|
|
|
if err != nil {
|
2018-04-05 15:49:21 +00:00
|
|
|
return nil, errwrap.Wrapf("failed to compute recovery key: {{err}}", err)
|
2016-04-04 14:44:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify the recovery key
|
2018-01-19 06:44:44 +00:00
|
|
|
if err := c.seal.VerifyRecoveryKey(ctx, recoveryKey); err != nil {
|
2018-04-03 00:46:59 +00:00
|
|
|
c.logger.Error("rekey aborted, recovery key verification failed", "error", err)
|
2016-04-04 14:44:22 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generate a new master key
|
|
|
|
newMasterKey, err := c.barrier.GenerateKey()
|
|
|
|
if err != nil {
|
2018-04-03 00:46:59 +00:00
|
|
|
c.logger.Error("failed to generate recovery key", "error", err)
|
2018-04-05 15:49:21 +00:00
|
|
|
return nil, errwrap.Wrapf("recovery key generation failed: {{err}}", err)
|
2016-04-04 14:44:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return the master key if only a single key part is used
|
|
|
|
results := &RekeyResult{
|
|
|
|
Backup: c.recoveryRekeyConfig.Backup,
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.recoveryRekeyConfig.SecretShares == 1 {
|
|
|
|
results.SecretShares = append(results.SecretShares, newMasterKey)
|
|
|
|
} else {
|
|
|
|
// Split the master key using the Shamir algorithm
|
|
|
|
shares, err := shamir.Split(newMasterKey, c.recoveryRekeyConfig.SecretShares, c.recoveryRekeyConfig.SecretThreshold)
|
|
|
|
if err != nil {
|
2018-04-03 00:46:59 +00:00
|
|
|
c.logger.Error("failed to generate shares", "error", err)
|
2018-04-05 15:49:21 +00:00
|
|
|
return nil, errwrap.Wrapf("failed to generate shares: {{err}}", err)
|
2016-04-04 14:44:22 +00:00
|
|
|
}
|
|
|
|
results.SecretShares = shares
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(c.recoveryRekeyConfig.PGPKeys) > 0 {
|
|
|
|
hexEncodedShares := make([][]byte, len(results.SecretShares))
|
|
|
|
for i, _ := range results.SecretShares {
|
|
|
|
hexEncodedShares[i] = []byte(hex.EncodeToString(results.SecretShares[i]))
|
|
|
|
}
|
|
|
|
results.PGPFingerprints, results.SecretShares, err = pgpkeys.EncryptShares(hexEncodedShares, c.recoveryRekeyConfig.PGPKeys)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.recoveryRekeyConfig.Backup {
|
|
|
|
backupInfo := map[string][]string{}
|
|
|
|
for i := 0; i < len(results.PGPFingerprints); i++ {
|
|
|
|
encShare := bytes.NewBuffer(results.SecretShares[i])
|
|
|
|
if backupInfo[results.PGPFingerprints[i]] == nil {
|
|
|
|
backupInfo[results.PGPFingerprints[i]] = []string{hex.EncodeToString(encShare.Bytes())}
|
|
|
|
} else {
|
|
|
|
backupInfo[results.PGPFingerprints[i]] = append(backupInfo[results.PGPFingerprints[i]], hex.EncodeToString(encShare.Bytes()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
backupVals := &RekeyBackup{
|
|
|
|
Nonce: c.recoveryRekeyConfig.Nonce,
|
|
|
|
Keys: backupInfo,
|
|
|
|
}
|
|
|
|
buf, err := json.Marshal(backupVals)
|
|
|
|
if err != nil {
|
2018-04-03 00:46:59 +00:00
|
|
|
c.logger.Error("failed to marshal recovery key backup", "error", err)
|
2018-04-05 15:49:21 +00:00
|
|
|
return nil, errwrap.Wrapf("failed to marshal recovery key backup: {{err}}", err)
|
2016-04-04 14:44:22 +00:00
|
|
|
}
|
|
|
|
pe := &physical.Entry{
|
|
|
|
Key: coreRecoveryUnsealKeysBackupPath,
|
|
|
|
Value: buf,
|
|
|
|
}
|
2018-01-19 06:44:44 +00:00
|
|
|
if err = c.physical.Put(ctx, pe); err != nil {
|
2018-04-03 00:46:59 +00:00
|
|
|
c.logger.Error("failed to save unseal key backup", "error", err)
|
2018-04-05 15:49:21 +00:00
|
|
|
return nil, errwrap.Wrapf("failed to save unseal key backup: {{err}}", err)
|
2016-04-04 14:44:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-19 06:44:44 +00:00
|
|
|
if err := c.seal.SetRecoveryKey(ctx, newMasterKey); err != nil {
|
2018-04-03 00:46:59 +00:00
|
|
|
c.logger.Error("failed to set recovery key", "error", err)
|
2018-04-05 15:49:21 +00:00
|
|
|
return nil, errwrap.Wrapf("failed to set recovery key: {{err}}", err)
|
2016-04-04 14:44:22 +00:00
|
|
|
}
|
|
|
|
|
2018-01-19 06:44:44 +00:00
|
|
|
if err := c.seal.SetRecoveryConfig(ctx, c.recoveryRekeyConfig); err != nil {
|
2018-04-03 00:46:59 +00:00
|
|
|
c.logger.Error("error saving rekey seal configuration", "error", err)
|
2018-04-05 15:49:21 +00:00
|
|
|
return nil, errwrap.Wrapf("failed to save rekey seal configuration: {{err}}", err)
|
2016-01-14 22:01:04 +00:00
|
|
|
}
|
|
|
|
|
2017-02-24 15:45:29 +00:00
|
|
|
// Write to the canary path, which will force a synchronous truing during
|
|
|
|
// replication
|
2018-01-19 06:44:44 +00:00
|
|
|
if err := c.barrier.Put(ctx, &Entry{
|
2017-02-24 15:45:29 +00:00
|
|
|
Key: coreKeyringCanaryPath,
|
|
|
|
Value: []byte(c.recoveryRekeyConfig.Nonce),
|
|
|
|
}); err != nil {
|
2018-04-03 00:46:59 +00:00
|
|
|
c.logger.Error("error saving keyring canary", "error", err)
|
2018-04-05 15:49:21 +00:00
|
|
|
return nil, errwrap.Wrapf("failed to save keyring canary: {{err}}", err)
|
2017-02-24 15:45:29 +00:00
|
|
|
}
|
|
|
|
|
2016-01-14 22:01:04 +00:00
|
|
|
// Done!
|
2016-04-04 14:44:22 +00:00
|
|
|
c.recoveryRekeyProgress = nil
|
|
|
|
c.recoveryRekeyConfig = nil
|
2016-01-14 22:01:04 +00:00
|
|
|
return results, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// RekeyCancel is used to cancel an inprogress rekey
|
2016-04-04 14:44:22 +00:00
|
|
|
func (c *Core) RekeyCancel(recovery bool) error {
|
2016-01-14 22:01:04 +00:00
|
|
|
c.stateLock.RLock()
|
|
|
|
defer c.stateLock.RUnlock()
|
|
|
|
if c.sealed {
|
2017-02-16 20:15:02 +00:00
|
|
|
return consts.ErrSealed
|
2016-01-14 22:01:04 +00:00
|
|
|
}
|
|
|
|
if c.standby {
|
2017-02-16 20:15:02 +00:00
|
|
|
return consts.ErrStandby
|
2016-01-14 22:01:04 +00:00
|
|
|
}
|
|
|
|
|
2016-04-04 14:44:22 +00:00
|
|
|
c.rekeyLock.Lock()
|
|
|
|
defer c.rekeyLock.Unlock()
|
|
|
|
|
2016-01-14 22:01:04 +00:00
|
|
|
// Clear any progress or config
|
2016-04-04 14:44:22 +00:00
|
|
|
if recovery {
|
|
|
|
c.recoveryRekeyConfig = nil
|
|
|
|
c.recoveryRekeyProgress = nil
|
|
|
|
} else {
|
|
|
|
c.barrierRekeyConfig = nil
|
|
|
|
c.barrierRekeyProgress = nil
|
|
|
|
}
|
2016-01-14 22:01:04 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// RekeyRetrieveBackup is used to retrieve any backed-up PGP-encrypted unseal
|
|
|
|
// keys
|
2018-01-19 06:44:44 +00:00
|
|
|
func (c *Core) RekeyRetrieveBackup(ctx context.Context, recovery bool) (*RekeyBackup, error) {
|
2016-01-14 22:01:04 +00:00
|
|
|
c.stateLock.RLock()
|
|
|
|
defer c.stateLock.RUnlock()
|
|
|
|
if c.sealed {
|
2017-02-16 20:15:02 +00:00
|
|
|
return nil, consts.ErrSealed
|
2016-01-14 22:01:04 +00:00
|
|
|
}
|
|
|
|
if c.standby {
|
2017-02-16 20:15:02 +00:00
|
|
|
return nil, consts.ErrStandby
|
2016-01-14 22:01:04 +00:00
|
|
|
}
|
|
|
|
|
2016-04-04 14:44:22 +00:00
|
|
|
c.rekeyLock.RLock()
|
|
|
|
defer c.rekeyLock.RUnlock()
|
|
|
|
|
|
|
|
var entry *physical.Entry
|
|
|
|
var err error
|
|
|
|
if recovery {
|
2018-01-19 06:44:44 +00:00
|
|
|
entry, err = c.physical.Get(ctx, coreRecoveryUnsealKeysBackupPath)
|
2016-04-04 14:44:22 +00:00
|
|
|
} else {
|
2018-01-19 06:44:44 +00:00
|
|
|
entry, err = c.physical.Get(ctx, coreBarrierUnsealKeysBackupPath)
|
2016-04-04 14:44:22 +00:00
|
|
|
}
|
2016-01-14 22:01:04 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if entry == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
ret := &RekeyBackup{}
|
2016-07-06 16:25:40 +00:00
|
|
|
err = jsonutil.DecodeJSON(entry.Value, ret)
|
2016-01-14 22:01:04 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// RekeyDeleteBackup is used to delete any backed-up PGP-encrypted unseal keys
|
2018-01-19 06:44:44 +00:00
|
|
|
func (c *Core) RekeyDeleteBackup(ctx context.Context, recovery bool) error {
|
2016-01-14 22:01:04 +00:00
|
|
|
c.stateLock.RLock()
|
|
|
|
defer c.stateLock.RUnlock()
|
|
|
|
if c.sealed {
|
2017-02-16 20:15:02 +00:00
|
|
|
return consts.ErrSealed
|
2016-01-14 22:01:04 +00:00
|
|
|
}
|
|
|
|
if c.standby {
|
2017-02-16 20:15:02 +00:00
|
|
|
return consts.ErrStandby
|
2016-01-14 22:01:04 +00:00
|
|
|
}
|
|
|
|
|
2016-04-04 14:44:22 +00:00
|
|
|
c.rekeyLock.Lock()
|
|
|
|
defer c.rekeyLock.Unlock()
|
|
|
|
|
|
|
|
if recovery {
|
2018-01-19 06:44:44 +00:00
|
|
|
return c.physical.Delete(ctx, coreRecoveryUnsealKeysBackupPath)
|
2016-04-04 14:44:22 +00:00
|
|
|
}
|
2018-01-19 06:44:44 +00:00
|
|
|
return c.physical.Delete(ctx, coreBarrierUnsealKeysBackupPath)
|
2016-01-14 22:01:04 +00:00
|
|
|
}
|