VirtualBox

source: vbox/trunk/src/VBox/Runtime/common/asn1/asn1-dump.cpp@ 51770

最後變更 在這個檔案從51770是 51770,由 vboxsync 提交於 11 年 前

Merged in iprt++ dev branch.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 40.2 KB
 
1/* $Id: asn1-dump.cpp 51770 2014-07-01 18:14:02Z vboxsync $ */
2/** @file
3 * IPRT - ASN.1, Structure Dumper.
4 */
5
6/*
7 * Copyright (C) 2006-2014 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.alldomusa.eu.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27/*******************************************************************************
28* Header Files *
29*******************************************************************************/
30#include "internal/iprt.h"
31#include <iprt/asn1.h>
32
33#include <iprt/err.h>
34#include <iprt/log.h>
35#ifdef IN_RING3
36# include <iprt/stream.h>
37#endif
38#include <iprt/string.h>
39
40#include <iprt/formats/asn1.h>
41
42
43/*******************************************************************************
44* Structures and Typedefs *
45*******************************************************************************/
46/**
47 * Dump data structure.
48 */
49typedef struct RTASN1DUMPDATA
50{
51 /** RTASN1DUMP_F_XXX. */
52 uint32_t fFlags;
53 /** The printfv like output function. */
54 PFNRTDUMPPRINTFV pfnPrintfV;
55 /** PrintfV user argument. */
56 void *pvUser;
57} RTASN1DUMPDATA;
58/** Pointer to a dump data structure. */
59typedef RTASN1DUMPDATA *PRTASN1DUMPDATA;
60
61
62/**
63 * Wrapper around FNRTASN1DUMPPRINTFV.
64 *
65 * @param pData The dump data structure.
66 * @param pszFormat Format string.
67 * @param ... Format arguments.
68 */
69static void rtAsn1DumpPrintf(PRTASN1DUMPDATA pData, const char *pszFormat, ...)
70{
71 va_list va;
72 va_start(va, pszFormat);
73 pData->pfnPrintfV(pData->pvUser, pszFormat, va);
74 va_end(va);
75}
76
77
78/**
79 * Prints indentation.
80 *
81 * @param pData The dump data structure.
82 * @param uDepth The indentation depth.
83 */
84static void rtAsn1DumpPrintIdent(PRTASN1DUMPDATA pData, uint32_t uDepth)
85{
86 uint32_t i = 0;
87 uDepth *= 2;
88 while (i < uDepth)
89 {
90 static char const s_szSpaces[] = " ";
91 uint32_t cch = RT_MIN(uDepth, sizeof(s_szSpaces) - 1);
92 rtAsn1DumpPrintf(pData, &s_szSpaces[sizeof(s_szSpaces) - 1 - cch]);
93 i += cch;
94 }
95}
96
97
98/**
99 * Dumps UTC TIME and GENERALIZED TIME
100 *
101 * @param pData The dump data structure.
102 * @param pAsn1Core The ASN.1 core object representation.
103 * @param pszName The member name.
104 * @param pszType The time type name.
105 */
106static void rtAsn1DumpTime(PRTASN1DUMPDATA pData, PCRTASN1CORE pAsn1Core, const char *pszName, const char *pszType)
107{
108 if ((pAsn1Core->fFlags & RTASN1CORE_F_PRIMITE_TAG_STRUCT))
109 {
110 PCRTASN1TIME pTime = (PCRTASN1TIME)pAsn1Core;
111 rtAsn1DumpPrintf(pData, "%-16s %s -- %04u-%02u-%02u %02u:%02u:%02.%09Z\n",
112 pszName, pszType,
113 pTime->Time.i32Year, pTime->Time.u8Month, pTime->Time.u8MonthDay,
114 pTime->Time.u8Hour, pTime->Time.u8Minute, pTime->Time.u8Second,
115 pTime->Time.u32Nanosecond);
116 }
117 else if (pAsn1Core->cb > 0 && pAsn1Core->cb < 32 && pAsn1Core->uData.pch)
118 rtAsn1DumpPrintf(pData, "%-16s %s '%.*s'\n",
119 pszName, pszType, (size_t)pAsn1Core->cb, pAsn1Core->uData.pch);
120 else
121 rtAsn1DumpPrintf(pData, "%-16s %s -- cb=%u\n", pszName, pszType, pAsn1Core->cb);
122}
123
124
125/**
126 * Dumps strings sharing the RTASN1STRING structure.
127 *
128 * @param pData The dump data structure.
129 * @param pAsn1Core The ASN.1 core object representation.
130 * @param pszName The member name.
131 * @param pszType The string type name.
132 * @param uDepth The current identation level.
133 */
134static void rtAsn1DumpString(PRTASN1DUMPDATA pData, PCRTASN1CORE pAsn1Core, const char *pszName, const char *pszType,
135 uint32_t uDepth)
136{
137 rtAsn1DumpPrintf(pData, "%-16s %s", pszName, pszType);
138
139 const char *pszPostfix = "'\n";
140 bool fUtf8 = false;
141 const char *pch = pAsn1Core->uData.pch;
142 uint32_t cch = pAsn1Core->cb;
143 PCRTASN1STRING pString = (PCRTASN1STRING)pAsn1Core;
144 if ( (pAsn1Core->fFlags & RTASN1CORE_F_PRIMITE_TAG_STRUCT)
145 && pString->pszUtf8
146 && pString->cchUtf8)
147 {
148 fUtf8 = true;
149 pszPostfix = "' -- utf-8\n";
150 }
151
152 if (cch == 0 || !pch)
153 rtAsn1DumpPrintf(pData, " -- cb=%u\n", pszName, pszType, pAsn1Core->cb);
154 else
155 {
156 if (cch >= 48)
157 {
158 rtAsn1DumpPrintf(pData, "\n");
159 rtAsn1DumpPrintIdent(pData, uDepth + 1);
160 }
161 rtAsn1DumpPrintf(pData, " '");
162
163 /** @todo Handle BMP and UNIVERSIAL strings specially. */
164 do
165 {
166 const char *pchStart = pch;
167 while ( cch > 0
168 && (uint8_t)*pch >= 0x20
169 && (!fUtf8 ? (uint8_t)*pch < 0x7f : (uint8_t)*pch != 0x7f)
170 && *pch != '\'')
171 cch--, pch++;
172 if (pchStart != pch)
173 rtAsn1DumpPrintf(pData, "%.*s", pch - pchStart, pchStart);
174
175 while ( cch > 0
176 && ( (uint8_t)*pch < 0x20
177 || (!fUtf8 ? (uint8_t)*pch >= 0x7f : (uint8_t)*pch == 0x7f)
178 || (uint8_t)*pch == '\'') )
179 {
180 rtAsn1DumpPrintf(pData, "\\x%02", *pch);
181 cch--;
182 pch++;
183 }
184 } while (cch > 0);
185
186 rtAsn1DumpPrintf(pData, pszPostfix);
187 }
188}
189
190
191/**
192 * Returns a name for the given object ID.
193 *
194 * This is just to make some of the dumps a little easier to read. It's no our
195 * intention to have the whole ODI repository encoded here.
196 *
197 * @returns Name if available, NULL if not.
198 * @param pszObjId The dotted object identifier string.
199 */
200static const char *rtAsn1DumpLookupObjIdName(const char *pszObjId)
201{
202#define STARTS_WITH_1(a_off, a_uValue) \
203 ( pszObjId[a_off] == (a_uValue) + '0' && pszObjId[a_off + 1] == '.' )
204#define STARTS_WITH_2(a_off, a_uValue) \
205 ( pszObjId[a_off] == (a_uValue) / 10 + '0' && pszObjId[a_off + 1] == (a_uValue) % 10 + '0' && pszObjId[a_off + 2] == '.' )
206#define STARTS_WITH_3(a_off, a_uValue) \
207 ( pszObjId[a_off] == (a_uValue) / 100 + '0' \
208 && pszObjId[a_off + 1] == ((a_uValue) % 100) / 10 + '0' \
209 && pszObjId[a_off + 2] == (a_uValue) % 10 + '0' \
210 && pszObjId[a_off + 3] == '.' )
211#define STARTS_WITH_6(a_off, a_uValue) \
212 ( pszObjId[a_off] == (a_uValue) / 100000 + '0' \
213 && pszObjId[a_off + 1] == ((a_uValue) % 100000) / 10000 + '0' \
214 && pszObjId[a_off + 2] == ((a_uValue) % 10000) / 1000 + '0' \
215 && pszObjId[a_off + 3] == ((a_uValue) % 1000) / 100 + '0' \
216 && pszObjId[a_off + 4] == ((a_uValue) % 100) / 10 + '0' \
217 && pszObjId[a_off + 5] == (a_uValue) % 10 + '0' \
218 && pszObjId[a_off + 6] == '.' )
219
220#define ENDS_WITH_1(a_off, a_uValue) \
221 ( pszObjId[a_off] == (a_uValue) + '0' && !pszObjId[a_off + 1] )
222#define ENDS_WITH_2(a_off, a_uValue) \
223 ( pszObjId[a_off] == (a_uValue) / 10 + '0' && pszObjId[a_off + 1] == (a_uValue) % 10 + '0' && !pszObjId[a_off + 2] )
224
225 if (STARTS_WITH_1(0, 0)) /* ITU-T assigned - top level 0. */
226 {
227
228 }
229 else if (STARTS_WITH_1(0, 1)) /* ISO assigned - top level 1. */
230 {
231 if (STARTS_WITH_1(2, 0)) /* ISO standard - 1.0. */
232 {
233 /* */
234 }
235 else if (STARTS_WITH_1(2, 2)) /* ISO member body - 1.2. */
236 {
237 if (STARTS_WITH_3(4, 840)) /* USA - 1.2.840. */
238 {
239 if (STARTS_WITH_6(8, 113549)) /* RSADSI / RSA Data Security inc - 1.2.840.113549. */
240 {
241 if (STARTS_WITH_1(15, 1)) /* PKCS - 1.2.840.113549.1. */
242 {
243 if (STARTS_WITH_1(17, 1)) /* PKCS-1 - 1.2.840.113549.1.1. */
244 {
245 if (ENDS_WITH_1(19, 1)) return "pkcs1-RsaEncryption";
246 else if (ENDS_WITH_1(19, 2)) return "pkcs1-Md2WithRsaEncryption";
247 else if (ENDS_WITH_1(19, 3)) return "pkcs1-Md4WithRsaEncryption";
248 else if (ENDS_WITH_1(19, 4)) return "pkcs1-Md5WithRsaEncryption";
249 else if (ENDS_WITH_1(19, 5)) return "pkcs1-Sha1WithRsaEncryption";
250 else if (ENDS_WITH_2(19, 10)) return "pkcs1-RsaPss";
251 else if (ENDS_WITH_2(19, 11)) return "pkcs1-Sha256WithRsaEncryption";
252 else if (ENDS_WITH_2(19, 12)) return "pkcs1-Sha384WithRsaEncryption";
253 else if (ENDS_WITH_2(19, 13)) return "pkcs1-Sha512WithRsaEncryption";
254 else if (ENDS_WITH_2(19, 14)) return "pkcs1-Sha224WithRsaEncryption";
255 }
256 else if (STARTS_WITH_1(17, 9)) /* PKCS-9 signatures - 1.2.840.113549.1.9. */
257 {
258 if (ENDS_WITH_1(19, 1)) return "pkcs9-EMailAddress";
259 else if (ENDS_WITH_1(19, 2)) return "pkcs9-UntrustedName";
260 else if (ENDS_WITH_1(19, 3)) return "pkcs9-ContentType";
261 else if (ENDS_WITH_1(19, 4)) return "pkcs9-MessageDigest";
262 else if (ENDS_WITH_1(19, 5)) return "pkcs9-SigningTime";
263 else if (ENDS_WITH_1(19, 6)) return "pkcs9-CounterSignature";
264 else if (ENDS_WITH_1(19, 7)) return "pkcs9-challengePassword";
265 else if (ENDS_WITH_1(19, 8)) return "pkcs9-UnstructuredAddress";
266 else if (ENDS_WITH_1(19, 9)) return "pkcs9-ExtendedCertificateAttributes";
267 else if (ENDS_WITH_2(19, 13)) return "pkcs9-SigningDescription";
268 else if (ENDS_WITH_2(19, 14)) return "pkcs9-ExtensionRequest";
269 else if (ENDS_WITH_2(19, 15)) return "pkcs9-SMimeCapabilities";
270 }
271 }
272 else if (STARTS_WITH_1(15, 2)) /* PKCS #2 - 1.2.840.113549.2. */
273 {
274 }
275 }
276 }
277 }
278 else if (STARTS_WITH_1(2, 3)) /* ISO identified organiziation - 1.3. */
279 {
280 if (STARTS_WITH_1(4, 6)) /* DOD - 1.3.6. */
281 {
282 if (STARTS_WITH_1(6, 1)) /* Internet - 1.3.6.1. */
283 {
284 if (STARTS_WITH_1(8, 4)) /* Private - 1.3.6.1.4. */
285 {
286 if (STARTS_WITH_1(10, 1)) /* IANA-registered Private Enterprises. */
287 {
288 if (STARTS_WITH_3(12, 311)) /* Microsoft - 1.3.6.1.4.1.311 */
289 {
290 if (STARTS_WITH_1(16, 1)) /* 1.3.6.1.4.1.311.1. */
291 {
292 }
293 else if (STARTS_WITH_1(16, 2)) /* 1.3.6.1.4.1.311.2 */
294 {
295 if (STARTS_WITH_1(18, 1)) /* 1.3.6.1.4.1.311.2.1. */
296 {
297 if (ENDS_WITH_1(20, 1)) return "Ms-??-2.1";
298 else if (ENDS_WITH_1(20, 4)) return "Ms-SpcIndirectDataContext";
299 else if (ENDS_WITH_2(20, 10)) return "Ms-SpcAgencyInfo";
300 else if (ENDS_WITH_2(20, 11)) return "Ms-SpcStatemntType";
301 else if (ENDS_WITH_2(20, 12)) return "Ms-SpcOpusInfo";
302 else if (ENDS_WITH_2(20, 14)) return "Ms-CertReqExtensions";
303 else if (ENDS_WITH_2(20, 15)) return "Ms-SpcPeImageData";
304 else if (ENDS_WITH_2(20, 18)) return "Ms-SpcRawFileData";
305 else if (ENDS_WITH_2(20, 19)) return "Ms-SpcStructuredStorageData";
306 else if (ENDS_WITH_2(20, 20)) return "Ms-SpcJavaClassDataType1";
307 else if (ENDS_WITH_2(20, 21)) return "Ms-SpcIndividualCodeSigning";
308 else if (ENDS_WITH_2(20, 22)) return "Ms-SpcCommericalSigning";
309 else if (ENDS_WITH_2(20, 25)) return "Ms-SpcLinkType2-Aka-CabData";
310 else if (ENDS_WITH_2(20, 26)) return "Ms-SpcMinimalCriterialInfo";
311 else if (ENDS_WITH_2(20, 27)) return "Ms-SpcFinacialCriterialInfo";
312 else if (ENDS_WITH_2(20, 28)) return "Ms-SpcLinkType3";
313 }
314 else if (STARTS_WITH_1(18, 3)) /* 1.3.6.1.4.1.311.2.3. */
315 {
316 if (ENDS_WITH_1(20, 1)) return "Ms-SpcPeImagePageHashesV1";
317 else if (ENDS_WITH_1(20, 2)) return "Ms-SpcPeImagePageHashesV2";
318 }
319 }
320 else if (STARTS_WITH_1(16, 3)) /* 1.3.6.1.4.1.311.3 */
321 {
322 if (STARTS_WITH_1(18, 3)) /* 1.3.6.1.4.1.311.3.3. */
323 {
324 if (ENDS_WITH_1(20, 1)) return "Ms-CounterSign";
325 else if (ENDS_WITH_1(20, 2)) return "Ms-??-3.2";
326 }
327 }
328 else if (STARTS_WITH_2(16, 10)) /* 1.3.6.1.4.1.311.10 */
329 {
330 if (STARTS_WITH_1(19, 3)) /* . */
331 {
332 if (ENDS_WITH_1(21, 1)) return "Ms-CertTrustListSigning";
333 else if (ENDS_WITH_1(21, 2)) return "Ms-TimeStampSigning";
334 else if (ENDS_WITH_1(21, 4)) return "Ms-EncryptedFileSystem";
335 else if (ENDS_WITH_1(21, 5)) return "Ms-WhqlCrypto";
336 else if (ENDS_WITH_1(21, 6)) return "Ms-Nt5Crypto";
337 else if (ENDS_WITH_1(21, 7)) return "Ms-OemWhqlCrypto";
338 else if (ENDS_WITH_1(21, 8)) return "Ms-EmbeddedNtCrypto";
339 else if (ENDS_WITH_1(21, 9)) return "Ms-RootListSigner";
340 else if (ENDS_WITH_2(21, 10)) return "Ms-QualifiedSubordination";
341 else if (ENDS_WITH_2(21, 11)) return "Ms-KeyRecovery";
342 else if (ENDS_WITH_2(21, 12)) return "Ms-DocumentSigning";
343 else if (ENDS_WITH_2(21, 13)) return "Ms-LifetimeSigning";
344 }
345 else if (STARTS_WITH_1(19, 5)) /* . */
346 {
347 if (ENDS_WITH_1(21, 1)) return "Ms-Drm";
348 else if (ENDS_WITH_1(21, 2)) return "Ms-DrmIndividualization";
349 }
350 else if (STARTS_WITH_1(19, 9)) /* . */
351 {
352 if (ENDS_WITH_1(21, 1)) return "Ms-CrossCertDistPoints";
353 }
354 }
355 else if (STARTS_WITH_2(16, 20)) /* 1.3.6.1.4.1.311.20 */
356 {
357 if (ENDS_WITH_1(19, 1)) return "Ms-AutoEnrollCtlUsage";
358 else if (ENDS_WITH_1(19, 2)) return "Ms-EnrollCerttypeExtension";
359 }
360 else if (STARTS_WITH_2(16, 21)) /* CertSrv Infrastructure - 1.3.6.1.4.1.311.21 */
361 {
362 if (ENDS_WITH_1(19, 1)) return "Ms-CaKeyCertIndexPair";
363 else if (ENDS_WITH_1(19, 2)) return "Ms-CertSrvPreviousCertHash";
364 else if (ENDS_WITH_1(19, 3)) return "Ms-CrlVirtualBase";
365 else if (ENDS_WITH_1(19, 4)) return "Ms-CrlNextPublish";
366 else if (ENDS_WITH_1(19, 6)) return "Ms-KeyRecovery";
367 else if (ENDS_WITH_1(19, 7)) return "Ms-CertificateTemplate";
368 else if (ENDS_WITH_1(19, 9)) return "Ms-DummySigner";
369 }
370 }
371 }
372 }
373 else if (STARTS_WITH_1(8, 5)) /* Security - 1.3.6.1.5. */
374 {
375 if (STARTS_WITH_1(10, 5)) /* Mechanisms - 1.3.6.1.5.5. */
376 {
377 if (STARTS_WITH_1(12, 7)) /* Public-Key Infrastructure (X.509) - 1.3.6.1.5.5.7. */
378 {
379 if (STARTS_WITH_1(14, 1)) /* Private Extension - 1.3.6.1.5.5.7.1. */
380 {
381 if (ENDS_WITH_1(16, 1)) return "pkix-AuthorityInfoAccess";
382 else if (ENDS_WITH_2(16, 12)) return "pkix-LogoType";
383 }
384 else if (STARTS_WITH_1(14, 2)) /* Private Extension - 1.3.6.1.5.5.7.2. */
385 {
386 if (ENDS_WITH_1(16, 1)) return "id-qt-CPS";
387 else if (ENDS_WITH_1(16, 2)) return "id-qt-UNotice";
388 else if (ENDS_WITH_1(16, 3)) return "id-qt-TextNotice";
389 else if (ENDS_WITH_1(16, 4)) return "id-qt-ACPS";
390 else if (ENDS_WITH_1(16, 5)) return "id-qt-ACUNotice";
391 }
392 else if (STARTS_WITH_1(14, 3)) /* Private Extension - 1.3.6.1.5.5.7.3. */
393 {
394 if (ENDS_WITH_1(16, 1)) return "id-kp-ServerAuth";
395 else if (ENDS_WITH_1(16, 2)) return "id-kp-ClientAuth";
396 else if (ENDS_WITH_1(16, 3)) return "id-kp-CodeSigning";
397 else if (ENDS_WITH_1(16, 4)) return "id-kp-EmailProtection";
398 else if (ENDS_WITH_1(16, 5)) return "id-kp-IPSecEndSystem";
399 else if (ENDS_WITH_1(16, 6)) return "id-kp-IPSecTunnel";
400 else if (ENDS_WITH_1(16, 7)) return "id-kp-IPSecUser";
401 else if (ENDS_WITH_1(16, 8)) return "id-kp-Timestamping";
402 else if (ENDS_WITH_1(16, 9)) return "id-kp-OCSPSigning";
403 else if (ENDS_WITH_2(16, 10)) return "id-kp-DVCS";
404 else if (ENDS_WITH_2(16, 11)) return "id-kp-SBGPCertAAServiceAuth";
405 else if (ENDS_WITH_2(16, 13)) return "id-kp-EAPOverPPP";
406 else if (ENDS_WITH_2(16, 14)) return "id-kp-EAPOverLAN";
407 }
408 }
409 }
410 }
411 }
412 }
413 else if (STARTS_WITH_2(4, 14)) /* 1.3.14. */
414 {
415 if (STARTS_WITH_1(7, 3)) /* OIW Security Special Interest Group - 1.3.14.3. */
416 {
417 if (STARTS_WITH_1(9, 2)) /* OIW SSIG algorithms - 1.3.14.3.2. */
418 {
419 if (ENDS_WITH_1(11, 2)) return "oiw-ssig-Md4WithRsa";
420 else if (ENDS_WITH_1(11, 3)) return "oiw-ssig-Md5WithRsa";
421 else if (ENDS_WITH_1(11, 4)) return "oiw-ssig-Md4WithRsaEncryption";
422 else if (ENDS_WITH_2(11, 15)) return "oiw-ssig-ShaWithRsaEncryption";
423 else if (ENDS_WITH_2(11, 24)) return "oiw-ssig-Md2WithRsaEncryption";
424 else if (ENDS_WITH_2(11, 25)) return "oiw-ssig-Md5WithRsaEncryption";
425 else if (ENDS_WITH_2(11, 26)) return "oiw-ssig-Sha1";
426 else if (ENDS_WITH_2(11, 29)) return "oiw-ssig-Sha1WithRsaEncryption";
427 }
428 }
429 }
430 }
431 }
432 else if (STARTS_WITH_1(0, 2)) /* Joint ISO/ITU-T assigned - top level 2.*/
433 {
434 if (STARTS_WITH_1(2, 1)) /* ASN.1 - 2.1. */
435 {
436 }
437 else if (STARTS_WITH_1(2, 5)) /* Directory (X.500) - 2.5. */
438 {
439 if (STARTS_WITH_1(4, 4)) /* X.500 Attribute types - 2.5.4. */
440 {
441 if (ENDS_WITH_1(6, 3)) return "x500-CommonName";
442 else if (ENDS_WITH_1(6, 6)) return "x500-CountryName";
443 else if (ENDS_WITH_1(6, 7)) return "x500-LocalityName";
444 else if (ENDS_WITH_1(6, 8)) return "x500-StatOrProvinceName";
445 else if (ENDS_WITH_2(6, 10)) return "x500-OrganizationName";
446 else if (ENDS_WITH_2(6, 11)) return "x500-OrganizationUnitName";
447 }
448 else if (STARTS_WITH_2(4, 29)) /* certificateExtension (id-ce) - 2.5.29. */
449 {
450 if (ENDS_WITH_1(7, 1)) return "id-ce-AuthorityKeyIdentifier-Deprecated";
451 else if (ENDS_WITH_1(7, 2)) return "id-ce-KeyAttributes-Deprecated";
452 else if (ENDS_WITH_1(7, 3)) return "id-ce-CertificatePolicies-Deprecated";
453 else if (ENDS_WITH_1(7, 4)) return "id-ce-KeyUsageRestriction-Deprecated";
454 else if (ENDS_WITH_1(7, 7)) return "id-ce-SubjectAltName-Deprecated";
455 else if (ENDS_WITH_1(7, 8)) return "id-ce-IssuerAltName-Deprecated";
456 else if (ENDS_WITH_2(7, 14)) return "id-ce-SubjectKeyIdentifier";
457 else if (ENDS_WITH_2(7, 15)) return "id-ce-KeyUsage";
458 else if (ENDS_WITH_2(7, 16)) return "id-ce-PrivateKeyUsagePeriod";
459 else if (ENDS_WITH_2(7, 17)) return "id-ce-SubjectAltName";
460 else if (ENDS_WITH_2(7, 18)) return "id-ce-issuerAltName";
461 else if (ENDS_WITH_2(7, 19)) return "id-ce-BasicConstraints";
462 else if (ENDS_WITH_2(7, 25)) return "id-ce-CrlDistributionPoints";
463 else if (ENDS_WITH_2(7, 29)) return "id-ce-CertificateIssuer";
464 else if (ENDS_WITH_2(7, 30)) return "id-ce-NameConstraints";
465 else if (ENDS_WITH_2(7, 31)) return "id-ce-CrlDistributionPoints";
466 else if (ENDS_WITH_2(7, 32)) return "id-ce-CertificatePolicies";
467 else if (STARTS_WITH_2(7, 32))
468 {
469 if (ENDS_WITH_1(10, 0)) return "id-ce-cp-anyPolicy";
470 }
471 else if (ENDS_WITH_2(7, 35)) return "id-ce-AuthorityKeyIdentifier";
472 else if (ENDS_WITH_2(7, 36)) return "id-ce-PolicyConstraints";
473 else if (ENDS_WITH_2(7, 37)) return "id-ce-ExtKeyUsage";
474 }
475 }
476 else if (STARTS_WITH_2(2, 16)) /* Join assignments by country - 2.16. */
477 {
478 if (0)
479 {
480 }
481 else if (STARTS_WITH_3(5, 840)) /* USA - 2.16.840. */
482 {
483 if (STARTS_WITH_1(9, 1)) /* US company arc. */
484 {
485 if (STARTS_WITH_3(11, 101)) /* US Government */
486 {
487 if (STARTS_WITH_1(15, 3)) /* Computer Security Objects Register */
488 {
489 if (STARTS_WITH_1(17, 4)) /* NIST Algorithms - 2.16.840.1.101.3.4. */
490 {
491 if (STARTS_WITH_1(19, 1)) /* AES - 2.16.840.1.101.3.4.1. */
492 {
493 }
494 else if (STARTS_WITH_1(19, 2)) /* Hash algorithms - 2.16.840.1.101.3.4.2. */
495 {
496 if (ENDS_WITH_1(21, 1)) return "nist-Sha256";
497 else if (ENDS_WITH_1(21, 2)) return "nist-Sha384";
498 else if (ENDS_WITH_1(21, 3)) return "nist-Sha512";
499 else if (ENDS_WITH_1(21, 4)) return "nist-Sha224";
500 }
501 }
502 }
503 }
504 else if (STARTS_WITH_6(11, 113730)) /* Netscape - 2.16.840.1.113730. */
505 {
506 if (STARTS_WITH_1(18, 1)) /* Netscape - 2.16.840.1.113730.1. */
507 {
508 if (ENDS_WITH_1(20, 1)) return "netscape-cert-type";
509 else if (ENDS_WITH_1(20, 2)) return "netscape-base-url";
510 else if (ENDS_WITH_1(20, 3)) return "netscape-revocation-url";
511 else if (ENDS_WITH_1(20, 4)) return "netscape-ca-revocation-url";
512 else if (ENDS_WITH_1(20, 7)) return "netscape-cert-renewal-url";
513 else if (ENDS_WITH_1(20, 8)) return "netscape-ca-policy-url";
514 else if (ENDS_WITH_1(20, 9)) return "netscape-HomePage-url";
515 else if (ENDS_WITH_2(20, 10)) return "netscape-EntityLogo";
516 else if (ENDS_WITH_2(20, 11)) return "netscape-UserPicture";
517 else if (ENDS_WITH_2(20, 12)) return "netscape-ssl-server-name";
518 else if (ENDS_WITH_2(20, 13)) return "netscape-comment";
519 }
520 else if (STARTS_WITH_1(18, 4)) /* Netscape - 2.16.840.1.113730.4. */
521 {
522 if (ENDS_WITH_1(20, 1)) return "netscape-eku-serverGatedCrypto";
523 }
524 }
525 else if (STARTS_WITH_6(11, 113733)) /* Verisign, Inc. - 2.16.840.1.113733. */
526 {
527 if (STARTS_WITH_1(18, 1)) /* Verisign PKI Sub Tree - 2.16.840.1.113733.1. */
528 {
529 if (ENDS_WITH_1(20, 6)) return "verisign-pki-extensions-subtree";
530 else if (STARTS_WITH_1(20, 6)) /* 2.16.840.1.113733.1.6. */
531 {
532 if (ENDS_WITH_1(22, 7)) return "verisign-pki-ext-RolloverID";
533 }
534 else if (ENDS_WITH_1(20, 7)) return "verisign-pki-policies";
535 else if (STARTS_WITH_1(20, 7)) /* 2.16.840.1.113733.1.7. */
536 {
537 if (ENDS_WITH_1(22, 9)) return "verisign-pki-policy-9";
538 else if (ENDS_WITH_2(22, 21)) return "verisign-pki-policy-21";
539 else if (ENDS_WITH_2(22, 23)) return "verisign-pki-policy-vtn-cp";
540 else if (STARTS_WITH_2(22, 23))
541 {
542 if (ENDS_WITH_1(25, 1)) return "verisign-pki-policy-vtn-cp-class1";
543 else if (ENDS_WITH_1(25, 2)) return "verisign-pki-policy-vtn-cp-class2";
544 else if (ENDS_WITH_1(25, 3)) return "verisign-pki-policy-vtn-cp-class3";
545 else if (ENDS_WITH_1(25, 4)) return "verisign-pki-policy-vtn-cp-class4";
546 else if (ENDS_WITH_1(25, 6)) return "verisign-pki-policy-vtn-cp-6";
547 }
548 }
549 else if (STARTS_WITH_1(20, 8)) /* 2.16.840.1.113733.1.8. */
550 {
551 if (ENDS_WITH_1(22, 1)) return "verisign-pki-eku-IssStrongCrypto";
552 }
553 else if (ENDS_WITH_2(22, 46)) return "verisign-pki-policy-cis";
554 else if (STARTS_WITH_2(22, 46))
555 {
556 if (ENDS_WITH_1(25, 1)) return "verisign-pki-policy-cis-type1";
557 else if (ENDS_WITH_1(25, 2)) return "verisign-pki-policy-cis-type2";
558 }
559 else if (ENDS_WITH_2(22, 48)) return "verisign-pki-policy-thawte";
560 else if (STARTS_WITH_2(22, 48))
561 {
562 if (ENDS_WITH_1(25, 1)) return "verisign-pki-policy-thawte-cps-1";
563 }
564 }
565 }
566 }
567 }
568 }
569 }
570 return NULL;
571}
572
573
574/** @callback_method_impl{FNRTASN1ENUMCALLBACK} */
575static DECLCALLBACK(int) rtAsn1DumpEnumCallback(PRTASN1CORE pAsn1Core, const char *pszName, uint32_t uDepth, void *pvUser)
576{
577 PRTASN1DUMPDATA pData = (PRTASN1DUMPDATA)pvUser;
578 if (!pAsn1Core->fFlags)
579 return VINF_SUCCESS;
580
581 rtAsn1DumpPrintIdent(pData, uDepth);
582
583 const char *pszValuePrefix = "-- value:";
584 const char *pszDefault = "";
585 if (pAsn1Core->fFlags & RTASN1CORE_F_DEFAULT)
586 {
587 pszValuePrefix = "DEFAULT";
588 pszDefault = "DEFAULT ";
589 }
590
591 bool fOpen = false;
592 switch (pAsn1Core->fClass & ASN1_TAGCLASS_MASK)
593 {
594 case ASN1_TAGCLASS_UNIVERSAL:
595 switch (pAsn1Core->fFlags & RTASN1CORE_F_TAG_IMPLICIT ? pAsn1Core->uRealTag : pAsn1Core->uTag)
596 {
597 case ASN1_TAG_BOOLEAN:
598 if (pAsn1Core->fFlags & RTASN1CORE_F_PRIMITE_TAG_STRUCT)
599 rtAsn1DumpPrintf(pData, "%-16s BOOLEAN %s %RTbool\n",
600 pszName, pszValuePrefix, ((PCRTASN1BOOLEAN)pAsn1Core)->fValue);
601 else if (pAsn1Core->cb == 1 && pAsn1Core->uData.pu8)
602 rtAsn1DumpPrintf(pData, "%-16s BOOLEAN %s %u\n",
603 pszName, pszValuePrefix, *pAsn1Core->uData.pu8);
604 else
605 rtAsn1DumpPrintf(pData, "%-16s BOOLEAN -- cb=%u\n", pszName, pAsn1Core->cb);
606 break;
607
608 case ASN1_TAG_INTEGER:
609 if ((pAsn1Core->fFlags & RTASN1CORE_F_PRIMITE_TAG_STRUCT) && pAsn1Core->cb <= 8)
610 rtAsn1DumpPrintf(pData, "%-16s INTEGER %s %llu / %#llx\n", pszName, pszValuePrefix,
611 ((PCRTASN1INTEGER)pAsn1Core)->uValue, ((PCRTASN1INTEGER)pAsn1Core)->uValue);
612 else if (pAsn1Core->cb == 0 || pAsn1Core->cb >= 512 || !pAsn1Core->uData.pu8)
613 rtAsn1DumpPrintf(pData, "%-16s INTEGER -- cb=%u\n", pszName, pAsn1Core->cb);
614 else if (pAsn1Core->cb <= 32)
615 rtAsn1DumpPrintf(pData, "%-16s INTEGER %s %.*Rhxs\n",
616 pszName, pszValuePrefix, (size_t)pAsn1Core->cb, pAsn1Core->uData.pu8);
617 else
618 rtAsn1DumpPrintf(pData, "%-16s INTEGER %s\n%.*Rhxd\n",
619 pszName, pszValuePrefix, (size_t)pAsn1Core->cb, pAsn1Core->uData.pu8);
620 break;
621
622 case ASN1_TAG_BIT_STRING:
623 if ((pAsn1Core->fFlags & RTASN1CORE_F_PRIMITE_TAG_STRUCT))
624 {
625 PCRTASN1BITSTRING pBitString = (PCRTASN1BITSTRING)pAsn1Core;
626 rtAsn1DumpPrintf(pData, "%-16s BIT STRING %s-- cb=%u cBits=%#x cMaxBits=%#x",
627 pszName, pszDefault, pBitString->Asn1Core.cb, pBitString->cBits, pBitString->cMaxBits);
628 if (pBitString->cBits <= 64)
629 rtAsn1DumpPrintf(pData, " value=%#llx\n", RTAsn1BitString_GetAsUInt64(pBitString));
630 else
631 rtAsn1DumpPrintf(pData, "\n");
632 }
633 else
634 rtAsn1DumpPrintf(pData, "%-16s BIT STRING %s-- cb=%u\n", pszName, pszDefault, pAsn1Core->cb);
635 fOpen = pAsn1Core->pOps != NULL;
636 break;
637
638 case ASN1_TAG_OCTET_STRING:
639 rtAsn1DumpPrintf(pData, "%-16s OCTET STRING %s-- cb=%u\n", pszName, pszDefault, pAsn1Core->cb);
640 fOpen = pAsn1Core->pOps != NULL;
641 break;
642
643 case ASN1_TAG_NULL:
644 rtAsn1DumpPrintf(pData, "%-16s NULL\n", pszName);
645 break;
646
647 case ASN1_TAG_OID:
648 if ((pAsn1Core->fFlags & RTASN1CORE_F_PRIMITE_TAG_STRUCT))
649 {
650 const char *pszObjIdName = rtAsn1DumpLookupObjIdName(((PCRTASN1OBJID)pAsn1Core)->szObjId);
651 if (pszObjIdName)
652 rtAsn1DumpPrintf(pData, "%-16s OBJECT IDENTIFIER %s%s ('%s')\n",
653 pszName, pszDefault, pszObjIdName, ((PCRTASN1OBJID)pAsn1Core)->szObjId);
654 else
655 rtAsn1DumpPrintf(pData, "%-16s OBJECT IDENTIFIER %s'%s'\n",
656 pszName, pszDefault, ((PCRTASN1OBJID)pAsn1Core)->szObjId);
657 }
658 else
659 rtAsn1DumpPrintf(pData, "%-16s OBJECT IDENTIFIER %s -- cb=%u\n",
660 pszName, pszDefault, pAsn1Core->cb);
661 break;
662
663 case ASN1_TAG_OBJECT_DESCRIPTOR:
664 rtAsn1DumpPrintf(pData, "%-16s OBJECT DESCRIPTOR -- cb=%u TODO\n", pszName, pAsn1Core->cb);
665 break;
666
667 case ASN1_TAG_EXTERNAL:
668 rtAsn1DumpPrintf(pData, "%-16s EXTERNAL -- cb=%u TODO\n", pszName, pAsn1Core->cb);
669 break;
670
671 case ASN1_TAG_REAL:
672 rtAsn1DumpPrintf(pData, "%-16s REAL -- cb=%u TODO\n", pszName, pAsn1Core->cb);
673 break;
674
675 case ASN1_TAG_ENUMERATED:
676 rtAsn1DumpPrintf(pData, "%-16s ENUMERATED -- cb=%u TODO\n", pszName, pAsn1Core->cb);
677 break;
678
679 case ASN1_TAG_EMBEDDED_PDV:
680 rtAsn1DumpPrintf(pData, "%-16s EMBEDDED PDV -- cb=%u TODO\n", pszName, pAsn1Core->cb);
681 break;
682
683 case ASN1_TAG_UTF8_STRING:
684 rtAsn1DumpString(pData, pAsn1Core, pszName, "UTF8 STRING", uDepth);
685 break;
686
687 case ASN1_TAG_RELATIVE_OID:
688 rtAsn1DumpPrintf(pData, "%-16s RELATIVE OBJECT IDENTIFIER -- cb=%u TODO\n", pszName, pAsn1Core->cb);
689 break;
690
691 case ASN1_TAG_SEQUENCE:
692 rtAsn1DumpPrintf(pData, "%-16s SEQUENCE -- cb=%u\n", pszName, pAsn1Core->cb);
693 fOpen = true;
694 break;
695 case ASN1_TAG_SET:
696 rtAsn1DumpPrintf(pData, "%-16s SET -- cb=%u\n", pszName, pAsn1Core->cb);
697 fOpen = true;
698 break;
699
700 case ASN1_TAG_NUMERIC_STRING:
701 rtAsn1DumpString(pData, pAsn1Core, pszName, "NUMERIC STRING", uDepth);
702 break;
703
704 case ASN1_TAG_PRINTABLE_STRING:
705 rtAsn1DumpString(pData, pAsn1Core, pszName, "PRINTABLE STRING", uDepth);
706 break;
707
708 case ASN1_TAG_T61_STRING:
709 rtAsn1DumpString(pData, pAsn1Core, pszName, "T61 STRING", uDepth);
710 break;
711
712 case ASN1_TAG_VIDEOTEX_STRING:
713 rtAsn1DumpString(pData, pAsn1Core, pszName, "VIDEOTEX STRING", uDepth);
714 break;
715
716 case ASN1_TAG_IA5_STRING:
717 rtAsn1DumpString(pData, pAsn1Core, pszName, "IA5 STRING", uDepth);
718 break;
719
720 case ASN1_TAG_GRAPHIC_STRING:
721 rtAsn1DumpString(pData, pAsn1Core, pszName, "GRAPHIC STRING", uDepth);
722 break;
723
724 case ASN1_TAG_VISIBLE_STRING:
725 rtAsn1DumpString(pData, pAsn1Core, pszName, "VISIBLE STRING", uDepth);
726 break;
727
728 case ASN1_TAG_GENERAL_STRING:
729 rtAsn1DumpString(pData, pAsn1Core, pszName, "GENERAL STRING", uDepth);
730 break;
731
732 case ASN1_TAG_UNIVERSAL_STRING:
733 rtAsn1DumpString(pData, pAsn1Core, pszName, "UNIVERSAL STRING", uDepth);
734 break;
735
736 case ASN1_TAG_BMP_STRING:
737 rtAsn1DumpString(pData, pAsn1Core, pszName, "BMP STRING", uDepth);
738 break;
739
740 case ASN1_TAG_UTC_TIME:
741 rtAsn1DumpTime(pData, pAsn1Core, pszName, "UTC TIME");
742 break;
743
744 case ASN1_TAG_GENERALIZED_TIME:
745 rtAsn1DumpTime(pData, pAsn1Core, pszName, "GENERALIZED TIME");
746 break;
747
748 case ASN1_TAG_CHARACTER_STRING:
749 rtAsn1DumpPrintf(pData, "%-16s CHARACTER STRING -- cb=%u TODO\n", pszName, pAsn1Core->cb);
750 break;
751
752 default:
753 rtAsn1DumpPrintf(pData, "[UNIVERSAL %u]\n", pAsn1Core->uTag);
754 break;
755 }
756 break;
757 case ASN1_TAGCLASS_CONTEXT:
758 rtAsn1DumpPrintf(pData, "%-16s [%u]\n", pszName, pAsn1Core->uTag);
759 fOpen = true;
760 break;
761 case ASN1_TAGCLASS_APPLICATION:
762 rtAsn1DumpPrintf(pData, "%-16s [APPLICATION %u]\n", pszName, pAsn1Core->uTag);
763 fOpen = true;
764 break;
765 case ASN1_TAGCLASS_PRIVATE:
766 rtAsn1DumpPrintf(pData, "%-16s [PRIVATE %u]\n", pszName, pAsn1Core->uTag);
767 fOpen = true;
768 break;
769 }
770 /** @todo {} */
771
772 /*
773 * Recurse.
774 */
775 if ( pAsn1Core->pOps
776 && pAsn1Core->pOps->pfnEnum)
777 pAsn1Core->pOps->pfnEnum(pAsn1Core, rtAsn1DumpEnumCallback, uDepth, pData);
778 return VINF_SUCCESS;
779}
780
781
782RTDECL(int) RTAsn1Dump(PCRTASN1CORE pAsn1Core, uint32_t fFlags, uint32_t uLevel, PFNRTDUMPPRINTFV pfnPrintfV, void *pvUser)
783{
784 if ( pAsn1Core->pOps
785 && pAsn1Core->pOps->pfnEnum)
786 {
787 RTASN1DUMPDATA Data;
788 Data.fFlags = fFlags;
789 Data.pfnPrintfV = pfnPrintfV;
790 Data.pvUser = pvUser;
791
792 return pAsn1Core->pOps->pfnEnum((PRTASN1CORE)pAsn1Core, rtAsn1DumpEnumCallback, uLevel, &Data);
793 }
794 return VINF_SUCCESS;
795}
796
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette