diff options
Diffstat (limited to 'src/lib/libcrypto/asn1/t_x509.c')
-rw-r--r-- | src/lib/libcrypto/asn1/t_x509.c | 469 |
1 files changed, 264 insertions, 205 deletions
diff --git a/src/lib/libcrypto/asn1/t_x509.c b/src/lib/libcrypto/asn1/t_x509.c index 32f1a4f4b0..de3fa22171 100644 --- a/src/lib/libcrypto/asn1/t_x509.c +++ b/src/lib/libcrypto/asn1/t_x509.c | |||
@@ -5,21 +5,21 @@ | |||
5 | * This package is an SSL implementation written | 5 | * This package is an SSL implementation written |
6 | * by Eric Young (eay@cryptsoft.com). | 6 | * by Eric Young (eay@cryptsoft.com). |
7 | * The implementation was written so as to conform with Netscapes SSL. | 7 | * The implementation was written so as to conform with Netscapes SSL. |
8 | * | 8 | * |
9 | * This library is free for commercial and non-commercial use as long as | 9 | * This library is free for commercial and non-commercial use as long as |
10 | * the following conditions are aheared to. The following conditions | 10 | * the following conditions are aheared to. The following conditions |
11 | * apply to all code found in this distribution, be it the RC4, RSA, | 11 | * apply to all code found in this distribution, be it the RC4, RSA, |
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation |
13 | * included with this distribution is covered by the same copyright terms | 13 | * included with this distribution is covered by the same copyright terms |
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). |
15 | * | 15 | * |
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | 16 | * Copyright remains Eric Young's, and as such any Copyright notices in |
17 | * the code are not to be removed. | 17 | * the code are not to be removed. |
18 | * If this package is used in a product, Eric Young should be given attribution | 18 | * If this package is used in a product, Eric Young should be given attribution |
19 | * as the author of the parts of the library used. | 19 | * as the author of the parts of the library used. |
20 | * This can be in the form of a textual message at program startup or | 20 | * This can be in the form of a textual message at program startup or |
21 | * in documentation (online or textual) provided with the package. | 21 | * in documentation (online or textual) provided with the package. |
22 | * | 22 | * |
23 | * Redistribution and use in source and binary forms, with or without | 23 | * Redistribution and use in source and binary forms, with or without |
24 | * modification, are permitted provided that the following conditions | 24 | * modification, are permitted provided that the following conditions |
25 | * are met: | 25 | * are met: |
@@ -34,10 +34,10 @@ | |||
34 | * Eric Young (eay@cryptsoft.com)" | 34 | * Eric Young (eay@cryptsoft.com)" |
35 | * The word 'cryptographic' can be left out if the rouines from the library | 35 | * The word 'cryptographic' can be left out if the rouines from the library |
36 | * being used are not cryptographic related :-). | 36 | * being used are not cryptographic related :-). |
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | 37 | * 4. If you include any Windows specific code (or a derivative thereof) from |
38 | * the apps directory (application code) you must include an acknowledgement: | 38 | * the apps directory (application code) you must include an acknowledgement: |
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" |
40 | * | 40 | * |
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND |
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
@@ -49,7 +49,7 @@ | |||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
51 | * SUCH DAMAGE. | 51 | * SUCH DAMAGE. |
52 | * | 52 | * |
53 | * The licence and distribution terms for any publically available version or | 53 | * The licence and distribution terms for any publically available version or |
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be |
55 | * copied and put under another distribution licence | 55 | * copied and put under another distribution licence |
@@ -75,92 +75,102 @@ | |||
75 | #include "asn1_locl.h" | 75 | #include "asn1_locl.h" |
76 | 76 | ||
77 | #ifndef OPENSSL_NO_FP_API | 77 | #ifndef OPENSSL_NO_FP_API |
78 | int X509_print_fp(FILE *fp, X509 *x) | 78 | int |
79 | X509_print_fp(FILE *fp, X509 *x) | ||
79 | { | 80 | { |
80 | return X509_print_ex_fp(fp, x, XN_FLAG_COMPAT, X509_FLAG_COMPAT); | 81 | return X509_print_ex_fp(fp, x, XN_FLAG_COMPAT, X509_FLAG_COMPAT); |
81 | } | 82 | } |
82 | 83 | ||
83 | int X509_print_ex_fp(FILE *fp, X509 *x, unsigned long nmflag, unsigned long cflag) | 84 | int |
84 | { | 85 | X509_print_ex_fp(FILE *fp, X509 *x, unsigned long nmflag, unsigned long cflag) |
85 | BIO *b; | 86 | { |
86 | int ret; | 87 | BIO *b; |
88 | int ret; | ||
87 | 89 | ||
88 | if ((b=BIO_new(BIO_s_file())) == NULL) { | 90 | if ((b = BIO_new(BIO_s_file())) == NULL) { |
89 | X509err(X509_F_X509_PRINT_EX_FP,ERR_R_BUF_LIB); | 91 | X509err(X509_F_X509_PRINT_EX_FP, ERR_R_BUF_LIB); |
90 | return(0); | 92 | return (0); |
91 | } | 93 | } |
92 | BIO_set_fp(b,fp,BIO_NOCLOSE); | 94 | BIO_set_fp(b, fp, BIO_NOCLOSE); |
93 | ret=X509_print_ex(b, x, nmflag, cflag); | 95 | ret = X509_print_ex(b, x, nmflag, cflag); |
94 | BIO_free(b); | 96 | BIO_free(b); |
95 | return(ret); | 97 | return (ret); |
96 | } | 98 | } |
97 | #endif | 99 | #endif |
98 | 100 | ||
99 | int X509_print(BIO *bp, X509 *x) | 101 | int |
102 | X509_print(BIO *bp, X509 *x) | ||
100 | { | 103 | { |
101 | return X509_print_ex(bp, x, XN_FLAG_COMPAT, X509_FLAG_COMPAT); | 104 | return X509_print_ex(bp, x, XN_FLAG_COMPAT, X509_FLAG_COMPAT); |
102 | } | 105 | } |
103 | 106 | ||
104 | int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags, unsigned long cflag) | 107 | int |
108 | X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags, unsigned long cflag) | ||
105 | { | 109 | { |
106 | long l; | 110 | long l; |
107 | int ret=0,i; | 111 | int ret = 0, i; |
108 | char *m=NULL,mlch = ' '; | 112 | char *m = NULL, mlch = ' '; |
109 | int nmindent = 0; | 113 | int nmindent = 0; |
110 | X509_CINF *ci; | 114 | X509_CINF *ci; |
111 | ASN1_INTEGER *bs; | 115 | ASN1_INTEGER *bs; |
112 | EVP_PKEY *pkey=NULL; | 116 | EVP_PKEY *pkey = NULL; |
113 | const char *neg; | 117 | const char *neg; |
114 | 118 | ||
115 | if((nmflags & XN_FLAG_SEP_MASK) == XN_FLAG_SEP_MULTILINE) { | 119 | if ((nmflags & XN_FLAG_SEP_MASK) == XN_FLAG_SEP_MULTILINE) { |
116 | mlch = '\n'; | 120 | mlch = '\n'; |
117 | nmindent = 12; | 121 | nmindent = 12; |
118 | } | 122 | } |
119 | 123 | ||
120 | if(nmflags == X509_FLAG_COMPAT) | 124 | if (nmflags == X509_FLAG_COMPAT) |
121 | nmindent = 16; | 125 | nmindent = 16; |
122 | 126 | ||
123 | ci=x->cert_info; | 127 | ci = x->cert_info; |
124 | if(!(cflag & X509_FLAG_NO_HEADER)) { | 128 | if (!(cflag & X509_FLAG_NO_HEADER)) { |
125 | if (BIO_write(bp,"Certificate:\n",13) <= 0) goto err; | 129 | if (BIO_write(bp, "Certificate:\n", 13) <= 0) |
126 | if (BIO_write(bp," Data:\n",10) <= 0) goto err; | 130 | goto err; |
131 | if (BIO_write(bp, " Data:\n", 10) <= 0) | ||
132 | goto err; | ||
127 | } | 133 | } |
128 | if(!(cflag & X509_FLAG_NO_VERSION)) { | 134 | if (!(cflag & X509_FLAG_NO_VERSION)) { |
129 | l=X509_get_version(x); | 135 | l = X509_get_version(x); |
130 | if (BIO_printf(bp,"%8sVersion: %lu (0x%lx)\n","",l+1,l) <= 0) goto err; | 136 | if (BIO_printf(bp, "%8sVersion: %lu (0x%lx)\n", |
137 | "", l + 1, l) <= 0) | ||
138 | goto err; | ||
131 | } | 139 | } |
132 | if(!(cflag & X509_FLAG_NO_SERIAL)) { | 140 | if (!(cflag & X509_FLAG_NO_SERIAL)) { |
133 | 141 | if (BIO_write(bp, " Serial Number:", 22) <= 0) | |
134 | if (BIO_write(bp," Serial Number:",22) <= 0) goto err; | 142 | goto err; |
135 | 143 | ||
136 | bs=X509_get_serialNumber(x); | 144 | bs = X509_get_serialNumber(x); |
137 | if (bs->length <= (int)sizeof(long)) { | 145 | if (bs->length <= (int)sizeof(long)) { |
138 | l=ASN1_INTEGER_get(bs); | 146 | l = ASN1_INTEGER_get(bs); |
139 | if (bs->type == V_ASN1_NEG_INTEGER) { | 147 | if (bs->type == V_ASN1_NEG_INTEGER) { |
140 | l= -l; | 148 | l = -l; |
141 | neg="-"; | 149 | neg = "-"; |
142 | } else | 150 | } else |
143 | neg=""; | 151 | neg = ""; |
144 | if (BIO_printf(bp," %s%lu (%s0x%lx)\n",neg,l,neg,l) <= 0) | 152 | if (BIO_printf(bp, " %s%lu (%s0x%lx)\n", |
153 | neg, l, neg, l) <= 0) | ||
145 | goto err; | 154 | goto err; |
146 | } else { | 155 | } else { |
147 | neg=(bs->type == V_ASN1_NEG_INTEGER)?" (Negative)":""; | 156 | neg = (bs->type == V_ASN1_NEG_INTEGER) ? |
148 | if (BIO_printf(bp,"\n%12s%s","",neg) <= 0) goto err; | 157 | " (Negative)" : ""; |
149 | 158 | if (BIO_printf(bp, "\n%12s%s", "", neg) <= 0) | |
150 | for (i=0; i<bs->length; i++) { | 159 | goto err; |
151 | if (BIO_printf(bp,"%02x%c",bs->data[i], | 160 | for (i = 0; i < bs->length; i++) { |
152 | ((i+1 == bs->length)?'\n':':')) <= 0) | 161 | if (BIO_printf(bp, "%02x%c", bs->data[i], |
162 | ((i + 1 == bs->length) ? '\n' : ':')) <= 0) | ||
153 | goto err; | 163 | goto err; |
154 | } | 164 | } |
155 | } | 165 | } |
156 | 166 | ||
157 | } | 167 | } |
158 | 168 | ||
159 | if(!(cflag & X509_FLAG_NO_SIGNAME)) { | 169 | if (!(cflag & X509_FLAG_NO_SIGNAME)) { |
160 | if(X509_signature_print(bp, x->sig_alg, NULL) <= 0) | 170 | if (X509_signature_print(bp, x->sig_alg, NULL) <= 0) |
161 | goto err; | 171 | goto err; |
162 | #if 0 | 172 | #if 0 |
163 | if (BIO_printf(bp,"%8sSignature Algorithm: ","") <= 0) | 173 | if (BIO_printf(bp, "%8sSignature Algorithm: ", "") <= 0) |
164 | goto err; | 174 | goto err; |
165 | if (i2a_ASN1_OBJECT(bp, ci->signature->algorithm) <= 0) | 175 | if (i2a_ASN1_OBJECT(bp, ci->signature->algorithm) <= 0) |
166 | goto err; | 176 | goto err; |
@@ -169,37 +179,52 @@ int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags, unsigned long cflag) | |||
169 | #endif | 179 | #endif |
170 | } | 180 | } |
171 | 181 | ||
172 | if(!(cflag & X509_FLAG_NO_ISSUER)) { | 182 | if (!(cflag & X509_FLAG_NO_ISSUER)) { |
173 | if (BIO_printf(bp," Issuer:%c",mlch) <= 0) goto err; | 183 | if (BIO_printf(bp, " Issuer:%c", mlch) <= 0) |
174 | if (X509_NAME_print_ex(bp,X509_get_issuer_name(x),nmindent, nmflags) < 0) goto err; | 184 | goto err; |
175 | if (BIO_write(bp,"\n",1) <= 0) goto err; | 185 | if (X509_NAME_print_ex(bp, X509_get_issuer_name(x), |
186 | nmindent, nmflags) < 0) | ||
187 | goto err; | ||
188 | if (BIO_write(bp, "\n", 1) <= 0) | ||
189 | goto err; | ||
176 | } | 190 | } |
177 | if(!(cflag & X509_FLAG_NO_VALIDITY)) { | 191 | if (!(cflag & X509_FLAG_NO_VALIDITY)) { |
178 | if (BIO_write(bp," Validity\n",17) <= 0) goto err; | 192 | if (BIO_write(bp, " Validity\n", 17) <= 0) |
179 | if (BIO_write(bp," Not Before: ",24) <= 0) goto err; | 193 | goto err; |
180 | if (!ASN1_TIME_print(bp,X509_get_notBefore(x))) goto err; | 194 | if (BIO_write(bp, " Not Before: ", 24) <= 0) |
181 | if (BIO_write(bp,"\n Not After : ",25) <= 0) goto err; | 195 | goto err; |
182 | if (!ASN1_TIME_print(bp,X509_get_notAfter(x))) goto err; | 196 | if (!ASN1_TIME_print(bp, X509_get_notBefore(x))) |
183 | if (BIO_write(bp,"\n",1) <= 0) goto err; | 197 | goto err; |
198 | if (BIO_write(bp, "\n Not After : ", 25) <= 0) | ||
199 | goto err; | ||
200 | if (!ASN1_TIME_print(bp, X509_get_notAfter(x))) | ||
201 | goto err; | ||
202 | if (BIO_write(bp, "\n", 1) <= 0) | ||
203 | goto err; | ||
184 | } | 204 | } |
185 | if(!(cflag & X509_FLAG_NO_SUBJECT)) { | 205 | if (!(cflag & X509_FLAG_NO_SUBJECT)) { |
186 | if (BIO_printf(bp," Subject:%c",mlch) <= 0) goto err; | 206 | if (BIO_printf(bp, " Subject:%c", mlch) <= 0) |
187 | if (X509_NAME_print_ex(bp,X509_get_subject_name(x),nmindent, nmflags) < 0) goto err; | 207 | goto err; |
188 | if (BIO_write(bp,"\n",1) <= 0) goto err; | 208 | if (X509_NAME_print_ex(bp, X509_get_subject_name(x), |
209 | nmindent, nmflags) < 0) | ||
210 | goto err; | ||
211 | if (BIO_write(bp, "\n", 1) <= 0) | ||
212 | goto err; | ||
189 | } | 213 | } |
190 | if(!(cflag & X509_FLAG_NO_PUBKEY)) { | 214 | if (!(cflag & X509_FLAG_NO_PUBKEY)) { |
191 | if (BIO_write(bp," Subject Public Key Info:\n",33) <= 0) | 215 | if (BIO_write(bp, " Subject Public Key Info:\n", |
216 | 33) <= 0) | ||
192 | goto err; | 217 | goto err; |
193 | if (BIO_printf(bp,"%12sPublic Key Algorithm: ","") <= 0) | 218 | if (BIO_printf(bp, "%12sPublic Key Algorithm: ", "") <= 0) |
194 | goto err; | 219 | goto err; |
195 | if (i2a_ASN1_OBJECT(bp, ci->key->algor->algorithm) <= 0) | 220 | if (i2a_ASN1_OBJECT(bp, ci->key->algor->algorithm) <= 0) |
196 | goto err; | 221 | goto err; |
197 | if (BIO_puts(bp, "\n") <= 0) | 222 | if (BIO_puts(bp, "\n") <= 0) |
198 | goto err; | 223 | goto err; |
199 | 224 | ||
200 | pkey=X509_get_pubkey(x); | 225 | pkey = X509_get_pubkey(x); |
201 | if (pkey == NULL) { | 226 | if (pkey == NULL) { |
202 | BIO_printf(bp,"%12sUnable to load Public Key\n",""); | 227 | BIO_printf(bp, "%12sUnable to load Public Key\n", ""); |
203 | ERR_print_errors(bp); | 228 | ERR_print_errors(bp); |
204 | } else { | 229 | } else { |
205 | EVP_PKEY_print_public(bp, pkey, 16, NULL); | 230 | EVP_PKEY_print_public(bp, pkey, 16, NULL); |
@@ -209,23 +234,27 @@ int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags, unsigned long cflag) | |||
209 | 234 | ||
210 | if (!(cflag & X509_FLAG_NO_EXTENSIONS)) | 235 | if (!(cflag & X509_FLAG_NO_EXTENSIONS)) |
211 | X509V3_extensions_print(bp, "X509v3 extensions", | 236 | X509V3_extensions_print(bp, "X509v3 extensions", |
212 | ci->extensions, cflag, 8); | 237 | ci->extensions, cflag, 8); |
213 | 238 | ||
214 | if(!(cflag & X509_FLAG_NO_SIGDUMP)) { | 239 | if (!(cflag & X509_FLAG_NO_SIGDUMP)) { |
215 | if(X509_signature_print(bp, x->sig_alg, x->signature) <= 0) goto err; | 240 | if (X509_signature_print(bp, x->sig_alg, x->signature) <= 0) |
241 | goto err; | ||
216 | } | 242 | } |
217 | if(!(cflag & X509_FLAG_NO_AUX)) { | 243 | if (!(cflag & X509_FLAG_NO_AUX)) { |
218 | if (!X509_CERT_AUX_print(bp, x->aux, 0)) goto err; | 244 | if (!X509_CERT_AUX_print(bp, x->aux, 0)) |
245 | goto err; | ||
219 | } | 246 | } |
220 | ret=1; | 247 | ret = 1; |
248 | |||
221 | err: | 249 | err: |
222 | if (m != NULL) free(m); | 250 | if (m != NULL) |
223 | return(ret); | 251 | free(m); |
252 | return (ret); | ||
224 | } | 253 | } |
225 | 254 | ||
226 | int X509_ocspid_print (BIO *bp, X509 *x) | 255 | int X509_ocspid_print (BIO *bp, X509 *x) |
227 | { | 256 | { |
228 | unsigned char *der=NULL ; | 257 | unsigned char *der = NULL; |
229 | unsigned char *dertmp; | 258 | unsigned char *dertmp; |
230 | int derlen; | 259 | int derlen; |
231 | int i; | 260 | int i; |
@@ -233,7 +262,7 @@ int X509_ocspid_print (BIO *bp, X509 *x) | |||
233 | 262 | ||
234 | /* display the hash of the subject as it would appear | 263 | /* display the hash of the subject as it would appear |
235 | in OCSP requests */ | 264 | in OCSP requests */ |
236 | if (BIO_printf(bp," Subject OCSP hash: ") <= 0) | 265 | if (BIO_printf(bp, " Subject OCSP hash: ") <= 0) |
237 | goto err; | 266 | goto err; |
238 | derlen = i2d_X509_NAME(x->cert_info->subject, NULL); | 267 | derlen = i2d_X509_NAME(x->cert_info->subject, NULL); |
239 | if ((der = dertmp = (unsigned char *)malloc (derlen)) == NULL) | 268 | if ((der = dertmp = (unsigned char *)malloc (derlen)) == NULL) |
@@ -242,58 +271,69 @@ int X509_ocspid_print (BIO *bp, X509 *x) | |||
242 | 271 | ||
243 | if (!EVP_Digest(der, derlen, SHA1md, NULL, EVP_sha1(), NULL)) | 272 | if (!EVP_Digest(der, derlen, SHA1md, NULL, EVP_sha1(), NULL)) |
244 | goto err; | 273 | goto err; |
245 | for (i=0; i < SHA_DIGEST_LENGTH; i++) { | 274 | for (i = 0; i < SHA_DIGEST_LENGTH; i++) { |
246 | if (BIO_printf(bp,"%02X",SHA1md[i]) <= 0) goto err; | 275 | if (BIO_printf(bp, "%02X", SHA1md[i]) <= 0) |
276 | goto err; | ||
247 | } | 277 | } |
248 | free (der); | 278 | free (der); |
249 | der=NULL; | 279 | der = NULL; |
250 | 280 | ||
251 | /* display the hash of the public key as it would appear | 281 | /* display the hash of the public key as it would appear |
252 | in OCSP requests */ | 282 | in OCSP requests */ |
253 | if (BIO_printf(bp,"\n Public key OCSP hash: ") <= 0) | 283 | if (BIO_printf(bp, "\n Public key OCSP hash: ") <= 0) |
254 | goto err; | 284 | goto err; |
255 | 285 | ||
256 | if (!EVP_Digest(x->cert_info->key->public_key->data, | 286 | if (!EVP_Digest(x->cert_info->key->public_key->data, |
257 | x->cert_info->key->public_key->length, | 287 | x->cert_info->key->public_key->length, |
258 | SHA1md, NULL, EVP_sha1(), NULL)) | 288 | SHA1md, NULL, EVP_sha1(), NULL)) |
259 | goto err; | 289 | goto err; |
260 | for (i=0; i < SHA_DIGEST_LENGTH; i++) { | 290 | for (i = 0; i < SHA_DIGEST_LENGTH; i++) { |
261 | if (BIO_printf(bp,"%02X",SHA1md[i]) <= 0) | 291 | if (BIO_printf(bp, "%02X", SHA1md[i]) <= 0) |
262 | goto err; | 292 | goto err; |
263 | } | 293 | } |
264 | BIO_printf(bp,"\n"); | 294 | BIO_printf(bp, "\n"); |
265 | 295 | ||
266 | return (1); | 296 | return (1); |
297 | |||
267 | err: | 298 | err: |
268 | if (der != NULL) free(der); | 299 | if (der != NULL) |
269 | return(0); | 300 | free(der); |
301 | return (0); | ||
270 | } | 302 | } |
271 | 303 | ||
272 | int X509_signature_dump(BIO *bp, const ASN1_STRING *sig, int indent) | 304 | int |
305 | X509_signature_dump(BIO *bp, const ASN1_STRING *sig, int indent) | ||
273 | { | 306 | { |
274 | const unsigned char *s; | 307 | const unsigned char *s; |
275 | int i, n; | 308 | int i, n; |
276 | 309 | ||
277 | n=sig->length; | 310 | n = sig->length; |
278 | s=sig->data; | 311 | s = sig->data; |
279 | for (i=0; i<n; i++) { | 312 | for (i = 0; i < n; i++) { |
280 | if ((i%18) == 0) { | 313 | if ((i % 18) == 0) { |
281 | if (BIO_write(bp,"\n",1) <= 0) return 0; | 314 | if (BIO_write(bp, "\n", 1) <= 0) |
282 | if (BIO_indent(bp, indent, indent) <= 0) return 0; | 315 | return 0; |
316 | if (BIO_indent(bp, indent, indent) <= 0) | ||
317 | return 0; | ||
283 | } | 318 | } |
284 | if (BIO_printf(bp,"%02x%s",s[i], | 319 | if (BIO_printf(bp, "%02x%s", s[i], |
285 | ((i+1) == n)?"":":") <= 0) return 0; | 320 | ((i + 1) == n) ? "" : ":") <= 0) |
321 | return 0; | ||
286 | } | 322 | } |
287 | if (BIO_write(bp,"\n",1) != 1) return 0; | 323 | if (BIO_write(bp, "\n", 1) != 1) |
324 | return 0; | ||
288 | 325 | ||
289 | return 1; | 326 | return 1; |
290 | } | 327 | } |
291 | 328 | ||
292 | int X509_signature_print(BIO *bp, X509_ALGOR *sigalg, ASN1_STRING *sig) | 329 | int |
330 | X509_signature_print(BIO *bp, X509_ALGOR *sigalg, ASN1_STRING *sig) | ||
293 | { | 331 | { |
294 | int sig_nid; | 332 | int sig_nid; |
295 | if (BIO_puts(bp," Signature Algorithm: ") <= 0) return 0; | 333 | if (BIO_puts(bp, " Signature Algorithm: ") <= 0) |
296 | if (i2a_ASN1_OBJECT(bp, sigalg->algorithm) <= 0) return 0; | 334 | return 0; |
335 | if (i2a_ASN1_OBJECT(bp, sigalg->algorithm) <= 0) | ||
336 | return 0; | ||
297 | 337 | ||
298 | sig_nid = OBJ_obj2nid(sigalg->algorithm); | 338 | sig_nid = OBJ_obj2nid(sigalg->algorithm); |
299 | if (sig_nid != NID_undef) { | 339 | if (sig_nid != NID_undef) { |
@@ -312,172 +352,191 @@ int X509_signature_print(BIO *bp, X509_ALGOR *sigalg, ASN1_STRING *sig) | |||
312 | return 1; | 352 | return 1; |
313 | } | 353 | } |
314 | 354 | ||
315 | int ASN1_STRING_print(BIO *bp, const ASN1_STRING *v) | 355 | int |
356 | ASN1_STRING_print(BIO *bp, const ASN1_STRING *v) | ||
316 | { | 357 | { |
317 | int i,n; | 358 | int i, n; |
318 | char buf[80]; | 359 | char buf[80]; |
319 | const char *p; | 360 | const char *p; |
320 | 361 | ||
321 | if (v == NULL) return(0); | 362 | if (v == NULL) |
322 | n=0; | 363 | return (0); |
323 | p=(const char *)v->data; | 364 | n = 0; |
324 | for (i=0; i<v->length; i++) { | 365 | p = (const char *)v->data; |
366 | for (i = 0; i < v->length; i++) { | ||
325 | if ((p[i] > '~') || ((p[i] < ' ') && | 367 | if ((p[i] > '~') || ((p[i] < ' ') && |
326 | (p[i] != '\n') && (p[i] != '\r'))) | 368 | (p[i] != '\n') && (p[i] != '\r'))) |
327 | buf[n]='.'; | 369 | buf[n] = '.'; |
328 | else | 370 | else |
329 | buf[n]=p[i]; | 371 | buf[n] = p[i]; |
330 | n++; | 372 | n++; |
331 | if (n >= 80) { | 373 | if (n >= 80) { |
332 | if (BIO_write(bp,buf,n) <= 0) | 374 | if (BIO_write(bp, buf, n) <= 0) |
333 | return(0); | 375 | return (0); |
334 | n=0; | 376 | n = 0; |
335 | } | 377 | } |
336 | } | 378 | } |
337 | if (n > 0) | 379 | if (n > 0) |
338 | if (BIO_write(bp,buf,n) <= 0) | 380 | if (BIO_write(bp, buf, n) <= 0) |
339 | return(0); | 381 | return (0); |
340 | return(1); | 382 | return (1); |
341 | } | 383 | } |
342 | 384 | ||
343 | int ASN1_TIME_print(BIO *bp, const ASN1_TIME *tm) | 385 | int |
386 | ASN1_TIME_print(BIO *bp, const ASN1_TIME *tm) | ||
344 | { | 387 | { |
345 | if(tm->type == V_ASN1_UTCTIME) return ASN1_UTCTIME_print(bp, tm); | 388 | if (tm->type == V_ASN1_UTCTIME) |
346 | if(tm->type == V_ASN1_GENERALIZEDTIME) | 389 | return ASN1_UTCTIME_print(bp, tm); |
347 | return ASN1_GENERALIZEDTIME_print(bp, tm); | 390 | if (tm->type == V_ASN1_GENERALIZEDTIME) |
348 | BIO_write(bp,"Bad time value",14); | 391 | return ASN1_GENERALIZEDTIME_print(bp, tm); |
349 | return(0); | 392 | BIO_write(bp, "Bad time value", 14); |
393 | return (0); | ||
350 | } | 394 | } |
351 | 395 | ||
352 | static const char *mon[12]= | 396 | static const char *mon[12] = { |
353 | { | 397 | "Jan", "Feb", "Mar", "Apr", "May", "Jun", |
354 | "Jan","Feb","Mar","Apr","May","Jun", | 398 | "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" |
355 | "Jul","Aug","Sep","Oct","Nov","Dec" | 399 | }; |
356 | }; | ||
357 | 400 | ||
358 | int ASN1_GENERALIZEDTIME_print(BIO *bp, const ASN1_GENERALIZEDTIME *tm) | 401 | int |
402 | ASN1_GENERALIZEDTIME_print(BIO *bp, const ASN1_GENERALIZEDTIME *tm) | ||
359 | { | 403 | { |
360 | char *v; | 404 | char *v; |
361 | int gmt=0; | 405 | int gmt = 0; |
362 | int i; | 406 | int i; |
363 | int y=0,M=0,d=0,h=0,m=0,s=0; | 407 | int y = 0, M = 0, d = 0, h = 0, m = 0, s = 0; |
364 | char *f = NULL; | 408 | char *f = NULL; |
365 | int f_len = 0; | 409 | int f_len = 0; |
366 | 410 | ||
367 | i=tm->length; | 411 | i = tm->length; |
368 | v=(char *)tm->data; | 412 | v = (char *)tm->data; |
369 | 413 | ||
370 | if (i < 12) goto err; | 414 | if (i < 12) |
371 | if (v[i-1] == 'Z') gmt=1; | 415 | goto err; |
372 | for (i=0; i<12; i++) | 416 | if (v[i-1] == 'Z') |
373 | if ((v[i] > '9') || (v[i] < '0')) goto err; | 417 | gmt = 1; |
374 | y= (v[0]-'0')*1000+(v[1]-'0')*100 + (v[2]-'0')*10+(v[3]-'0'); | 418 | for (i = 0; i < 12; i++) |
375 | M= (v[4]-'0')*10+(v[5]-'0'); | 419 | if ((v[i] > '9') || (v[i] < '0')) |
376 | if ((M > 12) || (M < 1)) goto err; | 420 | goto err; |
377 | d= (v[6]-'0')*10+(v[7]-'0'); | 421 | y = (v[0] - '0') * 1000 + (v[1] - '0') * 100 + |
378 | h= (v[8]-'0')*10+(v[9]-'0'); | 422 | (v[2] - '0') * 10 + (v[3] - '0'); |
379 | m= (v[10]-'0')*10+(v[11]-'0'); | 423 | M = (v[4] - '0') * 10 + (v[5] - '0'); |
424 | if ((M > 12) || (M < 1)) | ||
425 | goto err; | ||
426 | d = (v[6] - '0') * 10 + (v[7] - '0'); | ||
427 | h = (v[8] - '0') * 10 + (v[9] - '0'); | ||
428 | m = (v[10] - '0') * 10 + (v[11] - '0'); | ||
380 | if (tm->length >= 14 && | 429 | if (tm->length >= 14 && |
381 | (v[12] >= '0') && (v[12] <= '9') && | 430 | (v[12] >= '0') && (v[12] <= '9') && |
382 | (v[13] >= '0') && (v[13] <= '9')) { | 431 | (v[13] >= '0') && (v[13] <= '9')) { |
383 | s= (v[12]-'0')*10+(v[13]-'0'); | 432 | s = (v[12] - '0') * 10 + (v[13] - '0'); |
384 | /* Check for fractions of seconds. */ | 433 | /* Check for fractions of seconds. */ |
385 | if (tm->length >= 15 && v[14] == '.') { | 434 | if (tm->length >= 15 && v[14] == '.') { |
386 | int l = tm->length; | 435 | int l = tm->length; |
387 | f = &v[14]; /* The decimal point. */ | 436 | f = &v[14]; /* The decimal point. */ |
388 | f_len = 1; | 437 | f_len = 1; |
389 | while (14 + f_len < l && f[f_len] >= '0' && f[f_len] <= '9') | 438 | while (14 + f_len < l && f[f_len] >= '0' && |
439 | f[f_len] <= '9') | ||
390 | ++f_len; | 440 | ++f_len; |
391 | } | 441 | } |
392 | } | 442 | } |
393 | 443 | ||
394 | if (BIO_printf(bp,"%s %2d %02d:%02d:%02d%.*s %d%s", | 444 | if (BIO_printf(bp, "%s %2d %02d:%02d:%02d%.*s %d%s", |
395 | mon[M-1],d,h,m,s,f_len,f,y,(gmt)?" GMT":"") <= 0) | 445 | mon[M - 1], d, h, m, s, f_len, f, y, (gmt) ? " GMT" : "") <= 0) |
396 | return(0); | 446 | return (0); |
397 | else | 447 | else |
398 | return(1); | 448 | return (1); |
449 | |||
399 | err: | 450 | err: |
400 | BIO_write(bp,"Bad time value",14); | 451 | BIO_write(bp, "Bad time value", 14); |
401 | return(0); | 452 | return (0); |
402 | } | 453 | } |
403 | 454 | ||
404 | int ASN1_UTCTIME_print(BIO *bp, const ASN1_UTCTIME *tm) | 455 | int |
456 | ASN1_UTCTIME_print(BIO *bp, const ASN1_UTCTIME *tm) | ||
405 | { | 457 | { |
406 | const char *v; | 458 | const char *v; |
407 | int gmt=0; | 459 | int gmt = 0; |
408 | int i; | 460 | int i; |
409 | int y=0,M=0,d=0,h=0,m=0,s=0; | 461 | int y = 0, M = 0, d = 0, h = 0, m = 0, s = 0; |
410 | 462 | ||
411 | i=tm->length; | 463 | i = tm->length; |
412 | v=(const char *)tm->data; | 464 | v = (const char *)tm->data; |
413 | 465 | ||
414 | if (i < 10) goto err; | 466 | if (i < 10) |
415 | if (v[i-1] == 'Z') gmt=1; | 467 | goto err; |
416 | for (i=0; i<10; i++) | 468 | if (v[i-1] == 'Z') |
417 | if ((v[i] > '9') || (v[i] < '0')) goto err; | 469 | gmt = 1; |
418 | y= (v[0]-'0')*10+(v[1]-'0'); | 470 | for (i = 0; i < 10; i++) |
419 | if (y < 50) y+=100; | 471 | if ((v[i] > '9') || (v[i] < '0')) |
420 | M= (v[2]-'0')*10+(v[3]-'0'); | 472 | goto err; |
421 | if ((M > 12) || (M < 1)) goto err; | 473 | y = (v[0] - '0') * 10 + (v[1] - '0'); |
422 | d= (v[4]-'0')*10+(v[5]-'0'); | 474 | if (y < 50) |
423 | h= (v[6]-'0')*10+(v[7]-'0'); | 475 | y += 100; |
424 | m= (v[8]-'0')*10+(v[9]-'0'); | 476 | M = (v[2] - '0') * 10 + (v[3] - '0'); |
477 | if ((M > 12) || (M < 1)) | ||
478 | goto err; | ||
479 | d = (v[4] - '0') * 10 + (v[5] - '0'); | ||
480 | h = (v[6] - '0') * 10 + (v[7] - '0'); | ||
481 | m = (v[8] - '0') * 10 + (v[9] - '0'); | ||
425 | if (tm->length >=12 && | 482 | if (tm->length >=12 && |
426 | (v[10] >= '0') && (v[10] <= '9') && | 483 | (v[10] >= '0') && (v[10] <= '9') && |
427 | (v[11] >= '0') && (v[11] <= '9')) | 484 | (v[11] >= '0') && (v[11] <= '9')) |
428 | s= (v[10]-'0')*10+(v[11]-'0'); | 485 | s = (v[10] - '0') * 10 + (v[11] - '0'); |
429 | 486 | ||
430 | if (BIO_printf(bp,"%s %2d %02d:%02d:%02d %d%s", | 487 | if (BIO_printf(bp, "%s %2d %02d:%02d:%02d %d%s", |
431 | mon[M-1],d,h,m,s,y+1900,(gmt)?" GMT":"") <= 0) | 488 | mon[M - 1], d, h, m, s, y + 1900, (gmt) ? " GMT" : "") <= 0) |
432 | return(0); | 489 | return (0); |
433 | else | 490 | else |
434 | return(1); | 491 | return (1); |
492 | |||
435 | err: | 493 | err: |
436 | BIO_write(bp,"Bad time value",14); | 494 | BIO_write(bp, "Bad time value", 14); |
437 | return(0); | 495 | return (0); |
438 | } | 496 | } |
439 | 497 | ||
440 | int X509_NAME_print(BIO *bp, X509_NAME *name, int obase) | 498 | int |
499 | X509_NAME_print(BIO *bp, X509_NAME *name, int obase) | ||
441 | { | 500 | { |
442 | char *s,*c,*b; | 501 | char *s, *c, *b; |
443 | int ret=0,l,i; | 502 | int ret = 0, l, i; |
444 | 503 | ||
445 | l=80-2-obase; | 504 | l = 80 - 2 - obase; |
446 | 505 | ||
447 | b=X509_NAME_oneline(name,NULL,0); | 506 | b = X509_NAME_oneline(name, NULL, 0); |
448 | if (!*b) { | 507 | if (!*b) { |
449 | free(b); | 508 | free(b); |
450 | return 1; | 509 | return 1; |
451 | } | 510 | } |
452 | s=b+1; /* skip the first slash */ | 511 | s = b + 1; /* skip the first slash */ |
453 | 512 | ||
454 | c=s; | 513 | c = s; |
455 | for (;;) { | 514 | for (;;) { |
456 | if ( ((*s == '/') && | 515 | if (((*s == '/') && |
457 | ((s[1] >= 'A') && (s[1] <= 'Z') && ( | 516 | ((s[1] >= 'A') && (s[1] <= 'Z') && |
458 | (s[2] == '=') || | 517 | ((s[2] == '=') || ((s[2] >= 'A') && (s[2] <= 'Z') && |
459 | ((s[2] >= 'A') && (s[2] <= 'Z') && | 518 | (s[3] == '='))))) || (*s == '\0')) { |
460 | (s[3] == '=')) | 519 | i = s - c; |
461 | ))) || | 520 | if (BIO_write(bp, c, i) != i) |
462 | (*s == '\0')) { | 521 | goto err; |
463 | i=s-c; | 522 | c = s + 1; /* skip following slash */ |
464 | if (BIO_write(bp,c,i) != i) goto err; | ||
465 | c=s+1; /* skip following slash */ | ||
466 | if (*s != '\0') { | 523 | if (*s != '\0') { |
467 | if (BIO_write(bp,", ",2) != 2) goto err; | 524 | if (BIO_write(bp, ", ", 2) != 2) |
525 | goto err; | ||
468 | } | 526 | } |
469 | l--; | 527 | l--; |
470 | } | 528 | } |
471 | if (*s == '\0') break; | 529 | if (*s == '\0') |
530 | break; | ||
472 | s++; | 531 | s++; |
473 | l--; | 532 | l--; |
474 | } | 533 | } |
475 | 534 | ||
476 | ret=1; | 535 | ret = 1; |
477 | if (0) { | 536 | if (0) { |
478 | err: | 537 | err: |
479 | X509err(X509_F_X509_NAME_PRINT,ERR_R_BUF_LIB); | 538 | X509err(X509_F_X509_NAME_PRINT, ERR_R_BUF_LIB); |
480 | } | 539 | } |
481 | free(b); | 540 | free(b); |
482 | return(ret); | 541 | return (ret); |
483 | } | 542 | } |