OLD | NEW |
1 /* This Source Code Form is subject to the terms of the Mozilla Public | 1 /* This Source Code Form is subject to the terms of the Mozilla Public |
2 * License, v. 2.0. If a copy of the MPL was not distributed with this | 2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
4 | 4 |
5 /* | 5 /* |
6 ** secutil.c - various functions used by security stuff | 6 ** secutil.c - various functions used by security stuff |
7 ** | 7 ** |
8 */ | 8 */ |
9 | 9 |
10 /* pkcs #7 -related functions */ | 10 /* pkcs #7 -related functions */ |
11 | 11 |
12 · | |
13 #include "secutil.h" | 12 #include "secutil.h" |
14 #include "secpkcs7.h" | 13 #include "secpkcs7.h" |
15 #include "secoid.h" | 14 #include "secoid.h" |
16 #include <sys/stat.h> | 15 #include <sys/stat.h> |
17 #include <stdarg.h> | 16 #include <stdarg.h> |
18 | 17 |
19 #ifdef XP_UNIX | 18 #ifdef XP_UNIX |
20 #include <unistd.h> | 19 #include <unistd.h> |
21 #endif | 20 #endif |
22 | 21 |
23 /* for SEC_TraverseNames */ | 22 /* for SEC_TraverseNames */ |
24 #include "cert.h" | 23 #include "cert.h" |
25 #include "prtypes.h" | 24 #include "prtypes.h" |
26 #include "prtime.h" | 25 #include "prtime.h" |
27 | 26 |
28 #include "prlong.h" | 27 #include "prlong.h" |
29 #include "secmod.h" | 28 #include "secmod.h" |
30 #include "pk11func.h" | 29 #include "pk11func.h" |
31 #include "prerror.h" | 30 #include "prerror.h" |
32 · | |
33 | |
34 | |
35 | 31 |
36 /* | 32 /* |
37 ** PKCS7 Support | 33 ** PKCS7 Support |
38 */ | 34 */ |
39 | 35 |
40 /* forward declaration */ | 36 /* forward declaration */ |
41 int | 37 int sv_PrintPKCS7ContentInfo(FILE *, SEC_PKCS7ContentInfo *, char *); |
42 sv_PrintPKCS7ContentInfo(FILE *, SEC_PKCS7ContentInfo *, char *); | |
43 | 38 |
| 39 void sv_PrintAsHex(FILE *out, SECItem *data, char *m) { |
| 40 unsigned i; |
44 | 41 |
45 void | 42 if (m) fprintf(out, "%s", m); |
46 sv_PrintAsHex(FILE *out, SECItem *data, char *m) | |
47 { | |
48 unsigned i; | |
49 | 43 |
50 if (m) fprintf(out, "%s", m); | 44 for (i = 0; i < data->len; i++) { |
51 ···· | 45 if (i < data->len - 1) { |
52 for (i = 0; i < data->len; i++) { | 46 fprintf(out, "%02x:", data->data[i]); |
53 if (i < data->len - 1) { | 47 } else { |
54 fprintf(out, "%02x:", data->data[i]); | 48 fprintf(out, "%02x\n", data->data[i]); |
55 } else { | 49 break; |
56 fprintf(out, "%02x\n", data->data[i]); | 50 } |
| 51 } |
| 52 } |
| 53 |
| 54 void sv_PrintInteger(FILE *out, SECItem *i, char *m) { |
| 55 int iv; |
| 56 |
| 57 if (i->len > 4) { |
| 58 sv_PrintAsHex(out, i, m); |
| 59 } else { |
| 60 iv = DER_GetInteger(i); |
| 61 fprintf(out, "%s%d (0x%x)\n", m, iv, iv); |
| 62 } |
| 63 } |
| 64 |
| 65 int sv_PrintTime(FILE *out, SECItem *t, char *m) { |
| 66 PRExplodedTime printableTime; |
| 67 PRTime time; |
| 68 char *timeString; |
| 69 int rv; |
| 70 |
| 71 rv = DER_DecodeTimeChoice(&time, t); |
| 72 if (rv) return rv; |
| 73 |
| 74 /* Convert to local time */ |
| 75 PR_ExplodeTime(time, PR_LocalTimeParameters, &printableTime); |
| 76 |
| 77 timeString = (char *)PORT_Alloc(256); |
| 78 |
| 79 if (timeString) { |
| 80 if (PR_FormatTime(timeString, 256, "%a %b %d %H:%M:%S %Y", |
| 81 &printableTime)) { |
| 82 fprintf(out, "%s%s\n", m, timeString); |
| 83 } |
| 84 PORT_Free(timeString); |
| 85 return 0; |
| 86 } |
| 87 return SECFailure; |
| 88 } |
| 89 |
| 90 int sv_PrintValidity(FILE *out, CERTValidity *v, char *m) { |
| 91 int rv; |
| 92 |
| 93 fprintf(out, "%s", m); |
| 94 rv = sv_PrintTime(out, &v->notBefore, "notBefore="); |
| 95 if (rv) return rv; |
| 96 fprintf(out, "%s", m); |
| 97 sv_PrintTime(out, &v->notAfter, "notAfter="); |
| 98 return rv; |
| 99 } |
| 100 |
| 101 void sv_PrintObjectID(FILE *out, SECItem *oid, char *m) { |
| 102 const char *name; |
| 103 SECOidData *oiddata; |
| 104 |
| 105 oiddata = SECOID_FindOID(oid); |
| 106 if (oiddata == NULL) { |
| 107 sv_PrintAsHex(out, oid, m); |
| 108 return; |
| 109 } |
| 110 name = oiddata->desc; |
| 111 |
| 112 if (m != NULL) fprintf(out, "%s", m); |
| 113 fprintf(out, "%s\n", name); |
| 114 } |
| 115 |
| 116 void sv_PrintAlgorithmID(FILE *out, SECAlgorithmID *a, char *m) { |
| 117 sv_PrintObjectID(out, &a->algorithm, m); |
| 118 |
| 119 if ((a->parameters.len != 2) || |
| 120 (PORT_Memcmp(a->parameters.data, "\005\000", 2) != 0)) { |
| 121 /* Print args to algorithm */ |
| 122 sv_PrintAsHex(out, &a->parameters, "Args="); |
| 123 } |
| 124 } |
| 125 |
| 126 void sv_PrintAttribute(FILE *out, SEC_PKCS7Attribute *attr, char *m) { |
| 127 SECItem *value; |
| 128 int i; |
| 129 char om[100]; |
| 130 |
| 131 fprintf(out, "%s", m); |
| 132 |
| 133 /* |
| 134 * XXX Make this smarter; look at the type field and then decode |
| 135 * and print the value(s) appropriately! |
| 136 */ |
| 137 sv_PrintObjectID(out, &(attr->type), "type="); |
| 138 if (attr->values != NULL) { |
| 139 i = 0; |
| 140 while ((value = attr->values[i]) != NULL) { |
| 141 sprintf(om, "%svalue[%d]=%s", m, i++, attr->encoded ? "(encoded)" : ""); |
| 142 if (attr->encoded || attr->typeTag == NULL) { |
| 143 sv_PrintAsHex(out, value, om); |
| 144 } else { |
| 145 switch (attr->typeTag->offset) { |
| 146 default: |
| 147 sv_PrintAsHex(out, value, om); |
| 148 break; |
| 149 case SEC_OID_PKCS9_CONTENT_TYPE: |
| 150 sv_PrintObjectID(out, value, om); |
| 151 break; |
| 152 case SEC_OID_PKCS9_SIGNING_TIME: |
| 153 sv_PrintTime(out, value, om); |
57 break; | 154 break; |
58 } | 155 } |
| 156 } |
59 } | 157 } |
| 158 } |
60 } | 159 } |
61 | 160 |
62 void | 161 void sv_PrintName(FILE *out, CERTName *name, char *msg) { |
63 sv_PrintInteger(FILE *out, SECItem *i, char *m) | 162 char *str; |
64 { | |
65 int iv; | |
66 | 163 |
67 if (i->len > 4) { | 164 str = CERT_NameToAscii(name); |
68 sv_PrintAsHex(out, i, m); | 165 fprintf(out, "%s%s\n", msg, str); |
69 } else { | 166 PORT_Free(str); |
70 iv = DER_GetInteger(i); | |
71 fprintf(out, "%s%d (0x%x)\n", m, iv, iv); | |
72 } | |
73 } | 167 } |
74 | 168 |
75 | |
76 int | |
77 sv_PrintTime(FILE *out, SECItem *t, char *m) | |
78 { | |
79 PRExplodedTime printableTime;· | |
80 PRTime time; | |
81 char *timeString; | |
82 int rv; | |
83 | |
84 rv = DER_DecodeTimeChoice(&time, t); | |
85 if (rv) return rv; | |
86 | |
87 /* Convert to local time */ | |
88 PR_ExplodeTime(time, PR_LocalTimeParameters, &printableTime); | |
89 | |
90 timeString = (char *)PORT_Alloc(256); | |
91 | |
92 if ( timeString ) { | |
93 if (PR_FormatTime( timeString, 256, "%a %b %d %H:%M:%S %Y", &printableTi
me )) { | |
94 fprintf(out, "%s%s\n", m, timeString); | |
95 } | |
96 PORT_Free(timeString); | |
97 return 0; | |
98 } | |
99 return SECFailure; | |
100 } | |
101 | |
102 int | |
103 sv_PrintValidity(FILE *out, CERTValidity *v, char *m) | |
104 { | |
105 int rv; | |
106 | |
107 fprintf(out, "%s", m); | |
108 rv = sv_PrintTime(out, &v->notBefore, "notBefore="); | |
109 if (rv) return rv; | |
110 fprintf(out, "%s", m); | |
111 sv_PrintTime(out, &v->notAfter, "notAfter="); | |
112 return rv; | |
113 } | |
114 | |
115 void | |
116 sv_PrintObjectID(FILE *out, SECItem *oid, char *m) | |
117 { | |
118 const char *name; | |
119 SECOidData *oiddata; | |
120 ···· | |
121 oiddata = SECOID_FindOID(oid); | |
122 if (oiddata == NULL) { | |
123 sv_PrintAsHex(out, oid, m); | |
124 return; | |
125 } | |
126 name = oiddata->desc; | |
127 | |
128 if (m != NULL) | |
129 fprintf(out, "%s", m); | |
130 fprintf(out, "%s\n", name); | |
131 } | |
132 | |
133 void | |
134 sv_PrintAlgorithmID(FILE *out, SECAlgorithmID *a, char *m) | |
135 { | |
136 sv_PrintObjectID(out, &a->algorithm, m); | |
137 | |
138 if ((a->parameters.len != 2) || | |
139 (PORT_Memcmp(a->parameters.data, "\005\000", 2) != 0)) { | |
140 /* Print args to algorithm */ | |
141 sv_PrintAsHex(out, &a->parameters, "Args="); | |
142 } | |
143 } | |
144 | |
145 void | |
146 sv_PrintAttribute(FILE *out, SEC_PKCS7Attribute *attr, char *m) | |
147 { | |
148 SECItem *value; | |
149 int i; | |
150 char om[100]; | |
151 | |
152 fprintf(out, "%s", m); | |
153 | |
154 /* | |
155 * XXX Make this smarter; look at the type field and then decode | |
156 * and print the value(s) appropriately! | |
157 */ | |
158 sv_PrintObjectID(out, &(attr->type), "type="); | |
159 if (attr->values != NULL) { | |
160 i = 0; | |
161 while ((value = attr->values[i]) != NULL) { | |
162 sprintf(om, "%svalue[%d]=%s", m, i++, attr->encoded ? "(encoded)" :
"");· | |
163 if (attr->encoded || attr->typeTag == NULL) { | |
164 sv_PrintAsHex(out, value, om); | |
165 } else { | |
166 switch (attr->typeTag->offset) { | |
167 default: | |
168 sv_PrintAsHex(out, value, om); | |
169 break; | |
170 case SEC_OID_PKCS9_CONTENT_TYPE: | |
171 sv_PrintObjectID(out, value, om); | |
172 break; | |
173 case SEC_OID_PKCS9_SIGNING_TIME: | |
174 sv_PrintTime(out, value, om); | |
175 break; | |
176 } | |
177 } | |
178 } | |
179 } | |
180 } | |
181 | |
182 void | |
183 sv_PrintName(FILE *out, CERTName *name, char *msg) | |
184 { | |
185 char *str; | |
186 | |
187 str = CERT_NameToAscii(name); | |
188 fprintf(out, "%s%s\n", msg, str); | |
189 PORT_Free(str); | |
190 } | |
191 | |
192 | |
193 #if 0 | 169 #if 0 |
194 /* | 170 /* |
195 ** secu_PrintPKCS7EncContent | 171 ** secu_PrintPKCS7EncContent |
196 ** Prints a SEC_PKCS7EncryptedContentInfo (without decrypting it) | 172 ** Prints a SEC_PKCS7EncryptedContentInfo (without decrypting it) |
197 */ | 173 */ |
198 void | 174 void |
199 secu_PrintPKCS7EncContent(FILE *out, SEC_PKCS7EncryptedContentInfo *src,· | 175 secu_PrintPKCS7EncContent(FILE *out, SEC_PKCS7EncryptedContentInfo *src,· |
200 char *m, int level) | 176 char *m, int level) |
201 { | 177 { |
202 if (src->contentTypeTag == NULL) | 178 if (src->contentTypeTag == NULL) |
(...skipping 26 matching lines...) Expand all Loading... |
229 sv_PrintInteger(out, &(info->issuerAndSN->serialNumber),· | 205 sv_PrintInteger(out, &(info->issuerAndSN->serialNumber),· |
230 "Serial Number"); | 206 "Serial Number"); |
231 | 207 |
232 /* Parse and display encrypted key */ | 208 /* Parse and display encrypted key */ |
233 sv_PrintAlgorithmID(out, &(info->keyEncAlg),· | 209 sv_PrintAlgorithmID(out, &(info->keyEncAlg),· |
234 "Key Encryption Algorithm"); | 210 "Key Encryption Algorithm"); |
235 sv_PrintAsHex(out, &(info->encKey), "Encrypted Key", level + 1); | 211 sv_PrintAsHex(out, &(info->encKey), "Encrypted Key", level + 1); |
236 } | 212 } |
237 #endif | 213 #endif |
238 | 214 |
239 /* | 215 /* |
240 ** secu_PrintSignerInfo | 216 ** secu_PrintSignerInfo |
241 ** Prints a PKCS7SingerInfo type | 217 ** Prints a PKCS7SingerInfo type |
242 */ | 218 */ |
243 void | 219 void sv_PrintSignerInfo(FILE *out, SEC_PKCS7SignerInfo *info, char *m) { |
244 sv_PrintSignerInfo(FILE *out, SEC_PKCS7SignerInfo *info, char *m) | 220 SEC_PKCS7Attribute *attr; |
245 { | 221 int iv; |
246 SEC_PKCS7Attribute *attr; | 222 |
247 int iv; | 223 fprintf(out, "%s", m); |
248 ···· | 224 sv_PrintInteger(out, &(info->version), "version="); |
249 fprintf(out, "%s", m); | 225 |
250 sv_PrintInteger(out, &(info->version), "version="); | 226 fprintf(out, "%s", m); |
251 | 227 sv_PrintName(out, &(info->issuerAndSN->issuer), "issuerName="); |
252 fprintf(out, "%s", m); | 228 fprintf(out, "%s", m); |
253 sv_PrintName(out, &(info->issuerAndSN->issuer), "issuerName="); | 229 sv_PrintInteger(out, &(info->issuerAndSN->serialNumber), "serialNumber="); |
254 fprintf(out, "%s", m); | 230 |
255 sv_PrintInteger(out, &(info->issuerAndSN->serialNumber), | 231 fprintf(out, "%s", m); |
256 "serialNumber="); | 232 sv_PrintAlgorithmID(out, &(info->digestAlg), "digestAlgorithm="); |
257 ·· | 233 |
258 fprintf(out, "%s", m); | 234 if (info->authAttr != NULL) { |
259 sv_PrintAlgorithmID(out, &(info->digestAlg), "digestAlgorithm="); | 235 char mm[120]; |
260 ···· | 236 |
261 if (info->authAttr != NULL) { | 237 iv = 0; |
262 char mm[120]; | 238 while (info->authAttr[iv] != NULL) iv++; |
263 | 239 fprintf(out, "%sauthenticatedAttributes=%d\n", m, iv); |
264 iv = 0; | 240 iv = 0; |
265 while (info->authAttr[iv] != NULL) iv++; | 241 while ((attr = info->authAttr[iv]) != NULL) { |
266 fprintf(out, "%sauthenticatedAttributes=%d\n", m, iv); | 242 sprintf(mm, "%sattribute[%d].", m, iv++); |
267 iv = 0; | 243 sv_PrintAttribute(out, attr, mm); |
268 while ((attr = info->authAttr[iv]) != NULL) { | 244 } |
269 sprintf(mm, "%sattribute[%d].", m, iv++);· | 245 } |
270 sv_PrintAttribute(out, attr, mm); | 246 |
271 } | 247 /* Parse and display signature */ |
272 } | 248 fprintf(out, "%s", m); |
273 ···· | 249 sv_PrintAlgorithmID(out, &(info->digestEncAlg), "digestEncryptionAlgorithm="); |
274 /* Parse and display signature */ | 250 fprintf(out, "%s", m); |
275 fprintf(out, "%s", m); | 251 sv_PrintAsHex(out, &(info->encDigest), "encryptedDigest="); |
276 sv_PrintAlgorithmID(out, &(info->digestEncAlg), "digestEncryptionAlgorithm="
); | 252 |
277 fprintf(out, "%s", m); | 253 if (info->unAuthAttr != NULL) { |
278 sv_PrintAsHex(out, &(info->encDigest), "encryptedDigest="); | 254 char mm[120]; |
279 ···· | 255 |
280 if (info->unAuthAttr != NULL) { | 256 iv = 0; |
281 char mm[120]; | 257 while (info->unAuthAttr[iv] != NULL) iv++; |
282 | 258 fprintf(out, "%sunauthenticatedAttributes=%d\n", m, iv); |
283 iv = 0; | 259 iv = 0; |
284 while (info->unAuthAttr[iv] != NULL) iv++; | 260 while ((attr = info->unAuthAttr[iv]) != NULL) { |
285 fprintf(out, "%sunauthenticatedAttributes=%d\n", m, iv); | 261 sprintf(mm, "%sattribute[%d].", m, iv++); |
286 iv = 0; | 262 sv_PrintAttribute(out, attr, mm); |
287 while ((attr = info->unAuthAttr[iv]) != NULL) { | 263 } |
288 sprintf(mm, "%sattribute[%d].", m, iv++);· | 264 } |
289 sv_PrintAttribute(out, attr, mm); | 265 } |
290 } | 266 |
291 } | 267 void sv_PrintRSAPublicKey(FILE *out, SECKEYPublicKey *pk, char *m) { |
292 } | 268 fprintf(out, "%s", m); |
293 | 269 sv_PrintInteger(out, &pk->u.rsa.modulus, "modulus="); |
294 void | 270 fprintf(out, "%s", m); |
295 sv_PrintRSAPublicKey(FILE *out, SECKEYPublicKey *pk, char *m) | 271 sv_PrintInteger(out, &pk->u.rsa.publicExponent, "exponent="); |
296 { | 272 } |
297 fprintf(out, "%s", m); | 273 |
298 sv_PrintInteger(out, &pk->u.rsa.modulus, "modulus="); | 274 void sv_PrintDSAPublicKey(FILE *out, SECKEYPublicKey *pk, char *m) { |
299 fprintf(out, "%s", m); | 275 fprintf(out, "%s", m); |
300 sv_PrintInteger(out, &pk->u.rsa.publicExponent, "exponent="); | 276 sv_PrintInteger(out, &pk->u.dsa.params.prime, "prime="); |
301 } | 277 fprintf(out, "%s", m); |
302 | 278 sv_PrintInteger(out, &pk->u.dsa.params.subPrime, "subprime="); |
303 void | 279 fprintf(out, "%s", m); |
304 sv_PrintDSAPublicKey(FILE *out, SECKEYPublicKey *pk, char *m) | 280 sv_PrintInteger(out, &pk->u.dsa.params.base, "base="); |
305 { | 281 fprintf(out, "%s", m); |
306 fprintf(out, "%s", m); | 282 sv_PrintInteger(out, &pk->u.dsa.publicValue, "publicValue="); |
307 sv_PrintInteger(out, &pk->u.dsa.params.prime, "prime="); | 283 } |
308 fprintf(out, "%s", m); | 284 |
309 sv_PrintInteger(out, &pk->u.dsa.params.subPrime, "subprime="); | 285 int sv_PrintSubjectPublicKeyInfo(FILE *out, PLArenaPool *arena, |
310 fprintf(out, "%s", m); | 286 CERTSubjectPublicKeyInfo *i, char *msg) { |
311 sv_PrintInteger(out, &pk->u.dsa.params.base, "base="); | 287 SECKEYPublicKey *pk; |
312 fprintf(out, "%s", m); | 288 int rv; |
313 sv_PrintInteger(out, &pk->u.dsa.publicValue, "publicValue="); | 289 char mm[200]; |
314 } | 290 |
315 | 291 sprintf(mm, "%s.publicKeyAlgorithm=", msg); |
316 int | 292 sv_PrintAlgorithmID(out, &i->algorithm, mm); |
317 sv_PrintSubjectPublicKeyInfo(FILE *out, PLArenaPool *arena, | 293 |
318 CERTSubjectPublicKeyInfo *i, char *msg) | 294 pk = (SECKEYPublicKey *)PORT_ZAlloc(sizeof(SECKEYPublicKey)); |
319 { | 295 if (!pk) return PORT_GetError(); |
320 SECKEYPublicKey *pk; | 296 |
321 int rv; | 297 DER_ConvertBitString(&i->subjectPublicKey); |
322 char mm[200]; | 298 switch (SECOID_FindOIDTag(&i->algorithm.algorithm)) { |
323 | 299 case SEC_OID_PKCS1_RSA_ENCRYPTION: |
324 sprintf(mm, "%s.publicKeyAlgorithm=", msg); | 300 rv = SEC_ASN1DecodeItem(arena, pk, |
325 sv_PrintAlgorithmID(out, &i->algorithm, mm); | 301 SEC_ASN1_GET(SECKEY_RSAPublicKeyTemplate), |
326 | 302 &i->subjectPublicKey); |
327 pk = (SECKEYPublicKey*) PORT_ZAlloc(sizeof(SECKEYPublicKey)); | 303 if (rv) return rv; |
328 if (!pk) return PORT_GetError(); | 304 sprintf(mm, "%s.rsaPublicKey.", msg); |
329 | 305 sv_PrintRSAPublicKey(out, pk, mm); |
330 DER_ConvertBitString(&i->subjectPublicKey); | 306 break; |
331 switch(SECOID_FindOIDTag(&i->algorithm.algorithm)) { | 307 case SEC_OID_ANSIX9_DSA_SIGNATURE: |
332 case SEC_OID_PKCS1_RSA_ENCRYPTION: | 308 rv = SEC_ASN1DecodeItem(arena, pk, |
333 rv = SEC_ASN1DecodeItem(arena, pk, | 309 SEC_ASN1_GET(SECKEY_DSAPublicKeyTemplate), |
334 SEC_ASN1_GET(SECKEY_RSAPublicKeyTemplate), | 310 &i->subjectPublicKey); |
335 &i->subjectPublicKey); | 311 if (rv) return rv; |
336 if (rv) return rv; | 312 sprintf(mm, "%s.dsaPublicKey.", msg); |
337 sprintf(mm, "%s.rsaPublicKey.", msg); | 313 sv_PrintDSAPublicKey(out, pk, mm); |
338 sv_PrintRSAPublicKey(out, pk, mm); | 314 break; |
339 break; | 315 default: |
340 case SEC_OID_ANSIX9_DSA_SIGNATURE: | 316 fprintf(out, "%s=bad SPKI algorithm type\n", msg); |
341 rv = SEC_ASN1DecodeItem(arena, pk, | 317 return 0; |
342 SEC_ASN1_GET(SECKEY_DSAPublicKeyTemplate), | 318 } |
343 &i->subjectPublicKey); | 319 |
344 if (rv) return rv; | 320 return 0; |
345 sprintf(mm, "%s.dsaPublicKey.", msg); | 321 } |
346 sv_PrintDSAPublicKey(out, pk, mm); | 322 |
347 break; | 323 SECStatus sv_PrintInvalidDateExten(FILE *out, SECItem *value, char *msg) { |
348 default: | 324 SECItem decodedValue; |
349 fprintf(out, "%s=bad SPKI algorithm type\n", msg); | 325 SECStatus rv; |
350 return 0; | 326 PRTime invalidTime; |
351 } | 327 char *formattedTime = NULL; |
352 | 328 |
353 return 0; | 329 decodedValue.data = NULL; |
354 } | 330 rv = SEC_ASN1DecodeItem(NULL, &decodedValue, |
355 | 331 SEC_ASN1_GET(SEC_GeneralizedTimeTemplate), value); |
356 SECStatus | 332 if (rv == SECSuccess) { |
357 sv_PrintInvalidDateExten (FILE *out, SECItem *value, char *msg) | 333 rv = DER_GeneralizedTimeToTime(&invalidTime, &decodedValue); |
358 { | |
359 SECItem decodedValue; | |
360 SECStatus rv; | |
361 PRTime invalidTime; | |
362 char *formattedTime = NULL; | |
363 | |
364 decodedValue.data = NULL; | |
365 rv = SEC_ASN1DecodeItem (NULL, &decodedValue, | |
366 SEC_ASN1_GET(SEC_GeneralizedTimeTemplate), | |
367 value); | |
368 if (rv == SECSuccess) { | 334 if (rv == SECSuccess) { |
369 rv = DER_GeneralizedTimeToTime(&invalidTime, &decodedValue); | 335 formattedTime = |
370 if (rv == SECSuccess) { | 336 CERT_GenTime2FormattedAscii(invalidTime, "%a %b %d %H:%M:%S %Y"); |
371 formattedTime = CERT_GenTime2FormattedAscii(invalidTime, "%a %b %d %
H:%M:%S %Y"); | 337 fprintf(out, "%s: %s\n", msg, formattedTime); |
372 fprintf (out, "%s: %s\n", msg, formattedTime); | 338 PORT_Free(formattedTime); |
373 PORT_Free (formattedTime); | 339 } |
374 } | 340 } |
375 } | 341 PORT_Free(decodedValue.data); |
376 PORT_Free (decodedValue.data); | 342 |
377 | 343 return (rv); |
378 return (rv); | 344 } |
379 } | 345 |
380 | 346 int sv_PrintExtensions(FILE *out, CERTCertExtension **extensions, char *msg) { |
381 int | 347 SECOidTag oidTag; |
382 sv_PrintExtensions(FILE *out, CERTCertExtension **extensions, char *msg) | 348 |
383 { | 349 if (extensions) { |
384 SECOidTag oidTag; | 350 |
385 | 351 while (*extensions) { |
386 if (extensions) { | 352 SECItem *tmpitem; |
387 | 353 |
388 while ( *extensions ) { | 354 fprintf(out, "%sname=", msg); |
389 SECItem *tmpitem; | 355 |
390 | 356 tmpitem = &(*extensions)->id; |
391 fprintf(out, "%sname=", msg); | 357 sv_PrintObjectID(out, tmpitem, NULL); |
392 | 358 |
393 tmpitem = &(*extensions)->id; | 359 tmpitem = &(*extensions)->critical; |
394 sv_PrintObjectID(out, tmpitem, NULL); | 360 if (tmpitem->len) |
395 | 361 fprintf(out, "%scritical=%s\n", msg, |
396 tmpitem = &(*extensions)->critical; | 362 (tmpitem->data && tmpitem->data[0]) ? "True" : "False"); |
397 if ( tmpitem->len ) | 363 |
398 fprintf(out, "%scritical=%s\n", msg, | 364 oidTag = SECOID_FindOIDTag(&((*extensions)->id)); |
399 (tmpitem->data && tmpitem->data[0])? "True": "False"); | 365 |
400 | 366 fprintf(out, "%s", msg); |
401 oidTag = SECOID_FindOIDTag (&((*extensions)->id)); | 367 tmpitem = &((*extensions)->value); |
402 | 368 if (oidTag == SEC_OID_X509_INVALID_DATE) |
403 fprintf(out, "%s", msg); | 369 sv_PrintInvalidDateExten(out, tmpitem, "invalidExt"); |
404 tmpitem = &((*extensions)->value); | 370 else |
405 if (oidTag == SEC_OID_X509_INVALID_DATE)· | 371 sv_PrintAsHex(out, tmpitem, "data="); |
406 sv_PrintInvalidDateExten (out, tmpitem,"invalidExt"); | 372 |
407 else» » »··········· | 373 /*fprintf(out, "\n");*/ |
408 sv_PrintAsHex(out,tmpitem, "data="); | 374 extensions++; |
409 | 375 } |
410 /*fprintf(out, "\n");*/ | 376 } |
411 extensions++; | 377 |
412 } | 378 return 0; |
413 } | |
414 | |
415 return 0; | |
416 } | 379 } |
417 | 380 |
418 /* callers of this function must make sure that the CERTSignedCrl | 381 /* callers of this function must make sure that the CERTSignedCrl |
419 from which they are extracting the CERTCrl has been fully-decoded. | 382 from which they are extracting the CERTCrl has been fully-decoded. |
420 Otherwise it will not have the entries even though the CRL may have | 383 Otherwise it will not have the entries even though the CRL may have |
421 some */ | 384 some */ |
422 void | 385 void sv_PrintCRLInfo(FILE *out, CERTCrl *crl, char *m) { |
423 sv_PrintCRLInfo(FILE *out, CERTCrl *crl, char *m) | 386 CERTCrlEntry *entry; |
424 { | 387 int iv; |
425 CERTCrlEntry *entry; | 388 char om[100]; |
426 int iv; | 389 |
427 char om[100]; | 390 fprintf(out, "%s", m); |
428 ···· | 391 sv_PrintAlgorithmID(out, &(crl->signatureAlg), "signatureAlgorithm="); |
429 fprintf(out, "%s", m); | 392 fprintf(out, "%s", m); |
430 sv_PrintAlgorithmID(out, &(crl->signatureAlg), "signatureAlgorithm="); | 393 sv_PrintName(out, &(crl->name), "name="); |
431 fprintf(out, "%s", m); | 394 fprintf(out, "%s", m); |
432 sv_PrintName(out, &(crl->name), "name="); | 395 sv_PrintTime(out, &(crl->lastUpdate), "lastUpdate="); |
433 fprintf(out, "%s", m); | 396 fprintf(out, "%s", m); |
434 sv_PrintTime(out, &(crl->lastUpdate), "lastUpdate="); | 397 sv_PrintTime(out, &(crl->nextUpdate), "nextUpdate="); |
435 fprintf(out, "%s", m); | 398 |
436 sv_PrintTime(out, &(crl->nextUpdate), "nextUpdate="); | 399 if (crl->entries != NULL) { |
437 ···· | 400 iv = 0; |
438 if (crl->entries != NULL) { | 401 while ((entry = crl->entries[iv]) != NULL) { |
439 iv = 0; | 402 fprintf(out, "%sentry[%d].", m, iv); |
440 while ((entry = crl->entries[iv]) != NULL) { | 403 sv_PrintInteger(out, &(entry->serialNumber), "serialNumber="); |
441 fprintf(out, "%sentry[%d].", m, iv);· | 404 fprintf(out, "%sentry[%d].", m, iv); |
442 sv_PrintInteger(out, &(entry->serialNumber), "serialNumber="); | 405 sv_PrintTime(out, &(entry->revocationDate), "revocationDate="); |
443 fprintf(out, "%sentry[%d].", m, iv);· | 406 sprintf(om, "%sentry[%d].signedCRLEntriesExtensions.", m, iv++); |
444 sv_PrintTime(out, &(entry->revocationDate), "revocationDate="); | 407 sv_PrintExtensions(out, entry->extensions, om); |
445 sprintf(om, "%sentry[%d].signedCRLEntriesExtensions.", m, iv++);· | 408 } |
446 sv_PrintExtensions(out, entry->extensions, om); | 409 } |
447 } | 410 sprintf(om, "%ssignedCRLEntriesExtensions.", m); |
448 } | 411 sv_PrintExtensions(out, crl->extensions, om); |
449 sprintf(om, "%ssignedCRLEntriesExtensions.", m);· | 412 } |
450 sv_PrintExtensions(out, crl->extensions, om); | 413 |
451 } | 414 int sv_PrintCertificate(FILE *out, SECItem *der, char *m, int level) { |
452 | 415 PLArenaPool *arena = NULL; |
453 | 416 CERTCertificate *c; |
454 int | 417 int rv; |
455 sv_PrintCertificate(FILE *out, SECItem *der, char *m, int level) | 418 int iv; |
456 { | 419 char mm[200]; |
457 PLArenaPool *arena = NULL; | 420 |
458 CERTCertificate *c; | 421 /* Decode certificate */ |
459 int rv; | 422 c = (CERTCertificate *)PORT_ZAlloc(sizeof(CERTCertificate)); |
460 int iv; | 423 if (!c) return PORT_GetError(); |
461 char mm[200]; | 424 |
462 ···· | 425 arena = PORT_NewArena(DER_DEFAULT_CHUNKSIZE); |
463 /* Decode certificate */ | 426 if (!arena) return SEC_ERROR_NO_MEMORY; |
464 c = (CERTCertificate*) PORT_ZAlloc(sizeof(CERTCertificate)); | 427 |
465 if (!c) return PORT_GetError(); | 428 rv = |
466 | 429 SEC_ASN1DecodeItem(arena, c, SEC_ASN1_GET(CERT_CertificateTemplate), der); |
467 arena = PORT_NewArena(DER_DEFAULT_CHUNKSIZE); | 430 if (rv) { |
468 if (!arena) return SEC_ERROR_NO_MEMORY; | |
469 | |
470 rv = SEC_ASN1DecodeItem(arena, c, SEC_ASN1_GET(CERT_CertificateTemplate), | |
471 der); | |
472 if (rv) { | |
473 PORT_FreeArena(arena, PR_FALSE); | |
474 return rv; | |
475 } | |
476 | |
477 /* Pretty print it out */ | |
478 iv = DER_GetInteger(&c->version); | |
479 fprintf(out, "%sversion=%d (0x%x)\n", m, iv + 1, iv); | |
480 sprintf(mm, "%sserialNumber=", m); | |
481 sv_PrintInteger(out, &c->serialNumber, mm); | |
482 sprintf(mm, "%ssignatureAlgorithm=", m); | |
483 sv_PrintAlgorithmID(out, &c->signature, mm); | |
484 sprintf(mm, "%sissuerName=", m); | |
485 sv_PrintName(out, &c->issuer, mm); | |
486 sprintf(mm, "%svalidity.", m); | |
487 sv_PrintValidity(out, &c->validity, mm); | |
488 sprintf(mm, "%ssubject=", m); | |
489 sv_PrintName(out, &c->subject, mm); | |
490 sprintf(mm, "%ssubjectPublicKeyInfo", m); | |
491 rv = sv_PrintSubjectPublicKeyInfo(out, arena, &c->subjectPublicKeyInfo, mm); | |
492 if (rv) { | |
493 PORT_FreeArena(arena, PR_FALSE); | |
494 return rv; | |
495 } | |
496 sprintf(mm, "%ssignedExtensions.", m); | |
497 sv_PrintExtensions(out, c->extensions, mm); | |
498 ···· | |
499 PORT_FreeArena(arena, PR_FALSE); | 431 PORT_FreeArena(arena, PR_FALSE); |
500 return 0; | 432 return rv; |
501 } | 433 } |
502 | 434 |
503 int | 435 /* Pretty print it out */ |
504 sv_PrintSignedData(FILE *out, SECItem *der, char *m, SECU_PPFunc inner) | 436 iv = DER_GetInteger(&c->version); |
505 { | 437 fprintf(out, "%sversion=%d (0x%x)\n", m, iv + 1, iv); |
506 PLArenaPool *arena = NULL; | 438 sprintf(mm, "%sserialNumber=", m); |
507 CERTSignedData *sd; | 439 sv_PrintInteger(out, &c->serialNumber, mm); |
508 int rv; | 440 sprintf(mm, "%ssignatureAlgorithm=", m); |
509 | 441 sv_PrintAlgorithmID(out, &c->signature, mm); |
510 /* Strip off the signature */ | 442 sprintf(mm, "%sissuerName=", m); |
511 sd = (CERTSignedData*) PORT_ZAlloc(sizeof(CERTSignedData)); | 443 sv_PrintName(out, &c->issuer, mm); |
512 if (!sd) return PORT_GetError(); | 444 sprintf(mm, "%svalidity.", m); |
513 | 445 sv_PrintValidity(out, &c->validity, mm); |
514 arena = PORT_NewArena(DER_DEFAULT_CHUNKSIZE); | 446 sprintf(mm, "%ssubject=", m); |
515 if (!arena) return SEC_ERROR_NO_MEMORY; | 447 sv_PrintName(out, &c->subject, mm); |
516 | 448 sprintf(mm, "%ssubjectPublicKeyInfo", m); |
517 rv = SEC_ASN1DecodeItem(arena, sd, SEC_ASN1_GET(CERT_SignedDataTemplate), | 449 rv = sv_PrintSubjectPublicKeyInfo(out, arena, &c->subjectPublicKeyInfo, mm); |
518 der); | 450 if (rv) { |
519 if (rv) { | |
520 PORT_FreeArena(arena, PR_FALSE); | |
521 return rv; | |
522 } | |
523 | |
524 /* fprintf(out, "%s:\n", m); */ | |
525 PORT_Strcat(m, "data."); | |
526 | |
527 rv = (*inner)(out, &sd->data, m, 0); | |
528 if (rv) { | |
529 PORT_FreeArena(arena, PR_FALSE); | |
530 return rv; | |
531 } | |
532 | |
533 m[PORT_Strlen(m) - 5] = 0; | |
534 fprintf(out, "%s", m); | |
535 sv_PrintAlgorithmID(out, &sd->signatureAlgorithm, "signatureAlgorithm="); | |
536 DER_ConvertBitString(&sd->signature); | |
537 fprintf(out, "%s", m); | |
538 sv_PrintAsHex(out, &sd->signature, "signature="); | |
539 | |
540 PORT_FreeArena(arena, PR_FALSE); | 451 PORT_FreeArena(arena, PR_FALSE); |
541 return 0; | 452 return rv; |
542 | 453 } |
543 } | 454 sprintf(mm, "%ssignedExtensions.", m); |
544 | 455 sv_PrintExtensions(out, c->extensions, mm); |
| 456 |
| 457 PORT_FreeArena(arena, PR_FALSE); |
| 458 return 0; |
| 459 } |
| 460 |
| 461 int sv_PrintSignedData(FILE *out, SECItem *der, char *m, SECU_PPFunc inner) { |
| 462 PLArenaPool *arena = NULL; |
| 463 CERTSignedData *sd; |
| 464 int rv; |
| 465 |
| 466 /* Strip off the signature */ |
| 467 sd = (CERTSignedData *)PORT_ZAlloc(sizeof(CERTSignedData)); |
| 468 if (!sd) return PORT_GetError(); |
| 469 |
| 470 arena = PORT_NewArena(DER_DEFAULT_CHUNKSIZE); |
| 471 if (!arena) return SEC_ERROR_NO_MEMORY; |
| 472 |
| 473 rv = |
| 474 SEC_ASN1DecodeItem(arena, sd, SEC_ASN1_GET(CERT_SignedDataTemplate), der); |
| 475 if (rv) { |
| 476 PORT_FreeArena(arena, PR_FALSE); |
| 477 return rv; |
| 478 } |
| 479 |
| 480 /* fprintf(out, "%s:\n", m); */ |
| 481 PORT_Strcat(m, "data."); |
| 482 |
| 483 rv = (*inner)(out, &sd->data, m, 0); |
| 484 if (rv) { |
| 485 PORT_FreeArena(arena, PR_FALSE); |
| 486 return rv; |
| 487 } |
| 488 |
| 489 m[PORT_Strlen(m) - 5] = 0; |
| 490 fprintf(out, "%s", m); |
| 491 sv_PrintAlgorithmID(out, &sd->signatureAlgorithm, "signatureAlgorithm="); |
| 492 DER_ConvertBitString(&sd->signature); |
| 493 fprintf(out, "%s", m); |
| 494 sv_PrintAsHex(out, &sd->signature, "signature="); |
| 495 |
| 496 PORT_FreeArena(arena, PR_FALSE); |
| 497 return 0; |
| 498 } |
545 | 499 |
546 /* | 500 /* |
547 ** secu_PrintPKCS7Signed | 501 ** secu_PrintPKCS7Signed |
548 ** Pretty print a PKCS7 signed data type (up to version 1). | 502 ** Pretty print a PKCS7 signed data type (up to version 1). |
549 */ | 503 */ |
550 int | 504 int sv_PrintPKCS7Signed(FILE *out, SEC_PKCS7SignedData *src) { |
551 sv_PrintPKCS7Signed(FILE *out, SEC_PKCS7SignedData *src) | 505 SECAlgorithmID *digAlg; /* digest algorithms */ |
552 { | 506 SECItem *aCert; /* certificate */ |
553 SECAlgorithmID *digAlg;» » /* digest algorithms */ | 507 CERTSignedCrl *aCrl; /* certificate revocation list */ |
554 SECItem *aCert;» » » /* certificate */ | 508 SEC_PKCS7SignerInfo *sigInfo; /* signer information */ |
555 CERTSignedCrl *aCrl;» » /* certificate revocation list */ | 509 int rv, iv; |
556 SEC_PKCS7SignerInfo *sigInfo;» /* signer information */ | 510 char om[120]; |
557 int rv, iv; | 511 |
558 char om[120]; | 512 sv_PrintInteger(out, &(src->version), "pkcs7.version="); |
559 | 513 |
560 sv_PrintInteger(out, &(src->version), "pkcs7.version="); | 514 /* Parse and list digest algorithms (if any) */ |
561 | 515 if (src->digestAlgorithms != NULL) { |
562 /* Parse and list digest algorithms (if any) */ | 516 iv = 0; |
563 if (src->digestAlgorithms != NULL) { | 517 while (src->digestAlgorithms[iv] != NULL) iv++; |
564 iv = 0; | 518 fprintf(out, "pkcs7.digestAlgorithmListLength=%d\n", iv); |
565 while (src->digestAlgorithms[iv] != NULL) | 519 iv = 0; |
566 iv++; | 520 while ((digAlg = src->digestAlgorithms[iv]) != NULL) { |
567 fprintf(out, "pkcs7.digestAlgorithmListLength=%d\n", iv); | 521 sprintf(om, "pkcs7.digestAlgorithm[%d]=", iv++); |
568 iv = 0; | 522 sv_PrintAlgorithmID(out, digAlg, om); |
569 while ((digAlg = src->digestAlgorithms[iv]) != NULL) { | 523 } |
570 sprintf(om, "pkcs7.digestAlgorithm[%d]=", iv++); | 524 } |
571 sv_PrintAlgorithmID(out, digAlg, om); | 525 |
572 } | 526 /* Now for the content */ |
573 } | 527 rv = sv_PrintPKCS7ContentInfo(out, &(src->contentInfo), |
574 | 528 "pkcs7.contentInformation="); |
575 /* Now for the content */ | 529 if (rv != 0) return rv; |
576 rv = sv_PrintPKCS7ContentInfo(out, &(src->contentInfo),· | 530 |
577 » » » » "pkcs7.contentInformation=")
; | 531 /* Parse and list certificates (if any) */ |
578 if (rv != 0) return rv; | 532 if (src->rawCerts != NULL) { |
579 | 533 iv = 0; |
580 /* Parse and list certificates (if any) */ | 534 while (src->rawCerts[iv] != NULL) iv++; |
581 if (src->rawCerts != NULL) { | 535 fprintf(out, "pkcs7.certificateListLength=%d\n", iv); |
582 iv = 0; | 536 |
583 while (src->rawCerts[iv] != NULL) | 537 iv = 0; |
584 iv++; | 538 while ((aCert = src->rawCerts[iv]) != NULL) { |
585 fprintf(out, "pkcs7.certificateListLength=%d\n", iv); | 539 sprintf(om, "certificate[%d].", iv++); |
586 | 540 rv = sv_PrintSignedData(out, aCert, om, sv_PrintCertificate); |
587 iv = 0; | 541 if (rv) return rv; |
588 while ((aCert = src->rawCerts[iv]) != NULL) { | 542 } |
589 sprintf(om, "certificate[%d].", iv++); | 543 } |
590 rv = sv_PrintSignedData(out, aCert, om, sv_PrintCertificate); | 544 |
591 if (rv) return rv; | 545 /* Parse and list CRL's (if any) */ |
592 } | 546 if (src->crls != NULL) { |
593 } | 547 iv = 0; |
594 | 548 while (src->crls[iv] != NULL) iv++; |
595 /* Parse and list CRL's (if any) */ | 549 fprintf(out, "pkcs7.signedRevocationLists=%d\n", iv); |
596 if (src->crls != NULL) { | 550 iv = 0; |
597 iv = 0; | 551 while ((aCrl = src->crls[iv]) != NULL) { |
598 while (src->crls[iv] != NULL) iv++; | 552 sprintf(om, "signedRevocationList[%d].", iv); |
599 fprintf(out, "pkcs7.signedRevocationLists=%d\n", iv); | 553 fprintf(out, "%s", om); |
600 iv = 0; | 554 sv_PrintAlgorithmID(out, &aCrl->signatureWrap.signatureAlgorithm, |
601 while ((aCrl = src->crls[iv]) != NULL) { | 555 "signatureAlgorithm="); |
602 sprintf(om, "signedRevocationList[%d].", iv); | 556 DER_ConvertBitString(&aCrl->signatureWrap.signature); |
603 fprintf(out, "%s", om); | 557 fprintf(out, "%s", om); |
604 sv_PrintAlgorithmID(out, &aCrl->signatureWrap.signatureAlgorithm,· | 558 sv_PrintAsHex(out, &aCrl->signatureWrap.signature, "signature="); |
605 "signatureAlgorithm="); | 559 sprintf(om, "certificateRevocationList[%d].", iv); |
606 DER_ConvertBitString(&aCrl->signatureWrap.signature); | 560 sv_PrintCRLInfo(out, &aCrl->crl, om); |
607 fprintf(out, "%s", om); | 561 iv++; |
608 sv_PrintAsHex(out, &aCrl->signatureWrap.signature, "signature="); | 562 } |
609 sprintf(om, "certificateRevocationList[%d].", iv); | 563 } |
610 sv_PrintCRLInfo(out, &aCrl->crl, om); | 564 |
611 iv++; | 565 /* Parse and list signatures (if any) */ |
612 } | 566 if (src->signerInfos != NULL) { |
613 } | 567 iv = 0; |
614 | 568 while (src->signerInfos[iv] != NULL) iv++; |
615 /* Parse and list signatures (if any) */ | 569 fprintf(out, "pkcs7.signerInformationListLength=%d\n", iv); |
616 if (src->signerInfos != NULL) { | 570 iv = 0; |
617 iv = 0; | 571 while ((sigInfo = src->signerInfos[iv]) != NULL) { |
618 while (src->signerInfos[iv] != NULL) | 572 sprintf(om, "signerInformation[%d].", iv++); |
619 iv++; | 573 sv_PrintSignerInfo(out, sigInfo, om); |
620 fprintf(out, "pkcs7.signerInformationListLength=%d\n", iv); | 574 } |
621 iv = 0; | 575 } |
622 while ((sigInfo = src->signerInfos[iv]) != NULL) { | 576 |
623 sprintf(om, "signerInformation[%d].", iv++); | 577 return 0; |
624 sv_PrintSignerInfo(out, sigInfo, om); | |
625 } | |
626 }·· | |
627 | |
628 return 0; | |
629 } | 578 } |
630 | 579 |
631 #if 0 | 580 #if 0 |
632 /* | 581 /* |
633 ** secu_PrintPKCS7Enveloped | 582 ** secu_PrintPKCS7Enveloped |
634 ** Pretty print a PKCS7 enveloped data type (up to version 1). | 583 ** Pretty print a PKCS7 enveloped data type (up to version 1). |
635 */ | 584 */ |
636 void | 585 void |
637 secu_PrintPKCS7Enveloped(FILE *out, SEC_PKCS7EnvelopedData *src, | 586 secu_PrintPKCS7Enveloped(FILE *out, SEC_PKCS7EnvelopedData *src, |
638 char *m, int level) | 587 char *m, int level) |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
776 sv_PrintAlgorithmID(out, &src->digestAlg, "Digest Algorithm"); | 725 sv_PrintAlgorithmID(out, &src->digestAlg, "Digest Algorithm"); |
777 sv_PrintPKCS7ContentInfo(out, &src->contentInfo, "Content Information", | 726 sv_PrintPKCS7ContentInfo(out, &src->contentInfo, "Content Information", |
778 level + 1); | 727 level + 1); |
779 sv_PrintAsHex(out, &src->digest, "Digest", level + 1);·· | 728 sv_PrintAsHex(out, &src->digest, "Digest", level + 1);·· |
780 } | 729 } |
781 | 730 |
782 #endif | 731 #endif |
783 | 732 |
784 /* | 733 /* |
785 ** secu_PrintPKCS7ContentInfo | 734 ** secu_PrintPKCS7ContentInfo |
786 ** Takes a SEC_PKCS7ContentInfo type and sends the contents to the | 735 ** Takes a SEC_PKCS7ContentInfo type and sends the contents to the |
787 ** appropriate function | 736 ** appropriate function |
788 */ | 737 */ |
789 int | 738 int sv_PrintPKCS7ContentInfo(FILE *out, SEC_PKCS7ContentInfo *src, char *m) { |
790 sv_PrintPKCS7ContentInfo(FILE *out, SEC_PKCS7ContentInfo *src, char *m) | 739 const char *desc; |
791 { | 740 SECOidTag kind; |
792 const char *desc; | 741 int rv; |
793 SECOidTag kind; | |
794 int rv; | |
795 | 742 |
796 if (src->contentTypeTag == NULL) | 743 if (src->contentTypeTag == NULL) |
797 src->contentTypeTag = SECOID_FindOID(&(src->contentType)); | 744 src->contentTypeTag = SECOID_FindOID(&(src->contentType)); |
798 | 745 |
799 if (src->contentTypeTag == NULL) { | 746 if (src->contentTypeTag == NULL) { |
800 desc = "Unknown"; | 747 desc = "Unknown"; |
801 kind = SEC_OID_PKCS7_DATA; | 748 kind = SEC_OID_PKCS7_DATA; |
802 } else { | 749 } else { |
803 desc = src->contentTypeTag->desc; | 750 desc = src->contentTypeTag->desc; |
804 kind = src->contentTypeTag->offset; | 751 kind = src->contentTypeTag->offset; |
805 } | 752 } |
806 | 753 |
807 fprintf(out, "%s%s\n", m, desc); | 754 fprintf(out, "%s%s\n", m, desc); |
808 | 755 |
809 if (src->content.data == NULL) { | 756 if (src->content.data == NULL) { |
810 fprintf(out, "pkcs7.data=<no content>\n"); | 757 fprintf(out, "pkcs7.data=<no content>\n"); |
811 return 0; | 758 return 0; |
812 } | 759 } |
813 | 760 |
814 rv = 0; | 761 rv = 0; |
815 switch (kind) { | 762 switch (kind) { |
816 case SEC_OID_PKCS7_SIGNED_DATA: /* Signed Data */ | 763 case SEC_OID_PKCS7_SIGNED_DATA: /* Signed Data */ |
817 rv = sv_PrintPKCS7Signed(out, src->content.signedData); | 764 rv = sv_PrintPKCS7Signed(out, src->content.signedData); |
818 break; | 765 break; |
819 | 766 |
820 case SEC_OID_PKCS7_ENVELOPED_DATA: /* Enveloped Data */ | 767 case SEC_OID_PKCS7_ENVELOPED_DATA: /* Enveloped Data */ |
821 fprintf(out, "pkcs7EnvelopedData=<unsupported>\n"); | 768 fprintf(out, "pkcs7EnvelopedData=<unsupported>\n"); |
822 /*sv_PrintPKCS7Enveloped(out, src->content.envelopedData);*/ | 769 /*sv_PrintPKCS7Enveloped(out, src->content.envelopedData);*/ |
823 break; | 770 break; |
824 | 771 |
825 case SEC_OID_PKCS7_SIGNED_ENVELOPED_DATA: /* Signed and Enveloped */ | 772 case SEC_OID_PKCS7_SIGNED_ENVELOPED_DATA: /* Signed and Enveloped */ |
826 fprintf(out, "pkcs7SignedEnvelopedData=<unsupported>\n"); | 773 fprintf(out, "pkcs7SignedEnvelopedData=<unsupported>\n"); |
827 /*rv = sv_PrintPKCS7SignedAndEnveloped(out, | 774 /*rv = sv_PrintPKCS7SignedAndEnveloped(out, |
828 src->content.signedAndEnvelopedData);*/ | 775 src->content.signedAndEnvelopedData);*/ |
829 break; | 776 break; |
830 | 777 |
831 case SEC_OID_PKCS7_DIGESTED_DATA: /* Digested Data */ | 778 case SEC_OID_PKCS7_DIGESTED_DATA: /* Digested Data */ |
832 fprintf(out, "pkcs7DigestedData=<unsupported>\n"); | 779 fprintf(out, "pkcs7DigestedData=<unsupported>\n"); |
833 /*sv_PrintPKCS7Digested(out, src->content.digestedData);*/ | 780 /*sv_PrintPKCS7Digested(out, src->content.digestedData);*/ |
834 break; | 781 break; |
835 | 782 |
836 case SEC_OID_PKCS7_ENCRYPTED_DATA: /* Encrypted Data */ | 783 case SEC_OID_PKCS7_ENCRYPTED_DATA: /* Encrypted Data */ |
837 fprintf(out, "pkcs7EncryptedData=<unsupported>\n"); | 784 fprintf(out, "pkcs7EncryptedData=<unsupported>\n"); |
838 /*sv_PrintPKCS7Encrypted(out, src->content.encryptedData);*/ | 785 /*sv_PrintPKCS7Encrypted(out, src->content.encryptedData);*/ |
839 break; | 786 break; |
840 | 787 |
841 default: | 788 default: |
842 fprintf(out, "pkcs7UnknownData=<unsupported>\n"); | 789 fprintf(out, "pkcs7UnknownData=<unsupported>\n"); |
843 /*sv_PrintAsHex(out, src->content.data);*/ | 790 /*sv_PrintAsHex(out, src->content.data);*/ |
844 break; | 791 break; |
845 } | 792 } |
846 | 793 |
847 return rv; | 794 return rv; |
848 } | 795 } |
849 | 796 |
| 797 int SV_PrintPKCS7ContentInfo(FILE *out, SECItem *der) { |
| 798 SEC_PKCS7ContentInfo *cinfo; |
| 799 int rv = -1; |
850 | 800 |
851 int | 801 cinfo = SEC_PKCS7DecodeItem(der, NULL, NULL, NULL, NULL, NULL, NULL, NULL); |
852 SV_PrintPKCS7ContentInfo(FILE *out, SECItem *der) | |
853 { | |
854 SEC_PKCS7ContentInfo *cinfo; | |
855 int rv = -1; | |
856 | 802 |
857 cinfo = SEC_PKCS7DecodeItem(der, NULL, NULL, NULL, NULL, NULL, NULL, NULL); | 803 if (cinfo != NULL) { |
| 804 rv = sv_PrintPKCS7ContentInfo(out, cinfo, "pkcs7.contentInfo="); |
| 805 SEC_PKCS7DestroyContentInfo(cinfo); |
| 806 } |
858 | 807 |
859 if (cinfo != NULL) { | 808 return rv; |
860 rv = sv_PrintPKCS7ContentInfo(out, cinfo, "pkcs7.contentInfo="); | |
861 SEC_PKCS7DestroyContentInfo(cinfo); | |
862 } | |
863 | |
864 return rv; | |
865 } | 809 } |
866 /* | 810 /* |
867 ** End of PKCS7 functions | 811 ** End of PKCS7 functions |
868 */ | 812 */ |
OLD | NEW |