|
1 /* |
|
2 * Copyright (c) 2003-2009 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 the License "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 |
|
20 |
|
21 #include "pkcs7signerinfo.h" |
|
22 #include "pkcs7issuerserial.h" |
|
23 #include "pkcs7asn1.h" |
|
24 #include "signed.h" |
|
25 #include <asn1dec.h> |
|
26 #include <x509cert.h> |
|
27 |
|
28 CPKCS7SignerInfo* CPKCS7SignerInfo::NewL(const TDesC8& aRawData) |
|
29 { |
|
30 CPKCS7SignerInfo* self = new (ELeave) CPKCS7SignerInfo(); |
|
31 CleanupStack::PushL(self); |
|
32 self->ConstructL(aRawData); |
|
33 CleanupStack::Pop(self); |
|
34 return self; |
|
35 } |
|
36 |
|
37 CPKCS7SignerInfo::~CPKCS7SignerInfo(void) |
|
38 { |
|
39 delete iIssuerAndSerialNumber; |
|
40 delete iDigestAlgorithm; |
|
41 delete iDigestEncryptionAlgorithm; |
|
42 delete iEncryptedDigest; |
|
43 } |
|
44 |
|
45 CPKCS7SignerInfo::CPKCS7SignerInfo(void) |
|
46 { |
|
47 } |
|
48 |
|
49 EXPORT_C TInt CPKCS7SignerInfo::Version() const |
|
50 { |
|
51 return iVersion; |
|
52 } |
|
53 |
|
54 EXPORT_C const CPKCS7IssuerAndSerialNumber& CPKCS7SignerInfo::IssuerAndSerialNumber() const |
|
55 { |
|
56 return *iIssuerAndSerialNumber; |
|
57 } |
|
58 |
|
59 EXPORT_C const CX509AlgorithmIdentifier& CPKCS7SignerInfo::DigestAlgorithm() const |
|
60 { |
|
61 return *iDigestAlgorithm; |
|
62 } |
|
63 |
|
64 EXPORT_C const CX509AlgorithmIdentifier& CPKCS7SignerInfo::DigestEncryptionAlgorithm() const |
|
65 { |
|
66 return *iDigestEncryptionAlgorithm; |
|
67 } |
|
68 |
|
69 EXPORT_C const TPtrC8 CPKCS7SignerInfo::EncryptedDigest() const |
|
70 { |
|
71 return *iEncryptedDigest; |
|
72 } |
|
73 |
|
74 |
|
75 void CPKCS7SignerInfo::ConstructL(const TDesC8& aRawData) |
|
76 { |
|
77 CArrayPtr<TASN1DecGeneric>* signerInfo = PKCS7ASN1::DecodeSequenceLC(aRawData, 5, 7); |
|
78 TASN1DecInteger decInt; |
|
79 TInt pos = 3; |
|
80 |
|
81 // decodes version |
|
82 iVersion = decInt.DecodeDERShortL(*signerInfo->At(0)); |
|
83 |
|
84 iIssuerAndSerialNumber = CPKCS7IssuerAndSerialNumber::NewL(signerInfo->At(1)->Encoding()); |
|
85 |
|
86 iDigestAlgorithm = CX509AlgorithmIdentifier::NewL(signerInfo->At(2)->Encoding()); |
|
87 |
|
88 if(signerInfo->At(pos)->Tag() == 0) |
|
89 { |
|
90 // authenticated attributes not supported at this time |
|
91 pos++; |
|
92 } |
|
93 iDigestEncryptionAlgorithm = CX509AlgorithmIdentifier::NewL(signerInfo->At(pos++)->Encoding()); |
|
94 DecodeEncryptedDigestL(signerInfo->At(pos++)->Encoding()); |
|
95 |
|
96 if(pos < signerInfo->Count() && (signerInfo->At(pos)->Tag() == 0)) |
|
97 { |
|
98 // unauthenticated attributes not supported at this time |
|
99 pos++; |
|
100 } |
|
101 |
|
102 CleanupStack::PopAndDestroy(signerInfo); |
|
103 } |
|
104 |
|
105 void CPKCS7SignerInfo::DecodeEncryptedDigestL(const TDesC8& aRawData) |
|
106 { |
|
107 TASN1DecGeneric decGen(aRawData); |
|
108 decGen.InitL(); |
|
109 |
|
110 if(decGen.Tag() == EASN1OctetString) |
|
111 { |
|
112 TASN1DecOctetString decOct; |
|
113 iEncryptedDigest = decOct.DecodeDERL(decGen); |
|
114 } |
|
115 else |
|
116 { |
|
117 User::Leave(KErrArgument); |
|
118 } |
|
119 } |