@@ -147,7 +147,7 @@ func (sd *SignedData) SetEncryptionAlgorithm(d asn1.ObjectIdentifier) {
147
147
// AddSigner is a wrapper around AddSignerChain() that adds a signer without any parent.
148
148
func (sd * SignedData ) AddSigner (ee * x509.Certificate , pkey crypto.PrivateKey , config SignerInfoConfig ) error {
149
149
var parents []* x509.Certificate
150
- return sd .addSignerChain (ee , pkey , parents , config , true )
150
+ return sd .addSignerChain (ee , pkey , parents , config , true , true )
151
151
}
152
152
153
153
// One of the practical use cases of AddSignerNoChain is:
@@ -168,7 +168,7 @@ func (sd *SignedData) AddSigner(ee *x509.Certificate, pkey crypto.PrivateKey, co
168
168
// Use this method, if no certificate needs to be placed in SignedData certificates
169
169
func (sd * SignedData ) AddSignerNoChain (ee * x509.Certificate , pkey crypto.PrivateKey , config SignerInfoConfig ) error {
170
170
var parents []* x509.Certificate
171
- return sd .addSignerChain (ee , pkey , parents , config , false )
171
+ return sd .addSignerChain (ee , pkey , parents , config , false , true )
172
172
}
173
173
174
174
// AddSignerChain signs attributes about the content and adds certificates
@@ -185,10 +185,29 @@ func (sd *SignedData) AddSignerNoChain(ee *x509.Certificate, pkey crypto.Private
185
185
// section of the SignedData.SignerInfo, alongside the serial number of
186
186
// the end-entity.
187
187
func (sd * SignedData ) AddSignerChain (ee * x509.Certificate , pkey crypto.PrivateKey , chain []* x509.Certificate , config SignerInfoConfig ) error {
188
- return sd .addSignerChain (ee , pkey , chain , config , true )
188
+ return sd .addSignerChain (ee , pkey , chain , config , true , true )
189
189
}
190
190
191
- func (sd * SignedData ) addSignerChain (ee * x509.Certificate , pkey crypto.PrivateKey , chain []* x509.Certificate , config SignerInfoConfig , includeCertificates bool ) error {
191
+ // AddSignerChainPAdES signs attributes about the content and adds certificates
192
+ // and signers infos to the Signed Data. The certificate and private
193
+ // of the end-entity signer are used to issue the signature, and any
194
+ // parent of that end-entity that need to be added to the list of
195
+ // certifications can be specified in the parents slice.
196
+ //
197
+ // It is compatible with PAdES specifications.
198
+ //
199
+ // The signature algorithm used to hash the data is the one of the end-entity
200
+ // certificate.
201
+ //
202
+ // Following RFC 2315, 9.2 SignerInfo type, the distinguished name of
203
+ // the issuer of the end-entity signer is stored in the issuerAndSerialNumber
204
+ // section of the SignedData.SignerInfo, alongside the serial number of
205
+ // the end-entity.
206
+ func (sd * SignedData ) AddSignerChainPAdES (ee * x509.Certificate , pkey crypto.PrivateKey , chain []* x509.Certificate , config SignerInfoConfig ) error {
207
+ return sd .addSignerChain (ee , pkey , chain , config , true , false )
208
+ }
209
+
210
+ func (sd * SignedData ) addSignerChain (ee * x509.Certificate , pkey crypto.PrivateKey , chain []* x509.Certificate , config SignerInfoConfig , includeCertificates bool , enableSigningTime bool ) error {
192
211
sd .sd .DigestAlgorithmIdentifiers = append (sd .sd .DigestAlgorithmIdentifiers , pkix.AlgorithmIdentifier {Algorithm : sd .digestOid })
193
212
hash , err := getHashForOID (sd .digestOid )
194
213
if err != nil {
@@ -204,7 +223,9 @@ func (sd *SignedData) addSignerChain(ee *x509.Certificate, pkey crypto.PrivateKe
204
223
attrs := & attributes {}
205
224
attrs .Add (OIDAttributeContentType , sd .sd .ContentInfo .ContentType )
206
225
attrs .Add (OIDAttributeMessageDigest , sd .messageDigest )
207
- attrs .Add (OIDAttributeSigningTime , time .Now ())
226
+ if enableSigningTime {
227
+ attrs .Add (OIDAttributeSigningTime , time .Now ())
228
+ }
208
229
209
230
// Add id-aa-signing-certificate-v2.
210
231
if b , err := populateSigningCertificateV2Ext (ee ); err == nil {
0 commit comments