Skip to content
Snippets Groups Projects

Allow to reset key store and stop key fetching

Merged Malte Bauch requested to merge qkdnm-set-key-store into master
4 files
+ 88
33
Compare changes
  • Side-by-side
  • Inline
Files
4
@@ -31,6 +31,7 @@ type ETSI014HTTPQuantumModule struct {
@@ -31,6 +31,7 @@ type ETSI014HTTPQuantumModule struct {
keyFetchInterval int
keyFetchInterval int
keyFetchAmount int64
keyFetchAmount int64
maxKeyFillLevel uint64
maxKeyFillLevel uint64
 
stopFetch chan struct{}
}
}
func NewETSI014HTTPQuantumModule(addr, kmsId, localSAEID, targetSAEID string, tlsConfig config.TLSConfig, master bool, keyFetchInterval int, keyFetchAmount int64, maxKeyFillLevel uint64) (*ETSI014HTTPQuantumModule, error) {
func NewETSI014HTTPQuantumModule(addr, kmsId, localSAEID, targetSAEID string, tlsConfig config.TLSConfig, master bool, keyFetchInterval int, keyFetchAmount int64, maxKeyFillLevel uint64) (*ETSI014HTTPQuantumModule, error) {
@@ -106,6 +107,8 @@ func (qm *ETSI014HTTPQuantumModule) Client() *etsi14ClientImpl.ClientImpl {
@@ -106,6 +107,8 @@ func (qm *ETSI014HTTPQuantumModule) Client() *etsi14ClientImpl.ClientImpl {
}
}
func (qm *ETSI014HTTPQuantumModule) Initialize() error {
func (qm *ETSI014HTTPQuantumModule) Initialize() error {
 
qm.stopFetch = make(chan struct{}, 0)
 
// start polling keys
// start polling keys
if qm.master {
if qm.master {
go func() {
go func() {
@@ -115,42 +118,47 @@ func (qm *ETSI014HTTPQuantumModule) Initialize() error {
@@ -115,42 +118,47 @@ func (qm *ETSI014HTTPQuantumModule) Initialize() error {
failedAttemps := 0
failedAttemps := 0
// TODO: add context/channel to stop
// TODO: add context/channel to stop
for range ticker.C {
for {
if failedAttemps == maxFailedKeyRequestAttempts {
select {
log.Errorf("stopped trying to fetch keys from qkd module after %d tries", failedAttemps)
case <-ticker.C:
break
if failedAttemps == maxFailedKeyRequestAttempts {
}
log.Errorf("stopped trying to fetch keys from qkd module after %d tries", failedAttemps)
break
if qm.keyStore.Length() < int(qm.maxKeyFillLevel) {
container, err := qm.GetKeys(qm.keyFetchAmount, 256, nil, nil, nil)
if err != nil {
log.Error(err)
failedAttemps++
continue
}
keyIds := make([]string, len(container.GetKeys()))
for i, keyItem := range container.GetKeys() {
keyIds[i] = keyItem.GetKeyID()
}
_, err = qm.kmsClient.KeyIdNotification(context.Background(),
&pbIC.KeyIdNotificationRequest{
Timestamp: time.Now().Unix(),
KmsId: qm.kmsId,
KeyIds: keyIds,
})
if err != nil {
log.Error(err)
failedAttemps++
continue
}
}
if err := store.AddETSIKeysToKeystore(qm.keyStore, container.GetKeys()); err != nil {
if qm.keyStore.Length() < int(qm.maxKeyFillLevel) {
log.Error(err)
container, err := qm.GetKeys(qm.keyFetchAmount, 256, nil, nil, nil)
 
if err != nil {
 
log.Error(err)
 
failedAttemps++
 
continue
 
}
 
 
keyIds := make([]string, len(container.GetKeys()))
 
for i, keyItem := range container.GetKeys() {
 
keyIds[i] = keyItem.GetKeyID()
 
}
 
 
_, err = qm.kmsClient.KeyIdNotification(context.Background(),
 
&pbIC.KeyIdNotificationRequest{
 
Timestamp: time.Now().Unix(),
 
KmsId: qm.kmsId,
 
KeyIds: keyIds,
 
})
 
if err != nil {
 
log.Error(err)
 
failedAttemps++
 
continue
 
}
 
 
if err := store.AddETSIKeysToKeystore(qm.keyStore, container.GetKeys()); err != nil {
 
log.Error(err)
 
}
 
 
failedAttemps = 0
}
}
case <-qm.stopFetch:
failedAttemps = 0
break
}
}
}
}
}()
}()
@@ -158,6 +166,12 @@ func (qm *ETSI014HTTPQuantumModule) Initialize() error {
@@ -158,6 +166,12 @@ func (qm *ETSI014HTTPQuantumModule) Initialize() error {
return nil
return nil
}
}
 
func (qm *ETSI014HTTPQuantumModule) StopKeyFetching() {
 
if qm.master {
 
close(qm.stopFetch)
 
}
 
}
 
func (qm *ETSI014HTTPQuantumModule) SetKmsPeerInformation(kmsClient *GRPCClient, kmsEventBus *event.EventBus, kmsTcpSocketStr string) error {
func (qm *ETSI014HTTPQuantumModule) SetKmsPeerInformation(kmsClient *GRPCClient, kmsEventBus *event.EventBus, kmsTcpSocketStr string) error {
qm.kmsClient = kmsClient
qm.kmsClient = kmsClient
return nil
return nil
Loading