|
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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "CCMSRecipientEncryptedKey.h" |
|
21 #include "CCMSIssuerAndSerialNumber.h" |
|
22 #include "CCMSKeyIdentifier.h" |
|
23 #include <asn1dec.h> |
|
24 #include <asn1enc.h> |
|
25 |
|
26 // CONSTANTS |
|
27 const TInt KNumberOfSubModules = 2; |
|
28 const TTagType KRKeyIdTag = 0; |
|
29 |
|
30 // ============================ MEMBER FUNCTIONS =============================== |
|
31 |
|
32 // ----------------------------------------------------------------------------- |
|
33 // CCMSRecipientEncryptedKey::CCMSRecipientEncryptedKey |
|
34 // C++ default constructor can NOT contain any code, that |
|
35 // might leave. |
|
36 // ----------------------------------------------------------------------------- |
|
37 // |
|
38 EXPORT_C CCMSRecipientEncryptedKey::CCMSRecipientEncryptedKey() |
|
39 { |
|
40 } |
|
41 |
|
42 // ----------------------------------------------------------------------------- |
|
43 // CCMSRecipientEncryptedKey::ConstructL |
|
44 // Symbian 2nd phase constructor can leave. |
|
45 // ----------------------------------------------------------------------------- |
|
46 // |
|
47 EXPORT_C void CCMSRecipientEncryptedKey::ConstructL( |
|
48 const CCMSIssuerAndSerialNumber& aIssuerAndSerialNumber, |
|
49 const TDesC8& aEncryptedKey ) |
|
50 { |
|
51 SetIssuerAndSerialNumberL( aIssuerAndSerialNumber ); |
|
52 SetEncryptedKeyL( aEncryptedKey ); |
|
53 } |
|
54 |
|
55 // ----------------------------------------------------------------------------- |
|
56 // CCMSRecipientEncryptedKey::ConstructL |
|
57 // Symbian 2nd phase constructor can leave. |
|
58 // ----------------------------------------------------------------------------- |
|
59 // |
|
60 EXPORT_C void CCMSRecipientEncryptedKey::ConstructL( |
|
61 const CCMSKeyIdentifier& aRKeyId, |
|
62 const TDesC8& aEncryptedKey ) |
|
63 { |
|
64 SetRKeyIdL( aRKeyId ); |
|
65 SetEncryptedKeyL( aEncryptedKey ); |
|
66 } |
|
67 |
|
68 |
|
69 // ----------------------------------------------------------------------------- |
|
70 // CCMSRecipientEncryptedKey::NewL |
|
71 // Two-phased constructor. |
|
72 // ----------------------------------------------------------------------------- |
|
73 // |
|
74 EXPORT_C CCMSRecipientEncryptedKey* CCMSRecipientEncryptedKey::NewL() |
|
75 { |
|
76 // creating with empty/default values |
|
77 CCMSIssuerAndSerialNumber* issuer = CCMSIssuerAndSerialNumber::NewL(); |
|
78 CleanupStack::PushL( issuer ); |
|
79 CCMSRecipientEncryptedKey* self = NewL( *issuer, KNullDesC8() ); |
|
80 CleanupStack::PopAndDestroy( issuer ); |
|
81 return self; |
|
82 } |
|
83 |
|
84 // ----------------------------------------------------------------------------- |
|
85 // CCMSRecipientEncryptedKey::NewL |
|
86 // Two-phased copy constructor. |
|
87 // ----------------------------------------------------------------------------- |
|
88 // |
|
89 EXPORT_C CCMSRecipientEncryptedKey* CCMSRecipientEncryptedKey::NewL( |
|
90 const CCMSIssuerAndSerialNumber& aIssuerAndSerialNumber, |
|
91 const TDesC8& aEncryptedKey ) |
|
92 { |
|
93 CCMSRecipientEncryptedKey* self = |
|
94 new( ELeave ) CCMSRecipientEncryptedKey(); |
|
95 |
|
96 CleanupStack::PushL( self ); |
|
97 self->ConstructL( aIssuerAndSerialNumber, aEncryptedKey ); |
|
98 CleanupStack::Pop( self ); |
|
99 return self; |
|
100 } |
|
101 |
|
102 // ----------------------------------------------------------------------------- |
|
103 // CCMSRecipientEncryptedKey::NewL |
|
104 // Two-phased copy constructor. |
|
105 // ----------------------------------------------------------------------------- |
|
106 // |
|
107 EXPORT_C CCMSRecipientEncryptedKey* CCMSRecipientEncryptedKey::NewL( |
|
108 const CCMSKeyIdentifier& aRKeyId, |
|
109 const TDesC8& aEncryptedKey ) |
|
110 { |
|
111 CCMSRecipientEncryptedKey* self = |
|
112 new( ELeave ) CCMSRecipientEncryptedKey(); |
|
113 |
|
114 CleanupStack::PushL( self ); |
|
115 self->ConstructL( aRKeyId, aEncryptedKey ); |
|
116 CleanupStack::Pop( self ); |
|
117 return self; |
|
118 } |
|
119 |
|
120 |
|
121 // Destructor |
|
122 CCMSRecipientEncryptedKey::~CCMSRecipientEncryptedKey() |
|
123 { |
|
124 delete iEncryptedKey; |
|
125 delete iIssuerAndSerialNumber; |
|
126 delete iRKeyId; |
|
127 } |
|
128 |
|
129 // ----------------------------------------------------------------------------- |
|
130 // CCMSRecipientEncryptedKey::DecodeL |
|
131 // Decrypts raw data to this instance |
|
132 // ----------------------------------------------------------------------------- |
|
133 void CCMSRecipientEncryptedKey::DecodeL( const TDesC8& aRawData ) |
|
134 { |
|
135 CArrayPtr< TASN1DecGeneric >* itemsData = |
|
136 DecodeSequenceLC( aRawData, KNumberOfSubModules, KNumberOfSubModules ); |
|
137 |
|
138 // decode rid KeyAgreeRecipientIdentifier |
|
139 TASN1DecGeneric gen( *itemsData->At( 0 ) ); |
|
140 gen.InitL(); |
|
141 if( gen.Tag() == KRKeyIdTag ) |
|
142 { |
|
143 // decode rKeyId |
|
144 CCMSKeyIdentifier* keyId = CCMSKeyIdentifier::NewL(); |
|
145 CleanupStack::PushL( keyId ); |
|
146 keyId->DecodeImplicitTagL( gen.Encoding(), KRKeyIdTag ); |
|
147 CleanupStack::Pop( keyId ); |
|
148 delete iIssuerAndSerialNumber; |
|
149 iIssuerAndSerialNumber = NULL; |
|
150 delete iRKeyId; |
|
151 iRKeyId = keyId; |
|
152 } |
|
153 else |
|
154 { |
|
155 // delete issuerAndSerialNumber |
|
156 CCMSIssuerAndSerialNumber* issuer = CCMSIssuerAndSerialNumber::NewL(); |
|
157 CleanupStack::PushL( issuer ); |
|
158 issuer->DecodeL( gen.Encoding() ); |
|
159 CleanupStack::Pop( issuer ); |
|
160 delete iRKeyId; |
|
161 iRKeyId = NULL; |
|
162 delete iIssuerAndSerialNumber; |
|
163 iIssuerAndSerialNumber = issuer; |
|
164 } |
|
165 |
|
166 //decode encryptedKey |
|
167 TASN1DecGeneric keyDecoder( *itemsData->At( 1 ) ); |
|
168 keyDecoder.InitL(); |
|
169 TASN1DecOctetString octetStringDecoder; |
|
170 HBufC8* tmp = octetStringDecoder.DecodeDERL( keyDecoder ); |
|
171 delete iEncryptedKey; |
|
172 iEncryptedKey = tmp; |
|
173 CleanupStack::PopAndDestroy( itemsData ); |
|
174 } |
|
175 |
|
176 // ----------------------------------------------------------------------------- |
|
177 // CCMSRecipientEncryptedKey::EncoderLC |
|
178 // Returns ASN1 encoder for this instance |
|
179 // ----------------------------------------------------------------------------- |
|
180 |
|
181 CASN1EncBase* CCMSRecipientEncryptedKey::EncoderLC() const |
|
182 { |
|
183 CASN1EncSequence* root = CASN1EncSequence::NewLC(); |
|
184 |
|
185 // encode rid KeyAgreeRecipientIdentifier |
|
186 if( iIssuerAndSerialNumber ) |
|
187 { |
|
188 // encode issuerAndSerialNumber |
|
189 HBufC8* encodedIssuer = NULL; |
|
190 iIssuerAndSerialNumber->EncodeL( encodedIssuer ); |
|
191 CleanupStack::PushL( encodedIssuer ); |
|
192 CASN1EncEncoding* issuer = CASN1EncEncoding::NewLC( *encodedIssuer ); |
|
193 root->AddAndPopChildL( issuer ); |
|
194 CleanupStack::PopAndDestroy( encodedIssuer ); |
|
195 } |
|
196 else |
|
197 { |
|
198 // encode rKeyId [0] IMPLICIT RecipientKeyIdentifier |
|
199 HBufC8* encodedRKeyId = NULL; |
|
200 iRKeyId->EncodeL( encodedRKeyId ); |
|
201 CleanupStack::PushL( encodedRKeyId ); |
|
202 CASN1EncEncoding* rKeyId = CASN1EncEncoding::NewLC( *encodedRKeyId ); |
|
203 rKeyId->SetTag( KRKeyIdTag ); |
|
204 root->AddAndPopChildL( rKeyId ); |
|
205 CleanupStack::PopAndDestroy( encodedRKeyId ); |
|
206 } |
|
207 |
|
208 // encode encryptedKey |
|
209 CASN1EncOctetString* encryptedKey = |
|
210 CASN1EncOctetString::NewLC( *iEncryptedKey ); |
|
211 root->AddAndPopChildL( encryptedKey ); |
|
212 |
|
213 return root; |
|
214 } |
|
215 |
|
216 // ----------------------------------------------------------------------------- |
|
217 // CCMSRecipientEncryptedKey::EncryptedKey |
|
218 // EncryptedKey getter |
|
219 // ----------------------------------------------------------------------------- |
|
220 EXPORT_C const TDesC8& |
|
221 CCMSRecipientEncryptedKey::EncryptedKey() const |
|
222 { |
|
223 return *iEncryptedKey; |
|
224 } |
|
225 |
|
226 // ----------------------------------------------------------------------------- |
|
227 // CCMSRecipientEncryptedKey::IssuerAndSerialNumber |
|
228 // IssuerAndSerialNumber getter |
|
229 // ----------------------------------------------------------------------------- |
|
230 EXPORT_C const CCMSIssuerAndSerialNumber* |
|
231 CCMSRecipientEncryptedKey::IssuerAndSerialNumber() const |
|
232 { |
|
233 return iIssuerAndSerialNumber; |
|
234 } |
|
235 |
|
236 // ----------------------------------------------------------------------------- |
|
237 // CCMSRecipientEncryptedKey::RecipientKeyIdentifier |
|
238 // RecipientKeyIdentifier getter |
|
239 // ----------------------------------------------------------------------------- |
|
240 EXPORT_C const CCMSKeyIdentifier* |
|
241 CCMSRecipientEncryptedKey::RKeyId() const |
|
242 { |
|
243 return iRKeyId; |
|
244 } |
|
245 |
|
246 // ----------------------------------------------------------------------------- |
|
247 // CCMSRecipientEncryptedKey::SetEncryptedKeyL |
|
248 // EncryptedKey setter |
|
249 // ----------------------------------------------------------------------------- |
|
250 EXPORT_C void CCMSRecipientEncryptedKey::SetEncryptedKeyL( |
|
251 const TDesC8& aEncryptedKey ) |
|
252 { |
|
253 HBufC8* encryptedKey = aEncryptedKey.AllocL(); |
|
254 delete iEncryptedKey; |
|
255 iEncryptedKey = encryptedKey; |
|
256 } |
|
257 |
|
258 // ----------------------------------------------------------------------------- |
|
259 // CCMSRecipientEncryptedKey::SetIssuerAndSerialNumberL |
|
260 // IssuerAndSerialNumber setter, deletes also rKeyId |
|
261 // ----------------------------------------------------------------------------- |
|
262 EXPORT_C void CCMSRecipientEncryptedKey::SetIssuerAndSerialNumberL( |
|
263 const CCMSIssuerAndSerialNumber& aIssuerAndSerialNumber ) |
|
264 { |
|
265 CCMSIssuerAndSerialNumber* issuer = CCMSIssuerAndSerialNumber::NewL( |
|
266 aIssuerAndSerialNumber.IssuerName(), |
|
267 aIssuerAndSerialNumber.SerialNumber() ); |
|
268 delete iRKeyId; |
|
269 iRKeyId = NULL; |
|
270 delete iIssuerAndSerialNumber; |
|
271 iIssuerAndSerialNumber = issuer; |
|
272 } |
|
273 |
|
274 // ----------------------------------------------------------------------------- |
|
275 // CCMSRecipientEncryptedKey::SetRKeyIdL |
|
276 // rKeyId setter, deletes also IssuerAndSerialNumber |
|
277 // ----------------------------------------------------------------------------- |
|
278 EXPORT_C void CCMSRecipientEncryptedKey::SetRKeyIdL( |
|
279 const CCMSKeyIdentifier& aRKeyId ) |
|
280 { |
|
281 CCMSKeyIdentifier* keyId = NULL; |
|
282 const TTime* keyIdDate = aRKeyId.Date(); |
|
283 if( keyIdDate ) |
|
284 { |
|
285 keyId = CCMSKeyIdentifier::NewL( |
|
286 aRKeyId.KeyIdentifier(), *keyIdDate ); |
|
287 } |
|
288 else |
|
289 { |
|
290 keyId = CCMSKeyIdentifier::NewL( |
|
291 aRKeyId.KeyIdentifier() ); |
|
292 } |
|
293 delete iIssuerAndSerialNumber; |
|
294 iIssuerAndSerialNumber = NULL; |
|
295 delete iRKeyId; |
|
296 iRKeyId = keyId; |
|
297 } |
|
298 |
|
299 // End of File |