@@ -35,6 +35,8 @@ const (
35
35
protocolMajor = 1
36
36
protocolMinor = 4
37
37
38
+ // Expected secret data length in bits
39
+ cryptographicLength = 256
38
40
)
39
41
40
42
// KMIPSecretStorage is a KMIP backend Key Management Systems (KMS)
@@ -208,7 +210,7 @@ func (k *KMIPSecretStorage) response(respMsg *kmip.ResponseMessage, operation km
208
210
return nil , fmt .Errorf ("Unexpected uniqueBatchItemID, real %v expected %v" , bi .UniqueBatchItemID , uniqueBatchItemID )
209
211
}
210
212
if kmip14 .ResultStatusSuccess != bi .ResultStatus {
211
- return nil , fmt .Errorf ("Unexpected result status %v expected success %v" , bi .ResultStatus , kmip14 . ResultStatusSuccess )
213
+ return nil , fmt .Errorf ("Unexpected result status %v: Reason: %v Message: %v" , bi .ResultStatus , bi . ResultReason , bi . ResultMessage )
212
214
}
213
215
214
216
return & bi , nil
@@ -261,14 +263,21 @@ func (k *KMIPSecretStorage) GetSecret(
261
263
log := util .Logger ()
262
264
263
265
lookfor := KMIPUniqueID // Addition to upgrade
266
+ var activeKeyID string
264
267
if strings .HasSuffix (secretID , "-root-master-key-backend" ) {
265
268
lookfor = NewKMIPUniqueID
269
+ exists := false
270
+ activeKeyID , exists = k .secret .StringData [NewActiveKeyID ]
271
+ if ! exists {
272
+ log .Errorf ("KMIPSecretStorage.GetSecret() activeKeyID %v does not exist in secret %v" , activeKeyID , k .secret .Name )
273
+ return nil , secrets .NoVersion , secrets .ErrInvalidSecretId
274
+ }
266
275
}
267
276
268
277
// KMIP key uniqueIdentifier
269
278
uniqueIdentifier , exists := k .secret .StringData [lookfor ]
270
279
if ! exists {
271
- log .Errorf ("KMIPSecretStorage.GetSecret() uniqueIdentifier %v does not exist in secret %v" , lookfor , k .secret )
280
+ log .Errorf ("KMIPSecretStorage.GetSecret() uniqueIdentifier %v does not exist in secret %v" , lookfor , k .secret . Name )
272
281
return nil , secrets .NoVersion , secrets .ErrInvalidSecretId
273
282
}
274
283
@@ -306,6 +315,9 @@ func (k *KMIPSecretStorage) GetSecret(
306
315
if getRespPayload .SymmetricKey == nil {
307
316
return nil , secrets .NoVersion , fmt .Errorf ("Unexpected get response SymmetricKey can not be nil" )
308
317
}
318
+ if getRespPayload .SymmetricKey .KeyBlock .CryptographicLength != cryptographicLength {
319
+ return nil , secrets .NoVersion , fmt .Errorf ("Unexpected KeyBlock crypto len actual %v, expected %v" , getRespPayload .SymmetricKey .KeyBlock .CryptographicLength , cryptographicLength )
320
+ }
309
321
if getRespPayload .SymmetricKey .KeyBlock .KeyFormatType != kmip14 .KeyFormatTypeRaw {
310
322
return nil , secrets .NoVersion , fmt .Errorf ("Unexpected KeyBlock format type actual %v, expected KeyFormatTypeRaw %v" , getRespPayload .SymmetricKey .KeyBlock .KeyFormatType , kmip14 .KeyFormatTypeRaw )
311
323
}
@@ -316,10 +328,13 @@ func (k *KMIPSecretStorage) GetSecret(
316
328
secretBytes := getRespPayload .SymmetricKey .KeyBlock .KeyValue .KeyMaterial .([]byte )
317
329
secretBase64 := base64 .StdEncoding .EncodeToString (secretBytes )
318
330
319
- // Return the fetched key value
320
- r := map [string ]interface {}{secretID : secretBase64 }
321
-
322
- return r , secrets .NoVersion , nil
331
+ if len (activeKeyID ) > 0 {
332
+ r := map [string ]interface {}{ActiveRootKey : activeKeyID , activeKeyID : secretBase64 }
333
+ return r , secrets .NoVersion , nil
334
+ } else {
335
+ r := map [string ]interface {}{secretID : secretBase64 }
336
+ return r , secrets .NoVersion , nil
337
+ }
323
338
}
324
339
325
340
// PutSecret will associate an secretId to its secret data
@@ -332,7 +347,8 @@ func (k *KMIPSecretStorage) PutSecret(
332
347
log := util .Logger ()
333
348
334
349
// Register the key value the KMIP endpoint
335
- value := plainText [secretID ].(string )
350
+ activeKey := plainText [ActiveRootKey ].(string )
351
+ value := plainText [activeKey ].(string )
336
352
valueBytes , err := base64 .StdEncoding .DecodeString (value )
337
353
if err != nil {
338
354
return secrets .NoVersion , err
@@ -353,7 +369,7 @@ func (k *KMIPSecretStorage) PutSecret(
353
369
KeyValue : & kmip.KeyValue {
354
370
KeyMaterial : valueBytes ,
355
371
},
356
- CryptographicLength : len ( valueBytes ) * 8 , // in bits
372
+ CryptographicLength : cryptographicLength ,
357
373
CryptographicAlgorithm : kmip14 .CryptographicAlgorithmAES ,
358
374
},
359
375
},
@@ -377,6 +393,7 @@ func (k *KMIPSecretStorage) PutSecret(
377
393
return secrets .NoVersion , err
378
394
}
379
395
396
+ k .secret .StringData [NewActiveKeyID ] = activeKey
380
397
k .secret .StringData [NewKMIPUniqueID ] = registerRespPayload .UniqueIdentifier
381
398
if ! util .KubeUpdate (k .secret ) {
382
399
log .Errorf ("Failed to update KMS secret %v in ns %v" , k .secret .Name , k .secret .Namespace )
0 commit comments