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