Skip to content

Commit 7fa0664

Browse files
committedOct 26, 2018
change step provisioner OID and ASN1 representation
1 parent 71a3587 commit 7fa0664

File tree

2 files changed

+24
-32
lines changed

2 files changed

+24
-32
lines changed
 

Diff for: ‎authority/tls.go

+17-18
Original file line numberDiff line numberDiff line change
@@ -30,35 +30,34 @@ type SignOptions struct {
3030
}
3131

3232
var (
33-
stepOIDRoot = asn1.ObjectIdentifier([]int{1, 3, 6, 1, 4, 1, 37476, 9000, 64})
34-
stepOIDProvisioner = asn1.ObjectIdentifier(append([]int(nil), append(stepOIDRoot, 1)...))
35-
stepOIDProvisionerName = asn1.ObjectIdentifier(append([]int(nil), append(stepOIDProvisioner, 1)...))
36-
stepOIDProvisionerKeyID = asn1.ObjectIdentifier(append([]int(nil), append(stepOIDProvisioner, 2)...))
33+
stepOIDRoot = asn1.ObjectIdentifier{1, 3, 6, 1, 4, 1, 37476, 9000, 64}
34+
stepOIDProvisioner = append(asn1.ObjectIdentifier(nil), append(stepOIDRoot, 1)...)
3735
)
3836

37+
type stepProvisionerASN1 struct {
38+
Type int
39+
Name []byte
40+
CredentialID []byte
41+
}
42+
43+
const provisionerTypeJWK = 1
44+
3945
func withProvisionerOID(name, kid string) x509util.WithOption {
4046
return func(p x509util.Profile) error {
4147
crt := p.Subject()
4248

43-
irw := asn1.RawValue{Tag: asn1.TagGeneralString, Class: asn1.ClassPrivate, Bytes: []byte(name)}
44-
krw := asn1.RawValue{Tag: asn1.TagGeneralString, Class: asn1.ClassPrivate, Bytes: []byte(kid)}
45-
46-
irwb, err := asn1.Marshal(irw)
47-
if err != nil {
48-
return err
49-
}
50-
krwb, err := asn1.Marshal(krw)
49+
b, err := asn1.Marshal(stepProvisionerASN1{
50+
Type: provisionerTypeJWK,
51+
Name: []byte(name),
52+
CredentialID: []byte(kid),
53+
})
5154
if err != nil {
5255
return err
5356
}
5457
crt.ExtraExtensions = append(crt.ExtraExtensions, pkix.Extension{
55-
Id: stepOIDProvisionerName,
56-
Critical: false,
57-
Value: irwb,
58-
}, pkix.Extension{
59-
Id: stepOIDProvisionerKeyID,
58+
Id: stepOIDProvisioner,
6059
Critical: false,
61-
Value: krwb,
60+
Value: b,
6261
})
6362

6463
return nil

Diff for: ‎authority/tls_test.go

+7-14
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,6 @@ func TestSign(t *testing.T) {
148148
}
149149

150150
for name, genTestCase := range tests {
151-
if name != "ok" {
152-
continue
153-
}
154151
t.Run(name, func(t *testing.T) {
155152
tc := genTestCase(t)
156153

@@ -199,22 +196,18 @@ func TestSign(t *testing.T) {
199196
found := 0
200197
for _, ext := range leaf.Extensions {
201198
id := ext.Id.String()
202-
if id != stepOIDProvisionerName.String() && id != stepOIDProvisionerKeyID.String() {
199+
if id != stepOIDProvisioner.String() {
203200
continue
204201
}
205202
found++
206-
rw := asn1.RawValue{}
207-
_, err := asn1.Unmarshal(ext.Value, &rw)
203+
val := stepProvisionerASN1{}
204+
_, err := asn1.Unmarshal(ext.Value, &val)
208205
assert.FatalError(t, err)
209-
assert.Equals(t, rw.Tag, asn1.TagGeneralString)
210-
assert.Equals(t, rw.Class, asn1.ClassPrivate)
211-
if id == stepOIDProvisionerName.String() {
212-
assert.Equals(t, string(rw.Bytes), p.Issuer)
213-
} else {
214-
assert.Equals(t, string(rw.Bytes), p.Key.KeyID)
215-
}
206+
assert.Equals(t, val.Type, provisionerTypeJWK)
207+
assert.Equals(t, val.Name, []byte(p.Issuer))
208+
assert.Equals(t, val.CredentialID, []byte(p.Key.KeyID))
216209
}
217-
assert.Equals(t, found, 2)
210+
assert.Equals(t, found, 1)
218211

219212
realIntermediate, err := x509.ParseCertificate(a.intermediateIdentity.Crt.Raw)
220213
assert.FatalError(t, err)

0 commit comments

Comments
 (0)