Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package kms
import (
"context"
"net"
"strconv"
"time"
"code.fbi.h-da.de/danet/quantumlayer"
pb "code.fbi.h-da.de/danet/quipsec/gen/go/quipsec"
"github.com/sirupsen/logrus"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/peer"
"google.golang.org/grpc/status"
)
type quipSecServer struct {
pb.UnimplementedKmsQkdmCommunicationServiceServer
eKMS *EKMS
}
func (qs *quipSecServer) PushKeys(ctx context.Context, req *pb.PushKeysRequest) (*pb.PushKeysResponse, error) {
p, _ := peer.FromContext(ctx)
host, _, err := net.SplitHostPort(p.Addr.String())
if err != nil {
}
for _, qm := range qs.eKMS.quantumModules {
if qm.Address() == host {
eqm, ok := qm.(*EmulatedQuantumModule)
if !ok {
return nil, status.Errorf(codes.Internal, "quantum module is of wrong type")
}
bulkKeyId, err := strconv.ParseInt(req.GetKeyBulk().GetKeyId(), 10, 64)
if err != nil {
return nil, status.Errorf(codes.Internal, "could not get bulkkeyid")
}
req.GetKeyBulk().GetKeyId()
req.GetKeyBulk().GetKeys()
eqm.rawBulkKeysMutex.Lock()
eqm.rawBulkKeys[bulkKeyId] = &quantumlayer.QuantumLayerBulkKey{
BulkKeyId: bulkKeyId,
BulkKeyLength: int(req.GetKeyBulk().GetKeyLength()),
BulkKey: &req.GetKeyBulk().Keys,
}
eqm.rawBulkKeysMutex.Unlock()
logrus.Infof("%s received a new bulk with id: %s and a length of: %d", qs.eKMS.kmsName, req.GetKeyBulk().GetKeyId(), req.GetKeyBulk().GetKeyLength())
return &pb.PushKeysResponse{Timestamp: time.Now().Unix()}, nil
}
}
return nil, status.Errorf(codes.Internal, "could not find a quantum module for host address: %s", host)
}