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 #ifndef OPENSSL_NO_OCSP
00126 #include <openssl/ocsp.h>
00127 #endif
00128 #include <openssl/ossl_typ.h>
00129
00130 int app_RAND_load_file(const char *file, BIO *bio_e, int dont_warn);
00131 int app_RAND_write_file(const char *file, BIO *bio_e);
00132
00133
00134 void app_RAND_allow_write_file(void);
00135 long app_RAND_load_files(char *file);
00136
00137
00138
00139
00140 #ifndef MONOLITH
00141
00142 #define MAIN(a,v) main(a,v)
00143
00144 #ifndef NON_MAIN
00145 CONF *config=NULL;
00146 BIO *bio_err=NULL;
00147 #else
00148 extern CONF *config;
00149 extern BIO *bio_err;
00150 #endif
00151
00152 #else
00153
00154 #define MAIN(a,v) PROG(a,v)
00155 extern CONF *config;
00156 extern char *default_config_file;
00157 extern BIO *bio_err;
00158
00159 #endif
00160
00161 #ifndef OPENSSL_SYS_NETWARE
00162 #include <signal.h>
00163 #endif
00164
00165 #ifdef SIGPIPE
00166 #define do_pipe_sig() signal(SIGPIPE,SIG_IGN)
00167 #else
00168 #define do_pipe_sig()
00169 #endif
00170
00171 #ifdef OPENSSL_NO_COMP
00172 #define zlib_cleanup()
00173 #else
00174 #define zlib_cleanup() COMP_zlib_cleanup()
00175 #endif
00176
00177 #if defined(MONOLITH) && !defined(OPENSSL_C)
00178 # define apps_startup() \
00179 do_pipe_sig()
00180 # define apps_shutdown()
00181 #else
00182 # ifndef OPENSSL_NO_ENGINE
00183 # define apps_startup() \
00184 do { do_pipe_sig(); CRYPTO_malloc_init(); \
00185 ERR_load_crypto_strings(); OpenSSL_add_all_algorithms(); \
00186 ENGINE_load_builtin_engines(); setup_ui_method(); } while(0)
00187 # define apps_shutdown() \
00188 do { CONF_modules_unload(1); destroy_ui_method(); \
00189 OBJ_cleanup(); EVP_cleanup(); ENGINE_cleanup(); \
00190 CRYPTO_cleanup_all_ex_data(); ERR_remove_thread_state(NULL); \
00191 ERR_free_strings(); zlib_cleanup();} while(0)
00192 # else
00193 # define apps_startup() \
00194 do { do_pipe_sig(); CRYPTO_malloc_init(); \
00195 ERR_load_crypto_strings(); OpenSSL_add_all_algorithms(); \
00196 setup_ui_method(); } while(0)
00197 # define apps_shutdown() \
00198 do { CONF_modules_unload(1); destroy_ui_method(); \
00199 OBJ_cleanup(); EVP_cleanup(); \
00200 CRYPTO_cleanup_all_ex_data(); ERR_remove_thread_state(NULL); \
00201 ERR_free_strings(); zlib_cleanup(); } while(0)
00202 # endif
00203 #endif
00204
00205 #ifdef OPENSSL_SYSNAME_WIN32
00206 # define openssl_fdset(a,b) FD_SET((unsigned int)a, b)
00207 #else
00208 # define openssl_fdset(a,b) FD_SET(a, b)
00209 #endif
00210
00211
00212 typedef struct args_st
00213 {
00214 char **data;
00215 int count;
00216 } ARGS;
00217
00218 #define PW_MIN_LENGTH 4
00219 typedef struct pw_cb_data
00220 {
00221 const void *password;
00222 const char *prompt_info;
00223 } PW_CB_DATA;
00224
00225 int password_callback(char *buf, int bufsiz, int verify,
00226 PW_CB_DATA *cb_data);
00227
00228 int setup_ui_method(void);
00229 void destroy_ui_method(void);
00230
00231 int should_retry(int i);
00232 int args_from_file(char *file, int *argc, char **argv[]);
00233 int str2fmt(char *s);
00234 void program_name(char *in,char *out,int size);
00235 int chopup_args(ARGS *arg,char *buf, int *argc, char **argv[]);
00236 #ifdef HEADER_X509_H
00237 int dump_cert_text(BIO *out, X509 *x);
00238 void print_name(BIO *out, const char *title, X509_NAME *nm, unsigned long lflags);
00239 #endif
00240 int set_cert_ex(unsigned long *flags, const char *arg);
00241 int set_name_ex(unsigned long *flags, const char *arg);
00242 int set_ext_copy(int *copy_type, const char *arg);
00243 int copy_extensions(X509 *x, X509_REQ *req, int copy_type);
00244 int app_passwd(BIO *err, char *arg1, char *arg2, char **pass1, char **pass2);
00245 int add_oid_section(BIO *err, CONF *conf);
00246 X509 *load_cert(BIO *err, const char *file, int format,
00247 const char *pass, ENGINE *e, const char *cert_descrip);
00248 EVP_PKEY *load_key(BIO *err, const char *file, int format, int maybe_stdin,
00249 const char *pass, ENGINE *e, const char *key_descrip);
00250 EVP_PKEY *load_pubkey(BIO *err, const char *file, int format, int maybe_stdin,
00251 const char *pass, ENGINE *e, const char *key_descrip);
00252 STACK_OF(X509) *load_certs(BIO *err, const char *file, int format,
00253 const char *pass, ENGINE *e, const char *cert_descrip);
00254 STACK_OF(X509_CRL) *load_crls(BIO *err, const char *file, int format,
00255 const char *pass, ENGINE *e, const char *cert_descrip);
00256 X509_STORE *setup_verify(BIO *bp, const char *CAfile, char *CApath);
00257 #ifndef OPENSSL_NO_ENGINE
00258 ENGINE *setup_engine(BIO *err, const char *engine, int debug);
00259 #endif
00260
00261 #ifndef OPENSSL_NO_OCSP
00262 OCSP_RESPONSE *process_responder(BIO *err, OCSP_REQUEST *req,
00263 char *host, char *path, char *port, int use_ssl,
00264 STACK_OF(CONF_VALUE) *headers,
00265 int req_timeout);
00266 #endif
00267
00268 int load_config(BIO *err, CONF *cnf);
00269 char *make_config_name(void);
00270
00271
00272 int unpack_revinfo(ASN1_TIME **prevtm, int *preason, ASN1_OBJECT **phold,
00273 ASN1_GENERALIZEDTIME **pinvtm, const char *str);
00274
00275 #define DB_type 0
00276 #define DB_exp_date 1
00277 #define DB_rev_date 2
00278 #define DB_serial 3
00279 #define DB_file 4
00280 #define DB_name 5
00281 #define DB_NUMBER 6
00282
00283 #define DB_TYPE_REV 'R'
00284 #define DB_TYPE_EXP 'E'
00285 #define DB_TYPE_VAL 'V'
00286
00287 typedef struct db_attr_st
00288 {
00289 int unique_subject;
00290 } DB_ATTR;
00291 typedef struct ca_db_st
00292 {
00293 DB_ATTR attributes;
00294 TXT_DB *db;
00295 } CA_DB;
00296
00297 BIGNUM *load_serial(char *serialfile, int create, ASN1_INTEGER **retai);
00298 int save_serial(char *serialfile, char *suffix, BIGNUM *serial, ASN1_INTEGER **retai);
00299 int rotate_serial(char *serialfile, char *new_suffix, char *old_suffix);
00300 int rand_serial(BIGNUM *b, ASN1_INTEGER *ai);
00301 CA_DB *load_index(char *dbfile, DB_ATTR *dbattr);
00302 int index_index(CA_DB *db);
00303 int save_index(const char *dbfile, const char *suffix, CA_DB *db);
00304 int rotate_index(const char *dbfile, const char *new_suffix, const char *old_suffix);
00305 void free_index(CA_DB *db);
00306 #define index_name_cmp_noconst(a, b) \
00307 index_name_cmp((const OPENSSL_CSTRING *)CHECKED_PTR_OF(OPENSSL_STRING, a), \
00308 (const OPENSSL_CSTRING *)CHECKED_PTR_OF(OPENSSL_STRING, b))
00309 int index_name_cmp(const OPENSSL_CSTRING *a, const OPENSSL_CSTRING *b);
00310 int parse_yesno(const char *str, int def);
00311
00312 X509_NAME *parse_name(char *str, long chtype, int multirdn);
00313 int args_verify(char ***pargs, int *pargc,
00314 int *badarg, BIO *err, X509_VERIFY_PARAM **pm);
00315 void policies_print(BIO *out, X509_STORE_CTX *ctx);
00316 int bio_to_mem(unsigned char **out, int maxlen, BIO *in);
00317 int pkey_ctrl_string(EVP_PKEY_CTX *ctx, char *value);
00318 int init_gen_str(BIO *err, EVP_PKEY_CTX **pctx,
00319 const char *algname, ENGINE *e, int do_param);
00320 #ifndef OPENSSL_NO_PSK
00321 extern char *psk_key;
00322 #endif
00323 #ifndef OPENSSL_NO_JPAKE
00324 void jpake_client_auth(BIO *out, BIO *conn, const char *secret);
00325 void jpake_server_auth(BIO *out, BIO *conn, const char *secret);
00326 #endif
00327
00328 #define FORMAT_UNDEF 0
00329 #define FORMAT_ASN1 1
00330 #define FORMAT_TEXT 2
00331 #define FORMAT_PEM 3
00332 #define FORMAT_NETSCAPE 4
00333 #define FORMAT_PKCS12 5
00334 #define FORMAT_SMIME 6
00335 #define FORMAT_ENGINE 7
00336 #define FORMAT_IISSGC 8
00337
00338 #define FORMAT_PEMRSA 9
00339 #define FORMAT_ASN1RSA 10
00340 #define FORMAT_MSBLOB 11
00341 #define FORMAT_PVK 12
00342
00343 #define EXT_COPY_NONE 0
00344 #define EXT_COPY_ADD 1
00345 #define EXT_COPY_ALL 2
00346
00347 #define NETSCAPE_CERT_HDR "certificate"
00348
00349 #define APP_PASS_LEN 1024
00350
00351 #define SERIAL_RAND_BITS 64
00352
00353 int app_isdir(const char *);
00354 int raw_read_stdin(void *,int);
00355 int raw_write_stdout(const void *,int);
00356
00357 #define TM_START 0
00358 #define TM_STOP 1
00359 double app_tminterval (int stop,int usertime);
00360 #endif