#include "e_os.h"#include <openssl/bio.h>#include <openssl/x509.h>#include <openssl/lhash.h>#include <openssl/conf.h>#include <openssl/txt_db.h>#include <openssl/engine.h>#include <openssl/ossl_typ.h>#include <signal.h>Go to the source code of this file.
Classes | |
| struct | args_st |
| struct | pw_cb_data |
| struct | db_attr_st |
| struct | ca_db_st |
Defines | |
| #define | MAIN(a, v) main(a,v) |
| #define | do_pipe_sig() |
| #define | apps_startup() |
| #define | apps_shutdown() |
| #define | PW_MIN_LENGTH 4 |
| #define | DB_type 0 |
| #define | DB_exp_date 1 |
| #define | DB_rev_date 2 |
| #define | DB_serial 3 |
| #define | DB_file 4 |
| #define | DB_name 5 |
| #define | DB_NUMBER 6 |
| #define | DB_TYPE_REV 'R' |
| #define | DB_TYPE_EXP 'E' |
| #define | DB_TYPE_VAL 'V' |
| #define | FORMAT_UNDEF 0 |
| #define | FORMAT_ASN1 1 |
| #define | FORMAT_TEXT 2 |
| #define | FORMAT_PEM 3 |
| #define | FORMAT_NETSCAPE 4 |
| #define | FORMAT_PKCS12 5 |
| #define | FORMAT_SMIME 6 |
| #define | FORMAT_ENGINE 7 |
| #define | FORMAT_IISSGC 8 |
| #define | EXT_COPY_NONE 0 |
| #define | EXT_COPY_ADD 1 |
| #define | EXT_COPY_ALL 2 |
| #define | NETSCAPE_CERT_HDR "certificate" |
| #define | APP_PASS_LEN 1024 |
| #define | SERIAL_RAND_BITS 64 |
Typedefs | |
| typedef args_st | ARGS |
| typedef pw_cb_data | PW_CB_DATA |
| typedef db_attr_st | DB_ATTR |
| typedef ca_db_st | CA_DB |
Functions | |
| int | app_RAND_load_file (const char *file, BIO *bio_e, int dont_warn) |
| int | app_RAND_write_file (const char *file, BIO *bio_e) |
| void | app_RAND_allow_write_file (void) |
| long | app_RAND_load_files (char *file) |
| int | password_callback (char *buf, int bufsiz, int verify, PW_CB_DATA *cb_data) |
| int | setup_ui_method (void) |
| void | destroy_ui_method (void) |
| int | should_retry (int i) |
| int | args_from_file (char *file, int *argc, char **argv[]) |
| 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 | 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) |
| int | app_passwd (BIO *err, char *arg1, char *arg2, char **pass1, char **pass2) |
| int | add_oid_section (BIO *err, CONF *conf) |
| 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)*load_certs(BIO *err | |
| X509_STORE * | setup_verify (BIO *bp, char *CAfile, char *CApath) |
| ENGINE * | setup_engine (BIO *err, const char *engine, int debug) |
| int | load_config (BIO *err, CONF *cnf) |
| char * | make_config_name (void) |
| int | unpack_revinfo (ASN1_TIME **prevtm, int *preason, ASN1_OBJECT **phold, ASN1_GENERALIZEDTIME **pinvtm, const char *str) |
| BIGNUM * | load_serial (char *serialfile, int create, ASN1_INTEGER **retai) |
| 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 *dbattr) |
| 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 | index_name_cmp (const char **a, const char **b) |
| int | parse_yesno (const char *str, int def) |
| X509_NAME * | parse_name (char *str, long chtype, int multirdn) |
| int | args_verify (char ***pargs, int *pargc, int *badarg, BIO *err, X509_VERIFY_PARAM **pm) |
| void | policies_print (BIO *out, X509_STORE_CTX *ctx) |
Variables | |
| CONF * | config = NULL |
| BIO * | bio_err = NULL |
| const char * | file |
| const char int | format |
| const char int const char * | pass |
| const char int const char ENGINE * | e |
| const char int const char ENGINE const char * | cert_descrip |
|
|
Definition at line 341 of file apps.h. Referenced by app_get_pass(). |
|
|
Value: do { CONF_modules_unload(1); destroy_ui_method(); \ EVP_cleanup(); ENGINE_cleanup(); \ CRYPTO_cleanup_all_ex_data(); ERR_remove_state(0); \ ERR_free_strings(); } while(0) |
|
|
Value: do { do_pipe_sig(); OpenSSL_add_all_algorithms(); \ ERR_load_crypto_strings(); ENGINE_load_builtin_engines(); \ setup_ui_method(); } while(0) |
|
|
|
|
|
Definition at line 289 of file apps.h. Referenced by do_body(), and do_revoke(). |
|
|
Definition at line 290 of file apps.h. Referenced by do_body(), do_revoke(), index_index(), index_name_cmp(), and index_name_hash(). |
|
|
Definition at line 291 of file apps.h. Referenced by do_body(), do_revoke(), get_certificate_status(), load_index(), and lookup_serial(). |
|
|
Definition at line 287 of file apps.h. Referenced by make_ocsp_response(). |
|
|
Definition at line 288 of file apps.h. Referenced by do_body(), do_revoke(), do_updatedb(), get_certificate_status(), index_index(), index_serial_cmp(), index_serial_hash(), and lookup_serial(). |
|
|
Definition at line 285 of file apps.h. Referenced by do_body(), do_revoke(), do_updatedb(), get_certificate_status(), and make_ocsp_response(). |
|
|
|
|
|
Definition at line 293 of file apps.h. Referenced by make_ocsp_response(). |
|
|
Definition at line 295 of file apps.h. Referenced by make_ocsp_response(). |
|
|
|
|
|
Definition at line 336 of file apps.h. Referenced by copy_extensions(), and set_ext_copy(). |
|
|
Definition at line 337 of file apps.h. Referenced by set_ext_copy(). |
|
|
Definition at line 335 of file apps.h. Referenced by copy_extensions(), and set_ext_copy(). |
|
|
Definition at line 325 of file apps.h. Referenced by load_cert(), load_crl(), load_key(), load_pubkey(), load_sess_id(), and str2fmt(). |
|
|
Definition at line 331 of file apps.h. Referenced by load_key(), load_pubkey(), and str2fmt(). |
|
|
Definition at line 332 of file apps.h. Referenced by load_key(), load_netscape_key(), and load_pubkey(). |
|
|
Definition at line 328 of file apps.h. Referenced by load_cert(), load_key(), load_pubkey(), and str2fmt(). |
|
|
Definition at line 327 of file apps.h. Referenced by certify_cert(), check(), load_cert(), load_crl(), load_key(), load_pubkey(), load_sess_id(), MAIN(), STACK_OF(), and str2fmt(). |
|
|
Definition at line 329 of file apps.h. Referenced by load_cert(), load_key(), and str2fmt(). |
|
|
Definition at line 330 of file apps.h. Referenced by str2fmt(). |
|
|
Definition at line 326 of file apps.h. Referenced by str2fmt(). |
|
|
Definition at line 324 of file apps.h. Referenced by str2fmt(). |
|
|
|
|
|
Definition at line 339 of file apps.h. Referenced by load_cert(). |
|
|
Definition at line 237 of file apps.h. Referenced by password_callback(). |
|
|
Definition at line 343 of file apps.h. Referenced by rand_serial(). |
|
|
|
|
|
|
|
|
|
|
|
|
|
||||||||||||
|
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 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 215 of file app_rand.c. References seeded. Referenced by app_RAND_load_files(). 00216 { 00217 seeded = 1; 00218 }
|
|
||||||||||||||||
|
Definition at line 122 of file app_rand.c. References BIO_flush, BIO_printf(), egdsocket, RAND_egd(), RAND_file_name(), RAND_load_file(), RAND_status(), and seeded. Referenced by MAIN(). 00123 { 00124 int consider_randfile = (file == NULL); 00125 char buffer[200]; 00126 00127 #ifdef OPENSSL_SYS_WINDOWS 00128 BIO_printf(bio_e,"Loading 'screen' into random state -"); 00129 BIO_flush(bio_e); 00130 RAND_screen(); 00131 BIO_printf(bio_e," done\n"); 00132 #endif 00133 00134 if (file == NULL) 00135 file = RAND_file_name(buffer, sizeof buffer); 00136 else if (RAND_egd(file) > 0) 00137 { 00138 /* we try if the given filename is an EGD socket. 00139 if it is, we don't write anything back to the file. */ 00140 egdsocket = 1; 00141 return 1; 00142 } 00143 if (file == NULL || !RAND_load_file(file, -1)) 00144 { 00145 if (RAND_status() == 0) 00146 { 00147 if (!dont_warn) 00148 { 00149 BIO_printf(bio_e,"unable to load 'random state'\n"); 00150 BIO_printf(bio_e,"This means that the random number generator has not been seeded\n"); 00151 BIO_printf(bio_e,"with much random data.\n"); 00152 if (consider_randfile) /* explanation does not apply when a file is explicitly named */ 00153 { 00154 BIO_printf(bio_e,"Consider setting the RANDFILE environment variable to point at a file that\n"); 00155 BIO_printf(bio_e,"'random' data can be kept in (the file will be overwritten).\n"); 00156 } 00157 } 00158 return 0; 00159 } 00160 } 00161 seeded = 1; 00162 return 1; 00163 }
|
|
|
Definition at line 165 of file app_rand.c. References app_RAND_allow_write_file(), LIST_SEPARATOR_CHAR, p, RAND_egd(), and RAND_load_file(). Referenced by MAIN(). 00166 { 00167 char *p,*n; 00168 int last; 00169 long tot=0; 00170 int egd; 00171 00172 for (;;) 00173 { 00174 last=0; 00175 for (p=name; ((*p != '\0') && (*p != LIST_SEPARATOR_CHAR)); p++); 00176 if (*p == '\0') last=1; 00177 *p='\0'; 00178 n=name; 00179 name=p+1; 00180 if (*n == '\0') break; 00181 00182 egd=RAND_egd(n); 00183 if (egd > 0) 00184 tot+=egd; 00185 else 00186 tot+=RAND_load_file(n,-1); 00187 if (last) break; 00188 } 00189 if (tot > 512) 00190 app_RAND_allow_write_file(); 00191 return(tot); 00192 }
|
|
||||||||||||
|
Definition at line 194 of file app_rand.c. References BIO_printf(), egdsocket, RAND_file_name(), RAND_write_file(), and seeded. 00195 { 00196 char buffer[200]; 00197 00198 if (egdsocket || !seeded) 00199 /* If we did not manage to read the seed file, 00200 * we should not write a low-entropy seed file back -- 00201 * it would suppress a crucial warning the next time 00202 * we want to use it. */ 00203 return 0; 00204 00205 if (file == NULL) 00206 file = RAND_file_name(buffer, sizeof buffer); 00207 if (file == NULL || !RAND_write_file(file)) 00208 { 00209 BIO_printf(bio_e,"unable to write 'random state'\n"); 00210 return 0; 00211 } 00212 return 1; 00213 }
|
|
||||||||||||||||
|
|
|
||||||||||||||||||||||||
|
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 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 1452 of file apps.c. References DB_name. Referenced by do_revoke(), and index_index().
|
|
||||||||||||||||||||||||||||