Skip to content

Commit ea51cc5

Browse files
pkinit: Replace OID literals by their names
1 parent e406594 commit ea51cc5

4 files changed

Lines changed: 21 additions & 10 deletions

File tree

pkinit/asn1.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@ import (
1111
"github.com/jcmturner/gokrb5/v8/types"
1212
)
1313

14+
var (
15+
signedDataOID = asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 7, 2}
16+
idPKINITAuthDataOID = asn1.ObjectIdentifier{1, 3, 6, 1, 5, 2, 3, 1}
17+
idPKINITDHKeyDataOID = asn1.ObjectIdentifier{1, 3, 6, 1, 5, 2, 3, 2}
18+
sha1HashOID = asn1.ObjectIdentifier{1, 3, 14, 3, 2, 26}
19+
sha1WithRSAEncryptionOID = asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 1, 5}
20+
contentTypeOID = asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 9, 3}
21+
ephemeralStaticDiffieHellmanKeyAgreementAlgorithmOID = asn1.ObjectIdentifier{1, 2, 840, 10046, 2, 1}
22+
messageDigestOID = asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 9, 4}
23+
)
24+
1425
type SignerInfo struct {
1526
Version int `asn1:"default:1"`
1627
IssuerAndSerialNumber IssuerAndSerial

pkinit/asrep.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func ExtractNegotiatedKey(
6363
return ekey, fmt.Errorf("unmarshal signed data: %w", err)
6464
}
6565

66-
if !contentInfo.ContentType.Equal(asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 7, 2}) {
66+
if !contentInfo.ContentType.Equal(signedDataOID) {
6767
return ekey, fmt.Errorf("unexpected outer content type: %s", contentInfo.ContentType)
6868
}
6969

@@ -74,7 +74,7 @@ func ExtractNegotiatedKey(
7474
return ekey, fmt.Errorf("unmarshal signed data: %w", err)
7575
}
7676

77-
if !signedData.ContentInfo.ContentType.Equal(asn1.ObjectIdentifier{1, 3, 6, 1, 5, 2, 3, 2}) {
77+
if !signedData.ContentInfo.ContentType.Equal(idPKINITDHKeyDataOID) {
7878
return ekey, fmt.Errorf("unexpected inner content type: %s", signedData.ContentInfo.ContentType)
7979
}
8080

pkinit/asreq.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func ConfigureASReq(
5858
},
5959
ClientPublicValue: SubjectPublicKeyInfo{
6060
Algorithm: AlgorithmIdentifier{
61-
Algorithm: asn1.ObjectIdentifier{1, 2, 840, 10046, 2, 1},
61+
Algorithm: ephemeralStaticDiffieHellmanKeyAgreementAlgorithmOID,
6262
Parameters: DomainParameters{
6363
P: DiffieHellmanPrime,
6464
G: 2,

pkinit/pkcs7.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,29 +29,29 @@ func PKCS7Sign(data []byte, key *rsa.PrivateKey, cert *x509.Certificate) ([]byte
2929
return nil, fmt.Errorf("marshal digest: %w", err)
3030
}
3131

32-
serializedPKInitOID, err := asn1.Marshal(asn1.ObjectIdentifier{1, 3, 6, 1, 5, 2, 3, 1})
32+
serializedPKInitOID, err := asn1.Marshal(idPKINITAuthDataOID)
3333
if err != nil {
3434
return nil, fmt.Errorf("marshal PKInit OID: %w", err)
3535
}
3636

3737
sha1AlgorithmIdentifier := pkix.AlgorithmIdentifier{
38-
Algorithm: asn1.ObjectIdentifier{1, 3, 14, 3, 2, 26},
38+
Algorithm: sha1HashOID,
3939
}
4040

4141
rsaWithSHA1AlgorithmIdentifier := pkix.AlgorithmIdentifier{
42-
Algorithm: asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 1, 5},
42+
Algorithm: sha1WithRSAEncryptionOID,
4343
}
4444

4545
authenticatedAttributes := []Attribute{
4646
{
4747
// ContentType
48-
Type: asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 9, 3},
48+
Type: contentTypeOID,
4949
// id-pkinit-authData
5050
Value: asn1.RawValue{Tag: 17, IsCompound: true, Bytes: serializedPKInitOID},
5151
},
5252
{
5353
// MessageDigest
54-
Type: asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 9, 4},
54+
Type: messageDigestOID,
5555
Value: asn1.RawValue{Tag: 17, IsCompound: true, Bytes: serializedDigest},
5656
},
5757
}
@@ -66,7 +66,7 @@ func PKCS7Sign(data []byte, key *rsa.PrivateKey, cert *x509.Certificate) ([]byte
6666
DigestAlgorithmIdentifiers: []pkix.AlgorithmIdentifier{sha1AlgorithmIdentifier},
6767
ContentInfo: ContentInfo{
6868
// id-pkinit-authData
69-
ContentType: asn1.ObjectIdentifier{1, 3, 6, 1, 5, 2, 3, 1},
69+
ContentType: idPKINITAuthDataOID,
7070
Content: asn1.RawValue{Class: 2, Tag: 0, Bytes: serializedData, IsCompound: true},
7171
},
7272
Certificates: rawCert,
@@ -90,7 +90,7 @@ func PKCS7Sign(data []byte, key *rsa.PrivateKey, cert *x509.Certificate) ([]byte
9090

9191
contentInfo := ContentInfo{
9292
// signed data
93-
ContentType: asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 7, 2},
93+
ContentType: signedDataOID,
9494
Content: asn1.RawValue{Class: 2, Tag: 0, Bytes: signedDataBytes, IsCompound: true},
9595
}
9696

0 commit comments

Comments
 (0)