Skip to content

Commit 5fd70af

Browse files
committed
Make API responses aware of the new SCEP decrypter properties
1 parent 3ade92f commit 5fd70af

File tree

3 files changed

+35
-14
lines changed

3 files changed

+35
-14
lines changed

api/api_test.go

+21-7
Original file line numberDiff line numberDiff line change
@@ -1569,7 +1569,6 @@ func mustCertificate(t *testing.T, pub, priv interface{}) *x509.Certificate {
15691569
}
15701570

15711571
func TestProvisionersResponse_MarshalJSON(t *testing.T) {
1572-
15731572
k := map[string]any{
15741573
"use": "sig",
15751574
"kty": "EC",
@@ -1581,9 +1580,14 @@ func TestProvisionersResponse_MarshalJSON(t *testing.T) {
15811580
}
15821581
key := squarejose.JSONWebKey{}
15831582
b, err := json.Marshal(k)
1584-
assert.FatalError(t, err)
1583+
require.NoError(t, err)
15851584
err = json.Unmarshal(b, &key)
1586-
assert.FatalError(t, err)
1585+
require.NoError(t, err)
1586+
1587+
var encodedPassword bytes.Buffer
1588+
enc := base64.NewEncoder(base64.StdEncoding, &encodedPassword)
1589+
_, err = enc.Write([]byte("super-secret-password"))
1590+
require.NoError(t, err)
15871591

15881592
r := ProvisionersResponse{
15891593
Provisioners: provisioner.List{
@@ -1593,9 +1597,12 @@ func TestProvisionersResponse_MarshalJSON(t *testing.T) {
15931597
ChallengePassword: "not-so-secret",
15941598
MinimumPublicKeyLength: 2048,
15951599
EncryptionAlgorithmIdentifier: 2,
1600+
IncludeRoot: true,
1601+
ExcludeIntermediate: true,
15961602
DecrypterCertificate: []byte{1, 2, 3, 4},
1597-
DecrypterKey: "softkms:path=/path/to/private.key",
1598-
DecrypterKeyPassword: "super-secret-password",
1603+
DecrypterKeyPEM: []byte{5, 6, 7, 8},
1604+
DecrypterKeyURI: "softkms:path=/path/to/private.key",
1605+
DecrypterKeyPassword: encodedPassword.Bytes(),
15991606
},
16001607
&provisioner.JWK{
16011608
EncryptedKey: "eyJhbGciOiJQQkVTMi1IUzI1NitBMTI4S1ciLCJlbmMiOiJBMTI4R0NNIiwicDJjIjoxMDAwMDAsInAycyI6IlhOdmYxQjgxSUlLMFA2NUkwcmtGTGcifQ.XaN9zcPQeWt49zchUDm34FECUTHfQTn_.tmNHPQDqR3ebsWfd.9WZr3YVdeOyJh36vvx0VlRtluhvYp4K7jJ1KGDr1qypwZ3ziBVSNbYYQ71du7fTtrnfG1wgGTVR39tWSzBU-zwQ5hdV3rpMAaEbod5zeW6SHd95H3Bvcb43YiiqJFNL5sGZzFb7FqzVmpsZ1efiv6sZaGDHtnCAL6r12UG5EZuqGfM0jGCZitUz2m9TUKXJL5DJ7MOYbFfkCEsUBPDm_TInliSVn2kMJhFa0VOe5wZk5YOuYM3lNYW64HGtbf-llN2Xk-4O9TfeSPizBx9ZqGpeu8pz13efUDT2WL9tWo6-0UE-CrG0bScm8lFTncTkHcu49_a5NaUBkYlBjEiw.thPcx3t1AUcWuEygXIY3Fg",
@@ -1612,9 +1619,13 @@ func TestProvisionersResponse_MarshalJSON(t *testing.T) {
16121619
{
16131620
"type": "scep",
16141621
"name": "scep",
1622+
"forceCN": false,
1623+
"includeRoot": true,
1624+
"excludeIntermediate": true,
16151625
"challenge": "*** REDACTED ***",
16161626
"decrypterCertificate": "*** REDACTED ***",
16171627
"decrypterKey": "*** REDACTED ***",
1628+
"decrypterKeyPEM": "*** REDACTED ***",
16181629
"decrypterKeyPassword": "*** REDACTED ***",
16191630
"minimumPublicKeyLength": 2048,
16201631
"encryptionAlgorithmIdentifier": 2,
@@ -1652,9 +1663,12 @@ func TestProvisionersResponse_MarshalJSON(t *testing.T) {
16521663
ChallengePassword: "not-so-secret",
16531664
MinimumPublicKeyLength: 2048,
16541665
EncryptionAlgorithmIdentifier: 2,
1666+
IncludeRoot: true,
1667+
ExcludeIntermediate: true,
16551668
DecrypterCertificate: []byte{1, 2, 3, 4},
1656-
DecrypterKey: "softkms:path=/path/to/private.key",
1657-
DecrypterKeyPassword: "super-secret-password",
1669+
DecrypterKeyPEM: []byte{5, 6, 7, 8},
1670+
DecrypterKeyURI: "softkms:path=/path/to/private.key",
1671+
DecrypterKeyPassword: encodedPassword.Bytes(),
16581672
},
16591673
&provisioner.JWK{
16601674
EncryptedKey: "eyJhbGciOiJQQkVTMi1IUzI1NitBMTI4S1ciLCJlbmMiOiJBMTI4R0NNIiwicDJjIjoxMDAwMDAsInAycyI6IlhOdmYxQjgxSUlLMFA2NUkwcmtGTGcifQ.XaN9zcPQeWt49zchUDm34FECUTHfQTn_.tmNHPQDqR3ebsWfd.9WZr3YVdeOyJh36vvx0VlRtluhvYp4K7jJ1KGDr1qypwZ3ziBVSNbYYQ71du7fTtrnfG1wgGTVR39tWSzBU-zwQ5hdV3rpMAaEbod5zeW6SHd95H3Bvcb43YiiqJFNL5sGZzFb7FqzVmpsZ1efiv6sZaGDHtnCAL6r12UG5EZuqGfM0jGCZitUz2m9TUKXJL5DJ7MOYbFfkCEsUBPDm_TInliSVn2kMJhFa0VOe5wZk5YOuYM3lNYW64HGtbf-llN2Xk-4O9TfeSPizBx9ZqGpeu8pz13efUDT2WL9tWo6-0UE-CrG0bScm8lFTncTkHcu49_a5NaUBkYlBjEiw.thPcx3t1AUcWuEygXIY3Fg",

api/models/scep.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ type SCEP struct {
1919
ID string `json:"-"`
2020
Type string `json:"type"`
2121
Name string `json:"name"`
22-
ForceCN bool `json:"forceCN,omitempty"`
23-
ChallengePassword string `json:"challenge,omitempty"`
22+
ForceCN bool `json:"forceCN"`
23+
ChallengePassword string `json:"challenge"`
2424
Capabilities []string `json:"capabilities,omitempty"`
25-
IncludeRoot bool `json:"includeRoot,omitempty"`
26-
ExcludeIntermediate bool `json:"excludeIntermediate,omitempty"`
27-
MinimumPublicKeyLength int `json:"minimumPublicKeyLength,omitempty"`
25+
IncludeRoot bool `json:"includeRoot"`
26+
ExcludeIntermediate bool `json:"excludeIntermediate"`
27+
MinimumPublicKeyLength int `json:"minimumPublicKeyLength"`
2828
DecrypterCertificate string `json:"decrypterCertificate"`
2929
DecrypterKeyPEM string `json:"decrypterKeyPEM"`
3030
DecrypterKeyURI string `json:"decrypterKey"`
3131
DecrypterKeyPassword string `json:"decrypterKeyPassword"`
32-
EncryptionAlgorithmIdentifier int `json:"encryptionAlgorithmIdentifier,omitempty"`
32+
EncryptionAlgorithmIdentifier int `json:"encryptionAlgorithmIdentifier"`
3333
Options *provisioner.Options `json:"options,omitempty"`
3434
Claims *provisioner.Claims `json:"claims,omitempty"`
3535
}

authority/provisioners.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,8 @@ func ProvisionerToCertificates(p *linkedca.Provisioner) (provisioner.Interface,
990990
}
991991
if decrypter := cfg.GetDecrypter(); decrypter != nil {
992992
s.DecrypterCertificate = decrypter.DecrypterCertificate
993-
s.DecrypterKey = decrypter.DecrypterKey
993+
s.DecrypterKeyPEM = decrypter.DecrypterKey
994+
s.DecrypterKeyURI = decrypter.DecrypterKeyUri
994995
s.DecrypterKeyPassword = decrypter.DecrypterKeyPassword
995996
}
996997
return s, nil
@@ -1250,6 +1251,12 @@ func ProvisionerToLinkedca(p provisioner.Interface) (*linkedca.Provisioner, erro
12501251
IncludeRoot: p.IncludeRoot,
12511252
ExcludeIntermediate: p.ExcludeIntermediate,
12521253
EncryptionAlgorithmIdentifier: int32(p.EncryptionAlgorithmIdentifier),
1254+
Decrypter: &linkedca.SCEPDecrypter{
1255+
DecrypterCertificate: p.DecrypterCertificate,
1256+
DecrypterKey: p.DecrypterKeyPEM,
1257+
DecrypterKeyUri: p.DecrypterKeyURI,
1258+
DecrypterKeyPassword: p.DecrypterKeyPassword,
1259+
},
12531260
},
12541261
},
12551262
},

0 commit comments

Comments
 (0)