@@ -115,66 +115,25 @@ internal X509Certificate2Collection GetCertificatesFromMessage(CryptMsgSafeHandl
115
115
return certs ;
116
116
}
117
117
118
- public IReadOnlyList < ISignature > GetNestedSignatures ( )
119
- {
120
- var list = new List < ISignature > ( ) ;
121
- foreach ( var attribute in UnsignedAttributes )
122
- {
123
- foreach ( var value in attribute . Values )
124
- {
125
- ISignature signature ;
126
- if ( attribute . Oid . Value == KnownOids . AuthenticodeCounterSignature )
127
- {
128
- signature = new AuthenticodeSignature ( value ) ;
129
- }
130
- else if ( attribute . Oid . Value == KnownOids . Rfc3161CounterSignature )
131
- {
132
- signature = new Signature ( value , SignatureKind . Rfc3161Signature ) ;
133
- }
134
- else if ( attribute . Oid . Value == KnownOids . NestedSignatureOid )
135
- {
136
- signature = new Signature ( value , SignatureKind . NestedSignature ) ;
137
- }
138
- else
139
- {
140
- continue ;
141
- }
142
- var childAttributes = new CryptographicAttributeObjectCollection ( ) ;
143
- foreach ( var childAttribute in signature . UnsignedAttributes )
144
- {
145
- childAttributes . Add ( childAttribute ) ;
146
- }
147
- list . Add ( signature ) ;
148
- }
149
- }
150
- return list . AsReadOnly ( ) ;
151
- }
118
+ public abstract IReadOnlyList < ISignature > GetNestedSignatures ( ) ;
152
119
}
153
120
154
121
public class AuthenticodeSignature : SignatureBase
155
122
{
156
-
157
123
public override Oid DigestAlgorithm { get ; protected set ; }
158
124
public override Oid HashEncryptionAlgorithm { get ; protected set ; }
159
125
public override CryptographicAttributeObjectCollection UnsignedAttributes { get ; protected set ; }
160
126
public override CryptographicAttributeObjectCollection SignedAttributes { get ; protected set ; }
161
127
public override byte [ ] SerialNumber { get ; protected set ; }
162
128
public override X509Certificate2 Certificate { get ; protected set ; }
163
129
public override SignatureKind Kind { get ; } = SignatureKind . AuthenticodeSignature ;
164
- public override X509Certificate2Collection AdditionalCertificates
165
- {
166
- get
167
- {
168
- return new X509Certificate2Collection ( ) ;
169
- }
170
-
171
- protected set
172
- {
173
- }
174
- }
130
+ public override X509Certificate2Collection AdditionalCertificates { get ; protected set ; }
131
+ public ISignature OwningSignature { get ; }
175
132
176
- public unsafe AuthenticodeSignature ( AsnEncodedData data )
133
+ public unsafe AuthenticodeSignature ( AsnEncodedData data , ISignature owningSignature )
177
134
{
135
+ OwningSignature = owningSignature ;
136
+ AdditionalCertificates = owningSignature . AdditionalCertificates ;
178
137
fixed ( byte * dataPtr = data . RawData )
179
138
{
180
139
uint size = 0 ;
@@ -189,6 +148,15 @@ public unsafe AuthenticodeSignature(AsnEncodedData data)
189
148
SerialNumber = ReadBlob ( signerInfo . SerialNumber ) ;
190
149
UnsignedAttributes = ReadAttributes ( signerInfo . UnauthAttrs ) ;
191
150
SignedAttributes = ReadAttributes ( signerInfo . AuthAttrs ) ;
151
+ var subjectId = new UniversalSubjectIdentifier ( signerInfo . Issuer , signerInfo . SerialNumber ) ;
152
+ if ( subjectId . Type == SubjectIdentifierType . SubjectKeyIdentifier )
153
+ {
154
+ Certificate = FindCertificate ( ( string ) subjectId . Value , OwningSignature . AdditionalCertificates ) ;
155
+ }
156
+ else if ( subjectId . Type == SubjectIdentifierType . IssuerAndSerialNumber )
157
+ {
158
+ Certificate = FindCertificate ( ( X509IssuerSerial ) subjectId . Value , OwningSignature . AdditionalCertificates ) ;
159
+ }
192
160
}
193
161
}
194
162
else
@@ -197,6 +165,41 @@ public unsafe AuthenticodeSignature(AsnEncodedData data)
197
165
}
198
166
}
199
167
}
168
+
169
+ public override IReadOnlyList < ISignature > GetNestedSignatures ( )
170
+ {
171
+ var list = new List < ISignature > ( ) ;
172
+ foreach ( var attribute in UnsignedAttributes )
173
+ {
174
+ foreach ( var value in attribute . Values )
175
+ {
176
+ ISignature signature ;
177
+ if ( attribute . Oid . Value == KnownOids . AuthenticodeCounterSignature )
178
+ {
179
+ signature = new AuthenticodeSignature ( value , OwningSignature ) ;
180
+ }
181
+ else if ( attribute . Oid . Value == KnownOids . Rfc3161CounterSignature )
182
+ {
183
+ signature = new Signature ( value , SignatureKind . Rfc3161Signature ) ;
184
+ }
185
+ else if ( attribute . Oid . Value == KnownOids . NestedSignatureOid )
186
+ {
187
+ signature = new Signature ( value , SignatureKind . NestedSignature ) ;
188
+ }
189
+ else
190
+ {
191
+ continue ;
192
+ }
193
+ var childAttributes = new CryptographicAttributeObjectCollection ( ) ;
194
+ foreach ( var childAttribute in signature . UnsignedAttributes )
195
+ {
196
+ childAttributes . Add ( childAttribute ) ;
197
+ }
198
+ list . Add ( signature ) ;
199
+ }
200
+ }
201
+ return list . AsReadOnly ( ) ;
202
+ }
200
203
}
201
204
202
205
public class Signature : SignatureBase
@@ -284,6 +287,41 @@ internal unsafe Signature(AsnEncodedData data, SignatureKind kind)
284
287
}
285
288
}
286
289
}
290
+
291
+ public override IReadOnlyList < ISignature > GetNestedSignatures ( )
292
+ {
293
+ var list = new List < ISignature > ( ) ;
294
+ foreach ( var attribute in UnsignedAttributes )
295
+ {
296
+ foreach ( var value in attribute . Values )
297
+ {
298
+ ISignature signature ;
299
+ if ( attribute . Oid . Value == KnownOids . AuthenticodeCounterSignature )
300
+ {
301
+ signature = new AuthenticodeSignature ( value , this ) ;
302
+ }
303
+ else if ( attribute . Oid . Value == KnownOids . Rfc3161CounterSignature )
304
+ {
305
+ signature = new Signature ( value , SignatureKind . Rfc3161Signature ) ;
306
+ }
307
+ else if ( attribute . Oid . Value == KnownOids . NestedSignatureOid )
308
+ {
309
+ signature = new Signature ( value , SignatureKind . NestedSignature ) ;
310
+ }
311
+ else
312
+ {
313
+ continue ;
314
+ }
315
+ var childAttributes = new CryptographicAttributeObjectCollection ( ) ;
316
+ foreach ( var childAttribute in signature . UnsignedAttributes )
317
+ {
318
+ childAttributes . Add ( childAttribute ) ;
319
+ }
320
+ list . Add ( signature ) ;
321
+ }
322
+ }
323
+ return list . AsReadOnly ( ) ;
324
+ }
287
325
}
288
326
289
327
internal class UniversalSubjectIdentifier
0 commit comments