00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112 #ifndef HEADER_APPS_H
00113 #define HEADER_APPS_H
00114
00115 #include "e_os.h"
00116
00117 #include <openssl/bio.h>
00118 #include <openssl/x509.h>
00119 #include <openssl/lhash.h>
00120 #include <openssl/conf.h>
00121 #include <openssl/txt_db.h>
00122 #ifndef OPENSSL_NO_ENGINE
00123 #include <openssl/engine.h>
00124 #endif
00125 #include <openssl/ossl_typ.h>
00126
00127 int app_RAND_load_file(const char *file, BIO *bio_e, int dont_warn);
00128 int app_RAND_write_file(const char *file, BIO *bio_e);
00129
00130
00131 void app_RAND_allow_write_file(void);
00132 long app_RAND_load_files(char *file);
00133
00134
00135
00136
00137 #ifdef OPENSSL_SYS_WIN32
00138 #define rename(from,to) WIN32_rename((from),(to))
00139 int WIN32_rename(const char *oldname,const char *newname);
00140 #endif
00141
00142 #ifndef MONOLITH
00143
00144 #define MAIN(a,v) main(a,v)
00145
00146 #ifndef NON_MAIN
00147 CONF *config=NULL;
00148 BIO *bio_err=NULL;
00149 #else
00150 extern CONF *config;
00151 extern BIO *bio_err;
00152 #endif
00153
00154 #else
00155
00156 #define MAIN(a,v) PROG(a,v)
00157 extern CONF *config;
00158 extern char *default_config_file;
00159 extern BIO *bio_err;
00160
00161 #endif
00162
00163 #ifndef OPENSSL_SYS_NETWARE
00164 #include <signal.h>
00165 #endif
00166
00167 #ifdef SIGPIPE
00168 #define do_pipe_sig() signal(SIGPIPE,SIG_IGN)
00169 #else
00170 #define do_pipe_sig()
00171 #endif
00172
00173 #if defined(MONOLITH) && !defined(OPENSSL_C)
00174 # define apps_startup() \
00175 do_pipe_sig()
00176 # define apps_shutdown()
00177 #else
00178 # ifndef OPENSSL_NO_ENGINE
00179 # if defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_WIN16) || \
00180 defined(OPENSSL_SYS_WIN32)
00181 # ifdef _O_BINARY
00182 # define apps_startup() \
00183 do { _fmode=_O_BINARY; do_pipe_sig(); CRYPTO_malloc_init(); \
00184 ERR_load_crypto_strings(); OpenSSL_add_all_algorithms(); \
00185 ENGINE_load_builtin_engines(); setup_ui_method(); } while(0)
00186 # else
00187 # define apps_startup() \
00188 do { _fmode=O_BINARY; do_pipe_sig(); CRYPTO_malloc_init(); \
00189 ERR_load_crypto_strings(); OpenSSL_add_all_algorithms(); \
00190 ENGINE_load_builtin_engines(); setup_ui_method(); } while(0)
00191 # endif
00192 # else
00193 # define apps_startup() \
00194 do { do_pipe_sig(); OpenSSL_add_all_algorithms(); \
00195 ERR_load_crypto_strings(); ENGINE_load_builtin_engines(); \
00196 setup_ui_method(); } while(0)
00197 # endif
00198 # define apps_shutdown() \
00199 do { CONF_modules_unload(1); destroy_ui_method(); \
00200 EVP_cleanup(); ENGINE_cleanup(); \
00201 CRYPTO_cleanup_all_ex_data(); ERR_remove_state(0); \
00202 ERR_free_strings(); } while(0)
00203 # else
00204 # if defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_WIN16) || \
00205 defined(OPENSSL_SYS_WIN32)
00206 # ifdef _O_BINARY
00207 # define apps_startup() \
00208 do { _fmode=_O_BINARY; do_pipe_sig(); CRYPTO_malloc_init(); \
00209 ERR_load_crypto_strings(); OpenSSL_add_all_algorithms(); \
00210 setup_ui_method(); } while(0)
00211 # else
00212 # define apps_startup() \
00213 do { _fmode=O_BINARY; do_pipe_sig(); CRYPTO_malloc_init(); \
00214 ERR_load_crypto_strings(); OpenSSL_add_all_algorithms(); \
00215 setup_ui_method(); } while(0)
00216 # endif
00217 # else
00218 # define apps_startup() \
00219 do { do_pipe_sig(); OpenSSL_add_all_algorithms(); \
00220 ERR_load_crypto_strings(); \
00221 setup_ui_method(); } while(0)
00222 # endif
00223 # define apps_shutdown() \
00224 do { CONF_modules_unload(1); destroy_ui_method(); \
00225 EVP_cleanup(); \
00226 CRYPTO_cleanup_all_ex_data(); ERR_remove_state(0); \
00227 ERR_free_strings(); } while(0)
00228 # endif
00229 #endif
00230
00231 typedef struct args_st
00232 {
00233 char **data;
00234 int count;
00235 } ARGS;
00236
00237 #define PW_MIN_LENGTH 4
00238 typedef struct pw_cb_data
00239 {
00240 const void *password;
00241 const char *prompt_info;
00242 } PW_CB_DATA;
00243
00244 int password_callback(char *buf, int bufsiz, int verify,
00245 PW_CB_DATA *cb_data);
00246
00247 int setup_ui_method(void);
00248 void destroy_ui_method(void);
00249
00250 int should_retry(int i);
00251 int args_from_file(char *file, int *argc, char **argv[]);
00252 int str2fmt(char *s);
00253 void program_name(char *in,char *out,int size);
00254 int chopup_args(ARGS *arg,char *buf, int *argc, char **argv[]);
00255 #ifdef HEADER_X509_H
00256 int dump_cert_text(BIO *out, X509 *x);
00257 void print_name(BIO *out, const char *title, X509_NAME *nm, unsigned long lflags);
00258 #endif
00259 int set_cert_ex(unsigned long *flags, const char *arg);
00260 int set_name_ex(unsigned long *flags, const char *arg);
00261 int set_ext_copy(int *copy_type, const char *arg);
00262 int copy_extensions(X509 *x, X509_REQ *req, int copy_type);
00263 int app_passwd(BIO *err, char *arg1, char *arg2, char **pass1, char **pass2);
00264 int add_oid_section(BIO *err, CONF *conf);
00265 X509 *load_cert(BIO *err, const char *file, int format,
00266 const char *pass, ENGINE *e, const char *cert_descrip);
00267 EVP_PKEY *load_key(BIO *err, const char *file, int format, int maybe_stdin,
00268 const char *pass, ENGINE *e, const char *key_descrip);
00269 EVP_PKEY *load_pubkey(BIO *err, const char *file, int format, int maybe_stdin,
00270 const char *pass, ENGINE *e, const char *key_descrip);
00271 STACK_OF(X509) *load_certs(BIO *err, const char *file, int format,
00272 const char *pass, ENGINE *e, const char *cert_descrip);
00273 X509_STORE *setup_verify(BIO *bp, char *CAfile, char *CApath);
00274 #ifndef OPENSSL_NO_ENGINE
00275 ENGINE *setup_engine(BIO *err, const char *engine, int debug);
00276 #endif
00277
00278 int load_config(BIO *err, CONF *cnf);
00279 char *make_config_name(void);
00280
00281
00282 int unpack_revinfo(ASN1_TIME **prevtm, int *preason, ASN1_OBJECT **phold,
00283 ASN1_GENERALIZEDTIME **pinvtm, const char *str);
00284
00285 #define DB_type 0
00286 #define DB_exp_date 1
00287 #define DB_rev_date 2
00288 #define DB_serial 3
00289 #define DB_file 4
00290 #define DB_name 5
00291 #define DB_NUMBER 6
00292
00293 #define DB_TYPE_REV 'R'
00294 #define DB_TYPE_EXP 'E'
00295 #define DB_TYPE_VAL 'V'
00296
00297 typedef struct db_attr_st
00298 {
00299 int unique_subject;
00300 } DB_ATTR;
00301 typedef struct ca_db_st
00302 {
00303 DB_ATTR attributes;
00304 TXT_DB *db;
00305 } CA_DB;
00306
00307 BIGNUM *load_serial(char *serialfile, int create, ASN1_INTEGER **retai);
00308 int save_serial(char *serialfile, char *suffix, BIGNUM *serial, ASN1_INTEGER **retai);
00309 int rotate_serial(char *serialfile, char *new_suffix, char *old_suffix);
00310 int rand_serial(BIGNUM *b, ASN1_INTEGER *ai);
00311 CA_DB *load_index(char *dbfile, DB_ATTR *dbattr);
00312 int index_index(CA_DB *db);
00313 int save_index(const char *dbfile, const char *suffix, CA_DB *db);
00314 int rotate_index(const char *dbfile, const char *new_suffix, const char *old_suffix);
00315 void free_index(CA_DB *db);
00316 int index_name_cmp(const char **a, const char **b);
00317 int parse_yesno(const char *str, int def);
00318
00319 X509_NAME *parse_name(char *str, long chtype, int multirdn);
00320 int args_verify(char ***pargs, int *pargc,
00321 int *badarg, BIO *err, X509_VERIFY_PARAM **pm);
00322 void policies_print(BIO *out, X509_STORE_CTX *ctx);
00323
00324 #define FORMAT_UNDEF 0
00325 #define FORMAT_ASN1 1
00326 #define FORMAT_TEXT 2
00327 #define FORMAT_PEM 3
00328 #define FORMAT_NETSCAPE 4
00329 #define FORMAT_PKCS12 5
00330 #define FORMAT_SMIME 6
00331 #define FORMAT_ENGINE 7
00332 #define FORMAT_IISSGC 8
00333
00334
00335 #define EXT_COPY_NONE 0
00336 #define EXT_COPY_ADD 1
00337 #define EXT_COPY_ALL 2
00338
00339 #define NETSCAPE_CERT_HDR "certificate"
00340
00341 #define APP_PASS_LEN 1024
00342
00343 #define SERIAL_RAND_BITS 64
00344
00345 #endif