2020-01-10 02:41:13 +00:00
|
|
|
package kms
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/smallstep/certificates/kms/apiv1"
|
2020-05-15 18:32:12 +00:00
|
|
|
|
2020-06-12 21:55:35 +00:00
|
|
|
// Enable default implementation
|
2020-05-15 18:32:12 +00:00
|
|
|
_ "github.com/smallstep/certificates/kms/softkms"
|
2020-01-10 02:41:13 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// KeyManager is the interface implemented by all the KMS.
|
2020-05-12 01:47:22 +00:00
|
|
|
type KeyManager = apiv1.KeyManager
|
2020-01-10 02:41:13 +00:00
|
|
|
|
2020-05-12 01:47:22 +00:00
|
|
|
// CertificateManager is the interface implemented by the KMS that can load and
|
|
|
|
// store x509.Certificates.
|
|
|
|
type CertificateManager = apiv1.CertificateManager
|
2020-05-08 01:22:09 +00:00
|
|
|
|
2021-10-07 01:42:01 +00:00
|
|
|
// Options are the KMS options. They represent the kms object in the ca.json.
|
|
|
|
type Options = apiv1.Options
|
|
|
|
|
2020-01-10 02:41:13 +00:00
|
|
|
// New initializes a new KMS from the given type.
|
|
|
|
func New(ctx context.Context, opts apiv1.Options) (KeyManager, error) {
|
|
|
|
if err := opts.Validate(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2020-05-12 01:47:22 +00:00
|
|
|
t := apiv1.Type(strings.ToLower(opts.Type))
|
|
|
|
if t == apiv1.DefaultKMS {
|
|
|
|
t = apiv1.SoftKMS
|
|
|
|
}
|
|
|
|
|
|
|
|
fn, ok := apiv1.LoadKeyManagerNewFunc(t)
|
|
|
|
if !ok {
|
2020-05-15 18:32:12 +00:00
|
|
|
return nil, errors.Errorf("unsupported kms type '%s'", t)
|
2020-01-10 02:41:13 +00:00
|
|
|
}
|
2020-05-12 01:47:22 +00:00
|
|
|
return fn(ctx, opts)
|
2020-01-10 02:41:13 +00:00
|
|
|
}
|