|
1 /* |
|
2 * Copyright (c) 2004 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: X.509 Certificate type |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "CCMSX509Certificate.h" |
|
21 #include "CCMSX509AlgorithmIdentifier.h" |
|
22 #include "CCMSX509Validity.h" |
|
23 #include "CCMSX509SubjectPublicKeyInfo.h" |
|
24 #include <asn1dec.h> |
|
25 #include <asn1enc.h> |
|
26 |
|
27 // CONSTANTS |
|
28 const TInt KVersion2 = 1; |
|
29 const TInt KVersion3 = 2; |
|
30 const TTagType KVersionTag = 0; |
|
31 const TTagType KIssuerUniqueIdentifierTag = 1; |
|
32 const TTagType KSubjectUniqueIdentifierTag = 2; |
|
33 const TInt KToBeSignedItemsMin = 6; |
|
34 const TInt KToBeSignedItemsMax = 10; |
|
35 const TInt KDefaultGranularity = 1; |
|
36 |
|
37 // ============================ MEMBER FUNCTIONS =============================== |
|
38 |
|
39 // Destructor |
|
40 CCMSX509Certificate::CCertificateData::~CCertificateData() |
|
41 { |
|
42 delete iSerialNumber; |
|
43 delete iSignature; |
|
44 delete iIssuer; |
|
45 delete iValidity; |
|
46 delete iSubject; |
|
47 delete iSubjectPublicKeyInfo; |
|
48 delete iIssuerUniqueIdentifier; |
|
49 delete iSubjectUniqueIdentifier; |
|
50 } |
|
51 |
|
52 // ----------------------------------------------------------------------------- |
|
53 // CCMSX509Certificate::CCMSX509Certificate |
|
54 // C++ default constructor can NOT contain any code, that |
|
55 // might leave. |
|
56 // ----------------------------------------------------------------------------- |
|
57 // |
|
58 EXPORT_C CCMSX509Certificate::CCMSX509Certificate( ) |
|
59 { |
|
60 } |
|
61 |
|
62 // ----------------------------------------------------------------------------- |
|
63 // CCMSX509Certificate::ConstructL |
|
64 // Symbian 2nd phase constructor can leave. |
|
65 // ----------------------------------------------------------------------------- |
|
66 // |
|
67 EXPORT_C void CCMSX509Certificate::ConstructL( |
|
68 const TDesC8& aSerialNumber, |
|
69 const CCMSX509AlgorithmIdentifier& aSignature, |
|
70 const CX500DistinguishedName& aIssuer, |
|
71 const CCMSX509Validity& aValidity, |
|
72 const CX500DistinguishedName& aSubject, |
|
73 const CCMSX509SubjectPublicKeyInfo& aSubjectPublicKeyInfo, |
|
74 const CCMSX509AlgorithmIdentifier& aAlgorithmIdentifier, |
|
75 const TDesC8& aEncrypted ) |
|
76 { |
|
77 BaseConstructL( aAlgorithmIdentifier, aEncrypted ); |
|
78 iData = new( ELeave ) CCertificateData; |
|
79 SetSerialNumberL( aSerialNumber ); |
|
80 SetSignatureL( aSignature ); |
|
81 SetIssuerL( aIssuer ); |
|
82 SetValidityL( aValidity ); |
|
83 SetSubjectL( aSubject ); |
|
84 SetSubjectPublicKeyInfoL( aSubjectPublicKeyInfo ); |
|
85 } |
|
86 |
|
87 // ----------------------------------------------------------------------------- |
|
88 // CCMSX509Certificate::ConstructL |
|
89 // Symbian 2nd phase constructor can leave. |
|
90 // ----------------------------------------------------------------------------- |
|
91 // |
|
92 EXPORT_C void CCMSX509Certificate::ConstructL( |
|
93 const CX509Certificate& aCertificate ) |
|
94 { |
|
95 SetDataL( aCertificate ); |
|
96 } |
|
97 |
|
98 // ----------------------------------------------------------------------------- |
|
99 // CCMSX509Certificate::ConstructL |
|
100 // Symbian 2nd phase constructor can leave. |
|
101 // ----------------------------------------------------------------------------- |
|
102 // |
|
103 EXPORT_C void CCMSX509Certificate::ConstructL( ) |
|
104 { |
|
105 // creating empty/default values |
|
106 CArrayPtrFlat< CX520AttributeTypeAndValue >* elements = new( ELeave ) |
|
107 CArrayPtrFlat< CX520AttributeTypeAndValue >( KDefaultGranularity ); |
|
108 CleanupStack::PushL( elements ); |
|
109 |
|
110 iData = new( ELeave ) CCertificateData; |
|
111 iData->iSerialNumber = KNullDesC8().AllocL(); |
|
112 iData->iSignature = CCMSX509AlgorithmIdentifier::NewL(); |
|
113 iData->iIssuer = CX500DistinguishedName::NewL( *elements ); |
|
114 iData->iValidity = CCMSX509Validity::NewL(); |
|
115 iData->iSubject = CX500DistinguishedName::NewL( *elements ); |
|
116 iData->iSubjectPublicKeyInfo = CCMSX509SubjectPublicKeyInfo::NewL(); |
|
117 |
|
118 CleanupStack::PopAndDestroy( elements ); |
|
119 |
|
120 iAlgorithmIdentifier = CCMSX509AlgorithmIdentifier::NewL(); |
|
121 iEncrypted = KNullDesC8().AllocL(); |
|
122 |
|
123 } |
|
124 |
|
125 |
|
126 // ----------------------------------------------------------------------------- |
|
127 // CCMSX509Certificate::NewL |
|
128 // Two-phased constructor. |
|
129 // ----------------------------------------------------------------------------- |
|
130 // |
|
131 EXPORT_C CCMSX509Certificate* |
|
132 CCMSX509Certificate::NewL() |
|
133 { |
|
134 // creating with empty values |
|
135 CCMSX509Certificate* self = |
|
136 new( ELeave ) CCMSX509Certificate(); |
|
137 CleanupStack::PushL( self ); |
|
138 self->ConstructL( ); |
|
139 CleanupStack::Pop( self ); |
|
140 return self; |
|
141 } |
|
142 |
|
143 // ----------------------------------------------------------------------------- |
|
144 // CCMSX509Certificate::NewL |
|
145 // Two-phased constructor. |
|
146 // ----------------------------------------------------------------------------- |
|
147 // |
|
148 EXPORT_C CCMSX509Certificate* |
|
149 CCMSX509Certificate::NewL( |
|
150 const TDesC8& aSerialNumber, |
|
151 const CCMSX509AlgorithmIdentifier& aSignature, |
|
152 const CX500DistinguishedName& aIssuer, |
|
153 const CCMSX509Validity& aValidity, |
|
154 const CX500DistinguishedName& aSubject, |
|
155 const CCMSX509SubjectPublicKeyInfo& aSubjectPublicKeyInfo, |
|
156 const CCMSX509AlgorithmIdentifier& aAlgorithmIdentifier, |
|
157 const TDesC8& aEncrypted ) |
|
158 { |
|
159 CCMSX509Certificate* self = |
|
160 new( ELeave ) CCMSX509Certificate(); |
|
161 CleanupStack::PushL( self ); |
|
162 self->ConstructL( aSerialNumber, aSignature, aIssuer, aValidity, aSubject, |
|
163 aSubjectPublicKeyInfo, aAlgorithmIdentifier, aEncrypted ); |
|
164 CleanupStack::Pop(); |
|
165 |
|
166 return self; |
|
167 } |
|
168 |
|
169 // ----------------------------------------------------------------------------- |
|
170 // CCMSX509Certificate::NewL |
|
171 // Two-phased constructor. |
|
172 // ----------------------------------------------------------------------------- |
|
173 // |
|
174 EXPORT_C CCMSX509Certificate* |
|
175 CCMSX509Certificate::NewL( |
|
176 const CX509Certificate& aCertificate ) |
|
177 { |
|
178 CCMSX509Certificate* self = |
|
179 new( ELeave ) CCMSX509Certificate(); |
|
180 CleanupStack::PushL( self ); |
|
181 self->ConstructL( aCertificate ); |
|
182 CleanupStack::Pop(); |
|
183 |
|
184 return self; |
|
185 } |
|
186 |
|
187 // Destructor |
|
188 CCMSX509Certificate::~CCMSX509Certificate() |
|
189 { |
|
190 delete iData; |
|
191 } |
|
192 |
|
193 // ----------------------------------------------------------------------------- |
|
194 // CCMSX509Certificate::DecodeL |
|
195 // Decrypts raw data to this instance |
|
196 // ----------------------------------------------------------------------------- |
|
197 void CCMSX509Certificate::DecodeL( const TDesC8& aRawData ) |
|
198 { |
|
199 CCMSX509AlgorithmIdentifier* algId = NULL; |
|
200 HBufC8* encrypted = NULL; |
|
201 TASN1DecGeneric dataDecoder = |
|
202 DecodeSignatureL( aRawData, algId, encrypted ); |
|
203 |
|
204 CleanupStack::PushL( algId ); |
|
205 CleanupStack::PushL( encrypted ); |
|
206 |
|
207 CArrayPtr< TASN1DecGeneric >* itemList = DecodeSequenceLC( |
|
208 dataDecoder.Encoding(), KToBeSignedItemsMin, KToBeSignedItemsMax ); |
|
209 |
|
210 CCertificateData* data = new( ELeave ) CCertificateData(); |
|
211 CleanupStack::PushL( data ); |
|
212 |
|
213 TInt sequenceCounter = 0; |
|
214 |
|
215 // decode version |
|
216 TASN1DecGeneric* taggedVersion = itemList->At( sequenceCounter ); |
|
217 if( ( taggedVersion->Tag() == KVersionTag ) && |
|
218 ( taggedVersion->Class() == EContextSpecific ) ) |
|
219 { |
|
220 TASN1DecGeneric version( taggedVersion->GetContentDER() ); |
|
221 version.InitL(); |
|
222 TASN1DecInteger intDecoder; |
|
223 data->iVersion = |
|
224 intDecoder.DecodeDERShortL( version ); |
|
225 sequenceCounter++; |
|
226 } |
|
227 |
|
228 // decode serialNumber |
|
229 data->iSerialNumber = |
|
230 itemList->At( sequenceCounter++ )->GetContentDER().AllocL(); |
|
231 |
|
232 // decode signature |
|
233 data->iSignature = CCMSX509AlgorithmIdentifier::NewL(); |
|
234 data->iSignature->DecodeL( itemList->At( sequenceCounter++)->Encoding() ); |
|
235 |
|
236 // decode issuer |
|
237 data->iIssuer = CX500DistinguishedName::NewL( |
|
238 itemList->At( sequenceCounter++ )->Encoding() ); |
|
239 |
|
240 // decode validity |
|
241 data->iValidity = CCMSX509Validity::NewL(); |
|
242 data->iValidity->DecodeL( itemList->At( sequenceCounter++ )->Encoding() ); |
|
243 |
|
244 // decode subject |
|
245 data->iSubject = CX500DistinguishedName::NewL( |
|
246 itemList->At( sequenceCounter++ )->Encoding() ); |
|
247 |
|
248 // decode subjectPublicKeyInfo |
|
249 data->iSubjectPublicKeyInfo = CCMSX509SubjectPublicKeyInfo::NewL(); |
|
250 data->iSubjectPublicKeyInfo->DecodeL( |
|
251 itemList->At( sequenceCounter++ )->Encoding() ); |
|
252 |
|
253 // decode issuerUniqueIdentifier, if it exists |
|
254 TInt itemCount = itemList->Count(); |
|
255 TASN1DecBitString bsDecoder; |
|
256 if( sequenceCounter < itemCount ) |
|
257 { |
|
258 TASN1DecGeneric* taggedIssuerUniqueIdentifier = |
|
259 itemList->At( sequenceCounter ); |
|
260 if( taggedIssuerUniqueIdentifier->Tag() == KIssuerUniqueIdentifierTag ) |
|
261 { |
|
262 data->iIssuerUniqueIdentifier = |
|
263 bsDecoder.ExtractOctetStringL( *taggedIssuerUniqueIdentifier ); |
|
264 sequenceCounter++; |
|
265 } |
|
266 } |
|
267 |
|
268 // decode subjectUniqueIdentifier, if it exists |
|
269 if( sequenceCounter < itemCount ) |
|
270 { |
|
271 TASN1DecGeneric* taggedSubjectUniqueIdentifier = |
|
272 itemList->At( sequenceCounter ); |
|
273 if( taggedSubjectUniqueIdentifier->Tag() == KSubjectUniqueIdentifierTag ) |
|
274 { |
|
275 data->iSubjectUniqueIdentifier = |
|
276 bsDecoder.ExtractOctetStringL( *taggedSubjectUniqueIdentifier ); |
|
277 sequenceCounter++; |
|
278 } |
|
279 } |
|
280 |
|
281 // extensions are ignored |
|
282 |
|
283 // all done, change state |
|
284 delete iAlgorithmIdentifier; |
|
285 iAlgorithmIdentifier = algId; |
|
286 delete iEncrypted; |
|
287 iEncrypted = encrypted; |
|
288 delete iData; |
|
289 iData = data; |
|
290 CleanupStack::Pop( data ); |
|
291 CleanupStack::PopAndDestroy( itemList ); |
|
292 CleanupStack::Pop( encrypted ); |
|
293 CleanupStack::Pop( algId ); |
|
294 } |
|
295 |
|
296 // ----------------------------------------------------------------------------- |
|
297 // CCMSX509Certificate::EncoderLC |
|
298 // Returns ASN1 encoder for this instance |
|
299 // ----------------------------------------------------------------------------- |
|
300 |
|
301 CASN1EncBase* CCMSX509Certificate::EncoderLC() const |
|
302 { |
|
303 |
|
304 // encode ToBeSigned part |
|
305 CASN1EncBase* toBeSigned = ToBeSignedEncoderLC(); |
|
306 |
|
307 // sign |
|
308 CASN1EncSequence* root = SignAndPopLC( toBeSigned ); |
|
309 |
|
310 return root; |
|
311 } |
|
312 |
|
313 // ----------------------------------------------------------------------------- |
|
314 // CCMSX509Certificate::Version() |
|
315 // Getter for Version |
|
316 // ----------------------------------------------------------------------------- |
|
317 EXPORT_C TInt CCMSX509Certificate::Version() const |
|
318 { |
|
319 return iData->iVersion; |
|
320 } |
|
321 |
|
322 // ----------------------------------------------------------------------------- |
|
323 // CCMSX509Certificate::SerialNumber() |
|
324 // Getter for SerialNumber |
|
325 // ----------------------------------------------------------------------------- |
|
326 EXPORT_C const TDesC8& CCMSX509Certificate::SerialNumber() const |
|
327 { |
|
328 return *( iData->iSerialNumber ); |
|
329 } |
|
330 |
|
331 // ----------------------------------------------------------------------------- |
|
332 // CCMSX509Certificate::Signature() |
|
333 // Getter for signature |
|
334 // ----------------------------------------------------------------------------- |
|
335 EXPORT_C const CCMSX509AlgorithmIdentifier& CCMSX509Certificate::Signature() const |
|
336 { |
|
337 return *( iData->iSignature ); |
|
338 } |
|
339 |
|
340 // ----------------------------------------------------------------------------- |
|
341 // CCMSX509Certificate::Issuer() |
|
342 // Getter for issuer |
|
343 // ----------------------------------------------------------------------------- |
|
344 EXPORT_C const CX500DistinguishedName& CCMSX509Certificate::Issuer() const |
|
345 { |
|
346 return *( iData->iIssuer ); |
|
347 } |
|
348 |
|
349 // ----------------------------------------------------------------------------- |
|
350 // CCMSX509Certificate::Validity() |
|
351 // Getter for Validity |
|
352 // ----------------------------------------------------------------------------- |
|
353 EXPORT_C const CCMSX509Validity& CCMSX509Certificate::Validity() const |
|
354 { |
|
355 return *( iData->iValidity ); |
|
356 } |
|
357 |
|
358 // ----------------------------------------------------------------------------- |
|
359 // CCMSX509Certificate::Subject() |
|
360 // Getter for subject |
|
361 // ----------------------------------------------------------------------------- |
|
362 EXPORT_C const CX500DistinguishedName& CCMSX509Certificate::Subject() const |
|
363 { |
|
364 return *( iData->iSubject ); |
|
365 } |
|
366 |
|
367 // ----------------------------------------------------------------------------- |
|
368 // CCMSX509Certificate::SubjectPublicKeyInfo() |
|
369 // Getter for subjectPublicKeyInfo |
|
370 // ----------------------------------------------------------------------------- |
|
371 EXPORT_C const CCMSX509SubjectPublicKeyInfo& |
|
372 CCMSX509Certificate::SubjectPublicKeyInfo() const |
|
373 { |
|
374 return *( iData->iSubjectPublicKeyInfo ); |
|
375 } |
|
376 |
|
377 // ----------------------------------------------------------------------------- |
|
378 // CCMSX509Certificate::IssuerUniqueIdentifier() |
|
379 // Getter for issuerUniqueIdentifier |
|
380 // ----------------------------------------------------------------------------- |
|
381 EXPORT_C const TDesC8* CCMSX509Certificate::IssuerUniqueIdentifier() const |
|
382 { |
|
383 return iData->iIssuerUniqueIdentifier; |
|
384 } |
|
385 |
|
386 // ----------------------------------------------------------------------------- |
|
387 // CCMSX509Certificate::SubjectUniqueIdentifier() |
|
388 // Getter for subjectUniqueIdentifier |
|
389 // ----------------------------------------------------------------------------- |
|
390 EXPORT_C const TDesC8* CCMSX509Certificate::SubjectUniqueIdentifier() const |
|
391 { |
|
392 return iData->iSubjectUniqueIdentifier; |
|
393 } |
|
394 |
|
395 // ----------------------------------------------------------------------------- |
|
396 // CCMSX509Certificate::SetVersion() |
|
397 // Setter for version |
|
398 // ----------------------------------------------------------------------------- |
|
399 EXPORT_C void CCMSX509Certificate::SetVersion( const TInt aVersion ) |
|
400 { |
|
401 iData->iVersion = aVersion; |
|
402 } |
|
403 |
|
404 // ----------------------------------------------------------------------------- |
|
405 // CCMSX509Certificate::SetSerialNumberL() |
|
406 // Setter for serialNumber |
|
407 // ----------------------------------------------------------------------------- |
|
408 EXPORT_C void CCMSX509Certificate::SetSerialNumberL( const TDesC8& aSerialNumber ) |
|
409 { |
|
410 HBufC8* serialNumber = aSerialNumber.AllocLC(); |
|
411 delete iData->iSerialNumber; |
|
412 iData->iSerialNumber = serialNumber; |
|
413 CleanupStack::Pop( serialNumber ); |
|
414 } |
|
415 |
|
416 // ----------------------------------------------------------------------------- |
|
417 // CCMSX509Certificate::SetSignatureL() |
|
418 // Setter for signature |
|
419 // ----------------------------------------------------------------------------- |
|
420 EXPORT_C void CCMSX509Certificate::SetSignatureL( |
|
421 const CCMSX509AlgorithmIdentifier& aSignature ) |
|
422 { |
|
423 CCMSX509AlgorithmIdentifier* signature = |
|
424 CCMSX509AlgorithmIdentifier::NewL( aSignature.AlgorithmIdentifier() ); |
|
425 CleanupStack::PushL( signature ); |
|
426 const CAlgorithmIdentifier* digestIdentifier = |
|
427 aSignature.DigestAlgorithm(); |
|
428 if( digestIdentifier ) |
|
429 { |
|
430 signature->SetDigestAlgorithmL( digestIdentifier ); |
|
431 } |
|
432 CleanupStack::Pop( signature ); |
|
433 delete iData->iSignature; |
|
434 iData->iSignature = signature; |
|
435 } |
|
436 |
|
437 // ----------------------------------------------------------------------------- |
|
438 // CCMSX509Certificate::SetIssuerL() |
|
439 // Setter for issuer |
|
440 // ----------------------------------------------------------------------------- |
|
441 EXPORT_C void CCMSX509Certificate::SetIssuerL( |
|
442 const CX500DistinguishedName& aIssuer ) |
|
443 { |
|
444 CX500DistinguishedName* issuer = CX500DistinguishedName::NewL( aIssuer ); |
|
445 delete iData->iIssuer; |
|
446 iData->iIssuer = issuer; |
|
447 } |
|
448 |
|
449 // ----------------------------------------------------------------------------- |
|
450 // CCMSX509Certificate::SetValidityL() |
|
451 // Setter for validity |
|
452 // ----------------------------------------------------------------------------- |
|
453 EXPORT_C void CCMSX509Certificate::SetValidityL( |
|
454 const CCMSX509Validity& aValidity ) |
|
455 { |
|
456 CCMSX509Validity* validity = |
|
457 CCMSX509Validity::NewL( aValidity.NotBefore(), aValidity.NotAfter() ); |
|
458 delete iData->iValidity; |
|
459 iData->iValidity = validity; |
|
460 } |
|
461 |
|
462 // ----------------------------------------------------------------------------- |
|
463 // CCMSX509Certificate::SetSubjectL() |
|
464 // Setter for subject |
|
465 // ----------------------------------------------------------------------------- |
|
466 EXPORT_C void CCMSX509Certificate::SetSubjectL( |
|
467 const CX500DistinguishedName& aSubject ) |
|
468 { |
|
469 CX500DistinguishedName* subject = CX500DistinguishedName::NewL( aSubject ); |
|
470 delete iData->iSubject; |
|
471 iData->iSubject = subject; |
|
472 } |
|
473 |
|
474 // ----------------------------------------------------------------------------- |
|
475 // CCMSX509Certificate::SetSubjectPublicKeyInfoL() |
|
476 // Setter for subjectPublicKeyInfo |
|
477 // ----------------------------------------------------------------------------- |
|
478 EXPORT_C void CCMSX509Certificate::SetSubjectPublicKeyInfoL( |
|
479 const CCMSX509SubjectPublicKeyInfo& aSubjectPublicKeyInfo ) |
|
480 { |
|
481 CCMSX509SubjectPublicKeyInfo* spkInfo = CCMSX509SubjectPublicKeyInfo::NewL( |
|
482 aSubjectPublicKeyInfo.Algorithm(), |
|
483 aSubjectPublicKeyInfo.SubjectPublicKey() ); |
|
484 delete iData->iSubjectPublicKeyInfo; |
|
485 iData->iSubjectPublicKeyInfo = spkInfo; |
|
486 } |
|
487 |
|
488 // ----------------------------------------------------------------------------- |
|
489 // CCMSX509Certificate::SetIssuerUniqueIdentifierL() |
|
490 // Setter for issuerUniqueIdentifier, make sure version is v2 or v3 |
|
491 // ----------------------------------------------------------------------------- |
|
492 EXPORT_C void CCMSX509Certificate::SetIssuerUniqueIdentifierL( |
|
493 const TDesC8& aIssuerUniqueIdentifier ) |
|
494 { |
|
495 HBufC8* issuerUniqueIdentifier = aIssuerUniqueIdentifier.AllocL(); |
|
496 delete iData->iIssuerUniqueIdentifier; |
|
497 iData->iIssuerUniqueIdentifier = issuerUniqueIdentifier; |
|
498 if( ( iData->iVersion > KVersion3 ) || ( iData->iVersion < KVersion2 ) ) |
|
499 { |
|
500 iData->iVersion = KVersion2; |
|
501 } |
|
502 } |
|
503 |
|
504 // ----------------------------------------------------------------------------- |
|
505 // CCMSX509Certificate::SetSubjectUniqueIdentifierL() |
|
506 // Setter for subjectUniqueIdentifier, make sure version is v2 or v3 |
|
507 // ----------------------------------------------------------------------------- |
|
508 EXPORT_C void CCMSX509Certificate::SetSubjectUniqueIdentifierL( |
|
509 const TDesC8& aSubjectUniqueIdentifier ) |
|
510 { |
|
511 HBufC8* subjectUniqueIdentifier = aSubjectUniqueIdentifier.AllocL(); |
|
512 delete iData->iSubjectUniqueIdentifier; |
|
513 iData->iSubjectUniqueIdentifier = subjectUniqueIdentifier; |
|
514 if( ( iData->iVersion > KVersion3 ) || ( iData->iVersion < KVersion2 ) ) |
|
515 { |
|
516 iData->iVersion = KVersion2; |
|
517 } |
|
518 } |
|
519 |
|
520 // ----------------------------------------------------------------------------- |
|
521 // CCMSX509Certificate::ToBeSignedEncoderLC |
|
522 // Returns ASN1 encoder for the the ToBeSigned part |
|
523 // ----------------------------------------------------------------------------- |
|
524 |
|
525 CASN1EncBase* CCMSX509Certificate::ToBeSignedEncoderLC() const |
|
526 { |
|
527 CASN1EncSequence* root = CASN1EncSequence::NewLC(); |
|
528 |
|
529 // encode version |
|
530 CASN1EncInt* version = CASN1EncInt::NewL( iData->iVersion ); |
|
531 CASN1EncExplicitTag* taggedVersion = |
|
532 CASN1EncExplicitTag::NewLC( version, KVersionTag ); |
|
533 root->AddAndPopChildL( taggedVersion ); |
|
534 |
|
535 // encode serialNumber |
|
536 CASN1EncOctetString* serialNumber = |
|
537 CASN1EncOctetString::NewLC( *( iData->iSerialNumber ) ); |
|
538 serialNumber->SetTag( EASN1Integer, EUniversal ); |
|
539 root->AddAndPopChildL( serialNumber ); |
|
540 |
|
541 // encode signature |
|
542 CASN1EncBase* signature = iData->iSignature->EncoderLC(); |
|
543 root->AddAndPopChildL( signature ); |
|
544 |
|
545 // encode issuer |
|
546 CASN1EncSequence* issuer = iData->iIssuer->EncodeASN1LC(); |
|
547 root->AddAndPopChildL( issuer ); |
|
548 |
|
549 // encode validity |
|
550 CASN1EncBase* validity = iData->iValidity->EncoderLC(); |
|
551 root->AddAndPopChildL( validity ); |
|
552 |
|
553 // encode subject |
|
554 CASN1EncSequence* subject = iData->iSubject->EncodeASN1LC(); |
|
555 root->AddAndPopChildL( subject ); |
|
556 |
|
557 // encode subjectPublicKeyInfo |
|
558 CASN1EncBase* spkInfo = iData->iSubjectPublicKeyInfo->EncoderLC(); |
|
559 root->AddAndPopChildL( spkInfo ); |
|
560 |
|
561 if( iData->iIssuerUniqueIdentifier ) |
|
562 { |
|
563 CASN1EncBitString* iuIdentifier = |
|
564 CASN1EncBitString::NewLC( *iData->iIssuerUniqueIdentifier ); |
|
565 iuIdentifier->SetTag( KIssuerUniqueIdentifierTag ); |
|
566 root->AddAndPopChildL( iuIdentifier ); |
|
567 } |
|
568 if( iData->iSubjectUniqueIdentifier ) |
|
569 { |
|
570 CASN1EncBitString* suIdentifier = |
|
571 CASN1EncBitString::NewLC( *iData->iSubjectUniqueIdentifier ); |
|
572 suIdentifier->SetTag( KSubjectUniqueIdentifierTag ); |
|
573 root->AddAndPopChildL( suIdentifier ); |
|
574 } |
|
575 |
|
576 return root; |
|
577 } |
|
578 |
|
579 // ----------------------------------------------------------------------------- |
|
580 // CCMSX509Certificate::SetDataL |
|
581 // Copies the data from the CX509Certificate object |
|
582 // ----------------------------------------------------------------------------- |
|
583 void CCMSX509Certificate::SetDataL( const CX509Certificate& aCertificate ) |
|
584 { |
|
585 const CSigningAlgorithmIdentifier& signingAlgorithm = |
|
586 aCertificate.SigningAlgorithm(); |
|
587 CCMSX509AlgorithmIdentifier* algId = |
|
588 CCMSX509AlgorithmIdentifier::NewL( signingAlgorithm.AsymmetricAlgorithm(), |
|
589 signingAlgorithm.DigestAlgorithm() ); |
|
590 CleanupStack::PushL( algId ); |
|
591 |
|
592 HBufC8* encrypted = aCertificate.Signature().AllocLC(); |
|
593 |
|
594 CCertificateData* data = new( ELeave ) CCertificateData(); |
|
595 CleanupStack::PushL( data ); |
|
596 |
|
597 data->iVersion = aCertificate.Version(); |
|
598 |
|
599 data->iSerialNumber = aCertificate.SerialNumber().AllocL(); |
|
600 |
|
601 data->iSignature = CCMSX509AlgorithmIdentifier::NewL( |
|
602 signingAlgorithm.AsymmetricAlgorithm(), |
|
603 signingAlgorithm.DigestAlgorithm() ); |
|
604 |
|
605 data->iIssuer = CX500DistinguishedName::NewL( aCertificate.IssuerName() ); |
|
606 |
|
607 data->iValidity = CCMSX509Validity::NewL( aCertificate.ValidityPeriod() ); |
|
608 |
|
609 data->iSubject = CX500DistinguishedName::NewL( aCertificate.SubjectName() ); |
|
610 |
|
611 data->iSubjectPublicKeyInfo = CCMSX509SubjectPublicKeyInfo::NewL( |
|
612 aCertificate.PublicKey() ); |
|
613 |
|
614 // all done, change state |
|
615 delete iData; |
|
616 iData = data; |
|
617 delete iAlgorithmIdentifier; |
|
618 iAlgorithmIdentifier = algId; |
|
619 delete iEncrypted; |
|
620 iEncrypted = encrypted; |
|
621 CleanupStack::Pop( 3 ); // data, encrypted, algId |
|
622 } |
|
623 |
|
624 // End of File |