mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-07-28 09:44:08 -04:00
AB#1943 Extract KMS package (#56)
* Extract kmsapi from coordinator * Add kmsapi cmd server
This commit is contained in:
parent
2a6b1e2277
commit
c63d7126e7
25 changed files with 539 additions and 21 deletions
46
kms/server/kmsapi/kmsapi.go
Normal file
46
kms/server/kmsapi/kmsapi.go
Normal file
|
@ -0,0 +1,46 @@
|
|||
// Package kmsapi implements an API to manage encryption keys.
|
||||
package kmsapi
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/edgelesssys/constellation/kms/kms"
|
||||
"github.com/edgelesssys/constellation/kms/server/kmsapi/kmsproto"
|
||||
"go.uber.org/zap"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
// API resembles an encryption key management api server through logger, CloudKMS and proto-unimplemented server.
|
||||
type API struct {
|
||||
logger *zap.Logger
|
||||
conKMS kms.CloudKMS
|
||||
kmsproto.UnimplementedAPIServer
|
||||
}
|
||||
|
||||
// New creates a new API.
|
||||
func New(logger *zap.Logger, conKMS kms.CloudKMS) *API {
|
||||
return &API{
|
||||
logger: logger,
|
||||
conKMS: conKMS,
|
||||
}
|
||||
}
|
||||
|
||||
// GetDataKey returns a data key.
|
||||
func (a *API) GetDataKey(ctx context.Context, in *kmsproto.GetDataKeyRequest) (*kmsproto.GetDataKeyResponse, error) {
|
||||
// Error on 0 key length
|
||||
if in.Length == 0 {
|
||||
return nil, status.Error(codes.InvalidArgument, "can't derive key with length zero")
|
||||
}
|
||||
|
||||
// Error on empty DataKeyId
|
||||
if in.DataKeyId == "" {
|
||||
return nil, status.Error(codes.InvalidArgument, "no data key id specified")
|
||||
}
|
||||
|
||||
key, err := a.conKMS.GetDEK(ctx, "Constellation", "key-"+in.DataKeyId, int(in.Length))
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "%v", err)
|
||||
}
|
||||
return &kmsproto.GetDataKeyResponse{DataKey: key}, nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue