@@ -127,11 +127,13 @@ func GetLicense(w http.ResponseWriter, r *http.Request, s Server) {
127
127
problem .Error (w , r , problem.Problem {Detail : err .Error ()}, http .StatusInternalServerError )
128
128
return
129
129
}
130
+
131
+ encrypter := s .Encrypter ()
130
132
131
- ExistingLicense .Encryption .ContentKey .Algorithm = "http://www.w3.org/2001/04/xmlenc#aes256-cbc"
132
- ExistingLicense .Encryption .ContentKey .Value = encryptKey (content .EncryptionKey , ExistingLicense .Encryption .UserKey .Value ) //use old UserKey.Value
133
+ ExistingLicense .Encryption .ContentKey .Algorithm = encrypter . Signature ()
134
+ ExistingLicense .Encryption .ContentKey .Value = encryptKey (encrypter , content .EncryptionKey , ExistingLicense .Encryption .UserKey .Value ) //use old UserKey.Value
133
135
ExistingLicense .Encryption .UserKey .Algorithm = "http://www.w3.org/2001/04/xmlenc#sha256"
134
- err = buildKeyCheck (& ExistingLicense , ExistingLicense .Encryption .UserKey .Value )
136
+ err = buildKeyCheck (encrypter , & ExistingLicense , ExistingLicense .Encryption .UserKey .Value )
135
137
if err != nil {
136
138
problem .Error (w , r , problem.Problem {Detail : err .Error ()}, http .StatusBadRequest )
137
139
return
@@ -410,6 +412,8 @@ func completeLicense(l *license.License, key string, s Server) error {
410
412
return err
411
413
}
412
414
415
+ encrypter := s .Encrypter ()
416
+
413
417
license .Prepare (l )
414
418
l .ContentId = key
415
419
links := new ([]license.Link )
@@ -450,15 +454,15 @@ func completeLicense(l *license.License, key string, s Server) error {
450
454
encryptionKey = hash [:]
451
455
}
452
456
453
- l .Encryption .ContentKey .Algorithm = "http://www.w3.org/2001/04/xmlenc#aes256-cbc"
454
- l .Encryption .ContentKey .Value = encryptKey (c .EncryptionKey , encryptionKey [:])
457
+ l .Encryption .ContentKey .Algorithm = encrypter . Signature ()
458
+ l .Encryption .ContentKey .Value = encryptKey (encrypter , c .EncryptionKey , encryptionKey [:])
455
459
l .Encryption .UserKey .Algorithm = "http://www.w3.org/2001/04/xmlenc#sha256"
456
460
457
- err = encryptFields (l , encryptionKey [:])
461
+ err = encryptFields (encrypter , l , encryptionKey [:])
458
462
if err != nil {
459
463
return err
460
464
}
461
- err = buildKeyCheck (l , encryptionKey [:])
465
+ err = buildKeyCheck (encrypter , l , encryptionKey [:])
462
466
if err != nil {
463
467
return err
464
468
}
@@ -474,21 +478,21 @@ func completeLicense(l *license.License, key string, s Server) error {
474
478
return nil
475
479
}
476
480
477
- func buildKeyCheck (l * license.License , key []byte ) error {
481
+ func buildKeyCheck (encrypter crypto. Encrypter , l * license.License , key []byte ) error {
478
482
var out bytes.Buffer
479
- err := crypto .Encrypt (key , bytes .NewBufferString (l .Id ), & out )
483
+ err := encrypter .Encrypt (key , bytes .NewBufferString (l .Id ), & out )
480
484
if err != nil {
481
485
return err
482
486
}
483
487
l .Encryption .UserKey .Check = out .Bytes ()
484
488
return nil
485
489
}
486
490
487
- func encryptFields (l * license.License , key []byte ) error {
491
+ func encryptFields (encrypter crypto. Encrypter , l * license.License , key []byte ) error {
488
492
for _ , toEncrypt := range l .User .Encrypted {
489
493
var out bytes.Buffer
490
494
field := getField (& l .User , toEncrypt )
491
- err := crypto .Encrypt (key [:], bytes .NewBufferString (field .String ()), & out )
495
+ err := encrypter .Encrypt (key [:], bytes .NewBufferString (field .String ()), & out )
492
496
if err != nil {
493
497
return err
494
498
}
@@ -516,10 +520,10 @@ func signLicense(l *license.License, cert *tls.Certificate) error {
516
520
return nil
517
521
}
518
522
519
- func encryptKey (key []byte , kek []byte ) []byte {
523
+ func encryptKey (encrypter crypto. Encrypter , key []byte , kek []byte ) []byte {
520
524
var out bytes.Buffer
521
525
in := bytes .NewReader (key )
522
- crypto .Encrypt (kek [:], in , & out )
526
+ encrypter .Encrypt (kek [:], in , & out )
523
527
return out .Bytes ()
524
528
}
525
529
0 commit comments