kms.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package kms
  2. import (
  3. "context"
  4. "strings"
  5. "github.com/pkg/errors"
  6. "github.com/smallstep/certificates/kms/apiv1"
  7. // Enable default implementation
  8. "github.com/smallstep/certificates/kms/softkms"
  9. )
  10. // KeyManager is the interface implemented by all the KMS.
  11. type KeyManager = apiv1.KeyManager
  12. // CertificateManager is the interface implemented by the KMS that can load and
  13. // store x509.Certificates.
  14. type CertificateManager = apiv1.CertificateManager
  15. // Options are the KMS options. They represent the kms object in the ca.json.
  16. type Options = apiv1.Options
  17. // Default is the implementation of the default KMS.
  18. var Default = &softkms.SoftKMS{}
  19. // New initializes a new KMS from the given type.
  20. func New(ctx context.Context, opts apiv1.Options) (KeyManager, error) {
  21. if err := opts.Validate(); err != nil {
  22. return nil, err
  23. }
  24. t := apiv1.Type(strings.ToLower(opts.Type))
  25. if t == apiv1.DefaultKMS {
  26. t = apiv1.SoftKMS
  27. }
  28. fn, ok := apiv1.LoadKeyManagerNewFunc(t)
  29. if !ok {
  30. return nil, errors.Errorf("unsupported kms type '%s'", t)
  31. }
  32. return fn(ctx, opts)
  33. }