@@ -38,6 +38,10 @@ type CRL struct {
38
38
// All Certificates must be issued by the same Issuer.
39
39
// Self-signed certificates cannot be added.
40
40
Revoked []* Certificate
41
+
42
+ // Issuer is the CA certificate issuing this CRL.
43
+ // If not set, it defaults to the issuer of certificates added to Revoked list.
44
+ Issuer * Certificate
41
45
}
42
46
43
47
// Add appends a Certificate to CRL list.
@@ -58,8 +62,11 @@ func (crl *CRL) Add(cert *Certificate) error {
58
62
// DER returns the CRL as DER buffer.
59
63
// Error is not nil if generation fails.
60
64
func (crl * CRL ) DER () (crlBytes []byte , err error ) {
61
- if len (crl .Revoked ) == 0 {
62
- return nil , fmt .Errorf ("certificates have not been added to CRL" )
65
+ if crl .Issuer == nil {
66
+ if len (crl .Revoked ) == 0 {
67
+ return nil , fmt .Errorf ("Issuer not known: either set Issuer or add certificates to the CRL" )
68
+ }
69
+ crl .Issuer = crl .Revoked [0 ].Issuer
63
70
}
64
71
65
72
effectiveRevocationTime := time .Now ()
@@ -73,8 +80,6 @@ func (crl *CRL) DER() (crlBytes []byte, err error) {
73
80
effectiveExpiry = * crl .NextUpdate
74
81
}
75
82
76
- issuer := crl .Revoked [0 ].Issuer
77
-
78
83
var revokedCerts []pkix.RevokedCertificate
79
84
for _ , c := range crl .Revoked {
80
85
err := c .ensureGenerated ()
@@ -83,21 +88,21 @@ func (crl *CRL) DER() (crlBytes []byte, err error) {
83
88
}
84
89
if c .Issuer == nil {
85
90
return nil , fmt .Errorf ("cannot revoke self-signed certificate: %s" , c .Subject )
86
- } else if c .Issuer != issuer {
87
- return nil , fmt .Errorf ("CRL can contain certificates for single issuer only " )
91
+ } else if c .Issuer != crl . Issuer {
92
+ return nil , fmt .Errorf ("revoked certificates added from several issuers, or certificate does not match explicitly set Issuer " )
88
93
}
89
94
revokedCerts = append (revokedCerts , pkix.RevokedCertificate {
90
95
SerialNumber : c .SerialNumber ,
91
96
RevocationTime : effectiveRevocationTime ,
92
97
})
93
98
}
94
99
95
- ca , err := issuer .X509Certificate ()
100
+ ca , err := crl . Issuer .X509Certificate ()
96
101
if err != nil {
97
102
return nil , err
98
103
}
99
104
100
- privateKey , err := issuer .PrivateKey ()
105
+ privateKey , err := crl . Issuer .PrivateKey ()
101
106
if err != nil {
102
107
return nil , err
103
108
}
0 commit comments