diff options
Diffstat (limited to 'src/lib/libcrypto/asn1/t_x509.c')
| -rw-r--r-- | src/lib/libcrypto/asn1/t_x509.c | 101 |
1 files changed, 33 insertions, 68 deletions
diff --git a/src/lib/libcrypto/asn1/t_x509.c b/src/lib/libcrypto/asn1/t_x509.c index 30d49cc4dd..32f1a4f4b0 100644 --- a/src/lib/libcrypto/asn1/t_x509.c +++ b/src/lib/libcrypto/asn1/t_x509.c | |||
| @@ -85,8 +85,7 @@ int X509_print_ex_fp(FILE *fp, X509 *x, unsigned long nmflag, unsigned long cfla | |||
| 85 | BIO *b; | 85 | BIO *b; |
| 86 | int ret; | 86 | int ret; |
| 87 | 87 | ||
| 88 | if ((b=BIO_new(BIO_s_file())) == NULL) | 88 | if ((b=BIO_new(BIO_s_file())) == NULL) { |
| 89 | { | ||
| 90 | X509err(X509_F_X509_PRINT_EX_FP,ERR_R_BUF_LIB); | 89 | X509err(X509_F_X509_PRINT_EX_FP,ERR_R_BUF_LIB); |
| 91 | return(0); | 90 | return(0); |
| 92 | } | 91 | } |
| @@ -122,42 +121,33 @@ int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags, unsigned long cflag) | |||
| 122 | nmindent = 16; | 121 | nmindent = 16; |
| 123 | 122 | ||
| 124 | ci=x->cert_info; | 123 | ci=x->cert_info; |
| 125 | if(!(cflag & X509_FLAG_NO_HEADER)) | 124 | if(!(cflag & X509_FLAG_NO_HEADER)) { |
| 126 | { | ||
| 127 | if (BIO_write(bp,"Certificate:\n",13) <= 0) goto err; | 125 | if (BIO_write(bp,"Certificate:\n",13) <= 0) goto err; |
| 128 | if (BIO_write(bp," Data:\n",10) <= 0) goto err; | 126 | if (BIO_write(bp," Data:\n",10) <= 0) goto err; |
| 129 | } | 127 | } |
| 130 | if(!(cflag & X509_FLAG_NO_VERSION)) | 128 | if(!(cflag & X509_FLAG_NO_VERSION)) { |
| 131 | { | ||
| 132 | l=X509_get_version(x); | 129 | l=X509_get_version(x); |
| 133 | if (BIO_printf(bp,"%8sVersion: %lu (0x%lx)\n","",l+1,l) <= 0) goto err; | 130 | if (BIO_printf(bp,"%8sVersion: %lu (0x%lx)\n","",l+1,l) <= 0) goto err; |
| 134 | } | 131 | } |
| 135 | if(!(cflag & X509_FLAG_NO_SERIAL)) | 132 | if(!(cflag & X509_FLAG_NO_SERIAL)) { |
| 136 | { | ||
| 137 | 133 | ||
| 138 | if (BIO_write(bp," Serial Number:",22) <= 0) goto err; | 134 | if (BIO_write(bp," Serial Number:",22) <= 0) goto err; |
| 139 | 135 | ||
| 140 | bs=X509_get_serialNumber(x); | 136 | bs=X509_get_serialNumber(x); |
| 141 | if (bs->length <= (int)sizeof(long)) | 137 | if (bs->length <= (int)sizeof(long)) { |
| 142 | { | ||
| 143 | l=ASN1_INTEGER_get(bs); | 138 | l=ASN1_INTEGER_get(bs); |
| 144 | if (bs->type == V_ASN1_NEG_INTEGER) | 139 | if (bs->type == V_ASN1_NEG_INTEGER) { |
| 145 | { | ||
| 146 | l= -l; | 140 | l= -l; |
| 147 | neg="-"; | 141 | neg="-"; |
| 148 | } | 142 | } else |
| 149 | else | ||
| 150 | neg=""; | 143 | neg=""; |
| 151 | if (BIO_printf(bp," %s%lu (%s0x%lx)\n",neg,l,neg,l) <= 0) | 144 | if (BIO_printf(bp," %s%lu (%s0x%lx)\n",neg,l,neg,l) <= 0) |
| 152 | goto err; | 145 | goto err; |
| 153 | } | 146 | } else { |
| 154 | else | ||
| 155 | { | ||
| 156 | neg=(bs->type == V_ASN1_NEG_INTEGER)?" (Negative)":""; | 147 | neg=(bs->type == V_ASN1_NEG_INTEGER)?" (Negative)":""; |
| 157 | if (BIO_printf(bp,"\n%12s%s","",neg) <= 0) goto err; | 148 | if (BIO_printf(bp,"\n%12s%s","",neg) <= 0) goto err; |
| 158 | 149 | ||
| 159 | for (i=0; i<bs->length; i++) | 150 | for (i=0; i<bs->length; i++) { |
| 160 | { | ||
| 161 | if (BIO_printf(bp,"%02x%c",bs->data[i], | 151 | if (BIO_printf(bp,"%02x%c",bs->data[i], |
| 162 | ((i+1 == bs->length)?'\n':':')) <= 0) | 152 | ((i+1 == bs->length)?'\n':':')) <= 0) |
| 163 | goto err; | 153 | goto err; |
| @@ -166,8 +156,7 @@ int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags, unsigned long cflag) | |||
| 166 | 156 | ||
| 167 | } | 157 | } |
| 168 | 158 | ||
| 169 | if(!(cflag & X509_FLAG_NO_SIGNAME)) | 159 | if(!(cflag & X509_FLAG_NO_SIGNAME)) { |
| 170 | { | ||
| 171 | if(X509_signature_print(bp, x->sig_alg, NULL) <= 0) | 160 | if(X509_signature_print(bp, x->sig_alg, NULL) <= 0) |
| 172 | goto err; | 161 | goto err; |
| 173 | #if 0 | 162 | #if 0 |
| @@ -180,14 +169,12 @@ int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags, unsigned long cflag) | |||
| 180 | #endif | 169 | #endif |
| 181 | } | 170 | } |
| 182 | 171 | ||
| 183 | if(!(cflag & X509_FLAG_NO_ISSUER)) | 172 | if(!(cflag & X509_FLAG_NO_ISSUER)) { |
| 184 | { | ||
| 185 | if (BIO_printf(bp," Issuer:%c",mlch) <= 0) goto err; | 173 | if (BIO_printf(bp," Issuer:%c",mlch) <= 0) goto err; |
| 186 | if (X509_NAME_print_ex(bp,X509_get_issuer_name(x),nmindent, nmflags) < 0) goto err; | 174 | if (X509_NAME_print_ex(bp,X509_get_issuer_name(x),nmindent, nmflags) < 0) goto err; |
| 187 | if (BIO_write(bp,"\n",1) <= 0) goto err; | 175 | if (BIO_write(bp,"\n",1) <= 0) goto err; |
| 188 | } | 176 | } |
| 189 | if(!(cflag & X509_FLAG_NO_VALIDITY)) | 177 | if(!(cflag & X509_FLAG_NO_VALIDITY)) { |
| 190 | { | ||
| 191 | if (BIO_write(bp," Validity\n",17) <= 0) goto err; | 178 | if (BIO_write(bp," Validity\n",17) <= 0) goto err; |
| 192 | if (BIO_write(bp," Not Before: ",24) <= 0) goto err; | 179 | if (BIO_write(bp," Not Before: ",24) <= 0) goto err; |
| 193 | if (!ASN1_TIME_print(bp,X509_get_notBefore(x))) goto err; | 180 | if (!ASN1_TIME_print(bp,X509_get_notBefore(x))) goto err; |
| @@ -195,14 +182,12 @@ int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags, unsigned long cflag) | |||
| 195 | if (!ASN1_TIME_print(bp,X509_get_notAfter(x))) goto err; | 182 | if (!ASN1_TIME_print(bp,X509_get_notAfter(x))) goto err; |
| 196 | if (BIO_write(bp,"\n",1) <= 0) goto err; | 183 | if (BIO_write(bp,"\n",1) <= 0) goto err; |
| 197 | } | 184 | } |
| 198 | if(!(cflag & X509_FLAG_NO_SUBJECT)) | 185 | if(!(cflag & X509_FLAG_NO_SUBJECT)) { |
| 199 | { | ||
| 200 | if (BIO_printf(bp," Subject:%c",mlch) <= 0) goto err; | 186 | if (BIO_printf(bp," Subject:%c",mlch) <= 0) goto err; |
| 201 | if (X509_NAME_print_ex(bp,X509_get_subject_name(x),nmindent, nmflags) < 0) goto err; | 187 | if (X509_NAME_print_ex(bp,X509_get_subject_name(x),nmindent, nmflags) < 0) goto err; |
| 202 | if (BIO_write(bp,"\n",1) <= 0) goto err; | 188 | if (BIO_write(bp,"\n",1) <= 0) goto err; |
| 203 | } | 189 | } |
| 204 | if(!(cflag & X509_FLAG_NO_PUBKEY)) | 190 | if(!(cflag & X509_FLAG_NO_PUBKEY)) { |
| 205 | { | ||
| 206 | if (BIO_write(bp," Subject Public Key Info:\n",33) <= 0) | 191 | if (BIO_write(bp," Subject Public Key Info:\n",33) <= 0) |
| 207 | goto err; | 192 | goto err; |
| 208 | if (BIO_printf(bp,"%12sPublic Key Algorithm: ","") <= 0) | 193 | if (BIO_printf(bp,"%12sPublic Key Algorithm: ","") <= 0) |
| @@ -213,13 +198,10 @@ int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags, unsigned long cflag) | |||
| 213 | goto err; | 198 | goto err; |
| 214 | 199 | ||
| 215 | pkey=X509_get_pubkey(x); | 200 | pkey=X509_get_pubkey(x); |
| 216 | if (pkey == NULL) | 201 | if (pkey == NULL) { |
| 217 | { | ||
| 218 | BIO_printf(bp,"%12sUnable to load Public Key\n",""); | 202 | BIO_printf(bp,"%12sUnable to load Public Key\n",""); |
| 219 | ERR_print_errors(bp); | 203 | ERR_print_errors(bp); |
| 220 | } | 204 | } else { |
| 221 | else | ||
| 222 | { | ||
| 223 | EVP_PKEY_print_public(bp, pkey, 16, NULL); | 205 | EVP_PKEY_print_public(bp, pkey, 16, NULL); |
| 224 | EVP_PKEY_free(pkey); | 206 | EVP_PKEY_free(pkey); |
| 225 | } | 207 | } |
| @@ -229,12 +211,10 @@ int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags, unsigned long cflag) | |||
| 229 | X509V3_extensions_print(bp, "X509v3 extensions", | 211 | X509V3_extensions_print(bp, "X509v3 extensions", |
| 230 | ci->extensions, cflag, 8); | 212 | ci->extensions, cflag, 8); |
| 231 | 213 | ||
| 232 | if(!(cflag & X509_FLAG_NO_SIGDUMP)) | 214 | if(!(cflag & X509_FLAG_NO_SIGDUMP)) { |
| 233 | { | ||
| 234 | if(X509_signature_print(bp, x->sig_alg, x->signature) <= 0) goto err; | 215 | if(X509_signature_print(bp, x->sig_alg, x->signature) <= 0) goto err; |
| 235 | } | 216 | } |
| 236 | if(!(cflag & X509_FLAG_NO_AUX)) | 217 | if(!(cflag & X509_FLAG_NO_AUX)) { |
| 237 | { | ||
| 238 | if (!X509_CERT_AUX_print(bp, x->aux, 0)) goto err; | 218 | if (!X509_CERT_AUX_print(bp, x->aux, 0)) goto err; |
| 239 | } | 219 | } |
| 240 | ret=1; | 220 | ret=1; |
| @@ -262,8 +242,7 @@ int X509_ocspid_print (BIO *bp, X509 *x) | |||
| 262 | 242 | ||
| 263 | if (!EVP_Digest(der, derlen, SHA1md, NULL, EVP_sha1(), NULL)) | 243 | if (!EVP_Digest(der, derlen, SHA1md, NULL, EVP_sha1(), NULL)) |
| 264 | goto err; | 244 | goto err; |
| 265 | for (i=0; i < SHA_DIGEST_LENGTH; i++) | 245 | for (i=0; i < SHA_DIGEST_LENGTH; i++) { |
| 266 | { | ||
| 267 | if (BIO_printf(bp,"%02X",SHA1md[i]) <= 0) goto err; | 246 | if (BIO_printf(bp,"%02X",SHA1md[i]) <= 0) goto err; |
| 268 | } | 247 | } |
| 269 | free (der); | 248 | free (der); |
| @@ -278,8 +257,7 @@ int X509_ocspid_print (BIO *bp, X509 *x) | |||
| 278 | x->cert_info->key->public_key->length, | 257 | x->cert_info->key->public_key->length, |
| 279 | SHA1md, NULL, EVP_sha1(), NULL)) | 258 | SHA1md, NULL, EVP_sha1(), NULL)) |
| 280 | goto err; | 259 | goto err; |
| 281 | for (i=0; i < SHA_DIGEST_LENGTH; i++) | 260 | for (i=0; i < SHA_DIGEST_LENGTH; i++) { |
| 282 | { | ||
| 283 | if (BIO_printf(bp,"%02X",SHA1md[i]) <= 0) | 261 | if (BIO_printf(bp,"%02X",SHA1md[i]) <= 0) |
| 284 | goto err; | 262 | goto err; |
| 285 | } | 263 | } |
| @@ -298,10 +276,8 @@ int X509_signature_dump(BIO *bp, const ASN1_STRING *sig, int indent) | |||
| 298 | 276 | ||
| 299 | n=sig->length; | 277 | n=sig->length; |
| 300 | s=sig->data; | 278 | s=sig->data; |
| 301 | for (i=0; i<n; i++) | 279 | for (i=0; i<n; i++) { |
| 302 | { | 280 | if ((i%18) == 0) { |
| 303 | if ((i%18) == 0) | ||
| 304 | { | ||
| 305 | if (BIO_write(bp,"\n",1) <= 0) return 0; | 281 | if (BIO_write(bp,"\n",1) <= 0) return 0; |
| 306 | if (BIO_indent(bp, indent, indent) <= 0) return 0; | 282 | if (BIO_indent(bp, indent, indent) <= 0) return 0; |
| 307 | } | 283 | } |
| @@ -320,12 +296,10 @@ int X509_signature_print(BIO *bp, X509_ALGOR *sigalg, ASN1_STRING *sig) | |||
| 320 | if (i2a_ASN1_OBJECT(bp, sigalg->algorithm) <= 0) return 0; | 296 | if (i2a_ASN1_OBJECT(bp, sigalg->algorithm) <= 0) return 0; |
| 321 | 297 | ||
| 322 | sig_nid = OBJ_obj2nid(sigalg->algorithm); | 298 | sig_nid = OBJ_obj2nid(sigalg->algorithm); |
| 323 | if (sig_nid != NID_undef) | 299 | if (sig_nid != NID_undef) { |
| 324 | { | ||
| 325 | int pkey_nid, dig_nid; | 300 | int pkey_nid, dig_nid; |
| 326 | const EVP_PKEY_ASN1_METHOD *ameth; | 301 | const EVP_PKEY_ASN1_METHOD *ameth; |
| 327 | if (OBJ_find_sigid_algs(sig_nid, &dig_nid, &pkey_nid)) | 302 | if (OBJ_find_sigid_algs(sig_nid, &dig_nid, &pkey_nid)) { |
| 328 | { | ||
| 329 | ameth = EVP_PKEY_asn1_find(NULL, pkey_nid); | 303 | ameth = EVP_PKEY_asn1_find(NULL, pkey_nid); |
| 330 | if (ameth && ameth->sig_print) | 304 | if (ameth && ameth->sig_print) |
| 331 | return ameth->sig_print(bp, sigalg, sig, 9, 0); | 305 | return ameth->sig_print(bp, sigalg, sig, 9, 0); |
| @@ -347,16 +321,14 @@ int ASN1_STRING_print(BIO *bp, const ASN1_STRING *v) | |||
| 347 | if (v == NULL) return(0); | 321 | if (v == NULL) return(0); |
| 348 | n=0; | 322 | n=0; |
| 349 | p=(const char *)v->data; | 323 | p=(const char *)v->data; |
| 350 | for (i=0; i<v->length; i++) | 324 | for (i=0; i<v->length; i++) { |
| 351 | { | ||
| 352 | if ((p[i] > '~') || ((p[i] < ' ') && | 325 | if ((p[i] > '~') || ((p[i] < ' ') && |
| 353 | (p[i] != '\n') && (p[i] != '\r'))) | 326 | (p[i] != '\n') && (p[i] != '\r'))) |
| 354 | buf[n]='.'; | 327 | buf[n]='.'; |
| 355 | else | 328 | else |
| 356 | buf[n]=p[i]; | 329 | buf[n]=p[i]; |
| 357 | n++; | 330 | n++; |
| 358 | if (n >= 80) | 331 | if (n >= 80) { |
| 359 | { | ||
| 360 | if (BIO_write(bp,buf,n) <= 0) | 332 | if (BIO_write(bp,buf,n) <= 0) |
| 361 | return(0); | 333 | return(0); |
| 362 | n=0; | 334 | n=0; |
| @@ -407,12 +379,10 @@ int ASN1_GENERALIZEDTIME_print(BIO *bp, const ASN1_GENERALIZEDTIME *tm) | |||
| 407 | m= (v[10]-'0')*10+(v[11]-'0'); | 379 | m= (v[10]-'0')*10+(v[11]-'0'); |
| 408 | if (tm->length >= 14 && | 380 | if (tm->length >= 14 && |
| 409 | (v[12] >= '0') && (v[12] <= '9') && | 381 | (v[12] >= '0') && (v[12] <= '9') && |
| 410 | (v[13] >= '0') && (v[13] <= '9')) | 382 | (v[13] >= '0') && (v[13] <= '9')) { |
| 411 | { | ||
| 412 | s= (v[12]-'0')*10+(v[13]-'0'); | 383 | s= (v[12]-'0')*10+(v[13]-'0'); |
| 413 | /* Check for fractions of seconds. */ | 384 | /* Check for fractions of seconds. */ |
| 414 | if (tm->length >= 15 && v[14] == '.') | 385 | if (tm->length >= 15 && v[14] == '.') { |
| 415 | { | ||
| 416 | int l = tm->length; | 386 | int l = tm->length; |
| 417 | f = &v[14]; /* The decimal point. */ | 387 | f = &v[14]; /* The decimal point. */ |
| 418 | f_len = 1; | 388 | f_len = 1; |
| @@ -475,29 +445,25 @@ int X509_NAME_print(BIO *bp, X509_NAME *name, int obase) | |||
| 475 | l=80-2-obase; | 445 | l=80-2-obase; |
| 476 | 446 | ||
| 477 | b=X509_NAME_oneline(name,NULL,0); | 447 | b=X509_NAME_oneline(name,NULL,0); |
| 478 | if (!*b) | 448 | if (!*b) { |
| 479 | { | ||
| 480 | free(b); | 449 | free(b); |
| 481 | return 1; | 450 | return 1; |
| 482 | } | 451 | } |
| 483 | s=b+1; /* skip the first slash */ | 452 | s=b+1; /* skip the first slash */ |
| 484 | 453 | ||
| 485 | c=s; | 454 | c=s; |
| 486 | for (;;) | 455 | for (;;) { |
| 487 | { | ||
| 488 | if ( ((*s == '/') && | 456 | if ( ((*s == '/') && |
| 489 | ((s[1] >= 'A') && (s[1] <= 'Z') && ( | 457 | ((s[1] >= 'A') && (s[1] <= 'Z') && ( |
| 490 | (s[2] == '=') || | 458 | (s[2] == '=') || |
| 491 | ((s[2] >= 'A') && (s[2] <= 'Z') && | 459 | ((s[2] >= 'A') && (s[2] <= 'Z') && |
| 492 | (s[3] == '=')) | 460 | (s[3] == '=')) |
| 493 | ))) || | 461 | ))) || |
| 494 | (*s == '\0')) | 462 | (*s == '\0')) { |
| 495 | { | ||
| 496 | i=s-c; | 463 | i=s-c; |
| 497 | if (BIO_write(bp,c,i) != i) goto err; | 464 | if (BIO_write(bp,c,i) != i) goto err; |
| 498 | c=s+1; /* skip following slash */ | 465 | c=s+1; /* skip following slash */ |
| 499 | if (*s != '\0') | 466 | if (*s != '\0') { |
| 500 | { | ||
| 501 | if (BIO_write(bp,", ",2) != 2) goto err; | 467 | if (BIO_write(bp,", ",2) != 2) goto err; |
| 502 | } | 468 | } |
| 503 | l--; | 469 | l--; |
| @@ -508,8 +474,7 @@ int X509_NAME_print(BIO *bp, X509_NAME *name, int obase) | |||
| 508 | } | 474 | } |
| 509 | 475 | ||
| 510 | ret=1; | 476 | ret=1; |
| 511 | if (0) | 477 | if (0) { |
| 512 | { | ||
| 513 | err: | 478 | err: |
| 514 | X509err(X509_F_X509_NAME_PRINT,ERR_R_BUF_LIB); | 479 | X509err(X509_F_X509_NAME_PRINT,ERR_R_BUF_LIB); |
| 515 | } | 480 | } |
