#include <stdio.h>#include <stdlib.h>#include <string.h>#include <sys/types.h>#include <sys/stat.h>#include <ctype.h>#include <openssl/err.h>#include <openssl/x509.h>#include <openssl/x509v3.h>#include <openssl/pem.h>#include <openssl/pkcs12.h>#include <openssl/ui.h>#include <openssl/safestack.h>#include <openssl/engine.h>#include <openssl/rsa.h>#include <openssl/bn.h>#include "apps.h"Go to the source code of this file.
Classes | |
| struct | NAME_EX_TBL |
Defines | |
| #define | NON_MAIN |
| #define | X509V3_EXT_UNKNOWN_MASK (0xfL << 16) |
| #define | X509V3_EXT_DEFAULT 0 |
| #define | X509V3_EXT_ERROR_UNKNOWN (1L << 16) |
| #define | X509V3_EXT_PARSE_UNKNOWN (2L << 16) |
| #define | X509V3_EXT_DUMP_UNKNOWN (3L << 16) |
| #define | X509_FLAG_CA |
| #define | BSIZE 256 |
Functions | |
| static int | set_table_opts (unsigned long *flags, const char *arg, const NAME_EX_TBL *in_tbl) |
| static int | set_multi_opts (unsigned long *flags, const char *arg, const NAME_EX_TBL *in_tbl) |
| static EVP_PKEY * | load_netscape_key (BIO *err, BIO *key, const char *file, const char *key_descrip, int format) |
| int | app_init (long mesgwin) |
| int | str2fmt (char *s) |
| void | program_name (char *in, char *out, int size) |
| int | chopup_args (ARGS *arg, char *buf, int *argc, char **argv[]) |
| int | dump_cert_text (BIO *out, X509 *x) |
| static int | ui_open (UI *ui) |
| static int | ui_read (UI *ui, UI_STRING *uis) |
| static int | ui_write (UI *ui, UI_STRING *uis) |
| static int | ui_close (UI *ui) |
| int | setup_ui_method (void) |
| void | destroy_ui_method (void) |
| int | password_callback (char *buf, int bufsiz, int verify, PW_CB_DATA *cb_tmp) |
| static char * | app_get_pass (BIO *err, char *arg, int keepbio) |
| int | app_passwd (BIO *err, char *arg1, char *arg2, char **pass1, char **pass2) |
| int | add_oid_section (BIO *err, CONF *conf) |
| static int | load_pkcs12 (BIO *err, BIO *in, const char *desc, pem_password_cb *pem_cb, void *cb_data, EVP_PKEY **pkey, X509 **cert, STACK_OF(X509)**ca) |
| X509 * | load_cert (BIO *err, const char *file, int format, const char *pass, ENGINE *e, const char *cert_descrip) |
| EVP_PKEY * | load_key (BIO *err, const char *file, int format, int maybe_stdin, const char *pass, ENGINE *e, const char *key_descrip) |
| EVP_PKEY * | load_pubkey (BIO *err, const char *file, int format, int maybe_stdin, const char *pass, ENGINE *e, const char *key_descrip) |
| STACK_OF (X509) | |
| int | set_cert_ex (unsigned long *flags, const char *arg) |
| int | set_name_ex (unsigned long *flags, const char *arg) |
| int | set_ext_copy (int *copy_type, const char *arg) |
| int | copy_extensions (X509 *x, X509_REQ *req, int copy_type) |
| void | print_name (BIO *out, const char *title, X509_NAME *nm, unsigned long lflags) |
| X509_STORE * | setup_verify (BIO *bp, char *CAfile, char *CApath) |
| static ENGINE * | try_load_engine (BIO *err, const char *engine, int debug) |
| ENGINE * | setup_engine (BIO *err, const char *engine, int debug) |
| int | load_config (BIO *err, CONF *cnf) |
| char * | make_config_name () |
| static unsigned long | index_serial_hash (const char **a) |
| static int | index_serial_cmp (const char **a, const char **b) |
| static int | index_name_qual (char **a) |
| static unsigned long | index_name_hash (const char **a) |
| int | index_name_cmp (const char **a, const char **b) |
| static | IMPLEMENT_LHASH_HASH_FN (index_serial_hash, const char **) |
| int | save_serial (char *serialfile, char *suffix, BIGNUM *serial, ASN1_INTEGER **retai) |
| int | rotate_serial (char *serialfile, char *new_suffix, char *old_suffix) |
| int | rand_serial (BIGNUM *b, ASN1_INTEGER *ai) |
| CA_DB * | load_index (char *dbfile, DB_ATTR *db_attr) |
| int | index_index (CA_DB *db) |
| int | save_index (const char *dbfile, const char *suffix, CA_DB *db) |
| int | rotate_index (const char *dbfile, const char *new_suffix, const char *old_suffix) |
| void | free_index (CA_DB *db) |
| int | parse_yesno (const char *str, int def) |
| X509_NAME * | parse_name (char *subject, long chtype, int multirdn) |
| int | args_verify (char ***pargs, int *pargc, int *badarg, BIO *err, X509_VERIFY_PARAM **pm) |
| static void | nodes_print (BIO *out, const char *name, STACK_OF(X509_POLICY_NODE)*nodes) |
| void | policies_print (BIO *out, X509_STORE_CTX *ctx) |
Variables | |
| static UI_METHOD * | ui_method = NULL |
|
|
Referenced by DES_enc_read(), DES_enc_write(), load_index(), main(), rotate_index(), rotate_serial(), save_index(), and save_serial(). |
|
|
|
|
|
Value: Definition at line 1120 of file apps.c. Referenced by set_cert_ex(). |
|
|
Definition at line 1112 of file apps.c. Referenced by set_cert_ex(), and unknown_ext_print(). |
|
|
Definition at line 1118 of file apps.c. Referenced by set_cert_ex(), and unknown_ext_print(). |
|
|
Definition at line 1114 of file apps.c. Referenced by set_cert_ex(), and unknown_ext_print(). |
|
|
Definition at line 1116 of file apps.c. Referenced by set_cert_ex(), and unknown_ext_print(). |
|
|
Definition at line 1110 of file apps.c. Referenced by set_cert_ex(), and unknown_ext_print(). |
|
||||||||||||
|
Definition at line 674 of file apps.c. References BIO_printf(), ERR_clear_error(), CONF_VALUE::name, NCONF_get_string(), NID_undef, OBJ_create(), sk_CONF_VALUE_num, sk_CONF_VALUE_value, STACK_OF, and CONF_VALUE::value. 00675 { 00676 char *p; 00677 STACK_OF(CONF_VALUE) *sktmp; 00678 CONF_VALUE *cnf; 00679 int i; 00680 if(!(p=NCONF_get_string(conf,NULL,"oid_section"))) 00681 { 00682 ERR_clear_error(); 00683 return 1; 00684 } 00685 if(!(sktmp = NCONF_get_section(conf, p))) { 00686 BIO_printf(err, "problem loading oid section %s\n", p); 00687 return 0; 00688 } 00689 for(i = 0; i < sk_CONF_VALUE_num(sktmp); i++) { 00690 cnf = sk_CONF_VALUE_value(sktmp, i); 00691 if(OBJ_create(cnf->value, cnf->name, cnf->name) == NID_undef) { 00692 BIO_printf(err, "problem creating object %s=%s\n", 00693 cnf->name, cnf->value); 00694 return 0; 00695 } 00696 } 00697 return 1; 00698 }
|
|
||||||||||||||||
|
Definition at line 617 of file apps.c. References APP_PASS_LEN, BIO_f_buffer(), BIO_free_all(), BIO_gets(), BIO_new(), BIO_new_fd(), BIO_new_file(), BIO_new_fp(), BIO_NOCLOSE, BIO_printf(), BIO_push(), and BUF_strdup(). Referenced by app_passwd(). 00618 { 00619 char *tmp, tpass[APP_PASS_LEN]; 00620 static BIO *pwdbio = NULL; 00621 int i; 00622 if(!strncmp(arg, "pass:", 5)) return BUF_strdup(arg + 5); 00623 if(!strncmp(arg, "env:", 4)) { 00624 tmp = getenv(arg + 4); 00625 if(!tmp) { 00626 BIO_printf(err, "Can't read environment variable %s\n", arg + 4); 00627 return NULL; 00628 } 00629 return BUF_strdup(tmp); 00630 } 00631 if(!keepbio || !pwdbio) { 00632 if(!strncmp(arg, "file:", 5)) { 00633 pwdbio = BIO_new_file(arg + 5, "r"); 00634 if(!pwdbio) { 00635 BIO_printf(err, "Can't open file %s\n", arg + 5); 00636 return NULL; 00637 } 00638 } else if(!strncmp(arg, "fd:", 3)) { 00639 BIO *btmp; 00640 i = atoi(arg + 3); 00641 if(i >= 0) pwdbio = BIO_new_fd(i, BIO_NOCLOSE); 00642 if((i < 0) || !pwdbio) { 00643 BIO_printf(err, "Can't access file descriptor %s\n", arg + 3); 00644 return NULL; 00645 } 00646 /* Can't do BIO_gets on an fd BIO so add a buffering BIO */ 00647 btmp = BIO_new(BIO_f_buffer()); 00648 pwdbio = BIO_push(btmp, pwdbio); 00649 } else if(!strcmp(arg, "stdin")) { 00650 pwdbio = BIO_new_fp(stdin, BIO_NOCLOSE); 00651 if(!pwdbio) { 00652 BIO_printf(err, "Can't open BIO for stdin\n"); 00653 return NULL; 00654 } 00655 } else { 00656 BIO_printf(err, "Invalid password argument \"%s\"\n", arg); 00657 return NULL; 00658 } 00659 } 00660 i = BIO_gets(pwdbio, tpass, APP_PASS_LEN); 00661 if(keepbio != 1) { 00662 BIO_free_all(pwdbio); 00663 pwdbio = NULL; 00664 } 00665 if(i <= 0) { 00666 BIO_printf(err, "Error reading password from BIO\n"); 00667 return NULL; 00668 } 00669 tmp = strchr(tpass, '\n'); 00670 if(tmp) *tmp = 0; 00671 return BUF_strdup(tpass); 00672 }
|
|
|
Definition at line 421 of file apps.c.
|
|
||||||||||||||||||||||||
|
Definition at line 601 of file apps.c. References app_get_pass(). Referenced by MAIN(). 00602 { 00603 int same; 00604 if(!arg2 || !arg1 || strcmp(arg1, arg2)) same = 0; 00605 else same = 1; 00606 if(arg1) { 00607 *pass1 = app_get_pass(err, arg1, same); 00608 if(!*pass1) return 0; 00609 } else if(pass1) *pass1 = NULL; 00610 if(arg2) { 00611 *pass2 = app_get_pass(err, arg2, same ? 2 : 0); 00612 if(!*pass2) return 0; 00613 } else if(pass2) *pass2 = NULL; 00614 return 1; 00615 }
|
|
||||||||||||||||||||||||
|
Definition at line 2198 of file apps.c. References BIO_printf(), flags, OBJ_txt2obj(), X509_PURPOSE_get0(), X509_PURPOSE_get_by_sname(), X509_PURPOSE_get_id(), X509_V_FLAG_CB_ISSUER_CHECK, X509_V_FLAG_CRL_CHECK, X509_V_FLAG_CRL_CHECK_ALL, X509_V_FLAG_EXPLICIT_POLICY, X509_V_FLAG_IGNORE_CRITICAL, X509_V_FLAG_NOTIFY_POLICY, X509_V_FLAG_POLICY_CHECK, X509_V_FLAG_X509_STRICT, X509_VERIFY_PARAM_add0_policy(), X509_VERIFY_PARAM_free(), X509_VERIFY_PARAM_new(), X509_VERIFY_PARAM_set_flags(), and X509_VERIFY_PARAM_set_purpose(). 02200 { 02201 ASN1_OBJECT *otmp = NULL; 02202 unsigned long flags = 0; 02203 int i; 02204 int purpose = 0; 02205 char **oldargs = *pargs; 02206 char *arg = **pargs, *argn = (*pargs)[1]; 02207 if (!strcmp(arg, "-policy")) 02208 { 02209 if (!argn) 02210 *badarg = 1; 02211 else 02212 { 02213 otmp = OBJ_txt2obj(argn, 0); 02214 if (!otmp) 02215 { 02216 BIO_printf(err, "Invalid Policy \"%s\"\n", 02217 argn); 02218 *badarg = 1; 02219 } 02220 } 02221 (*pargs)++; 02222 } 02223 else if (strcmp(arg,"-purpose") == 0) 02224 { 02225 X509_PURPOSE *xptmp; 02226 if (!argn) 02227 *badarg = 1; 02228 else 02229 { 02230 i = X509_PURPOSE_get_by_sname(argn); 02231 if(i < 0) 02232 { 02233 BIO_printf(err, "unrecognized purpose\n"); 02234 *badarg = 1; 02235 } 02236 else 02237 { 02238 xptmp = X509_PURPOSE_get0(i); 02239 purpose = X509_PURPOSE_get_id(xptmp); 02240 } 02241 } 02242 (*pargs)++; 02243 } 02244 else if (!strcmp(arg, "-ignore_critical")) 02245 flags |= X509_V_FLAG_IGNORE_CRITICAL; 02246 else if (!strcmp(arg, "-issuer_checks")) 02247 flags |= X509_V_FLAG_CB_ISSUER_CHECK; 02248 else if (!strcmp(arg, "-crl_check")) 02249 flags |= X509_V_FLAG_CRL_CHECK; 02250 else if (!strcmp(arg, "-crl_check_all")) 02251 flags |= X509_V_FLAG_CRL_CHECK|X509_V_FLAG_CRL_CHECK_ALL; 02252 else if (!strcmp(arg, "-policy_check")) 02253 flags |= X509_V_FLAG_POLICY_CHECK; 02254 else if (!strcmp(arg, "-explicit_policy")) 02255 flags |= X509_V_FLAG_EXPLICIT_POLICY; 02256 else if (!strcmp(arg, "-x509_strict")) 02257 flags |= X509_V_FLAG_X509_STRICT; 02258 else if (!strcmp(arg, "-policy_print")) 02259 flags |= X509_V_FLAG_NOTIFY_POLICY; 02260 else 02261 return 0; 02262 02263 if (*badarg) 02264 { 02265 if (*pm) 02266 X509_VERIFY_PARAM_free(*pm); 02267 *pm = NULL; 02268 goto end; 02269 } 02270 02271 if (!*pm && !(*pm = X509_VERIFY_PARAM_new())) 02272 { 02273 *badarg = 1; 02274 goto end; 02275 } 02276 02277 if (otmp) 02278 X509_VERIFY_PARAM_add0_policy(*pm, otmp); 02279 if (flags) 02280 X509_VERIFY_PARAM_set_flags(*pm, flags); 02281 02282 if (purpose) 02283 X509_VERIFY_PARAM_set_purpose(*pm, purpose); 02284 02285 end: 02286 02287 (*pargs)++; 02288 02289 if (pargc) 02290 *pargc -= *pargs - oldargs; 02291 02292 return 1; 02293 02294 }
|
|
||||||||||||||||||||
|
Definition at line 348 of file apps.c. References args_st::count, args_st::data, OPENSSL_malloc, and OPENSSL_realloc. Referenced by main(). 00349 { 00350 int num,len,i; 00351 char *p; 00352 00353 *argc=0; 00354 *argv=NULL; 00355 00356 len=strlen(buf); 00357 i=0; 00358 if (arg->count == 0) 00359 { 00360 arg->count=20; 00361 arg->data=(char **)OPENSSL_malloc(sizeof(char *)*arg->count); 00362 } 00363 for (i=0; i<arg->count; i++) 00364 arg->data[i]=NULL; 00365 00366 num=0; 00367 p=buf; 00368 for (;;) 00369 { 00370 /* first scan over white space */ 00371 if (!*p) break; 00372 while (*p && ((*p == ' ') || (*p == '\t') || (*p == '\n'))) 00373 p++; 00374 if (!*p) break; 00375 00376 /* The start of something good :-) */ 00377 if (num >= arg->count) 00378 { 00379 char **tmp_p; 00380 int tlen = arg->count + 20; 00381 tmp_p = (char **)OPENSSL_realloc(arg->data, 00382 sizeof(char *)*tlen); 00383 if (tmp_p == NULL) 00384 return 0; 00385 arg->data = tmp_p; 00386 arg->count = tlen; 00387 /* initialize newly allocated data */ 00388 for (i = num; i < arg->count; i++) 00389 arg->data[i] = NULL; 00390 } 00391 arg->data[num++]=p; 00392 00393 /* now look for the end of this */ 00394 if ((*p == '\'') || (*p == '\"')) /* scan for closing quote */ 00395 { 00396 i= *(p++); 00397 arg->data[num-1]++; /* jump over quote */ 00398 while (*p && (*p != i)) 00399 p++; 00400 *p='\0'; 00401 } 00402 else 00403 { 00404 while (*p && ((*p != ' ') && 00405 (*p != '\t') && (*p != '\n'))) 00406 p++; 00407 00408 if (*p == '\0') 00409 p--; 00410 else 00411 *p='\0'; 00412 } 00413 p++; 00414 } 00415 *argc=num; 00416 *argv=arg->data; 00417 return(1); 00418 }
|
|
||||||||||||||||
|
Definition at line 1197 of file apps.c. References EXT_COPY_ADD, EXT_COPY_NONE, obj, ret, sk_X509_EXTENSION_num, sk_X509_EXTENSION_pop_free, sk_X509_EXTENSION_value, STACK_OF, X509_add_ext(), X509_delete_ext(), X509_EXTENSION_get_object(), X509_get_ext(), and X509_get_ext_by_OBJ(). Referenced by do_body(). 01198 { 01199 STACK_OF(X509_EXTENSION) *exts = NULL; 01200 X509_EXTENSION *ext, *tmpext; 01201 ASN1_OBJECT *obj; 01202 int i, idx, ret = 0; 01203 if (!x || !req || (copy_type == EXT_COPY_NONE)) 01204 return 1; 01205 exts = X509_REQ_get_extensions(req); 01206 01207 for(i = 0; i < sk_X509_EXTENSION_num(exts); i++) { 01208 ext = sk_X509_EXTENSION_value(exts, i); 01209 obj = X509_EXTENSION_get_object(ext); 01210 idx = X509_get_ext_by_OBJ(x, obj, -1); 01211 /* Does extension exist? */ 01212 if (idx != -1) { 01213 /* If normal copy don't override existing extension */ 01214 if (copy_type == EXT_COPY_ADD) 01215 continue; 01216 /* Delete all extensions of same type */ 01217 do { 01218 tmpext = X509_get_ext(x, idx); 01219 X509_delete_ext(x, idx); 01220 X509_EXTENSION_free(tmpext); 01221 idx = X509_get_ext_by_OBJ(x, obj, -1); 01222 } while (idx != -1); 01223 } 01224 if (!X509_add_ext(x, ext, -1)) 01225 goto end; 01226 } 01227 01228 ret = 1; 01229 01230 end: 01231 01232 sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free); 01233 01234 return ret; 01235 }
|
|
|
Definition at line 508 of file apps.c. References UI_destroy_method(). 00509 { 00510 if(ui_method) 00511 { 00512 UI_destroy_method(ui_method); 00513 ui_method = NULL; 00514 } 00515 }
|
|
||||||||||||
|
Definition at line 428 of file apps.c. References BIO_puts(), OPENSSL_free, X509_get_issuer_name(), X509_get_subject_name(), and X509_NAME_oneline(). Referenced by dump_certs_pkeys_bag(). 00429 { 00430 char *p; 00431 00432 p=X509_NAME_oneline(X509_get_subject_name(x),NULL,0); 00433 BIO_puts(out,"subject="); 00434 BIO_puts(out,p); 00435 OPENSSL_free(p); 00436 00437 p=X509_NAME_oneline(X509_get_issuer_name(x),NULL,0); 00438 BIO_puts(out,"\nissuer="); 00439 BIO_puts(out,p); 00440 BIO_puts(out,"\n"); 00441 OPENSSL_free(p); 00442 00443 return 0; 00444 }
|
|
|
Definition at line 1985 of file apps.c. References ca_db_st::db, OPENSSL_free, and TXT_DB_free(). 01986 { 01987 if (db) 01988 { 01989 if (db->db) TXT_DB_free(db->db); 01990 OPENSSL_free(db); 01991 } 01992 }
|
|
||||||||||||
|
Definition at line 1456 of file apps.c. References a2i_ASN1_INTEGER(), ASN1_INTEGER_to_BN(), bio_err, BIO_free(), BIO_new(), BIO_printf(), BIO_read_filename, BIO_s_file(), BN_new(), ERR_print_errors(), MS_STATIC, rand_serial(), and ret. 01465 { 01466 BIO *in=NULL; 01467 BIGNUM *ret=NULL; 01468 MS_STATIC char buf[1024]; 01469 ASN1_INTEGER *ai=NULL; 01470 01471 ai=ASN1_INTEGER_new(); 01472 if (ai == NULL) goto err; 01473 01474 if ((in=BIO_new(BIO_s_file())) == NULL) 01475 { 01476 ERR_print_errors(bio_err); 01477 goto err; 01478 } 01479 01480 if (BIO_read_filename(in,serialfile) <= 0) 01481 { 01482 if (!create) 01483 { 01484 perror(serialfile); 01485 goto err; 01486 } 01487 else 01488 { 01489 ret=BN_new(); 01490 if (ret == NULL || !rand_serial(ret, ai)) 01491 BIO_printf(bio_err, "Out of memory\n"); 01492 } 01493 } 01494 else 01495 { 01496 if (!a2i_ASN1_INTEGER(in,ai,buf,1024)) 01497 { 01498 BIO_printf(bio_err,"unable to load number from %s\n", 01499 serialfile); 01500 goto err; 01501 } 01502 ret=ASN1_INTEGER_to_BN(ai,NULL); 01503 if (ret == NULL) 01504 { 01505 BIO_printf(bio_err,"error converting number from bin to BIGNUM\n"); 01506 goto err; 01507 } 01508 } 01509 01510 if (ret && retai) 01511 { 01512 *retai = ai; 01513 ai = NULL; 01514 } 01515 err: 01516 if (in != NULL) BIO_free(in); 01517 if (ai != NULL) ASN1_INTEGER_free(ai); 01518 return(ret); 01519 }
|
|
|
||||||||||||
|
Definition at line 1452 of file apps.c. References DB_name. Referenced by do_revoke(), and index_index().
|
|
|
Definition at line 1449 of file apps.c. References DB_name, and lh_strhash(). Referenced by index_index(). 01450 { return(lh_strhash(a[DB_name])); }
|
|
|
Definition at line 1446 of file apps.c. Referenced by index_index(). 01447 { return(a[0][0] == 'V'); }
|
|
||||||||||||
|
Definition at line 1437 of file apps.c. Referenced by index_index(). 01438 { 01439 const char *aa,*bb; 01440 01441 for (aa=a[DB_serial]; *aa == '0'; aa++); 01442 for (bb=b[DB_serial]; *bb == '0'; bb++); 01443 return(strcmp(aa,bb)); 01444 }
|
|
|
Definition at line 1428 of file apps.c. References DB_serial, and lh_strhash(). Referenced by index_index(). 01429 { 01430 const char *n; 01431 01432 n=a[DB_serial]; 01433 while (*n == '0') n++; 01434 return(lh_strhash(n)); 01435 }
|
|
||||||||||||||||||||||||||||
|
Definition at line 745 of file apps.c. References ASN1_HEADER_free(), BIO_free(), BIO_new(), BIO_NOCLOSE, BIO_printf(), BIO_read(), BIO_read_filename, BIO_s_file(), BIO_set_fp, BUF_MEM_free(), BUF_MEM_grow(), BUF_MEM_new(), d2i_ASN1_HEADER(), d2i_X509_bio(), buf_mem_st::data, asn1_string_st::data, asn1_header_st::data, ERR_print_errors(), FORMAT_ASN1, FORMAT_NETSCAPE, FORMAT_PEM, FORMAT_PKCS12, asn1_header_st::header, asn1_string_st::length, load_pkcs12(), asn1_header_st::meth, NETSCAPE_CERT_HDR, password_callback(), x, and X509_asn1_meth(). Referenced by certify_cert(), check(), and MAIN(). 00747 { 00748 ASN1_HEADER *ah=NULL; 00749 BUF_MEM *buf=NULL; 00750 X509 *x=NULL; 00751 BIO *cert; 00752 00753 if ((cert=BIO_new(BIO_s_file())) == NULL) 00754 { 00755 ERR_print_errors(err); 00756 goto end; 00757 } 00758 00759 if (file == NULL) 00760 { 00761 setvbuf(stdin, NULL, _IONBF, 0); 00762 BIO_set_fp(cert,stdin,BIO_NOCLOSE); 00763 } 00764 else 00765 { 00766 if (BIO_read_filename(cert,file) <= 0) 00767 { 00768 BIO_printf(err, "Error opening %s %s\n", 00769 cert_descrip, file); 00770 ERR_print_errors(err); 00771 goto end; 00772 } 00773 } 00774 00775 if (format == FORMAT_ASN1) 00776 x=d2i_X509_bio(cert,NULL); 00777 else if (format == FORMAT_NETSCAPE) 00778 { 00779 const unsigned char *p,*op; 00780 int size=0,i; 00781 00782 /* We sort of have to do it this way because it is sort of nice 00783 * to read the header first and check it, then 00784 * try to read the certificate */ 00785 buf=BUF_MEM_new(); 00786 for (;;) 00787 { 00788 if ((buf == NULL) || (!BUF_MEM_grow(buf,size+1024*10))) 00789 goto end; 00790 i=BIO_read(cert,&(buf->data[size]),1024*10); 00791 size+=i; 00792 if (i == 0) break; 00793 if (i < 0) 00794 { 00795 perror("reading certificate"); 00796 goto end; 00797 } 00798 } 00799 p=(unsigned char *)buf->data; 00800 op=p; 00801 00802 /* First load the header */ 00803 if ((ah=d2i_ASN1_HEADER(NULL,&p,(long)size)) == NULL) 00804 goto end; 00805 if ((ah->header == NULL) || (ah->header->data == NULL) || 00806 (strncmp(NETSCAPE_CERT_HDR,(char *)ah->header->data, 00807 ah->header->length) != 0)) 00808 { 00809 BIO_printf(err,"Error reading header on certificate\n"); 00810 goto end; 00811 } 00812 /* header is ok, so now read the object */ 00813 p=op; 00814 ah->meth=X509_asn1_meth(); 00815 if ((ah=d2i_ASN1_HEADER(&ah,&p,(long)size)) == NULL) 00816 goto end; 00817 x=(X509 *)ah->data; 00818 ah->data=NULL; 00819 } 00820 else if (format == FORMAT_PEM) 00821 x=PEM_read_bio_X509_AUX(cert,NULL, 00822 (pem_password_cb *)password_callback, NULL); 00823 else if (format == FORMAT_PKCS12) 00824 { 00825 if (!load_pkcs12(err, cert,cert_descrip, NULL, NULL, 00826 NULL, &x, NULL)) 00827 goto end; 00828 } 00829 else { 00830 BIO_printf(err,"bad input format specified for %s\n", 00831 cert_descrip); 00832 goto end; 00833 } 00834 end: 00835 if (x == NULL) 00836 { 00837 BIO_printf(err,"unable to load certificate\n"); 00838 ERR_print_errors(err); 00839 } 00840 if (ah != NULL) ASN1_HEADER_free(ah); 00841 if (cert != NULL) BIO_free(cert); 00842 if (buf != NULL) BUF_MEM_free(buf); 00843 return(x); 00844 }
|
|
||||||||||||
|
Definition at line 1393 of file apps.c. References BIO_printf(), CONF_modules_load(), config, ERR_print_errors(), and OPENSSL_load_builtin_modules(). Referenced by MAIN(). 01394 { 01395 if (!cnf) 01396 cnf = config; 01397 if (!cnf) 01398 return 1; 01399 01400 OPENSSL_load_builtin_modules(); 01401 01402 if (CONF_modules_load(cnf, NULL, 0) <= 0) 01403 { 01404 BIO_printf(err, "Error configuring OpenSSL\n"); 01405 ERR_print_errors(err); 01406 return 0; 01407 } 01408 return 1; 01409 }
|
|
||||||||||||
|
Definition at line 1681 of file apps.c. References ca_db_st::attributes, bio_err, BIO_free_all(), BIO_new(), BIO_printf(), BIO_read_filename, BIO_s_file(), BIO_snprintf(), BSIZE, ca_db_st::db, DB_NUMBER, ERR_print_errors(), NCONF_free(), NCONF_get_string(), NCONF_load(), NCONF_new(), OPENSSL_malloc, parse_yesno(), TXT_DB_free(), TXT_DB_read(), and db_attr_st::unique_subject. 01682 { 01683 CA_DB *retdb = NULL; 01684 TXT_DB *tmpdb = NULL; 01685 BIO *in = BIO_new(BIO_s_file()); 01686 CONF *dbattr_conf = NULL; 01687 char buf[1][BSIZE]; 01688 long errorline= -1; 01689 01690 if (in == NULL) 01691 { 01692 ERR_print_errors(bio_err); 01693 goto err; 01694 } 01695 if (BIO_read_filename(in,dbfile) <= 0) 01696 { 01697 perror(dbfile); 01698 BIO_printf( |