2018-09-18 03:03:00 +00:00
|
|
|
package vault
|
|
|
|
|
2019-06-20 19:14:58 +00:00
|
|
|
import (
|
2019-06-24 03:05:51 +00:00
|
|
|
"github.com/hashicorp/go-hclog"
|
2020-01-11 01:39:52 +00:00
|
|
|
wrapping "github.com/hashicorp/go-kms-wrapping"
|
|
|
|
aeadwrapper "github.com/hashicorp/go-kms-wrapping/wrappers/aead"
|
2019-10-18 18:46:00 +00:00
|
|
|
"github.com/hashicorp/vault/sdk/helper/logging"
|
|
|
|
"github.com/hashicorp/vault/vault/seal"
|
2019-06-20 19:14:58 +00:00
|
|
|
testing "github.com/mitchellh/go-testing-interface"
|
|
|
|
)
|
2018-09-18 03:03:00 +00:00
|
|
|
|
2020-01-11 01:39:52 +00:00
|
|
|
func NewTestSeal(t testing.T, opts *seal.TestSealOpts) Seal {
|
2019-10-18 18:46:00 +00:00
|
|
|
t.Helper()
|
|
|
|
if opts == nil {
|
2020-01-11 01:39:52 +00:00
|
|
|
opts = &seal.TestSealOpts{}
|
2019-10-18 18:46:00 +00:00
|
|
|
}
|
|
|
|
if opts.Logger == nil {
|
|
|
|
opts.Logger = logging.NewVaultLogger(hclog.Debug)
|
|
|
|
}
|
|
|
|
|
|
|
|
switch opts.StoredKeys {
|
2020-01-11 01:39:52 +00:00
|
|
|
case seal.StoredKeysSupportedShamirMaster:
|
|
|
|
newSeal := NewDefaultSeal(&seal.Access{
|
|
|
|
Wrapper: aeadwrapper.NewWrapper(&wrapping.WrapperOptions{
|
|
|
|
Logger: opts.Logger,
|
|
|
|
}),
|
|
|
|
})
|
2019-10-18 18:46:00 +00:00
|
|
|
// Need StoredShares set or this will look like a legacy shamir seal.
|
|
|
|
newSeal.SetCachedBarrierConfig(&SealConfig{
|
|
|
|
StoredShares: 1,
|
|
|
|
SecretThreshold: 1,
|
|
|
|
SecretShares: 1,
|
|
|
|
})
|
|
|
|
return newSeal
|
2020-01-11 01:39:52 +00:00
|
|
|
case seal.StoredKeysNotSupported:
|
|
|
|
newSeal := NewDefaultSeal(&seal.Access{
|
|
|
|
Wrapper: aeadwrapper.NewWrapper(&wrapping.WrapperOptions{
|
|
|
|
Logger: opts.Logger,
|
|
|
|
}),
|
|
|
|
})
|
2019-10-18 18:46:00 +00:00
|
|
|
newSeal.SetCachedBarrierConfig(&SealConfig{
|
|
|
|
StoredShares: 0,
|
|
|
|
SecretThreshold: 1,
|
|
|
|
SecretShares: 1,
|
|
|
|
})
|
|
|
|
return newSeal
|
|
|
|
default:
|
2020-01-11 01:39:52 +00:00
|
|
|
return NewAutoSeal(seal.NewTestSeal(opts))
|
2019-06-24 03:05:51 +00:00
|
|
|
}
|
2018-09-18 03:03:00 +00:00
|
|
|
}
|