2015-04-16 00:08:12 +00:00
|
|
|
package transit
|
|
|
|
|
|
|
|
import (
|
2017-02-16 21:29:30 +00:00
|
|
|
"strings"
|
|
|
|
|
2016-10-26 23:52:31 +00:00
|
|
|
"github.com/hashicorp/vault/helper/keysutil"
|
2015-04-16 00:08:12 +00:00
|
|
|
"github.com/hashicorp/vault/logical"
|
|
|
|
"github.com/hashicorp/vault/logical/framework"
|
|
|
|
)
|
|
|
|
|
2015-07-01 00:45:20 +00:00
|
|
|
func Factory(conf *logical.BackendConfig) (logical.Backend, error) {
|
2016-04-21 20:32:06 +00:00
|
|
|
b := Backend(conf)
|
2016-01-27 21:24:11 +00:00
|
|
|
be, err := b.Backend.Setup(conf)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return be, nil
|
2015-04-16 00:08:12 +00:00
|
|
|
}
|
|
|
|
|
2016-04-21 20:32:06 +00:00
|
|
|
func Backend(conf *logical.BackendConfig) *backend {
|
2015-04-16 00:08:12 +00:00
|
|
|
var b backend
|
|
|
|
b.Backend = &framework.Backend{
|
|
|
|
Paths: []*framework.Path{
|
2015-09-17 22:49:50 +00:00
|
|
|
// Rotate/Config needs to come before Keys
|
2015-09-14 20:28:46 +00:00
|
|
|
// as the handler is greedy
|
2016-02-02 14:26:25 +00:00
|
|
|
b.pathConfig(),
|
2016-01-27 21:24:11 +00:00
|
|
|
b.pathRotate(),
|
|
|
|
b.pathRewrap(),
|
|
|
|
b.pathKeys(),
|
2016-10-18 14:13:01 +00:00
|
|
|
b.pathListKeys(),
|
2017-01-23 16:04:43 +00:00
|
|
|
b.pathExportKeys(),
|
2016-01-27 21:24:11 +00:00
|
|
|
b.pathEncrypt(),
|
|
|
|
b.pathDecrypt(),
|
|
|
|
b.pathDatakey(),
|
2016-09-21 14:29:42 +00:00
|
|
|
b.pathRandom(),
|
|
|
|
b.pathHash(),
|
|
|
|
b.pathHMAC(),
|
|
|
|
b.pathSign(),
|
|
|
|
b.pathVerify(),
|
2015-04-16 00:08:12 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
Secrets: []*framework.Secret{},
|
2017-02-16 21:29:30 +00:00
|
|
|
|
|
|
|
Invalidate: b.invalidate,
|
2015-04-16 00:08:12 +00:00
|
|
|
}
|
|
|
|
|
2016-10-26 23:52:31 +00:00
|
|
|
b.lm = keysutil.NewLockManager(conf.System.CachingDisabled())
|
2016-01-27 21:24:11 +00:00
|
|
|
|
|
|
|
return &b
|
2015-04-16 00:08:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type backend struct {
|
|
|
|
*framework.Backend
|
2016-10-26 23:52:31 +00:00
|
|
|
lm *keysutil.LockManager
|
2015-04-16 00:08:12 +00:00
|
|
|
}
|
2017-02-16 21:29:30 +00:00
|
|
|
|
|
|
|
func (b *backend) invalidate(key string) {
|
|
|
|
if b.Logger().IsTrace() {
|
|
|
|
b.Logger().Trace("transit: invalidating key", "key", key)
|
|
|
|
}
|
|
|
|
switch {
|
|
|
|
case strings.HasPrefix(key, "policy/"):
|
|
|
|
name := strings.TrimPrefix(key, "policy/")
|
|
|
|
b.lm.InvalidatePolicy(name)
|
|
|
|
}
|
|
|
|
}
|