|
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 "CCMSX509AttributeCertificate.h" |
|
21 #include "CCMSX509AttributeCertificateInfo.h" |
|
22 #include "CCMSX509AlgorithmIdentifier.h" |
|
23 #include <asn1dec.h> |
|
24 #include <asn1enc.h> |
|
25 |
|
26 |
|
27 // ============================ MEMBER FUNCTIONS =============================== |
|
28 |
|
29 // ----------------------------------------------------------------------------- |
|
30 // CCMSX509AttributeCertificate::CCMSX509AttributeCertificate |
|
31 // C++ default constructor can NOT contain any code, that |
|
32 // might leave. |
|
33 // ----------------------------------------------------------------------------- |
|
34 // |
|
35 EXPORT_C CCMSX509AttributeCertificate::CCMSX509AttributeCertificate() |
|
36 { |
|
37 } |
|
38 |
|
39 // ----------------------------------------------------------------------------- |
|
40 // CCMSX509AttributeCertificate::ConstructL |
|
41 // Symbian 2nd phase constructor can leave. |
|
42 // ----------------------------------------------------------------------------- |
|
43 // |
|
44 EXPORT_C void CCMSX509AttributeCertificate::ConstructL( |
|
45 const CCMSX509AttributeCertificateInfo& aInfo, |
|
46 const CCMSX509AlgorithmIdentifier& aAlgorithmIdentifier, |
|
47 const TDesC8& aEncrypted ) |
|
48 { |
|
49 BaseConstructL( aAlgorithmIdentifier, aEncrypted ); |
|
50 SetInfoL( aInfo ); |
|
51 } |
|
52 |
|
53 // ----------------------------------------------------------------------------- |
|
54 // CCMSX509AttributeCertificate::ConstructL |
|
55 // Symbian 2nd phase constructor can leave. |
|
56 // ----------------------------------------------------------------------------- |
|
57 // |
|
58 EXPORT_C void CCMSX509AttributeCertificate::ConstructL( ) |
|
59 { |
|
60 // creating empty/default values |
|
61 iInfo = CCMSX509AttributeCertificateInfo::NewL(); |
|
62 iAlgorithmIdentifier = CCMSX509AlgorithmIdentifier::NewL(); |
|
63 iEncrypted = KNullDesC8().AllocL(); |
|
64 } |
|
65 |
|
66 |
|
67 // ----------------------------------------------------------------------------- |
|
68 // CCMSX509AttributeCertificate::NewL |
|
69 // Two-phased constructor. |
|
70 // ----------------------------------------------------------------------------- |
|
71 // |
|
72 EXPORT_C CCMSX509AttributeCertificate* |
|
73 CCMSX509AttributeCertificate::NewL() |
|
74 { |
|
75 // creating with empty values |
|
76 CCMSX509AttributeCertificate* self = |
|
77 new( ELeave ) CCMSX509AttributeCertificate(); |
|
78 CleanupStack::PushL( self ); |
|
79 self->ConstructL( ); |
|
80 CleanupStack::Pop( self ); |
|
81 return self; |
|
82 } |
|
83 |
|
84 // ----------------------------------------------------------------------------- |
|
85 // CCMSX509AttributeCertificate::NewL |
|
86 // Two-phased constructor. |
|
87 // ----------------------------------------------------------------------------- |
|
88 // |
|
89 EXPORT_C CCMSX509AttributeCertificate* |
|
90 CCMSX509AttributeCertificate::NewL( |
|
91 const CCMSX509AttributeCertificateInfo& aInfo, |
|
92 const CCMSX509AlgorithmIdentifier& aAlgorithmIdentifier, |
|
93 const TDesC8& aEncrypted ) |
|
94 { |
|
95 CCMSX509AttributeCertificate* self = |
|
96 new( ELeave ) CCMSX509AttributeCertificate(); |
|
97 CleanupStack::PushL( self ); |
|
98 self->ConstructL( aInfo, aAlgorithmIdentifier, aEncrypted ); |
|
99 CleanupStack::Pop(); |
|
100 |
|
101 return self; |
|
102 } |
|
103 |
|
104 // Destructor |
|
105 CCMSX509AttributeCertificate::~CCMSX509AttributeCertificate() |
|
106 { |
|
107 delete iInfo; |
|
108 } |
|
109 |
|
110 // ----------------------------------------------------------------------------- |
|
111 // CCMSX509AttributeCertificate::DecodeL |
|
112 // Decrypts raw data to this instance |
|
113 // ----------------------------------------------------------------------------- |
|
114 void CCMSX509AttributeCertificate::DecodeL( const TDesC8& aRawData ) |
|
115 { |
|
116 CCMSX509AlgorithmIdentifier* algId = NULL; |
|
117 HBufC8* encrypted = NULL; |
|
118 TASN1DecGeneric infoDecoder = |
|
119 DecodeSignatureL( aRawData, algId, encrypted ); |
|
120 |
|
121 CleanupStack::PushL( algId ); |
|
122 CleanupStack::PushL( encrypted ); |
|
123 |
|
124 // decode info |
|
125 CCMSX509AttributeCertificateInfo* info = |
|
126 CCMSX509AttributeCertificateInfo::NewL( ); |
|
127 CleanupStack::PushL( info ); |
|
128 info->DecodeL( infoDecoder.Encoding() ); |
|
129 |
|
130 // all done, change state |
|
131 delete iInfo; |
|
132 iInfo = info; |
|
133 delete iAlgorithmIdentifier; |
|
134 iAlgorithmIdentifier = algId; |
|
135 delete iEncrypted; |
|
136 iEncrypted = encrypted; |
|
137 CleanupStack::Pop( 3 ); // info, encrypted, algId |
|
138 } |
|
139 |
|
140 // ----------------------------------------------------------------------------- |
|
141 // CCMSX509AttributeCertificate::EncoderLC |
|
142 // Returns ASN1 encoder for this instance |
|
143 // ----------------------------------------------------------------------------- |
|
144 |
|
145 CASN1EncBase* CCMSX509AttributeCertificate::EncoderLC() const |
|
146 { |
|
147 // encode AttributeCertificateInfo |
|
148 CASN1EncBase* info = iInfo->EncoderLC( ); |
|
149 |
|
150 // sign |
|
151 CASN1EncSequence* root = SignAndPopLC( info ); |
|
152 |
|
153 return root; |
|
154 } |
|
155 |
|
156 // ----------------------------------------------------------------------------- |
|
157 // CCMSX509AttributeCertificate::Info() |
|
158 // Getter for AttributeCertificateInfo |
|
159 // ----------------------------------------------------------------------------- |
|
160 EXPORT_C const CCMSX509AttributeCertificateInfo& |
|
161 CCMSX509AttributeCertificate::Info() const |
|
162 { |
|
163 return *iInfo; |
|
164 } |
|
165 |
|
166 // ----------------------------------------------------------------------------- |
|
167 // CCMSX509AttributeCertificate::SetInfoL() |
|
168 // Setter for AttributeCertificateInfo |
|
169 // ----------------------------------------------------------------------------- |
|
170 EXPORT_C void CCMSX509AttributeCertificate::SetInfoL( |
|
171 const CCMSX509AttributeCertificateInfo& aInfo ) |
|
172 { |
|
173 CCMSX509AttributeCertificateInfo* info = NULL; |
|
174 const CCMSX509IssuerSerial* baseCertificateID = aInfo.BaseCertificateID(); |
|
175 if( baseCertificateID ) |
|
176 { |
|
177 info = CCMSX509AttributeCertificateInfo::NewL( |
|
178 *baseCertificateID, |
|
179 aInfo.Issuer(), |
|
180 aInfo.Signature(), |
|
181 aInfo.SerialNumber(), |
|
182 aInfo.NotBeforeTime(), |
|
183 aInfo.NotAfterTime(), |
|
184 aInfo.Attributes() ); |
|
185 } |
|
186 else |
|
187 { |
|
188 info = CCMSX509AttributeCertificateInfo::NewL( |
|
189 *aInfo.SubjectName(), |
|
190 aInfo.Issuer(), |
|
191 aInfo.Signature(), |
|
192 aInfo.SerialNumber(), |
|
193 aInfo.NotBeforeTime(), |
|
194 aInfo.NotAfterTime(), |
|
195 aInfo.Attributes() ); |
|
196 } |
|
197 CleanupStack::PushL( info ); |
|
198 |
|
199 info->SetVersion( aInfo.Version() ); |
|
200 |
|
201 const TDesC8* issuerUniqueID = aInfo.IssuerUniqueID(); |
|
202 if( issuerUniqueID ) |
|
203 { |
|
204 info->SetIssuerUniqueIDL( *issuerUniqueID ); |
|
205 } |
|
206 |
|
207 delete iInfo; |
|
208 iInfo = info; |
|
209 CleanupStack::Pop( info ); |
|
210 |
|
211 } |
|
212 |
|
213 // ----------------------------------------------------------------------------- |
|
214 // CCMSX509AttributeCertificate::DecodeImplicitTagL |
|
215 // Decrypts raw data with implicit tag |
|
216 // ----------------------------------------------------------------------------- |
|
217 void CCMSX509AttributeCertificate::DecodeImplicitTagL( |
|
218 const TDesC8& aRawData, |
|
219 const TTagType aImplicitTag ) |
|
220 { |
|
221 CArrayPtr< TASN1DecGeneric >* items = NULL; |
|
222 |
|
223 // Check the tag |
|
224 TASN1DecGeneric decGen( aRawData ); |
|
225 decGen.InitL(); |
|
226 // Accept only given tag |
|
227 if( decGen.Tag() != aImplicitTag ) |
|
228 { |
|
229 User::Leave( KErrArgument ); |
|
230 } |
|
231 TASN1DecSequence decSeq; |
|
232 items = decSeq.DecodeDERLC( decGen ); |
|
233 DecodeArrayL( items ); |
|
234 CleanupStack::PopAndDestroy( items ); |
|
235 } |
|
236 |
|
237 // ----------------------------------------------------------------------------- |
|
238 // CCMSX509AttributeCertificate::DecodeArrayL |
|
239 // Decodes data from an array of decoders |
|
240 // ----------------------------------------------------------------------------- |
|
241 void CCMSX509AttributeCertificate::DecodeArrayL( |
|
242 CArrayPtr< TASN1DecGeneric >* aItems ) |
|
243 { |
|
244 CCMSX509AlgorithmIdentifier* algId = NULL; |
|
245 HBufC8* encrypted = NULL; |
|
246 TASN1DecGeneric infoDecoder = |
|
247 DecodeSignatureArrayL( *aItems, algId, encrypted ); |
|
248 |
|
249 CleanupStack::PushL( algId ); |
|
250 CleanupStack::PushL( encrypted ); |
|
251 |
|
252 // decode info |
|
253 CCMSX509AttributeCertificateInfo* info = |
|
254 CCMSX509AttributeCertificateInfo::NewL( ); |
|
255 CleanupStack::PushL( info ); |
|
256 info->DecodeL( infoDecoder.Encoding() ); |
|
257 |
|
258 // all done, change state |
|
259 delete iInfo; |
|
260 iInfo = info; |
|
261 delete iAlgorithmIdentifier; |
|
262 iAlgorithmIdentifier = algId; |
|
263 delete iEncrypted; |
|
264 iEncrypted = encrypted; |
|
265 CleanupStack::Pop( 3 ); // info, encrypted, algId |
|
266 } |
|
267 |
|
268 // End of File |