|
| 1 | +package platform |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "crypto" |
| 6 | + "crypto/x509" |
| 7 | + |
| 8 | + "go.step.sm/crypto/kms/apiv1" |
| 9 | +) |
| 10 | + |
| 11 | +const Scheme = "kms" |
| 12 | + |
| 13 | +func init() { |
| 14 | + apiv1.Register(apiv1.PlatformKMS, func(ctx context.Context, opts apiv1.Options) (apiv1.KeyManager, error) { |
| 15 | + return New(ctx, opts) |
| 16 | + }) |
| 17 | +} |
| 18 | + |
| 19 | +type extendedKeyManager interface { |
| 20 | + apiv1.KeyManager |
| 21 | + apiv1.KeyDeleter |
| 22 | + apiv1.CertificateManager |
| 23 | + apiv1.CertificateChainManager |
| 24 | +} |
| 25 | + |
| 26 | +var _ apiv1.KeyManager = (*KMS)(nil) |
| 27 | +var _ apiv1.CertificateManager = (*KMS)(nil) |
| 28 | +var _ apiv1.CertificateChainManager = (*KMS)(nil) |
| 29 | + |
| 30 | +type KMS struct { |
| 31 | + backend extendedKeyManager |
| 32 | +} |
| 33 | + |
| 34 | +func New(ctx context.Context, opts apiv1.Options) (*KMS, error) { |
| 35 | + return newKMS(ctx, opts) |
| 36 | +} |
| 37 | + |
| 38 | +func (k *KMS) GetPublicKey(req *apiv1.GetPublicKeyRequest) (crypto.PublicKey, error) { |
| 39 | + return k.backend.GetPublicKey(req) |
| 40 | +} |
| 41 | + |
| 42 | +func (k *KMS) CreateKey(req *apiv1.CreateKeyRequest) (*apiv1.CreateKeyResponse, error) { |
| 43 | + return k.backend.CreateKey(req) |
| 44 | +} |
| 45 | + |
| 46 | +func (k *KMS) CreateSigner(req *apiv1.CreateSignerRequest) (crypto.Signer, error) { |
| 47 | + return k.backend.CreateSigner(req) |
| 48 | +} |
| 49 | + |
| 50 | +func (k *KMS) Close() error { |
| 51 | + return k.backend.Close() |
| 52 | +} |
| 53 | + |
| 54 | +func (k *KMS) DeleteKey(req *apiv1.DeleteKeyRequest) error { |
| 55 | + return k.backend.DeleteKey(req) |
| 56 | +} |
| 57 | + |
| 58 | +func (k *KMS) LoadCertificate(req *apiv1.LoadCertificateRequest) (*x509.Certificate, error) { |
| 59 | + return k.backend.LoadCertificate(req) |
| 60 | +} |
| 61 | + |
| 62 | +func (k *KMS) StoreCertificate(req *apiv1.StoreCertificateRequest) error { |
| 63 | + return k.backend.StoreCertificate(req) |
| 64 | +} |
| 65 | + |
| 66 | +func (k *KMS) LoadCertificateChain(req *apiv1.LoadCertificateChainRequest) ([]*x509.Certificate, error) { |
| 67 | + return k.backend.LoadCertificateChain(req) |
| 68 | +} |
| 69 | + |
| 70 | +func (k *KMS) StoreCertificateChain(req *apiv1.StoreCertificateChainRequest) error { |
| 71 | + if km, ok := k.backend.(apiv1.CertificateChainManager); ok { |
| 72 | + return km.StoreCertificateChain(req) |
| 73 | + } |
| 74 | + |
| 75 | + return apiv1.NotImplementedError{} |
| 76 | +} |
0 commit comments