|
1 /* |
|
2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "CCMSSignerInfo.h" |
|
21 #include "TCMSTimeUtil.h" |
|
22 |
|
23 #include <x500dn.h> |
|
24 #include <asn1dec.h> |
|
25 #include <asn1enc.h> |
|
26 #include <signed.h> |
|
27 |
|
28 // CONSTANTS |
|
29 const TInt KMinNumberOfSubModules = 5; |
|
30 const TInt KMaxNumberOfSubModules = 7; |
|
31 const TInt KDefaultGranularity = 2; |
|
32 const TInt KCMSVersion1 = 1; |
|
33 const TInt KCMSVersion3 = 3; |
|
34 const TInt KSignedAttrsTag = 0; |
|
35 const TInt KUnsignedAttrsTag = 1; |
|
36 |
|
37 // CMS SignedAttributes useful types |
|
38 _LIT( KContentTypeOID, "1.2.840.113549.1.9.3" ); |
|
39 _LIT( KMessageDigestOID, "1.2.840.113549.1.9.4" ); |
|
40 _LIT( KSignTimeOID, "1.2.840.113549.1.9.5" ); |
|
41 |
|
42 // Additional oid for adding certificates |
|
43 _LIT( KPKCS9SigCertOID, "1.2.840.113549.1.9.16.2.12" ); |
|
44 |
|
45 // X509 URL certificate OID |
|
46 _LIT( KURLCertificateOID, "2.23.43.2.1" ); |
|
47 |
|
48 // Defaulta id-data oid |
|
49 _LIT( KIDDataOID, "1.2.840.113549.1.7.1" ); |
|
50 |
|
51 // ============================ MEMBER FUNCTIONS =============================== |
|
52 |
|
53 // Destructor |
|
54 CCMSSignerInfo::CSignerInfoData::~CSignerInfoData() |
|
55 { |
|
56 delete iIssuerAndSerial; |
|
57 delete iSubjectKeyIdentifier; |
|
58 |
|
59 if( iSignedAttributes ) |
|
60 { |
|
61 iSignedAttributes->ResetAndDestroy(); |
|
62 delete iSignedAttributes; |
|
63 } |
|
64 |
|
65 if( iUnsignedAttributes ) |
|
66 { |
|
67 iUnsignedAttributes->ResetAndDestroy(); |
|
68 delete iUnsignedAttributes; |
|
69 } |
|
70 |
|
71 delete iDigestAI; |
|
72 delete iSignatureAI; |
|
73 delete iSignatureValue; |
|
74 } |
|
75 |
|
76 // ----------------------------------------------------------------------------- |
|
77 // CCMSSignerInfo::CCMSSignerInfo |
|
78 // C++ default constructor can NOT contain any code, that |
|
79 // might leave. |
|
80 // ----------------------------------------------------------------------------- |
|
81 // |
|
82 EXPORT_C CCMSSignerInfo::CCMSSignerInfo() |
|
83 { |
|
84 } |
|
85 |
|
86 // ----------------------------------------------------------------------------- |
|
87 // CCMSSignerInfo::ConstructL |
|
88 // Symbian 2nd phase constructor can leave. |
|
89 // ----------------------------------------------------------------------------- |
|
90 // |
|
91 EXPORT_C void CCMSSignerInfo::ConstructL( |
|
92 const TDesC8& aCertificateUrl, |
|
93 const TDesC8& aSubjectKeyID, |
|
94 const TDesC8& aMessageDigest ) |
|
95 { |
|
96 iData = new(ELeave) CSignerInfoData(); |
|
97 BaseConstructL( aMessageDigest ); |
|
98 SetCertificateUrlL( aCertificateUrl, aSubjectKeyID ); |
|
99 } |
|
100 |
|
101 // ----------------------------------------------------------------------------- |
|
102 // CCMSSignerInfo::ConstructL |
|
103 // Symbian 2nd phase constructor can leave. |
|
104 // ----------------------------------------------------------------------------- |
|
105 // |
|
106 EXPORT_C void CCMSSignerInfo::ConstructL( |
|
107 const CCMSX509Certificate& aCertificate, |
|
108 const TDesC8& aMessageDigest ) |
|
109 { |
|
110 iData = new(ELeave) CSignerInfoData(); |
|
111 BaseConstructL( aMessageDigest ); |
|
112 SetCertificateL( aCertificate ); |
|
113 } |
|
114 |
|
115 void CCMSSignerInfo::BaseConstructL( const TDesC8& aMessageDigest ) |
|
116 { |
|
117 iData->iDigestAI = CCMSX509AlgorithmIdentifier::NewL( ESHA1 ); |
|
118 iData->iSignatureAI = CCMSX509AlgorithmIdentifier::NewL(); |
|
119 TTime time; |
|
120 time.UniversalTime(); |
|
121 iData->iSignedAttributes = new(ELeave)CArrayPtrFlat<CCMSAttribute>( KDefaultGranularity ); |
|
122 SetSignedAttributesL( KIDDataOID(), |
|
123 aMessageDigest, |
|
124 time, |
|
125 NULL ); |
|
126 iData->iUnsignedAttributes = new(ELeave)CArrayPtrFlat<CCMSAttribute>( KDefaultGranularity ); |
|
127 SetSignatureValueL( aMessageDigest ); |
|
128 } |
|
129 |
|
130 // ----------------------------------------------------------------------------- |
|
131 // CCMSSignerInfo::NewL |
|
132 // Two-phased constructor. |
|
133 // ----------------------------------------------------------------------------- |
|
134 // |
|
135 EXPORT_C CCMSSignerInfo* CCMSSignerInfo::NewL() |
|
136 { |
|
137 // creating with empty values |
|
138 CCMSSignerInfo* self = NewL( KNullDesC8(), |
|
139 KNullDesC8(), |
|
140 KNullDesC8() ); |
|
141 |
|
142 return self; |
|
143 } |
|
144 |
|
145 // ----------------------------------------------------------------------------- |
|
146 // CCMSSignerInfo::NewL |
|
147 // Two-phased constructor. |
|
148 // ----------------------------------------------------------------------------- |
|
149 // |
|
150 EXPORT_C CCMSSignerInfo* CCMSSignerInfo::NewL( |
|
151 const TDesC8& aCertificateUrl, |
|
152 const TDesC8& aSubjectKeyID, |
|
153 const TDesC8& aMessageDigest ) |
|
154 { |
|
155 CCMSSignerInfo* self = new( ELeave ) CCMSSignerInfo(); |
|
156 CleanupStack::PushL( self ); |
|
157 self->ConstructL( aCertificateUrl, aSubjectKeyID, aMessageDigest ); |
|
158 CleanupStack::Pop(); |
|
159 |
|
160 return self; |
|
161 } |
|
162 |
|
163 // ----------------------------------------------------------------------------- |
|
164 // CCMSSignerInfo::NewL |
|
165 // Two-phased constructor. |
|
166 // ----------------------------------------------------------------------------- |
|
167 // |
|
168 EXPORT_C CCMSSignerInfo* CCMSSignerInfo::NewL( |
|
169 const CCMSX509Certificate& aCertificate, |
|
170 const TDesC8& aMessageDigest ) |
|
171 { |
|
172 CCMSSignerInfo* self = new( ELeave ) CCMSSignerInfo(); |
|
173 CleanupStack::PushL( self ); |
|
174 self->ConstructL( aCertificate, aMessageDigest ); |
|
175 CleanupStack::Pop(); |
|
176 |
|
177 return self; |
|
178 } |
|
179 |
|
180 // Destructor |
|
181 CCMSSignerInfo::~CCMSSignerInfo() |
|
182 { |
|
183 delete iData; |
|
184 } |
|
185 |
|
186 // ----------------------------------------------------------------------------- |
|
187 // CCMSSignerInfo::DecodeL |
|
188 // Decrypts raw data to this instance |
|
189 // ----------------------------------------------------------------------------- |
|
190 void CCMSSignerInfo::DecodeL( const TDesC8& aRawData ) |
|
191 { |
|
192 CSignerInfoData* tmpData = new(ELeave) CSignerInfoData(); |
|
193 CleanupStack::PushL( tmpData ); |
|
194 CArrayPtr<TASN1DecGeneric>* signerInfo = DecodeSequenceLC( aRawData, |
|
195 KMinNumberOfSubModules, |
|
196 KMaxNumberOfSubModules ); |
|
197 // we would not get this far if there is not min 5 elements |
|
198 TInt pos = 0; |
|
199 // decode Version |
|
200 TASN1DecInteger version; |
|
201 tmpData->iVersion = version.DecodeDERShortL( *signerInfo->At( pos++ ) ); |
|
202 |
|
203 if( tmpData->iVersion == KCMSVersion1 ) |
|
204 { |
|
205 // decode IssuerAndSerialNumber |
|
206 tmpData->iIssuerAndSerial = |
|
207 CCMSIssuerAndSerialNumber::NewL(); |
|
208 tmpData->iIssuerAndSerial->DecodeL( signerInfo->At( pos++ )->Encoding() ); |
|
209 } |
|
210 else |
|
211 { |
|
212 // decode SubjectKeyIdentifier |
|
213 TASN1DecOctetString subjectKey; |
|
214 tmpData->iSubjectKeyIdentifier = |
|
215 subjectKey.DecodeDERL( *signerInfo->At( pos++ ) ); |
|
216 } |
|
217 |
|
218 // decode DigestAlgorithIdentifier |
|
219 tmpData->iDigestAI = CCMSX509AlgorithmIdentifier::NewL(); |
|
220 tmpData->iDigestAI->DecodeL( signerInfo->At( pos++ )->Encoding() ); |
|
221 |
|
222 // decode possible SignedAttributes |
|
223 tmpData->iSignedAttributes = |
|
224 new( ELeave )CArrayPtrFlat<CCMSAttribute>( KDefaultGranularity ); |
|
225 if( signerInfo->At( pos )->Tag() == KSignedAttrsTag ) |
|
226 { |
|
227 DecodeAttributesL( signerInfo->At( pos++ )->Encoding(), |
|
228 tmpData->iSignedAttributes ); |
|
229 } |
|
230 |
|
231 // decode SignatureAlgorithIdentifier |
|
232 tmpData->iSignatureAI = CCMSX509AlgorithmIdentifier::NewL(); |
|
233 tmpData->iSignatureAI->DecodeL( signerInfo->At( pos++ )->Encoding() ); |
|
234 |
|
235 // check that we have enough parameters for mandatory fields |
|
236 if( pos >= signerInfo->Count() ) |
|
237 { |
|
238 User::Leave( KErrArgument ); |
|
239 } |
|
240 |
|
241 // decode SignatureValue |
|
242 TASN1DecOctetString signValue; |
|
243 tmpData->iSignatureValue = signValue.DecodeDERL( *signerInfo->At( pos++ ) ); |
|
244 |
|
245 // decode possible UnsignedAttributes |
|
246 tmpData->iUnsignedAttributes = |
|
247 new( ELeave )CArrayPtrFlat<CCMSAttribute>( KDefaultGranularity ); |
|
248 if( ( pos < signerInfo->Count() ) && |
|
249 ( signerInfo->At( pos )->Tag() == KUnsignedAttrsTag ) ) |
|
250 { |
|
251 DecodeAttributesL( signerInfo->At( pos++ )->Encoding(), |
|
252 tmpData->iUnsignedAttributes ); |
|
253 } |
|
254 |
|
255 CleanupStack::PopAndDestroy( signerInfo ); |
|
256 |
|
257 delete iData; |
|
258 iData = tmpData; |
|
259 CleanupStack::Pop( tmpData ); |
|
260 } |
|
261 |
|
262 // ----------------------------------------------------------------------------- |
|
263 // CCMSSignerInfo::EncoderLC |
|
264 // Returns ASN1 encoder for this instance |
|
265 // ----------------------------------------------------------------------------- |
|
266 |
|
267 CASN1EncBase* CCMSSignerInfo::EncoderLC() const |
|
268 { |
|
269 CASN1EncSequence* root = CASN1EncSequence::NewLC(); |
|
270 |
|
271 // Add version |
|
272 CASN1EncInt* version = CASN1EncInt::NewLC( iData->iVersion ); |
|
273 root->AddAndPopChildL( version ); |
|
274 |
|
275 // Add IssuerAndSerialNumber or SubjectKeyIdentifier |
|
276 if( iData->iIssuerAndSerial ) |
|
277 { |
|
278 CASN1EncBase* issuer = iData->iIssuerAndSerial->EncoderLC(); |
|
279 root->AddAndPopChildL( issuer ); |
|
280 } |
|
281 else |
|
282 { |
|
283 CASN1EncOctetString* subjectKey = |
|
284 CASN1EncOctetString::NewLC( *iData->iSubjectKeyIdentifier ); |
|
285 root->AddAndPopChildL( subjectKey ); |
|
286 } |
|
287 |
|
288 // Add DigestAlgorithmIdentifier |
|
289 CASN1EncBase* digestAlg = iData->iDigestAI->EncoderLC(); |
|
290 root->AddAndPopChildL( digestAlg ); |
|
291 |
|
292 // Add SignedAttributes if they exists |
|
293 TInt signedAttributes = iData->iSignedAttributes->Count(); |
|
294 if( signedAttributes > 0 ) |
|
295 { |
|
296 CASN1EncSequence* signedAttributesSet |
|
297 = CASN1EncSequence::NewLC(); |
|
298 signedAttributesSet->SetTag( KSignedAttrsTag ); |
|
299 |
|
300 for( TInt i = 0; i < signedAttributes; i++ ) |
|
301 { |
|
302 CASN1EncBase* attribute = iData->iSignedAttributes->At( i )->EncoderLC(); |
|
303 signedAttributesSet->AddAndPopChildL( attribute ); |
|
304 } |
|
305 root->AddAndPopChildL( signedAttributesSet ); |
|
306 } |
|
307 |
|
308 // Add SignatureAlgorithmIdentifier |
|
309 CASN1EncBase* signatureAlg = iData->iSignatureAI->EncoderLC(); |
|
310 root->AddAndPopChildL( signatureAlg ); |
|
311 |
|
312 // Add SignatureValue |
|
313 CASN1EncOctetString* signValue = |
|
314 CASN1EncOctetString::NewLC( *iData->iSignatureValue ); |
|
315 root->AddAndPopChildL( signValue ); |
|
316 |
|
317 // Add UnsignedAttributes if they exists |
|
318 TInt unsignedAttributes = iData->iUnsignedAttributes->Count(); |
|
319 if( unsignedAttributes > 0 ) |
|
320 { |
|
321 CASN1EncSequence* unsignedAttributesSet |
|
322 = CASN1EncSequence::NewLC(); |
|
323 unsignedAttributesSet->SetTag( KUnsignedAttrsTag ); |
|
324 |
|
325 for( TInt i = 0; i < unsignedAttributes; i++ ) |
|
326 { |
|
327 CASN1EncBase* attribute = iData->iUnsignedAttributes->At( i )->EncoderLC(); |
|
328 unsignedAttributesSet->AddAndPopChildL( attribute ); |
|
329 } |
|
330 root->AddAndPopChildL( unsignedAttributesSet ); |
|
331 } |
|
332 |
|
333 return root; |
|
334 } |
|
335 |
|
336 // ----------------------------------------------------------------------------- |
|
337 // CCMSSignerInfo::CMSVersion() |
|
338 // Getter for Version |
|
339 // ----------------------------------------------------------------------------- |
|
340 EXPORT_C TInt CCMSSignerInfo::CMSVersion() const |
|
341 { |
|
342 return iData->iVersion; |
|
343 } |
|
344 |
|
345 // ----------------------------------------------------------------------------- |
|
346 // CCMSSignerInfo::IssuerAndSerialNumber() |
|
347 // Getter for IssuerAndSerialNumber |
|
348 // ----------------------------------------------------------------------------- |
|
349 EXPORT_C const CCMSIssuerAndSerialNumber* CCMSSignerInfo::IssuerAndSerialNumber() const |
|
350 { |
|
351 return iData->iIssuerAndSerial; |
|
352 } |
|
353 |
|
354 // ----------------------------------------------------------------------------- |
|
355 // CCMSSignerInfo::SubjectKeyIdentifier() |
|
356 // Getter for SubjectKeyIdentifier |
|
357 // ----------------------------------------------------------------------------- |
|
358 EXPORT_C const TDesC8* CCMSSignerInfo::SubjectKeyIdentifier() const |
|
359 { |
|
360 return iData->iSubjectKeyIdentifier; |
|
361 } |
|
362 |
|
363 // ----------------------------------------------------------------------------- |
|
364 // CCMSSignerInfo::DigestAlgorithmIdentifier() |
|
365 // Getter for DigestAlgorithmIdentifier |
|
366 // ----------------------------------------------------------------------------- |
|
367 EXPORT_C const CCMSX509AlgorithmIdentifier& CCMSSignerInfo::DigestAlgorithmIdentifier() const |
|
368 { |
|
369 return *iData->iDigestAI; |
|
370 } |
|
371 |
|
372 // ----------------------------------------------------------------------------- |
|
373 // CCMSSignerInfo::SignedAttributes() |
|
374 // Getter for SignedAttributes |
|
375 // ----------------------------------------------------------------------------- |
|
376 EXPORT_C const CArrayPtrFlat<CCMSAttribute>& CCMSSignerInfo::SignedAttributes() const |
|
377 { |
|
378 return *iData->iSignedAttributes; |
|
379 } |
|
380 |
|
381 // ----------------------------------------------------------------------------- |
|
382 // CCMSSignerInfo::SignedAttributesEncodedL() |
|
383 // Getter for encoded SignedAttributes |
|
384 // ----------------------------------------------------------------------------- |
|
385 EXPORT_C HBufC8* CCMSSignerInfo::SignedAttributesEncodedL() const |
|
386 { |
|
387 HBufC8* retVal = NULL; |
|
388 TInt signedAttributes = iData->iSignedAttributes->Count(); |
|
389 if( signedAttributes > 0 ) |
|
390 { |
|
391 CASN1EncSequence* signedAttributesSet |
|
392 = CASN1EncSequence::NewLC(); |
|
393 signedAttributesSet->SetTag( EASN1Set, EUniversal ); |
|
394 |
|
395 for( TInt i = 0; i < signedAttributes; i++ ) |
|
396 { |
|
397 CASN1EncBase* attribute = iData->iSignedAttributes->At( i )->EncoderLC(); |
|
398 signedAttributesSet->AddAndPopChildL( attribute ); |
|
399 } |
|
400 retVal = CreateDerEncodingL( signedAttributesSet ); |
|
401 CleanupStack::PopAndDestroy( signedAttributesSet ); |
|
402 } |
|
403 return retVal; |
|
404 } |
|
405 |
|
406 // ----------------------------------------------------------------------------- |
|
407 // CCMSSignerInfo::SignatureAlgorithmIdentifier() |
|
408 // Getter for SignatureAlgorithmIdentifier |
|
409 // ----------------------------------------------------------------------------- |
|
410 EXPORT_C const CCMSX509AlgorithmIdentifier& CCMSSignerInfo::SignatureAlgorithmIdentifier() const |
|
411 { |
|
412 return *iData->iSignatureAI; |
|
413 } |
|
414 |
|
415 // ----------------------------------------------------------------------------- |
|
416 // CCMSSignerInfo::SignatureValue() |
|
417 // Getter for SignatureValue |
|
418 // ----------------------------------------------------------------------------- |
|
419 EXPORT_C const TDesC8& CCMSSignerInfo::SignatureValue() const |
|
420 { |
|
421 return *iData->iSignatureValue; |
|
422 } |
|
423 |
|
424 // ----------------------------------------------------------------------------- |
|
425 // CCMSSignerInfo::UnsignedAttributes() |
|
426 // Getter for UnsignedAttributes |
|
427 // ----------------------------------------------------------------------------- |
|
428 EXPORT_C const CArrayPtrFlat<CCMSAttribute>& CCMSSignerInfo::UnsignedAttributes() const |
|
429 { |
|
430 return *iData->iUnsignedAttributes; |
|
431 } |
|
432 |
|
433 // ----------------------------------------------------------------------------- |
|
434 // CCMSSignerInfo::SetCertificateL() |
|
435 // Setter for Certificate |
|
436 // ----------------------------------------------------------------------------- |
|
437 EXPORT_C void CCMSSignerInfo::SetCertificateL( const CCMSX509Certificate& aCertificate ) |
|
438 { |
|
439 // creating Issuer and serial |
|
440 CCMSIssuerAndSerialNumber* tmpIssuer = CCMSIssuerAndSerialNumber::NewL( |
|
441 aCertificate.Issuer(), |
|
442 aCertificate.SerialNumber() ); |
|
443 |
|
444 delete iData->iIssuerAndSerial; |
|
445 iData->iIssuerAndSerial = tmpIssuer; |
|
446 |
|
447 // setting normal certificate, deleting possible certificate url |
|
448 // and subject key identifier |
|
449 TInt unsignedAttCount = iData->iUnsignedAttributes->Count(); |
|
450 for( TInt i = 0; i < unsignedAttCount; i++ ) |
|
451 { |
|
452 CCMSAttribute* att = iData->iUnsignedAttributes->At( i ); |
|
453 if( att->AttributeType() == KURLCertificateOID() ) |
|
454 { |
|
455 iData->iUnsignedAttributes->Delete( i ); |
|
456 delete att; |
|
457 } |
|
458 } |
|
459 delete iData->iSubjectKeyIdentifier; |
|
460 iData->iSubjectKeyIdentifier = NULL; |
|
461 |
|
462 // changing version to 1 |
|
463 iData->iVersion = KCMSVersion1; |
|
464 } |
|
465 |
|
466 // ----------------------------------------------------------------------------- |
|
467 // CCMSSignerInfo::SetCertificateUrlL() |
|
468 // Setter for certificate URL |
|
469 // ----------------------------------------------------------------------------- |
|
470 EXPORT_C void CCMSSignerInfo::SetCertificateUrlL( const TDesC8& aCertificateUrl, |
|
471 const TDesC8& aSubjectKeyID ) |
|
472 { |
|
473 CCMSAttribute* certUrl = CreateCertificateUrlLC( aCertificateUrl ); |
|
474 |
|
475 // remove possible URL from unsigned attributes |
|
476 TInt unsignedAttCount = iData->iUnsignedAttributes->Count(); |
|
477 for( TInt i = 0; i < unsignedAttCount; i++ ) |
|
478 { |
|
479 CCMSAttribute* att = iData->iUnsignedAttributes->At( i ); |
|
480 if( att->AttributeType() == KURLCertificateOID() ) |
|
481 { |
|
482 iData->iUnsignedAttributes->Delete( i ); |
|
483 delete att; |
|
484 } |
|
485 } |
|
486 iData->iUnsignedAttributes->AppendL( certUrl ); |
|
487 CleanupStack::Pop( certUrl ); |
|
488 |
|
489 // taking copy of subject key identifier |
|
490 HBufC8* tmpSubjectKeyID = aSubjectKeyID.AllocL(); |
|
491 |
|
492 delete iData->iSubjectKeyIdentifier; |
|
493 iData->iSubjectKeyIdentifier = tmpSubjectKeyID; |
|
494 |
|
495 // Issuer and serial is only for real certificates |
|
496 delete iData->iIssuerAndSerial; |
|
497 iData->iIssuerAndSerial = NULL; |
|
498 |
|
499 // changing version to 3 |
|
500 iData->iVersion = KCMSVersion3; |
|
501 } |
|
502 |
|
503 // ----------------------------------------------------------------------------- |
|
504 // CCMSSignerInfo::SetDigestAlgorithmIdentifier() |
|
505 // Setter for DigestAlgorithmIdentifier |
|
506 // ----------------------------------------------------------------------------- |
|
507 EXPORT_C void CCMSSignerInfo::SetDigestAlgorithmIdentifier( |
|
508 CCMSX509AlgorithmIdentifier& aDigestAI ) |
|
509 { |
|
510 delete iData->iDigestAI; |
|
511 iData->iDigestAI = &aDigestAI; |
|
512 } |
|
513 |
|
514 // ----------------------------------------------------------------------------- |
|
515 // CCMSSignerInfo::SetSignatureAlgorithmIdentifier() |
|
516 // Setter for SignatureAlgorithmIdentifier |
|
517 // ----------------------------------------------------------------------------- |
|
518 EXPORT_C void CCMSSignerInfo::SetSignatureAlgorithmIdentifier( |
|
519 CCMSX509AlgorithmIdentifier& aSignatureAI ) |
|
520 { |
|
521 delete iData->iSignatureAI; |
|
522 iData->iSignatureAI = &aSignatureAI; |
|
523 } |
|
524 |
|
525 // ----------------------------------------------------------------------------- |
|
526 // CCMSSignerInfo::SetSignatureValueL() |
|
527 // Setter for SignatureValue |
|
528 // ----------------------------------------------------------------------------- |
|
529 EXPORT_C void CCMSSignerInfo::SetSignatureValueL( const TDesC8& aSignatureValue ) |
|
530 { |
|
531 HBufC8* tmpSignValue = aSignatureValue.AllocL(); |
|
532 delete iData->iSignatureValue; |
|
533 iData->iSignatureValue = tmpSignValue; |
|
534 } |
|
535 |
|
536 // ----------------------------------------------------------------------------- |
|
537 // CCMSSignerInfo::SetSignedAttributesL() |
|
538 // Setter for Signed attributes |
|
539 // ----------------------------------------------------------------------------- |
|
540 EXPORT_C void CCMSSignerInfo::SetSignedAttributesL( const TDesC& aContentType, |
|
541 const TDesC8& aMessageDigest, |
|
542 const TTime& aSigningTime, |
|
543 const TDesC8* aCertHash ) |
|
544 { |
|
545 CArrayPtrFlat<CCMSAttribute>* tmpAttributes = |
|
546 new(ELeave)CArrayPtrFlat<CCMSAttribute>( KDefaultGranularity ); |
|
547 CleanupStack::PushL( tmpAttributes ); |
|
548 CleanupResetAndDestroy< CArrayPtrFlat<CCMSAttribute> >::PushL( *tmpAttributes ); |
|
549 |
|
550 |
|
551 if( aContentType != KNullDesC() ) |
|
552 { |
|
553 // creating content type |
|
554 CASN1EncObjectIdentifier* contOid = |
|
555 CASN1EncObjectIdentifier::NewLC( aContentType ); |
|
556 HBufC8* contentType = CreateDerEncodingL( contOid ); |
|
557 CleanupStack::PushL( contentType ); |
|
558 CCMSAttribute* contType = CCMSAttribute::NewLC( KContentTypeOID, *contentType ); |
|
559 tmpAttributes->AppendL( contType ); |
|
560 CleanupStack::Pop( contType ); |
|
561 CleanupStack::PopAndDestroy( contentType ); |
|
562 CleanupStack::PopAndDestroy( contOid ); |
|
563 } |
|
564 |
|
565 if( aMessageDigest != KNullDesC8() ) |
|
566 { |
|
567 // creating MessageDigest |
|
568 CASN1EncOctetString* signature = |
|
569 CASN1EncOctetString::NewLC( aMessageDigest ); |
|
570 HBufC8* messageDigest = CreateDerEncodingL( signature ); |
|
571 CleanupStack::PushL( messageDigest ); |
|
572 CCMSAttribute* mDigest = CCMSAttribute::NewLC( KMessageDigestOID, *messageDigest ); |
|
573 tmpAttributes->AppendL( mDigest ); |
|
574 CleanupStack::Pop( mDigest ); |
|
575 CleanupStack::PopAndDestroy( messageDigest ); |
|
576 CleanupStack::PopAndDestroy( signature ); |
|
577 } |
|
578 |
|
579 // creating Signing time |
|
580 CASN1EncBase* signTimeDER = TCMSTimeUtil::ConvertToEncoderLC( aSigningTime ); |
|
581 HBufC8* signTime = CreateDerEncodingL( signTimeDER ); |
|
582 CleanupStack::PushL( signTime ); |
|
583 CCMSAttribute* sTime = CCMSAttribute::NewLC( KSignTimeOID, *signTime ); |
|
584 tmpAttributes->AppendL( sTime ); |
|
585 CleanupStack::Pop( sTime ); |
|
586 CleanupStack::PopAndDestroy( signTime ); |
|
587 CleanupStack::PopAndDestroy( signTimeDER ); |
|
588 |
|
589 // are we adding certificates |
|
590 if( aCertHash ) |
|
591 { |
|
592 CCMSAttribute* signingCert = |
|
593 CCMSAttribute::NewLC( KPKCS9SigCertOID, *aCertHash ); |
|
594 tmpAttributes->AppendL( signingCert ); |
|
595 CleanupStack::Pop( signingCert ); |
|
596 } |
|
597 |
|
598 iData->iSignedAttributes->ResetAndDestroy(); |
|
599 delete iData->iSignedAttributes; |
|
600 iData->iSignedAttributes = tmpAttributes; |
|
601 CleanupStack::Pop( tmpAttributes ); // ResetAndDestroy |
|
602 CleanupStack::Pop( tmpAttributes ); |
|
603 } |
|
604 |
|
605 // ----------------------------------------------------------------------------- |
|
606 // CCMSSignerInfo::SetUnsignedAttributesL() |
|
607 // Setter for Unsigned attributes |
|
608 // ----------------------------------------------------------------------------- |
|
609 EXPORT_C void CCMSSignerInfo::SetUnsignedAttributesL( |
|
610 CArrayPtrFlat<CCMSAttribute>& aUnsignedAttributes ) |
|
611 { |
|
612 iData->iUnsignedAttributes->ResetAndDestroy(); |
|
613 delete iData->iUnsignedAttributes; |
|
614 iData->iUnsignedAttributes = &aUnsignedAttributes; |
|
615 } |
|
616 |
|
617 |
|
618 // ----------------------------------------------------------------------------- |
|
619 // CCMSSignerInfo::DecodeAttributesL() |
|
620 // Decodes Attributes to array |
|
621 // ----------------------------------------------------------------------------- |
|
622 void CCMSSignerInfo::DecodeAttributesL( |
|
623 const TDesC8& aRawData, |
|
624 CArrayPtrFlat<CCMSAttribute>* aAttributes ) |
|
625 { |
|
626 TASN1DecSet attributeDec; |
|
627 TInt pos = 0; |
|
628 CArrayPtrFlat<TASN1DecGeneric>* attributes = |
|
629 attributeDec.DecodeDERLC( aRawData, pos ); |
|
630 |
|
631 TInt numOfAttributes = attributes->Count(); |
|
632 for( TInt i = 0; i < numOfAttributes; i++ ) |
|
633 { |
|
634 CCMSAttribute* att = CCMSAttribute::NewLC(); |
|
635 att->DecodeL( attributes->At( i )->Encoding() ); |
|
636 aAttributes->AppendL( att ); |
|
637 CleanupStack::Pop( att ); |
|
638 } |
|
639 CleanupStack::PopAndDestroy( attributes ); |
|
640 } |
|
641 |
|
642 // ----------------------------------------------------------------------------- |
|
643 // CCMSSignerInfo::CreateCertificateUrlLC() |
|
644 // Creates certificate url attribute |
|
645 // ----------------------------------------------------------------------------- |
|
646 CCMSAttribute* CCMSSignerInfo::CreateCertificateUrlLC( const TDesC8& aCertificateUrl ) |
|
647 { |
|
648 // Add certificate URL to unsigned attributes |
|
649 CASN1EncOctetString* certificateUrlEnc = |
|
650 CASN1EncOctetString::NewLC( aCertificateUrl ); |
|
651 //change tag to IA5 |
|
652 certificateUrlEnc->SetTag( EASN1IA5String ); |
|
653 |
|
654 HBufC8* certificateURL = CreateDerEncodingL( certificateUrlEnc ); |
|
655 CleanupStack::PushL( certificateURL ); |
|
656 CCMSAttribute* certUrl = CCMSAttribute::NewL( KURLCertificateOID, *certificateURL ); |
|
657 CleanupStack::PopAndDestroy( certificateURL ); |
|
658 CleanupStack::PopAndDestroy( certificateUrlEnc ); |
|
659 CleanupStack::PushL( certUrl ); |
|
660 return certUrl; |
|
661 } |
|
662 // End of File |