Skip to content

Commit 625465a

Browse files
committed
Use Policy field for CA policies
Signed-off-by: Sorin Dumitru <[email protected]>
1 parent 9b7f71d commit 625465a

File tree

6 files changed

+131
-100
lines changed

6 files changed

+131
-100
lines changed

pkg/server/ca/manager/manager_test.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"crypto/rsa"
88
"crypto/x509"
99
"crypto/x509/pkix"
10-
"encoding/asn1"
1110
"errors"
1211
"fmt"
1312
"math/big"
@@ -161,17 +160,17 @@ func TestCAPolicyIdentifiers(t *testing.T) {
161160

162161
test := setupTest(t)
163162
test.initSelfSignedManager()
164-
test.cc.policyIdentifiers = []asn1.ObjectIdentifier{
165-
asn1.ObjectIdentifier{1, 2, 3, 4},
166-
}
163+
policy, err := x509.ParseOID("1.2.3.4")
164+
require.NoError(t, err)
165+
test.cc.policies = append(test.cc.policies, policy)
167166

168167
t.Run("contains policy identifiers", func(t *testing.T) {
169168
require.NoError(t, test.m.PrepareX509CA(ctx))
170169

171170
currentSlot := test.m.GetCurrentX509CASlot()
172171
slot := currentSlot.(*x509CASlot)
173172
require.NotNil(t, slot.x509CA)
174-
require.Equal(t, slot.x509CA.Certificate.PolicyIdentifiers, test.cc.policyIdentifiers)
173+
require.Equal(t, slot.x509CA.Certificate.Policies, test.cc.policies)
175174
})
176175
}
177176

@@ -1575,11 +1574,11 @@ func (s *fakeCA) NotifyTaintedX509Authorities(taintedAuthorities []*x509.Certifi
15751574
type fakeCC struct {
15761575
catalog.PluginInfo
15771576

1578-
policyIdentifiers []asn1.ObjectIdentifier
1577+
policies []x509.OID
15791578
}
15801579

15811580
func (cc fakeCC) ComposeServerX509CA(_ context.Context, attributes credentialcomposer.X509CAAttributes) (credentialcomposer.X509CAAttributes, error) {
1582-
attributes.PolicyIdentifiers = append(attributes.PolicyIdentifiers, cc.policyIdentifiers...)
1581+
attributes.Policies = append(attributes.Policies, cc.policies...)
15831582
return attributes, nil
15841583
}
15851584

pkg/server/credtemplate/builder.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,9 @@ func (b *Builder) BuildSelfSignedX509CATemplate(ctx context.Context, params Self
181181
if err != nil {
182182
return nil, err
183183
}
184-
applyX509CAAttributes(tmpl, attributes)
184+
if err := applyX509CAAttributes(tmpl, attributes); err != nil {
185+
return nil, err
186+
}
185187
}
186188

187189
return tmpl, nil
@@ -198,11 +200,13 @@ func (b *Builder) BuildUpstreamSignedX509CACSR(ctx context.Context, params Upstr
198200
if err != nil {
199201
return nil, err
200202
}
201-
applyX509CAAttributes(tmpl, attributes)
203+
if err := applyX509CAAttributes(tmpl, attributes); err != nil {
204+
return nil, err
205+
}
202206
}
203207

204208
// Create the CertificateRequest from the Certificate template. The
205-
// PolicyIdentifiers field is ignored since that can be applied by the
209+
// Policies field is ignored since that can be applied by the
206210
// upstream signer and isn't a part of the native CertificateRequest type.
207211
// TODO: maybe revisit this if needed and embed the policy identifiers in
208212
// the extra extensions.
@@ -237,7 +241,9 @@ func (b *Builder) BuildDownstreamX509CATemplate(ctx context.Context, params Down
237241
if err != nil {
238242
return nil, err
239243
}
240-
applyX509CAAttributes(tmpl, attributes)
244+
if err := applyX509CAAttributes(tmpl, attributes); err != nil {
245+
return nil, err
246+
}
241247
}
242248

243249
return tmpl, nil
@@ -458,9 +464,9 @@ func (b *Builder) computeX509SVIDLifetime(parentChain []*x509.Certificate, ttl t
458464

459465
func x509CAAttributesFromTemplate(tmpl *x509.Certificate) credentialcomposer.X509CAAttributes {
460466
return credentialcomposer.X509CAAttributes{
461-
Subject: tmpl.Subject,
462-
PolicyIdentifiers: tmpl.PolicyIdentifiers,
463-
ExtraExtensions: tmpl.ExtraExtensions,
467+
Subject: tmpl.Subject,
468+
Policies: tmpl.Policies,
469+
ExtraExtensions: tmpl.ExtraExtensions,
464470
}
465471
}
466472
func x509SVIDAttributesFromTemplate(tmpl *x509.Certificate) credentialcomposer.X509SVIDAttributes {
@@ -471,10 +477,11 @@ func x509SVIDAttributesFromTemplate(tmpl *x509.Certificate) credentialcomposer.X
471477
}
472478
}
473479

474-
func applyX509CAAttributes(tmpl *x509.Certificate, attribs credentialcomposer.X509CAAttributes) {
480+
func applyX509CAAttributes(tmpl *x509.Certificate, attribs credentialcomposer.X509CAAttributes) error {
475481
tmpl.Subject = attribs.Subject
476-
tmpl.PolicyIdentifiers = attribs.PolicyIdentifiers
482+
tmpl.Policies = attribs.Policies
477483
tmpl.ExtraExtensions = attribs.ExtraExtensions
484+
return nil
478485
}
479486

480487
func applyX509SVIDAttributes(tmpl *x509.Certificate, attribs credentialcomposer.X509SVIDAttributes) {

0 commit comments

Comments
 (0)