sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description:
|
sl@0
|
15 |
* -- FingerPrint Note:
|
sl@0
|
16 |
* Developers have to be aware that if they are going to change the fingerprint for this certificate
|
sl@0
|
17 |
* for a different hash, then there are other places that need to reflect this change
|
sl@0
|
18 |
* -- Location
|
sl@0
|
19 |
* void CWTLSCertificate::ConstructL(const TDesC8& aBinaryData, TInt& aPos)
|
sl@0
|
20 |
* EXPORT_C void CWTLSCertificate::InternalizeL(RReadStream& aStream)
|
sl@0
|
21 |
* Also change the CX509Certificate and search for other occurences of the current
|
sl@0
|
22 |
* hash.
|
sl@0
|
23 |
*
|
sl@0
|
24 |
*/
|
sl@0
|
25 |
|
sl@0
|
26 |
|
sl@0
|
27 |
#include <wtlscert.h>
|
sl@0
|
28 |
#include <wtlskeys.h>
|
sl@0
|
29 |
#include "wtlsdec.h"
|
sl@0
|
30 |
#include <hash.h>
|
sl@0
|
31 |
|
sl@0
|
32 |
enum TEncAlgorithmType
|
sl@0
|
33 |
{
|
sl@0
|
34 |
EEncRSA = 0x02
|
sl@0
|
35 |
};
|
sl@0
|
36 |
|
sl@0
|
37 |
enum TEncSigAlgorithmType
|
sl@0
|
38 |
{
|
sl@0
|
39 |
EEncRSAwithSHA1 = 0x02
|
sl@0
|
40 |
};
|
sl@0
|
41 |
|
sl@0
|
42 |
const TInt KMinAlgIdLength = 2;
|
sl@0
|
43 |
const TInt KMinExpLengthBytes = 1;
|
sl@0
|
44 |
const TInt KMaxExpLengthBytes = 65535;
|
sl@0
|
45 |
const TInt KMinModLengthBytes = 1;
|
sl@0
|
46 |
const TInt KMaxModLengthBytes = 65535;
|
sl@0
|
47 |
|
sl@0
|
48 |
//WTLS RSA signature result
|
sl@0
|
49 |
EXPORT_C CWTLSRSASignatureResult* CWTLSRSASignatureResult::NewL(const CAlgorithmIdentifier& aDigestAlgorithm, const TDesC8& aDigest)
|
sl@0
|
50 |
{
|
sl@0
|
51 |
CWTLSRSASignatureResult* self = CWTLSRSASignatureResult::NewLC(aDigestAlgorithm, aDigest);
|
sl@0
|
52 |
CleanupStack::Pop();
|
sl@0
|
53 |
return self;
|
sl@0
|
54 |
}
|
sl@0
|
55 |
|
sl@0
|
56 |
EXPORT_C CWTLSRSASignatureResult* CWTLSRSASignatureResult::NewLC(const CAlgorithmIdentifier& aDigestAlgorithm, const TDesC8& aDigest)
|
sl@0
|
57 |
{
|
sl@0
|
58 |
CWTLSRSASignatureResult* self = new(ELeave) CWTLSRSASignatureResult;
|
sl@0
|
59 |
CleanupStack::PushL(self);
|
sl@0
|
60 |
self->ConstructL(aDigestAlgorithm, aDigest);
|
sl@0
|
61 |
return self;
|
sl@0
|
62 |
}
|
sl@0
|
63 |
|
sl@0
|
64 |
EXPORT_C TBool CWTLSRSASignatureResult::VerifyL(const TDesC8& aResult)
|
sl@0
|
65 |
{
|
sl@0
|
66 |
return aResult == *iDigest;
|
sl@0
|
67 |
}
|
sl@0
|
68 |
|
sl@0
|
69 |
void CWTLSRSASignatureResult::ConstructL(const CAlgorithmIdentifier& aDigestAlgorithm, const TDesC8& aDigest)
|
sl@0
|
70 |
{
|
sl@0
|
71 |
iDigestAlgorithm = CAlgorithmIdentifier::NewL(aDigestAlgorithm);
|
sl@0
|
72 |
iDigest = aDigest.AllocL();
|
sl@0
|
73 |
}
|
sl@0
|
74 |
|
sl@0
|
75 |
//WTLS KeyFactory
|
sl@0
|
76 |
CRSAPublicKey* TWTLSKeyFactory::RSAPublicKeyL(const TDesC8& aEncoding) const
|
sl@0
|
77 |
{
|
sl@0
|
78 |
return CWTLSRSAPublicKey::NewL(aEncoding);
|
sl@0
|
79 |
}
|
sl@0
|
80 |
|
sl@0
|
81 |
CRSASignatureResult* TWTLSKeyFactory::RSASignatureResultL(const CAlgorithmIdentifier& aDigestAlgorithm, TDesC8& aDigest) const
|
sl@0
|
82 |
{
|
sl@0
|
83 |
return CWTLSRSASignatureResult::NewL(aDigestAlgorithm, aDigest);
|
sl@0
|
84 |
}
|
sl@0
|
85 |
|
sl@0
|
86 |
CDSAPublicKey* TWTLSKeyFactory::DSAPublicKeyL(const CDSAParameters& /*aParams*/, const TDesC8& /*aEncoding*/) const
|
sl@0
|
87 |
{
|
sl@0
|
88 |
User::Leave(KErrNotSupported);
|
sl@0
|
89 |
return NULL;
|
sl@0
|
90 |
}
|
sl@0
|
91 |
|
sl@0
|
92 |
CDSAPublicKey* TWTLSKeyFactory::DSAPublicKeyL(const TDesC8& /*aParams*/, const TDesC8& /*aEncoding*/) const
|
sl@0
|
93 |
{
|
sl@0
|
94 |
User::Leave(KErrNotSupported);
|
sl@0
|
95 |
return NULL;
|
sl@0
|
96 |
}
|
sl@0
|
97 |
|
sl@0
|
98 |
CDSASignature* TWTLSKeyFactory::DSASignatureL(const TDesC8& /*aEncoding*/) const
|
sl@0
|
99 |
{
|
sl@0
|
100 |
User::Leave(KErrNotSupported);
|
sl@0
|
101 |
return NULL;
|
sl@0
|
102 |
}
|
sl@0
|
103 |
|
sl@0
|
104 |
|
sl@0
|
105 |
CDSAParameters* TWTLSKeyFactory::DSAParametersL(const TDesC8& /*aParamsEncoding*/) const
|
sl@0
|
106 |
{
|
sl@0
|
107 |
User::Leave(KErrNotSupported);
|
sl@0
|
108 |
return NULL;
|
sl@0
|
109 |
}
|
sl@0
|
110 |
|
sl@0
|
111 |
//validity period
|
sl@0
|
112 |
EXPORT_C CWTLSValidityPeriod* CWTLSValidityPeriod::NewL(const TDesC8& aBinaryData)
|
sl@0
|
113 |
{
|
sl@0
|
114 |
TInt pos = 0;
|
sl@0
|
115 |
return CWTLSValidityPeriod::NewL(aBinaryData, pos);
|
sl@0
|
116 |
}
|
sl@0
|
117 |
|
sl@0
|
118 |
EXPORT_C CWTLSValidityPeriod* CWTLSValidityPeriod::NewLC(const TDesC8& aBinaryData)
|
sl@0
|
119 |
{
|
sl@0
|
120 |
TInt pos = 0;
|
sl@0
|
121 |
return CWTLSValidityPeriod::NewLC(aBinaryData, pos);
|
sl@0
|
122 |
}
|
sl@0
|
123 |
|
sl@0
|
124 |
EXPORT_C CWTLSValidityPeriod* CWTLSValidityPeriod::NewL(const TDesC8& aBinaryData, TInt& aPos)
|
sl@0
|
125 |
{
|
sl@0
|
126 |
CWTLSValidityPeriod* self = CWTLSValidityPeriod::NewLC(aBinaryData, aPos);
|
sl@0
|
127 |
CleanupStack::Pop();
|
sl@0
|
128 |
return self;
|
sl@0
|
129 |
}
|
sl@0
|
130 |
|
sl@0
|
131 |
EXPORT_C CWTLSValidityPeriod* CWTLSValidityPeriod::NewLC(const TDesC8& aBinaryData, TInt& aPos)
|
sl@0
|
132 |
{
|
sl@0
|
133 |
CWTLSValidityPeriod* self = new(ELeave) CWTLSValidityPeriod;
|
sl@0
|
134 |
CleanupStack::PushL(self);
|
sl@0
|
135 |
self->ConstructL(aBinaryData, aPos);
|
sl@0
|
136 |
return self;
|
sl@0
|
137 |
}
|
sl@0
|
138 |
|
sl@0
|
139 |
CWTLSValidityPeriod::CWTLSValidityPeriod()
|
sl@0
|
140 |
{
|
sl@0
|
141 |
}
|
sl@0
|
142 |
|
sl@0
|
143 |
void CWTLSValidityPeriod::ConstructL(const TDesC8& aBinaryData, TInt& aPos)
|
sl@0
|
144 |
{
|
sl@0
|
145 |
TWTLSDecTime timeDec;
|
sl@0
|
146 |
iStart = timeDec.DecodeL(aBinaryData, aPos);
|
sl@0
|
147 |
iFinish = timeDec.DecodeL(aBinaryData, aPos);
|
sl@0
|
148 |
}
|
sl@0
|
149 |
|
sl@0
|
150 |
//algorithm id
|
sl@0
|
151 |
EXPORT_C CWTLSAlgorithmIdentifier* CWTLSAlgorithmIdentifier::NewL(const TDesC8& aBinaryData)
|
sl@0
|
152 |
{
|
sl@0
|
153 |
TInt pos = 0;
|
sl@0
|
154 |
return CWTLSAlgorithmIdentifier::NewL(aBinaryData, pos);
|
sl@0
|
155 |
}
|
sl@0
|
156 |
|
sl@0
|
157 |
EXPORT_C CWTLSAlgorithmIdentifier* CWTLSAlgorithmIdentifier::NewLC(const TDesC8& aBinaryData)
|
sl@0
|
158 |
{
|
sl@0
|
159 |
TInt pos = 0;
|
sl@0
|
160 |
return CWTLSAlgorithmIdentifier::NewLC(aBinaryData, pos);
|
sl@0
|
161 |
}
|
sl@0
|
162 |
|
sl@0
|
163 |
EXPORT_C CWTLSAlgorithmIdentifier* CWTLSAlgorithmIdentifier::NewL(const TDesC8& aBinaryData, TInt& aPos)
|
sl@0
|
164 |
{
|
sl@0
|
165 |
CWTLSAlgorithmIdentifier* self = CWTLSAlgorithmIdentifier::NewLC(aBinaryData, aPos);
|
sl@0
|
166 |
CleanupStack::Pop();
|
sl@0
|
167 |
return self;
|
sl@0
|
168 |
}
|
sl@0
|
169 |
|
sl@0
|
170 |
EXPORT_C CWTLSAlgorithmIdentifier* CWTLSAlgorithmIdentifier::NewLC(const TDesC8& aBinaryData, TInt& aPos)
|
sl@0
|
171 |
{
|
sl@0
|
172 |
CWTLSAlgorithmIdentifier* self = new(ELeave) CWTLSAlgorithmIdentifier;
|
sl@0
|
173 |
CleanupStack::PushL(self);
|
sl@0
|
174 |
self->ConstructL(aBinaryData, aPos);
|
sl@0
|
175 |
return self;
|
sl@0
|
176 |
}
|
sl@0
|
177 |
|
sl@0
|
178 |
CWTLSAlgorithmIdentifier::CWTLSAlgorithmIdentifier()
|
sl@0
|
179 |
{
|
sl@0
|
180 |
}
|
sl@0
|
181 |
|
sl@0
|
182 |
void CWTLSAlgorithmIdentifier::ConstructL(const TDesC8& aBinaryData, TInt& aPos)
|
sl@0
|
183 |
{
|
sl@0
|
184 |
if ((aBinaryData.Length() - aPos) < KMinAlgIdLength)
|
sl@0
|
185 |
{
|
sl@0
|
186 |
User::Leave(KErrArgument);
|
sl@0
|
187 |
}
|
sl@0
|
188 |
switch (aBinaryData[aPos])
|
sl@0
|
189 |
{
|
sl@0
|
190 |
case EEncRSA:
|
sl@0
|
191 |
{
|
sl@0
|
192 |
iAlgorithmId = ERSA;
|
sl@0
|
193 |
aPos++;
|
sl@0
|
194 |
if (aBinaryData[aPos] != 0)
|
sl@0
|
195 |
{
|
sl@0
|
196 |
User::Leave(KErrArgument);
|
sl@0
|
197 |
}
|
sl@0
|
198 |
aPos++;
|
sl@0
|
199 |
iEncodedParams = HBufC8::NewL(1);
|
sl@0
|
200 |
*iEncodedParams = KNullDesC8;
|
sl@0
|
201 |
break;
|
sl@0
|
202 |
}
|
sl@0
|
203 |
default:
|
sl@0
|
204 |
//we only support RSA just now...
|
sl@0
|
205 |
{
|
sl@0
|
206 |
User::Leave(KErrNotSupported);
|
sl@0
|
207 |
}
|
sl@0
|
208 |
}
|
sl@0
|
209 |
}
|
sl@0
|
210 |
|
sl@0
|
211 |
//signing algorithm id
|
sl@0
|
212 |
EXPORT_C CWTLSSigningAlgorithmIdentifier* CWTLSSigningAlgorithmIdentifier::NewL(const TDesC8& aBinaryData)
|
sl@0
|
213 |
{
|
sl@0
|
214 |
TInt pos = 0;
|
sl@0
|
215 |
return CWTLSSigningAlgorithmIdentifier::NewL(aBinaryData, pos);
|
sl@0
|
216 |
}
|
sl@0
|
217 |
|
sl@0
|
218 |
EXPORT_C CWTLSSigningAlgorithmIdentifier* CWTLSSigningAlgorithmIdentifier::NewLC(const TDesC8& aBinaryData)
|
sl@0
|
219 |
{
|
sl@0
|
220 |
TInt pos = 0;
|
sl@0
|
221 |
return CWTLSSigningAlgorithmIdentifier::NewLC(aBinaryData, pos);
|
sl@0
|
222 |
}
|
sl@0
|
223 |
|
sl@0
|
224 |
EXPORT_C CWTLSSigningAlgorithmIdentifier* CWTLSSigningAlgorithmIdentifier::NewL(const TDesC8& aBinaryData, TInt& aPos)
|
sl@0
|
225 |
{
|
sl@0
|
226 |
CWTLSSigningAlgorithmIdentifier* self = CWTLSSigningAlgorithmIdentifier::NewLC(aBinaryData, aPos);
|
sl@0
|
227 |
CleanupStack::Pop();
|
sl@0
|
228 |
return self;
|
sl@0
|
229 |
}
|
sl@0
|
230 |
|
sl@0
|
231 |
EXPORT_C CWTLSSigningAlgorithmIdentifier* CWTLSSigningAlgorithmIdentifier::NewLC(const TDesC8& aBinaryData, TInt& aPos)
|
sl@0
|
232 |
{
|
sl@0
|
233 |
CWTLSSigningAlgorithmIdentifier* self = new(ELeave) CWTLSSigningAlgorithmIdentifier;
|
sl@0
|
234 |
CleanupStack::PushL(self);
|
sl@0
|
235 |
self->ConstructL(aBinaryData, aPos);
|
sl@0
|
236 |
return self;
|
sl@0
|
237 |
}
|
sl@0
|
238 |
|
sl@0
|
239 |
CWTLSSigningAlgorithmIdentifier::CWTLSSigningAlgorithmIdentifier()
|
sl@0
|
240 |
{
|
sl@0
|
241 |
}
|
sl@0
|
242 |
|
sl@0
|
243 |
void CWTLSSigningAlgorithmIdentifier::ConstructL(const TDesC8& aBinaryData, TInt& aPos)
|
sl@0
|
244 |
{
|
sl@0
|
245 |
if ((aBinaryData.Length() - aPos) < 1)
|
sl@0
|
246 |
{
|
sl@0
|
247 |
User::Leave(KErrArgument);
|
sl@0
|
248 |
}
|
sl@0
|
249 |
switch (aBinaryData[aPos])
|
sl@0
|
250 |
{
|
sl@0
|
251 |
case EEncRSAwithSHA1:
|
sl@0
|
252 |
{
|
sl@0
|
253 |
TAlgorithmId asym = ERSA;
|
sl@0
|
254 |
TAlgorithmId dig = ESHA1;
|
sl@0
|
255 |
iAsymmetricAlgorithm = CAlgorithmIdentifier::NewL(asym, KNullDesC8);
|
sl@0
|
256 |
iDigestAlgorithm = CAlgorithmIdentifier::NewL(dig, KNullDesC8);
|
sl@0
|
257 |
aPos++;
|
sl@0
|
258 |
break;
|
sl@0
|
259 |
}
|
sl@0
|
260 |
default:
|
sl@0
|
261 |
//we only support RSA-SHA1 just now...
|
sl@0
|
262 |
{
|
sl@0
|
263 |
User::Leave(KErrNotSupported);
|
sl@0
|
264 |
}
|
sl@0
|
265 |
}
|
sl@0
|
266 |
}
|
sl@0
|
267 |
|
sl@0
|
268 |
//wtls subject public key info
|
sl@0
|
269 |
EXPORT_C CWTLSSubjectPublicKeyInfo* CWTLSSubjectPublicKeyInfo::NewL(const TDesC8& aBinaryData)
|
sl@0
|
270 |
{
|
sl@0
|
271 |
TInt pos = 0;
|
sl@0
|
272 |
return CWTLSSubjectPublicKeyInfo::NewL(aBinaryData, pos);
|
sl@0
|
273 |
}
|
sl@0
|
274 |
|
sl@0
|
275 |
EXPORT_C CWTLSSubjectPublicKeyInfo* CWTLSSubjectPublicKeyInfo::NewLC(const TDesC8& aBinaryData)
|
sl@0
|
276 |
{
|
sl@0
|
277 |
TInt pos = 0;
|
sl@0
|
278 |
return CWTLSSubjectPublicKeyInfo::NewLC(aBinaryData, pos);
|
sl@0
|
279 |
}
|
sl@0
|
280 |
|
sl@0
|
281 |
EXPORT_C CWTLSSubjectPublicKeyInfo* CWTLSSubjectPublicKeyInfo::NewL(const TDesC8& aBinaryData, TInt& aPos)
|
sl@0
|
282 |
{
|
sl@0
|
283 |
CWTLSSubjectPublicKeyInfo* self = CWTLSSubjectPublicKeyInfo::NewLC(aBinaryData, aPos);
|
sl@0
|
284 |
CleanupStack::Pop();
|
sl@0
|
285 |
return self;
|
sl@0
|
286 |
}
|
sl@0
|
287 |
|
sl@0
|
288 |
EXPORT_C CWTLSSubjectPublicKeyInfo* CWTLSSubjectPublicKeyInfo::NewLC(const TDesC8& aBinaryData, TInt& aPos)
|
sl@0
|
289 |
{
|
sl@0
|
290 |
CWTLSSubjectPublicKeyInfo* self = new(ELeave) CWTLSSubjectPublicKeyInfo;
|
sl@0
|
291 |
CleanupStack::PushL(self);
|
sl@0
|
292 |
self->ConstructL(aBinaryData, aPos);
|
sl@0
|
293 |
return self;
|
sl@0
|
294 |
}
|
sl@0
|
295 |
|
sl@0
|
296 |
CWTLSSubjectPublicKeyInfo::CWTLSSubjectPublicKeyInfo()
|
sl@0
|
297 |
{
|
sl@0
|
298 |
}
|
sl@0
|
299 |
|
sl@0
|
300 |
void CWTLSSubjectPublicKeyInfo::ConstructL(const TDesC8& aBinaryData, TInt& aPos)
|
sl@0
|
301 |
{
|
sl@0
|
302 |
iAlgId = CWTLSAlgorithmIdentifier::NewL(aBinaryData, aPos);
|
sl@0
|
303 |
if (iAlgId->Algorithm() != ERSA)
|
sl@0
|
304 |
{
|
sl@0
|
305 |
User::Leave(KErrNotSupported);
|
sl@0
|
306 |
}
|
sl@0
|
307 |
TInt totalLength = aBinaryData.Length();
|
sl@0
|
308 |
TInt tempPos = aPos;
|
sl@0
|
309 |
|
sl@0
|
310 |
const TPtrC8 expEnc = aBinaryData.Right(totalLength - aPos);
|
sl@0
|
311 |
TWTLSDecVector exp(expEnc, KMinExpLengthBytes, KMaxExpLengthBytes);
|
sl@0
|
312 |
exp.InitL();
|
sl@0
|
313 |
|
sl@0
|
314 |
aPos += exp.EncodingLength();
|
sl@0
|
315 |
|
sl@0
|
316 |
const TPtrC8 modEnc = aBinaryData.Right(totalLength - aPos);
|
sl@0
|
317 |
TWTLSDecVector mod(modEnc, KMinModLengthBytes, KMaxModLengthBytes);
|
sl@0
|
318 |
mod.InitL();
|
sl@0
|
319 |
|
sl@0
|
320 |
aPos+= mod.EncodingLength();
|
sl@0
|
321 |
iEncodedKeyData = (aBinaryData.Mid(tempPos, aPos - tempPos)).AllocL();
|
sl@0
|
322 |
}
|
sl@0
|
323 |
|
sl@0
|
324 |
//wtls certificate
|
sl@0
|
325 |
EXPORT_C CWTLSCertificate* CWTLSCertificate::NewL(const TDesC8& aBinaryData)
|
sl@0
|
326 |
{
|
sl@0
|
327 |
TInt pos = 0;
|
sl@0
|
328 |
return CWTLSCertificate::NewL(aBinaryData, pos);
|
sl@0
|
329 |
}
|
sl@0
|
330 |
|
sl@0
|
331 |
EXPORT_C CWTLSCertificate* CWTLSCertificate::NewLC(const TDesC8& aBinaryData)
|
sl@0
|
332 |
{
|
sl@0
|
333 |
TInt pos = 0;
|
sl@0
|
334 |
return CWTLSCertificate::NewLC(aBinaryData, pos);
|
sl@0
|
335 |
}
|
sl@0
|
336 |
|
sl@0
|
337 |
EXPORT_C CWTLSCertificate* CWTLSCertificate::NewL(const TDesC8& aBinaryData, TInt& aPos)
|
sl@0
|
338 |
{
|
sl@0
|
339 |
CWTLSCertificate* self = CWTLSCertificate::NewLC(aBinaryData, aPos);
|
sl@0
|
340 |
CleanupStack::Pop();
|
sl@0
|
341 |
return self;
|
sl@0
|
342 |
}
|
sl@0
|
343 |
|
sl@0
|
344 |
EXPORT_C CWTLSCertificate* CWTLSCertificate::NewLC(const TDesC8& aBinaryData, TInt& aPos)
|
sl@0
|
345 |
{
|
sl@0
|
346 |
CWTLSCertificate* self = new(ELeave) CWTLSCertificate;
|
sl@0
|
347 |
CleanupStack::PushL(self);
|
sl@0
|
348 |
self->ConstructL(aBinaryData, aPos);
|
sl@0
|
349 |
return self;
|
sl@0
|
350 |
}
|
sl@0
|
351 |
|
sl@0
|
352 |
EXPORT_C CWTLSCertificate* CWTLSCertificate::NewL(RReadStream& aStream)
|
sl@0
|
353 |
{
|
sl@0
|
354 |
CWTLSCertificate* self = CWTLSCertificate::NewLC(aStream);
|
sl@0
|
355 |
CleanupStack::Pop();//self
|
sl@0
|
356 |
return self;
|
sl@0
|
357 |
}
|
sl@0
|
358 |
|
sl@0
|
359 |
EXPORT_C CWTLSCertificate* CWTLSCertificate::NewLC(RReadStream& aStream)
|
sl@0
|
360 |
{
|
sl@0
|
361 |
CWTLSCertificate* self = new(ELeave) CWTLSCertificate;
|
sl@0
|
362 |
CleanupStack::PushL(self);
|
sl@0
|
363 |
self->InternalizeL(aStream);
|
sl@0
|
364 |
return self;
|
sl@0
|
365 |
}
|
sl@0
|
366 |
/*
|
sl@0
|
367 |
EXPORT_C CWTLSCertificate* CWTLSCertificate::NewL(CCertStore& aStore, const CCertStoreEntry& aEntry)
|
sl@0
|
368 |
{
|
sl@0
|
369 |
CWTLSCertificate* self = CWTLSCertificate::NewLC(aStore, aEntry);
|
sl@0
|
370 |
CleanupStack::Pop();//self
|
sl@0
|
371 |
return self;
|
sl@0
|
372 |
}
|
sl@0
|
373 |
|
sl@0
|
374 |
EXPORT_C CWTLSCertificate* CWTLSCertificate::NewLC(CCertStore& aStore, const CCertStoreEntry& aEntry)
|
sl@0
|
375 |
{
|
sl@0
|
376 |
CWTLSCertificate* self = new(ELeave) CWTLSCertificate;
|
sl@0
|
377 |
CleanupStack::PushL(self);
|
sl@0
|
378 |
aStore.LoadL(*self, aEntry);
|
sl@0
|
379 |
return self;
|
sl@0
|
380 |
}
|
sl@0
|
381 |
*/
|
sl@0
|
382 |
EXPORT_C CWTLSCertificate* CWTLSCertificate::NewL(const CWTLSCertificate& aCert)
|
sl@0
|
383 |
{
|
sl@0
|
384 |
CWTLSCertificate* self = CWTLSCertificate::NewLC(aCert);
|
sl@0
|
385 |
CleanupStack::Pop();//self
|
sl@0
|
386 |
return self;
|
sl@0
|
387 |
}
|
sl@0
|
388 |
|
sl@0
|
389 |
EXPORT_C CWTLSCertificate* CWTLSCertificate::NewLC(const CWTLSCertificate& aCert)
|
sl@0
|
390 |
{
|
sl@0
|
391 |
CWTLSCertificate* self = new(ELeave) CWTLSCertificate;
|
sl@0
|
392 |
CleanupStack::PushL(self);
|
sl@0
|
393 |
self->ConstructL(aCert);
|
sl@0
|
394 |
return self;
|
sl@0
|
395 |
}
|
sl@0
|
396 |
|
sl@0
|
397 |
EXPORT_C CWTLSCertificate::~CWTLSCertificate()
|
sl@0
|
398 |
{
|
sl@0
|
399 |
delete iIssuerName;
|
sl@0
|
400 |
delete iSubjectName;
|
sl@0
|
401 |
|
sl@0
|
402 |
if (iDataElements != NULL)
|
sl@0
|
403 |
{
|
sl@0
|
404 |
for (TInt i = 0; i < KWTLSCertMaxDataElements; i++)
|
sl@0
|
405 |
{
|
sl@0
|
406 |
delete iDataElements->At(i);
|
sl@0
|
407 |
}
|
sl@0
|
408 |
delete iDataElements;
|
sl@0
|
409 |
}
|
sl@0
|
410 |
}
|
sl@0
|
411 |
|
sl@0
|
412 |
EXPORT_C TBool CWTLSCertificate::IsEqualL(const CWTLSCertificate& aCert) const
|
sl@0
|
413 |
{
|
sl@0
|
414 |
return (*(iFingerprint) == (*(aCert.iFingerprint)));
|
sl@0
|
415 |
}
|
sl@0
|
416 |
|
sl@0
|
417 |
//extra accessors
|
sl@0
|
418 |
EXPORT_C const TPtrC8 CWTLSCertificate::SignedDataL() const
|
sl@0
|
419 |
{
|
sl@0
|
420 |
return iEncoding->Left(iEncoding->Length() - (iSignature->Length() +2));
|
sl@0
|
421 |
}
|
sl@0
|
422 |
|
sl@0
|
423 |
EXPORT_C TInt CWTLSCertificate::Version() const
|
sl@0
|
424 |
{
|
sl@0
|
425 |
return iVersion;
|
sl@0
|
426 |
}
|
sl@0
|
427 |
|
sl@0
|
428 |
EXPORT_C const CWTLSName& CWTLSCertificate::IssuerName() const
|
sl@0
|
429 |
{
|
sl@0
|
430 |
return *iIssuerName;
|
sl@0
|
431 |
}
|
sl@0
|
432 |
|
sl@0
|
433 |
EXPORT_C const CWTLSName& CWTLSCertificate::SubjectName() const
|
sl@0
|
434 |
{
|
sl@0
|
435 |
return *iSubjectName;
|
sl@0
|
436 |
}
|
sl@0
|
437 |
|
sl@0
|
438 |
EXPORT_C HBufC* CWTLSCertificate::IssuerL() const
|
sl@0
|
439 |
{
|
sl@0
|
440 |
return iIssuerName->DisplayNameL();
|
sl@0
|
441 |
}
|
sl@0
|
442 |
|
sl@0
|
443 |
EXPORT_C HBufC* CWTLSCertificate::SubjectL() const
|
sl@0
|
444 |
{
|
sl@0
|
445 |
return iSubjectName->DisplayNameL();
|
sl@0
|
446 |
}
|
sl@0
|
447 |
|
sl@0
|
448 |
EXPORT_C TBool CWTLSCertificate::IsSelfSignedL() const
|
sl@0
|
449 |
{
|
sl@0
|
450 |
return iSubjectName->ExactMatchL(*iIssuerName);
|
sl@0
|
451 |
}
|
sl@0
|
452 |
|
sl@0
|
453 |
EXPORT_C const TPtrC8* CWTLSCertificate::DataElementEncoding(const TUint aIndex) const
|
sl@0
|
454 |
{
|
sl@0
|
455 |
return iDataElements->At(aIndex);
|
sl@0
|
456 |
}
|
sl@0
|
457 |
|
sl@0
|
458 |
EXPORT_C void CWTLSCertificate::InternalizeL(RReadStream& aStream)
|
sl@0
|
459 |
{
|
sl@0
|
460 |
if (iIssuerName != NULL) //just to check cert is uninitialised
|
sl@0
|
461 |
{
|
sl@0
|
462 |
User::Leave(KErrArgument);
|
sl@0
|
463 |
}
|
sl@0
|
464 |
iKeyFactory = new(ELeave) TWTLSKeyFactory;
|
sl@0
|
465 |
TInt len = aStream.ReadInt32L();
|
sl@0
|
466 |
iEncoding = HBufC8::NewL(aStream,len);
|
sl@0
|
467 |
TInt pos = 0;
|
sl@0
|
468 |
ConstructCertL(*iEncoding, pos);
|
sl@0
|
469 |
|
sl@0
|
470 |
TWTLSDecUnsignedInteger decInt;
|
sl@0
|
471 |
TInt sigLength = decInt.DecodeShortL(*iEncoding, pos, 2);
|
sl@0
|
472 |
iSignature = (iEncoding->Mid(pos, sigLength)).AllocL();
|
sl@0
|
473 |
CSHA1* hash = CSHA1::NewL();
|
sl@0
|
474 |
CleanupStack::PushL(hash);
|
sl@0
|
475 |
iFingerprint = hash->Final(Encoding()).AllocL();
|
sl@0
|
476 |
CleanupStack::PopAndDestroy();
|
sl@0
|
477 |
|
sl@0
|
478 |
InitEncodedDataElementsL();
|
sl@0
|
479 |
}
|
sl@0
|
480 |
|
sl@0
|
481 |
EXPORT_C TBool CWTLSCertificate::IsTCAL() const
|
sl@0
|
482 |
{
|
sl@0
|
483 |
TBool isTCA = EFalse;
|
sl@0
|
484 |
TPtrC8 nameData = SubjectName().NameData();
|
sl@0
|
485 |
CWTLSStructuredText* sText = NULL; //inited to get rid of warning
|
sl@0
|
486 |
TRAPD(err, sText = CWTLSStructuredText::NewL(nameData) );
|
sl@0
|
487 |
if( err == KErrNone )
|
sl@0
|
488 |
{
|
sl@0
|
489 |
const TWTLSStructuredTextField* sTextField = sText->FieldByName(KWTLSTCAType);
|
sl@0
|
490 |
if(sTextField != NULL)
|
sl@0
|
491 |
{
|
sl@0
|
492 |
if(sTextField->Value().Compare(KWTLSTCAValue) == 0)
|
sl@0
|
493 |
{
|
sl@0
|
494 |
isTCA = ETrue;
|
sl@0
|
495 |
}
|
sl@0
|
496 |
}
|
sl@0
|
497 |
delete sText;
|
sl@0
|
498 |
}
|
sl@0
|
499 |
return isTCA;
|
sl@0
|
500 |
}
|
sl@0
|
501 |
|
sl@0
|
502 |
CWTLSCertificate::CWTLSCertificate()
|
sl@0
|
503 |
{
|
sl@0
|
504 |
}
|
sl@0
|
505 |
|
sl@0
|
506 |
void CWTLSCertificate::ConstructL(const TDesC8& aBinaryData, TInt& aPos)
|
sl@0
|
507 |
{
|
sl@0
|
508 |
TInt tempPos = aPos;
|
sl@0
|
509 |
ConstructCertL(aBinaryData, aPos);
|
sl@0
|
510 |
iKeyFactory = new(ELeave) TWTLSKeyFactory;
|
sl@0
|
511 |
|
sl@0
|
512 |
TWTLSDecUnsignedInteger decInt;
|
sl@0
|
513 |
TInt sigLength = decInt.DecodeShortL(aBinaryData, aPos, 2);
|
sl@0
|
514 |
if ((sigLength + aPos) > aBinaryData.Length())
|
sl@0
|
515 |
{
|
sl@0
|
516 |
User::Leave(KErrArgument);
|
sl@0
|
517 |
}
|
sl@0
|
518 |
iSignature = (aBinaryData.Mid(aPos, sigLength)).AllocL();
|
sl@0
|
519 |
aPos+= sigLength;
|
sl@0
|
520 |
iEncoding = aBinaryData.Mid(tempPos, aPos - tempPos).AllocL();
|
sl@0
|
521 |
|
sl@0
|
522 |
CSHA1* hash = CSHA1::NewL();
|
sl@0
|
523 |
CleanupStack::PushL(hash);
|
sl@0
|
524 |
iFingerprint = hash->Final(Encoding()).AllocL();
|
sl@0
|
525 |
CleanupStack::PopAndDestroy();
|
sl@0
|
526 |
|
sl@0
|
527 |
InitEncodedDataElementsL();
|
sl@0
|
528 |
}
|
sl@0
|
529 |
|
sl@0
|
530 |
void CWTLSCertificate::ConstructL(const CWTLSCertificate& aCertificate)
|
sl@0
|
531 |
{
|
sl@0
|
532 |
iEncoding = aCertificate.Encoding().AllocL();
|
sl@0
|
533 |
iKeyFactory = new(ELeave) TWTLSKeyFactory;
|
sl@0
|
534 |
iSignature = aCertificate.Signature().AllocL();
|
sl@0
|
535 |
iFingerprint = aCertificate.Fingerprint().AllocL();
|
sl@0
|
536 |
iSigningAlgorithm = CSigningAlgorithmIdentifier::NewL(aCertificate.SigningAlgorithm());
|
sl@0
|
537 |
iSerialNumber = aCertificate.iSerialNumber->Des().AllocL();
|
sl@0
|
538 |
iIssuerName = CWTLSName::NewL(*(aCertificate.iIssuerName));
|
sl@0
|
539 |
iValidityPeriod = new(ELeave) CValidityPeriod(*(aCertificate.iValidityPeriod));
|
sl@0
|
540 |
iSubjectName = CWTLSName::NewL(*(aCertificate.iSubjectName));
|
sl@0
|
541 |
iSubjectPublicKeyInfo = CSubjectPublicKeyInfo::NewL(*(aCertificate.iSubjectPublicKeyInfo));
|
sl@0
|
542 |
|
sl@0
|
543 |
InitEncodedDataElementsL();
|
sl@0
|
544 |
}
|
sl@0
|
545 |
|
sl@0
|
546 |
void CWTLSCertificate::ConstructCertL(const TDesC8& aBinaryData, TInt& aPos)
|
sl@0
|
547 |
{
|
sl@0
|
548 |
if ((aBinaryData.Length() - aPos) < 1)
|
sl@0
|
549 |
{
|
sl@0
|
550 |
User::Leave(KErrArgument);
|
sl@0
|
551 |
}
|
sl@0
|
552 |
iVersion = aBinaryData[aPos];
|
sl@0
|
553 |
|
sl@0
|
554 |
aPos++;
|
sl@0
|
555 |
iSigningAlgorithm = CWTLSSigningAlgorithmIdentifier::NewL(aBinaryData, aPos);
|
sl@0
|
556 |
iIssuerName = CWTLSName::NewL(aBinaryData, aPos);
|
sl@0
|
557 |
iValidityPeriod = CWTLSValidityPeriod::NewL(aBinaryData, aPos);
|
sl@0
|
558 |
iSubjectName = CWTLSName::NewL(aBinaryData, aPos);
|
sl@0
|
559 |
iSubjectPublicKeyInfo = CWTLSSubjectPublicKeyInfo::NewL(aBinaryData, aPos);
|
sl@0
|
560 |
iSerialNumber = HBufC8::NewL(0);
|
sl@0
|
561 |
*iSerialNumber = KNullDesC8;
|
sl@0
|
562 |
}
|
sl@0
|
563 |
|
sl@0
|
564 |
void CWTLSCertificate::InitEncodedDataElementsL()
|
sl@0
|
565 |
{
|
sl@0
|
566 |
iDataElements = new(ELeave) TFixedArray<TPtrC8*, KWTLSCertMaxDataElements>;
|
sl@0
|
567 |
iDataElements->Reset();
|
sl@0
|
568 |
const TPtrC8 signedData = SignedDataL();
|
sl@0
|
569 |
TInt aPos = 0;
|
sl@0
|
570 |
TPtrC8** pElement = iDataElements->Begin();
|
sl@0
|
571 |
*pElement++ = new(ELeave) TPtrC8(signedData.Left(++aPos));
|
sl@0
|
572 |
*pElement++ = new(ELeave) TPtrC8(signedData.Mid(aPos, aPos));
|
sl@0
|
573 |
aPos++; // Defect fix from Jetstream
|
sl@0
|
574 |
TInt issuerEncodedLength = IssuerName().NameData().Length() + 1;//1 for the identifier type
|
sl@0
|
575 |
*pElement++ = new(ELeave) TPtrC8(signedData.Mid(aPos, issuerEncodedLength));
|
sl@0
|
576 |
aPos+=+issuerEncodedLength;
|
sl@0
|
577 |
*pElement++ = new(ELeave) TPtrC8(signedData.Mid(aPos, 8));
|
sl@0
|
578 |
aPos+=8;
|
sl@0
|
579 |
TInt subjectEncodedLength = SubjectName().NameData().Length() + 1;//1 for the identifier type
|
sl@0
|
580 |
*pElement++ = new(ELeave) TPtrC8(signedData.Mid(aPos, subjectEncodedLength));
|
sl@0
|
581 |
aPos+=+subjectEncodedLength;
|
sl@0
|
582 |
*pElement++ = new(ELeave) TPtrC8(signedData.Right(signedData.Length() - aPos));
|
sl@0
|
583 |
}
|
sl@0
|
584 |
|