sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 1998-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 |
* TCERTSTOREOUT.CPP
|
sl@0
|
16 |
*
|
sl@0
|
17 |
*/
|
sl@0
|
18 |
|
sl@0
|
19 |
|
sl@0
|
20 |
#include "t_certstoreout.h"
|
sl@0
|
21 |
|
sl@0
|
22 |
X509CertWriter::X509CertWriter(Output& aOut)
|
sl@0
|
23 |
:iOut(aOut)
|
sl@0
|
24 |
{
|
sl@0
|
25 |
}
|
sl@0
|
26 |
|
sl@0
|
27 |
void X509CertWriter::WriteCert(const CX509Certificate& aCertificate)
|
sl@0
|
28 |
{
|
sl@0
|
29 |
#ifdef SHOW_EXTENDED
|
sl@0
|
30 |
ShowSerialNumber(aCertificate.SerialNumber());
|
sl@0
|
31 |
ShowValidityPeriod(aCertificate);
|
sl@0
|
32 |
iOut.writeString(_L("Issuer Name = "));
|
sl@0
|
33 |
iOut.writeNewLine();
|
sl@0
|
34 |
ShowDN(aCertificate.IssuerName());
|
sl@0
|
35 |
iOut.writeString(_L("Subject Name = "));
|
sl@0
|
36 |
iOut.writeNewLine();
|
sl@0
|
37 |
ShowDN(aCertificate.SubjectName());
|
sl@0
|
38 |
ShowSigningAlgorithm(aCertificate.SigningAlgorithm());
|
sl@0
|
39 |
ShowExtensions(aCertificate);
|
sl@0
|
40 |
WriteEncodings(aCertificate);
|
sl@0
|
41 |
#endif // SHOW_EXTENDED
|
sl@0
|
42 |
iOut.writeString(_L("\t\tShort Issuer Name = "));
|
sl@0
|
43 |
HBufC* issuer = aCertificate.IssuerL();
|
sl@0
|
44 |
iOut.writeString(*issuer);
|
sl@0
|
45 |
iOut.writeNewLine();
|
sl@0
|
46 |
delete issuer;
|
sl@0
|
47 |
|
sl@0
|
48 |
iOut.writeString(_L("\t\tShort Subject Name = "));
|
sl@0
|
49 |
HBufC* subject = aCertificate.SubjectL();
|
sl@0
|
50 |
iOut.writeString(*subject);
|
sl@0
|
51 |
iOut.writeNewLine();
|
sl@0
|
52 |
delete subject;
|
sl@0
|
53 |
}
|
sl@0
|
54 |
|
sl@0
|
55 |
// The rest of these are only compiled of SHOW_EXTENDED defined - this
|
sl@0
|
56 |
// eliminates warnings from WINS/UREL build
|
sl@0
|
57 |
#ifdef SHOW_EXTENDED
|
sl@0
|
58 |
void X509CertWriter::ShowSigningAlgorithm(const CSigningAlgorithmIdentifier& aSigningAlgorithm)
|
sl@0
|
59 |
{
|
sl@0
|
60 |
iOut.writeString(_L("Signed using: "));
|
sl@0
|
61 |
iOut.writeNewLine();
|
sl@0
|
62 |
iOut.writeSpaces(4);
|
sl@0
|
63 |
iOut.writeString(_L("Asymmetric algorithm = "));
|
sl@0
|
64 |
const CAlgorithmIdentifier& algId = aSigningAlgorithm.AsymmetricAlgorithm();
|
sl@0
|
65 |
switch(algId.Algorithm())
|
sl@0
|
66 |
{
|
sl@0
|
67 |
case ERSA:
|
sl@0
|
68 |
{
|
sl@0
|
69 |
iOut.writeString(_L("RSA"));
|
sl@0
|
70 |
break;
|
sl@0
|
71 |
}
|
sl@0
|
72 |
case EDSA:
|
sl@0
|
73 |
{
|
sl@0
|
74 |
iOut.writeString(_L("DSA"));
|
sl@0
|
75 |
break;
|
sl@0
|
76 |
}
|
sl@0
|
77 |
case EDH:
|
sl@0
|
78 |
{
|
sl@0
|
79 |
iOut.writeString(_L("DH"));
|
sl@0
|
80 |
break;
|
sl@0
|
81 |
}
|
sl@0
|
82 |
default:
|
sl@0
|
83 |
iOut.writeString(_L("Unknown"));
|
sl@0
|
84 |
break;
|
sl@0
|
85 |
}
|
sl@0
|
86 |
iOut.writeNewLine();
|
sl@0
|
87 |
iOut.writeSpaces(4);
|
sl@0
|
88 |
iOut.writeString(_L("Digest algorithm = "));
|
sl@0
|
89 |
const CAlgorithmIdentifier& digestId = aSigningAlgorithm.DigestAlgorithm();
|
sl@0
|
90 |
switch(digestId.Algorithm())
|
sl@0
|
91 |
{
|
sl@0
|
92 |
case EMD2:
|
sl@0
|
93 |
{
|
sl@0
|
94 |
iOut.writeString(_L("MD2"));
|
sl@0
|
95 |
break;
|
sl@0
|
96 |
}
|
sl@0
|
97 |
case EMD5:
|
sl@0
|
98 |
{
|
sl@0
|
99 |
iOut.writeString(_L("MD5"));
|
sl@0
|
100 |
break;
|
sl@0
|
101 |
}
|
sl@0
|
102 |
case ESHA1:
|
sl@0
|
103 |
{
|
sl@0
|
104 |
iOut.writeString(_L("SHA1"));
|
sl@0
|
105 |
break;
|
sl@0
|
106 |
}
|
sl@0
|
107 |
default:
|
sl@0
|
108 |
iOut.writeString(_L("Unknown"));
|
sl@0
|
109 |
}
|
sl@0
|
110 |
iOut.writeNewLine();
|
sl@0
|
111 |
}
|
sl@0
|
112 |
|
sl@0
|
113 |
void X509CertWriter::ShowSerialNumber(const TPtrC8& aSerialNumber)
|
sl@0
|
114 |
{
|
sl@0
|
115 |
iOut.writeString(_L("Serial Number = "));
|
sl@0
|
116 |
iOut.writeOctetString(aSerialNumber);
|
sl@0
|
117 |
iOut.writeNewLine();
|
sl@0
|
118 |
}
|
sl@0
|
119 |
|
sl@0
|
120 |
//dn display code
|
sl@0
|
121 |
void X509CertWriter::ShowAVA(const CX520AttributeTypeAndValue& aAva)
|
sl@0
|
122 |
{
|
sl@0
|
123 |
iOut.writeString(aAva.Type());
|
sl@0
|
124 |
HBufC* val = aAva.ValueL();
|
sl@0
|
125 |
CleanupStack::PushL(val);
|
sl@0
|
126 |
iOut.writeString(_L(" = "));
|
sl@0
|
127 |
iOut.writeString(val->Des());
|
sl@0
|
128 |
CleanupStack::PopAndDestroy();
|
sl@0
|
129 |
}
|
sl@0
|
130 |
|
sl@0
|
131 |
void X509CertWriter::ShowDN(const CX500DistinguishedName& aName)
|
sl@0
|
132 |
{
|
sl@0
|
133 |
TInt count = aName.Count();
|
sl@0
|
134 |
for (TInt i = 0; i < count; i++)
|
sl@0
|
135 |
{
|
sl@0
|
136 |
const CX520AttributeTypeAndValue& ava = aName.Element(i);
|
sl@0
|
137 |
iOut.writeSpaces(4);
|
sl@0
|
138 |
ShowAVA(ava);
|
sl@0
|
139 |
iOut.writeNewLine();
|
sl@0
|
140 |
}
|
sl@0
|
141 |
}
|
sl@0
|
142 |
|
sl@0
|
143 |
void X509CertWriter::ShowAKI(const CX509Certificate& aCert)
|
sl@0
|
144 |
{
|
sl@0
|
145 |
const CX509CertExtension* akiExt = aCert.Extension(KAuthorityKeyId);
|
sl@0
|
146 |
if (akiExt)
|
sl@0
|
147 |
{
|
sl@0
|
148 |
iOut.writeString(_L("Authority Key ID = "));
|
sl@0
|
149 |
iOut.writeNewLine();
|
sl@0
|
150 |
const CX509AuthorityKeyIdExt* ext = CX509AuthorityKeyIdExt::NewLC(akiExt->Data());
|
sl@0
|
151 |
const CArrayPtrFlat<CX509GeneralName>& authorityName = ext->AuthorityName();
|
sl@0
|
152 |
TInt count = authorityName.Count();
|
sl@0
|
153 |
if (count > 0)
|
sl@0
|
154 |
{
|
sl@0
|
155 |
iOut.writeSpaces(4);
|
sl@0
|
156 |
iOut.writeString(_L("Authority name = "));
|
sl@0
|
157 |
iOut.writeNewLine();
|
sl@0
|
158 |
for (TInt i = 0; i < count; i++)
|
sl@0
|
159 |
{
|
sl@0
|
160 |
ShowGN(*(authorityName.At(i)));
|
sl@0
|
161 |
}
|
sl@0
|
162 |
}
|
sl@0
|
163 |
if (ext->AuthorityCertSerialNumber().Length() > 0)
|
sl@0
|
164 |
{
|
sl@0
|
165 |
iOut.writeSpaces(4);
|
sl@0
|
166 |
iOut.writeString(_L("Authority cert serial no = "));
|
sl@0
|
167 |
iOut.writeOctetString(ext->AuthorityCertSerialNumber());
|
sl@0
|
168 |
iOut.writeNewLine();
|
sl@0
|
169 |
}
|
sl@0
|
170 |
iOut.writeSpaces(4);
|
sl@0
|
171 |
iOut.writeString(_L("Key Id = "));
|
sl@0
|
172 |
iOut.writeOctetString(ext->KeyId());
|
sl@0
|
173 |
iOut.writeNewLine();
|
sl@0
|
174 |
CleanupStack::PopAndDestroy();
|
sl@0
|
175 |
}
|
sl@0
|
176 |
}
|
sl@0
|
177 |
|
sl@0
|
178 |
void X509CertWriter::ShowSKI(const CX509Certificate& aCert)
|
sl@0
|
179 |
{
|
sl@0
|
180 |
const CX509CertExtension* skiExt = aCert.Extension(KSubjectKeyId);
|
sl@0
|
181 |
if (skiExt)
|
sl@0
|
182 |
{
|
sl@0
|
183 |
iOut.writeString(_L("Subject Key ID = "));
|
sl@0
|
184 |
iOut.writeNewLine();
|
sl@0
|
185 |
const CX509SubjectKeyIdExt* ext = CX509SubjectKeyIdExt::NewLC(skiExt->Data());
|
sl@0
|
186 |
iOut.writeSpaces(4);
|
sl@0
|
187 |
iOut.writeString(_L("Key Id = "));
|
sl@0
|
188 |
iOut.writeOctetString(ext->KeyId());
|
sl@0
|
189 |
iOut.writeNewLine();
|
sl@0
|
190 |
CleanupStack::PopAndDestroy();
|
sl@0
|
191 |
}
|
sl@0
|
192 |
}
|
sl@0
|
193 |
|
sl@0
|
194 |
void X509CertWriter::ShowGN(const CX509GeneralName& aName)
|
sl@0
|
195 |
{
|
sl@0
|
196 |
iOut.writeSpaces(4);
|
sl@0
|
197 |
switch(aName.Tag())
|
sl@0
|
198 |
{
|
sl@0
|
199 |
case 1:
|
sl@0
|
200 |
{
|
sl@0
|
201 |
//rfc822
|
sl@0
|
202 |
CX509RFC822NameSubtree* email = CX509RFC822NameSubtree::NewLC(aName.Data());
|
sl@0
|
203 |
const RArray<TPtrC>& rep = email->Rep();
|
sl@0
|
204 |
TInt count = rep.Count();
|
sl@0
|
205 |
for (TInt i = 0; i < count; i++)
|
sl@0
|
206 |
{
|
sl@0
|
207 |
iOut.writeString(rep[i]);
|
sl@0
|
208 |
iOut.writeSpaces(1);
|
sl@0
|
209 |
}
|
sl@0
|
210 |
iOut.writeNewLine();
|
sl@0
|
211 |
CleanupStack::PopAndDestroy();//email
|
sl@0
|
212 |
break;
|
sl@0
|
213 |
}
|
sl@0
|
214 |
case 2:
|
sl@0
|
215 |
{
|
sl@0
|
216 |
//dns name
|
sl@0
|
217 |
CX509DNSNameSubtree* dns = CX509DNSNameSubtree::NewLC(aName.Data());
|
sl@0
|
218 |
const RArray<TPtrC>& rep = dns->Rep();
|
sl@0
|
219 |
TInt count = rep.Count();
|
sl@0
|
220 |
for (TInt i = 0; i < count; i++)
|
sl@0
|
221 |
{
|
sl@0
|
222 |
iOut.writeString(rep[i]);
|
sl@0
|
223 |
iOut.writeSpaces(1);
|
sl@0
|
224 |
}
|
sl@0
|
225 |
CleanupStack::PopAndDestroy();//dns
|
sl@0
|
226 |
break;
|
sl@0
|
227 |
}
|
sl@0
|
228 |
case 4:
|
sl@0
|
229 |
{
|
sl@0
|
230 |
//DN
|
sl@0
|
231 |
CX500DistinguishedName* dN = CX500DistinguishedName::NewLC(aName.Data());
|
sl@0
|
232 |
ShowDN(*dN);
|
sl@0
|
233 |
CleanupStack::PopAndDestroy();
|
sl@0
|
234 |
break;
|
sl@0
|
235 |
}
|
sl@0
|
236 |
case 6:
|
sl@0
|
237 |
{
|
sl@0
|
238 |
//uri
|
sl@0
|
239 |
CX509IPBasedURI* uri = CX509IPBasedURI::NewLC(aName.Data());
|
sl@0
|
240 |
iOut.writeString(uri->Name());
|
sl@0
|
241 |
iOut.writeNewLine();
|
sl@0
|
242 |
CleanupStack::PopAndDestroy();//uri
|
sl@0
|
243 |
break;
|
sl@0
|
244 |
}
|
sl@0
|
245 |
case 7:
|
sl@0
|
246 |
{
|
sl@0
|
247 |
//ip address//!!!!not done for writing to file yet!!!
|
sl@0
|
248 |
CX509IPSubnetMask* ip = CX509IPSubnetMask::NewLC(aName.Data());
|
sl@0
|
249 |
TPtrC8 pBA(ip->BaseAddress());
|
sl@0
|
250 |
TInt counter;
|
sl@0
|
251 |
counter = pBA.Length();
|
sl@0
|
252 |
TPtrC8 pM(ip->Mask());
|
sl@0
|
253 |
counter = pM.Length();
|
sl@0
|
254 |
CleanupStack::PopAndDestroy();
|
sl@0
|
255 |
break;
|
sl@0
|
256 |
}
|
sl@0
|
257 |
}
|
sl@0
|
258 |
}
|
sl@0
|
259 |
|
sl@0
|
260 |
|
sl@0
|
261 |
void X509CertWriter::ShowFingerprint(const CX509Certificate& aCertificate)
|
sl@0
|
262 |
{
|
sl@0
|
263 |
iOut.writeOctetString(aCertificate.Fingerprint());
|
sl@0
|
264 |
iOut.writeNewLine();
|
sl@0
|
265 |
}
|
sl@0
|
266 |
|
sl@0
|
267 |
void X509CertWriter::ShowValidityPeriod(const CX509Certificate& aCertificate)
|
sl@0
|
268 |
{
|
sl@0
|
269 |
const CValidityPeriod& vp = aCertificate.ValidityPeriod();
|
sl@0
|
270 |
iOut.writeString(_L("Validity Period = "));
|
sl@0
|
271 |
iOut.writeNewLine();
|
sl@0
|
272 |
const TTime& start = vp.Start();
|
sl@0
|
273 |
const TTime& finish = vp.Finish();
|
sl@0
|
274 |
TBuf<30> dateString1;
|
sl@0
|
275 |
start.FormatL(dateString1,(_L("%H%:1%T:%S %*E%*D %X%*N%Y %1 %2 %3")));
|
sl@0
|
276 |
|
sl@0
|
277 |
iOut.writeSpaces(4);
|
sl@0
|
278 |
iOut.writeString(_L("Valid From = "));
|
sl@0
|
279 |
iOut.writeString(dateString1);
|
sl@0
|
280 |
iOut.writeNewLine();
|
sl@0
|
281 |
|
sl@0
|
282 |
TBuf<30> dateString2;
|
sl@0
|
283 |
finish.FormatL(dateString2,(_L("%H%:1%T:%S %*E%*D %X%*N%Y %1 %2 %3")));
|
sl@0
|
284 |
|
sl@0
|
285 |
iOut.writeSpaces(4);
|
sl@0
|
286 |
iOut.writeString(_L("Valid Until = "));
|
sl@0
|
287 |
|
sl@0
|
288 |
iOut.writeString(dateString2);
|
sl@0
|
289 |
iOut.writeNewLine();
|
sl@0
|
290 |
}
|
sl@0
|
291 |
|
sl@0
|
292 |
//extensions
|
sl@0
|
293 |
void X509CertWriter::ShowExtensions(const CX509Certificate& aCertificate)
|
sl@0
|
294 |
{
|
sl@0
|
295 |
const CArrayPtrFlat<CX509CertExtension>& exts = aCertificate.Extensions();
|
sl@0
|
296 |
TInt count = exts.Count();
|
sl@0
|
297 |
for (TInt i = 0; i < count; i++)
|
sl@0
|
298 |
{
|
sl@0
|
299 |
const CX509CertExtension* ext = exts.At(i);
|
sl@0
|
300 |
iOut.writeString(_L("extension"));
|
sl@0
|
301 |
iOut.writeNum(i);
|
sl@0
|
302 |
if (!(ext->Critical()))
|
sl@0
|
303 |
{
|
sl@0
|
304 |
iOut.writeString(_L(" not"));
|
sl@0
|
305 |
}
|
sl@0
|
306 |
iOut.writeString(_L(" critical"));
|
sl@0
|
307 |
iOut.writeString(_L(" ID = "));
|
sl@0
|
308 |
TPtrC id(ext->Id());
|
sl@0
|
309 |
iOut.writeString(id);
|
sl@0
|
310 |
iOut.writeNewLine();
|
sl@0
|
311 |
if (id == KBasicConstraints)
|
sl@0
|
312 |
{
|
sl@0
|
313 |
ShowBC(*ext);
|
sl@0
|
314 |
}
|
sl@0
|
315 |
if (id == KSubjectAltName)
|
sl@0
|
316 |
{
|
sl@0
|
317 |
iOut.writeString(_L("SubjectAltName: \n"));
|
sl@0
|
318 |
ShowAltName(*ext);
|
sl@0
|
319 |
}
|
sl@0
|
320 |
if (id == KIssuerAltName)
|
sl@0
|
321 |
{
|
sl@0
|
322 |
iOut.writeString(_L("IssuerAltName: \n"));
|
sl@0
|
323 |
ShowAltName(*ext);
|
sl@0
|
324 |
}
|
sl@0
|
325 |
if (id == KKeyUsage)
|
sl@0
|
326 |
{
|
sl@0
|
327 |
ShowKU(*ext);
|
sl@0
|
328 |
}
|
sl@0
|
329 |
if (id == KNameConstraints)
|
sl@0
|
330 |
{
|
sl@0
|
331 |
ShowNC(*ext);
|
sl@0
|
332 |
}
|
sl@0
|
333 |
if (id == KPolicyConstraints)
|
sl@0
|
334 |
{
|
sl@0
|
335 |
ShowPC(*ext);
|
sl@0
|
336 |
}
|
sl@0
|
337 |
if (id == KCertPolicies)
|
sl@0
|
338 |
{
|
sl@0
|
339 |
ShowCP(*ext);
|
sl@0
|
340 |
}
|
sl@0
|
341 |
if (id == KPolicyMapping)
|
sl@0
|
342 |
{
|
sl@0
|
343 |
ShowPM(*ext);
|
sl@0
|
344 |
}
|
sl@0
|
345 |
if (id == KAuthorityKeyId)
|
sl@0
|
346 |
{
|
sl@0
|
347 |
ShowAKI(aCertificate);
|
sl@0
|
348 |
}
|
sl@0
|
349 |
if (id == KSubjectKeyId)
|
sl@0
|
350 |
{
|
sl@0
|
351 |
ShowSKI(aCertificate);
|
sl@0
|
352 |
}
|
sl@0
|
353 |
if (id == KExtendedKeyUsage)
|
sl@0
|
354 |
{
|
sl@0
|
355 |
ShowEKU(*ext);
|
sl@0
|
356 |
}
|
sl@0
|
357 |
}
|
sl@0
|
358 |
}
|
sl@0
|
359 |
|
sl@0
|
360 |
void X509CertWriter::ShowBC(const CX509CertExtension& aExt)
|
sl@0
|
361 |
{
|
sl@0
|
362 |
iOut.writeString(_L("Basic Constraints:"));
|
sl@0
|
363 |
iOut.writeNewLine();
|
sl@0
|
364 |
CX509BasicConstraintsExt* ext = CX509BasicConstraintsExt::NewLC(aExt.Data());
|
sl@0
|
365 |
if (ext->IsCA())
|
sl@0
|
366 |
{
|
sl@0
|
367 |
iOut.writeSpaces(4);
|
sl@0
|
368 |
iOut.writeString(_L("CA cert"));
|
sl@0
|
369 |
iOut.writeNewLine();
|
sl@0
|
370 |
if (ext->MaxChainLength() < KMaxTInt)
|
sl@0
|
371 |
{
|
sl@0
|
372 |
iOut.writeSpaces(4);
|
sl@0
|
373 |
iOut.writeString(_L("Max Chain Length = "));
|
sl@0
|
374 |
iOut.writeNum(ext->MaxChainLength());
|
sl@0
|
375 |
iOut.writeNewLine();
|
sl@0
|
376 |
}
|
sl@0
|
377 |
}
|
sl@0
|
378 |
else
|
sl@0
|
379 |
{
|
sl@0
|
380 |
iOut.writeSpaces(4);
|
sl@0
|
381 |
iOut.writeString(_L("EE cert"));
|
sl@0
|
382 |
iOut.writeNewLine();
|
sl@0
|
383 |
}
|
sl@0
|
384 |
CleanupStack::PopAndDestroy();
|
sl@0
|
385 |
}
|
sl@0
|
386 |
|
sl@0
|
387 |
void X509CertWriter::ShowAltName(const CX509CertExtension& aExt)
|
sl@0
|
388 |
{
|
sl@0
|
389 |
CX509AltNameExt* ext = CX509AltNameExt::NewLC(aExt.Data());
|
sl@0
|
390 |
const CArrayPtrFlat<CX509GeneralName>& names = ext->AltName();
|
sl@0
|
391 |
TInt count = names.Count();
|
sl@0
|
392 |
for (TInt i = 0; i < count; i++)
|
sl@0
|
393 |
{
|
sl@0
|
394 |
ShowGN(*(names.At(i)));
|
sl@0
|
395 |
}
|
sl@0
|
396 |
CleanupStack::PopAndDestroy();
|
sl@0
|
397 |
}
|
sl@0
|
398 |
|
sl@0
|
399 |
|
sl@0
|
400 |
_LIT(KDigSig, "digital signature");
|
sl@0
|
401 |
_LIT(KNonRep, "non-repudiation");
|
sl@0
|
402 |
_LIT(KKeyEnc, "key encipherment");
|
sl@0
|
403 |
_LIT(KDataEnc, "data encipherment");
|
sl@0
|
404 |
_LIT(KKeyAgree, "key agreement");
|
sl@0
|
405 |
_LIT(KCertSign, "key cert sign");
|
sl@0
|
406 |
_LIT(KCRLSign, "crl sign");
|
sl@0
|
407 |
_LIT(KEnciph, "encipher only");
|
sl@0
|
408 |
_LIT(KDeciph, "decipher only");
|
sl@0
|
409 |
|
sl@0
|
410 |
void X509CertWriter::ShowKU(const CX509CertExtension& aExt)
|
sl@0
|
411 |
{
|
sl@0
|
412 |
iOut.writeString(_L("Key Usage:"));
|
sl@0
|
413 |
iOut.writeNewLine();
|
sl@0
|
414 |
CX509KeyUsageExt* ext = CX509KeyUsageExt::NewLC(aExt.Data());
|
sl@0
|
415 |
if (ext->IsSet(EX509DigitalSignature))
|
sl@0
|
416 |
{
|
sl@0
|
417 |
iOut.writeSpaces(4);
|
sl@0
|
418 |
iOut.writeString(KDigSig);
|
sl@0
|
419 |
iOut.writeNewLine();
|
sl@0
|
420 |
}
|
sl@0
|
421 |
if (ext->IsSet(EX509NonRepudiation))
|
sl@0
|
422 |
{
|
sl@0
|
423 |
iOut.writeSpaces(4);
|
sl@0
|
424 |
iOut.writeString(KNonRep);
|
sl@0
|
425 |
iOut.writeNewLine();
|
sl@0
|
426 |
}
|
sl@0
|
427 |
if (ext->IsSet(EX509KeyEncipherment))
|
sl@0
|
428 |
{
|
sl@0
|
429 |
iOut.writeSpaces(4);
|
sl@0
|
430 |
iOut.writeString(KKeyEnc);
|
sl@0
|
431 |
iOut.writeNewLine();
|
sl@0
|
432 |
}
|
sl@0
|
433 |
if (ext->IsSet(EX509DataEncipherment))
|
sl@0
|
434 |
{
|
sl@0
|
435 |
iOut.writeSpaces(4);
|
sl@0
|
436 |
iOut.writeString(KDataEnc);
|
sl@0
|
437 |
iOut.writeNewLine();
|
sl@0
|
438 |
}
|
sl@0
|
439 |
if (ext->IsSet(EX509KeyAgreement))
|
sl@0
|
440 |
{
|
sl@0
|
441 |
iOut.writeSpaces(4);
|
sl@0
|
442 |
iOut.writeString(KKeyAgree);
|
sl@0
|
443 |
iOut.writeNewLine();
|
sl@0
|
444 |
}
|
sl@0
|
445 |
if (ext->IsSet(EX509KeyCertSign))
|
sl@0
|
446 |
{
|
sl@0
|
447 |
iOut.writeSpaces(4);
|
sl@0
|
448 |
iOut.writeString(KCertSign);
|
sl@0
|
449 |
iOut.writeNewLine();
|
sl@0
|
450 |
}
|
sl@0
|
451 |
if (ext->IsSet(EX509CRLSign))
|
sl@0
|
452 |
{
|
sl@0
|
453 |
iOut.writeSpaces(4);
|
sl@0
|
454 |
iOut.writeString(KCRLSign);
|
sl@0
|
455 |
iOut.writeNewLine();
|
sl@0
|
456 |
}
|
sl@0
|
457 |
if (ext->IsSet(EX509EncipherOnly))
|
sl@0
|
458 |
{
|
sl@0
|
459 |
iOut.writeSpaces(4);
|
sl@0
|
460 |
iOut.writeString(KEnciph);
|
sl@0
|
461 |
iOut.writeNewLine();
|
sl@0
|
462 |
}
|
sl@0
|
463 |
if (ext->IsSet(EX509DecipherOnly))
|
sl@0
|
464 |
{
|
sl@0
|
465 |
iOut.writeSpaces(4);
|
sl@0
|
466 |
iOut.writeString(KDeciph);
|
sl@0
|
467 |
iOut.writeNewLine();
|
sl@0
|
468 |
}
|
sl@0
|
469 |
CleanupStack::PopAndDestroy();//ext
|
sl@0
|
470 |
}
|
sl@0
|
471 |
|
sl@0
|
472 |
void X509CertWriter::ShowSubtrees(const CArrayPtrFlat<CX509GeneralSubtree>& aSubtrees)
|
sl@0
|
473 |
{
|
sl@0
|
474 |
TInt count = aSubtrees.Count();
|
sl@0
|
475 |
for (TInt i = 0; i < count; i++)
|
sl@0
|
476 |
{
|
sl@0
|
477 |
const CX509GeneralSubtree* subtree = aSubtrees.At(i);
|
sl@0
|
478 |
ShowGN(subtree->Name());
|
sl@0
|
479 |
///!!!!!don't write these outFile either!!
|
sl@0
|
480 |
}
|
sl@0
|
481 |
}
|
sl@0
|
482 |
|
sl@0
|
483 |
void X509CertWriter::ShowNC(const CX509CertExtension& aExt)
|
sl@0
|
484 |
{//!!!!don't write these outFile
|
sl@0
|
485 |
|
sl@0
|
486 |
CX509NameConstraintsExt* ext = CX509NameConstraintsExt::NewLC(aExt.Data());
|
sl@0
|
487 |
ShowSubtrees(ext->ExcludedSubtrees());
|
sl@0
|
488 |
ShowSubtrees(ext->PermittedSubtrees());
|
sl@0
|
489 |
CleanupStack::PopAndDestroy();
|
sl@0
|
490 |
}
|
sl@0
|
491 |
|
sl@0
|
492 |
void X509CertWriter::ShowPC(const CX509CertExtension& /*aExt*/)
|
sl@0
|
493 |
{//!!!!don't write these outFile
|
sl@0
|
494 |
//CX509PolicyConstraintsExt* ext = CX509PolicyConstraintsExt::NewLC(aExt.Data());
|
sl@0
|
495 |
//TX509PolicyConstraint required = ext->ExplicitPolicyRequired();
|
sl@0
|
496 |
//TX509PolicyConstraint mapping = ext->InhibitPolicyMapping();
|
sl@0
|
497 |
//CleanupStack::PopAndDestroy();
|
sl@0
|
498 |
}
|
sl@0
|
499 |
|
sl@0
|
500 |
void X509CertWriter::ShowCP(const CX509CertExtension& aExt)
|
sl@0
|
501 |
{
|
sl@0
|
502 |
iOut.writeString(_L("Cert Policies = "));
|
sl@0
|
503 |
iOut.writeNewLine();
|
sl@0
|
504 |
|
sl@0
|
505 |
CX509CertPoliciesExt* ext = CX509CertPoliciesExt::NewLC(aExt.Data());
|
sl@0
|
506 |
const CArrayPtrFlat<CX509CertPolicyInfo>& policies = ext->Policies();
|
sl@0
|
507 |
TInt count = policies.Count();
|
sl@0
|
508 |
for (TInt i = 0; i < count; i++)
|
sl@0
|
509 |
{
|
sl@0
|
510 |
const CX509CertPolicyInfo* policy = policies.At(i);
|
sl@0
|
511 |
|
sl@0
|
512 |
iOut.writeSpaces(4);
|
sl@0
|
513 |
iOut.writeString(_L("Policy ID = "));
|
sl@0
|
514 |
iOut.writeString(policy->Id());
|
sl@0
|
515 |
iOut.writeNewLine();
|
sl@0
|
516 |
const CArrayPtrFlat<CX509PolicyQualifierInfo>& qualifiers = policy->Qualifiers();
|
sl@0
|
517 |
TInt qCount = qualifiers.Count();
|
sl@0
|
518 |
|
sl@0
|
519 |
if (qCount > 0)
|
sl@0
|
520 |
{
|
sl@0
|
521 |
|
sl@0
|
522 |
iOut.writeSpaces(4);
|
sl@0
|
523 |
iOut.writeString(_L("Qualified by: "));
|
sl@0
|
524 |
iOut.writeNewLine();
|
sl@0
|
525 |
}
|
sl@0
|
526 |
|
sl@0
|
527 |
for (TInt i = 0; i < qCount; i++)
|
sl@0
|
528 |
{
|
sl@0
|
529 |
CX509PolicyQualifierInfo* qualifier = qualifiers.At(i);
|
sl@0
|
530 |
|
sl@0
|
531 |
iOut.writeSpaces(8);
|
sl@0
|
532 |
iOut.writeString(_L("Qualifier ID = "));
|
sl@0
|
533 |
iOut.writeString(qualifier->Id());
|
sl@0
|
534 |
iOut.writeNewLine();
|
sl@0
|
535 |
}
|
sl@0
|
536 |
}
|
sl@0
|
537 |
CleanupStack::PopAndDestroy();//ext
|
sl@0
|
538 |
}
|
sl@0
|
539 |
|
sl@0
|
540 |
void X509CertWriter::ShowPM(const CX509CertExtension& aExt)
|
sl@0
|
541 |
{//!!!!we don't write this one outFile either
|
sl@0
|
542 |
CX509PolicyMappingExt* ext = CX509PolicyMappingExt::NewLC(aExt.Data());
|
sl@0
|
543 |
const CArrayPtrFlat<CX509PolicyMapping>& mappings = ext->Mappings();
|
sl@0
|
544 |
TInt count = mappings.Count();
|
sl@0
|
545 |
for (TInt i = 0; i < count; i++)
|
sl@0
|
546 |
{
|
sl@0
|
547 |
//const CX509PolicyMapping* mapping = mappings.At(i);
|
sl@0
|
548 |
}
|
sl@0
|
549 |
CleanupStack::PopAndDestroy();
|
sl@0
|
550 |
}
|
sl@0
|
551 |
|
sl@0
|
552 |
|
sl@0
|
553 |
void X509CertWriter::ShowEKU(const CX509CertExtension& aExt)
|
sl@0
|
554 |
{
|
sl@0
|
555 |
iOut.writeString(_L("Extended Key Usage = "));
|
sl@0
|
556 |
iOut.writeNewLine();
|
sl@0
|
557 |
|
sl@0
|
558 |
CX509ExtendedKeyUsageExt* ext = CX509ExtendedKeyUsageExt::NewLC(aExt.Data());
|
sl@0
|
559 |
const CArrayPtrFlat<HBufC>& usages = ext->KeyUsages();
|
sl@0
|
560 |
TInt count = usages.Count();
|
sl@0
|
561 |
for (TInt i = 0; i < count; i++)
|
sl@0
|
562 |
{
|
sl@0
|
563 |
iOut.writeSpaces(4);
|
sl@0
|
564 |
iOut.writeString(usages.At(i)->Des());
|
sl@0
|
565 |
iOut.writeNewLine();
|
sl@0
|
566 |
}
|
sl@0
|
567 |
CleanupStack::PopAndDestroy();
|
sl@0
|
568 |
}
|
sl@0
|
569 |
|
sl@0
|
570 |
void X509CertWriter::ShowSignature(const CX509Certificate& /*aCert*/)
|
sl@0
|
571 |
{
|
sl@0
|
572 |
/* HBufC8* sig = aCert.SignatureL();
|
sl@0
|
573 |
CleanupStack::PushL(sig);
|
sl@0
|
574 |
User::LeaveIfError(outFile.Write(sig->Des()));
|
sl@0
|
575 |
User::LeaveIfError(outFile.Flush()); // Commit data
|
sl@0
|
576 |
CleanupStack::PopAndDestroy();*/
|
sl@0
|
577 |
}
|
sl@0
|
578 |
|
sl@0
|
579 |
void X509CertWriter::WriteEncodings(const CX509Certificate& aCertificate)
|
sl@0
|
580 |
{
|
sl@0
|
581 |
iOut.writeString(_L("Version:"));
|
sl@0
|
582 |
iOut.writeNewLine();
|
sl@0
|
583 |
WriteEncoding(aCertificate, CX509Certificate::EVersionNumber);
|
sl@0
|
584 |
iOut.writeNewLine();
|
sl@0
|
585 |
|
sl@0
|
586 |
iOut.writeString(_L("Serial Number:"));
|
sl@0
|
587 |
iOut.writeNewLine();
|
sl@0
|
588 |
WriteEncoding(aCertificate, CX509Certificate::ESerialNumber);
|
sl@0
|
589 |
iOut.writeNewLine();
|
sl@0
|
590 |
|
sl@0
|
591 |
iOut.writeString(_L("Algorithm:"));
|
sl@0
|
592 |
iOut.writeNewLine();
|
sl@0
|
593 |
WriteEncoding(aCertificate, CX509Certificate::EAlgorithmId);
|
sl@0
|
594 |
iOut.writeNewLine();
|
sl@0
|
595 |
|
sl@0
|
596 |
iOut.writeString(_L("Issuer:"));
|
sl@0
|
597 |
iOut.writeNewLine();
|
sl@0
|
598 |
WriteEncoding(aCertificate, CX509Certificate::EIssuerName);
|
sl@0
|
599 |
iOut.writeNewLine();
|
sl@0
|
600 |
|
sl@0
|
601 |
iOut.writeString(_L("Validity:"));
|
sl@0
|
602 |
iOut.writeNewLine();
|
sl@0
|
603 |
WriteEncoding(aCertificate, CX509Certificate::EValidityPeriod);
|
sl@0
|
604 |
iOut.writeNewLine();
|
sl@0
|
605 |
|
sl@0
|
606 |
iOut.writeString(_L("Subject:"));
|
sl@0
|
607 |
iOut.writeNewLine();
|
sl@0
|
608 |
WriteEncoding(aCertificate, CX509Certificate::ESubjectName);
|
sl@0
|
609 |
iOut.writeNewLine();
|
sl@0
|
610 |
|
sl@0
|
611 |
iOut.writeString(_L("Public Key:"));
|
sl@0
|
612 |
iOut.writeNewLine();
|
sl@0
|
613 |
WriteEncoding(aCertificate, CX509Certificate::ESubjectPublicKeyInfo);
|
sl@0
|
614 |
iOut.writeNewLine();
|
sl@0
|
615 |
|
sl@0
|
616 |
iOut.writeString(_L("Issuer ID:"));
|
sl@0
|
617 |
iOut.writeNewLine();
|
sl@0
|
618 |
WriteEncoding(aCertificate, CX509Certificate::EIssuerUID);
|
sl@0
|
619 |
iOut.writeNewLine();
|
sl@0
|
620 |
|
sl@0
|
621 |
iOut.writeString(_L("Subject ID:"));
|
sl@0
|
622 |
iOut.writeNewLine();
|
sl@0
|
623 |
WriteEncoding(aCertificate, CX509Certificate::ESubjectUID);
|
sl@0
|
624 |
iOut.writeNewLine();
|
sl@0
|
625 |
|
sl@0
|
626 |
iOut.writeString(_L("Extensions:"));
|
sl@0
|
627 |
iOut.writeNewLine();
|
sl@0
|
628 |
WriteEncoding(aCertificate, CX509Certificate::EExtensionList);
|
sl@0
|
629 |
iOut.writeNewLine();
|
sl@0
|
630 |
}
|
sl@0
|
631 |
|
sl@0
|
632 |
void X509CertWriter::WriteEncoding(const CX509Certificate& aCertificate, const TUint aIndex)
|
sl@0
|
633 |
{
|
sl@0
|
634 |
if (aCertificate.DataElementEncoding(aIndex))
|
sl@0
|
635 |
{
|
sl@0
|
636 |
iOut.writeOctetString(*(aCertificate.DataElementEncoding(aIndex)));
|
sl@0
|
637 |
}
|
sl@0
|
638 |
}
|
sl@0
|
639 |
|
sl@0
|
640 |
#endif // SHOW_EXTENDED
|
sl@0
|
641 |
|
sl@0
|
642 |
/**********************************************************/
|
sl@0
|
643 |
|
sl@0
|
644 |
WTLSCertWriter::WTLSCertWriter(Output& aOut)
|
sl@0
|
645 |
:iOut(aOut)
|
sl@0
|
646 |
{
|
sl@0
|
647 |
}
|
sl@0
|
648 |
|
sl@0
|
649 |
void WTLSCertWriter::WriteCert(const CWTLSCertificate& aCertificate)
|
sl@0
|
650 |
{
|
sl@0
|
651 |
iOut.writeString(_L("\t\tIssuer Name = "));
|
sl@0
|
652 |
HBufC* issuer = aCertificate.IssuerL();
|
sl@0
|
653 |
iOut.writeString(*issuer);
|
sl@0
|
654 |
delete issuer;
|
sl@0
|
655 |
iOut.writeNewLine();
|
sl@0
|
656 |
iOut.writeString(_L("\t\tSubject Name = "));
|
sl@0
|
657 |
HBufC* subject = aCertificate.SubjectL();
|
sl@0
|
658 |
iOut.writeString(*subject);
|
sl@0
|
659 |
delete subject;
|
sl@0
|
660 |
iOut.writeNewLine();
|
sl@0
|
661 |
}
|
sl@0
|
662 |
|
sl@0
|
663 |
void WTLSCertWriter::ShowName(const CWTLSName& /*aName*/)
|
sl@0
|
664 |
{
|
sl@0
|
665 |
// iOut.writeString(aName.Name());
|
sl@0
|
666 |
}
|
sl@0
|
667 |
|
sl@0
|
668 |
|