155714Skris/* apps/apps.h */ 255714Skris/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 355714Skris * All rights reserved. 455714Skris * 555714Skris * This package is an SSL implementation written 655714Skris * by Eric Young (eay@cryptsoft.com). 755714Skris * The implementation was written so as to conform with Netscapes SSL. 8280297Sjkim * 955714Skris * This library is free for commercial and non-commercial use as long as 1055714Skris * the following conditions are aheared to. The following conditions 1155714Skris * apply to all code found in this distribution, be it the RC4, RSA, 1255714Skris * lhash, DES, etc., code; not just the SSL code. The SSL documentation 1355714Skris * included with this distribution is covered by the same copyright terms 1455714Skris * except that the holder is Tim Hudson (tjh@cryptsoft.com). 15280297Sjkim * 1655714Skris * Copyright remains Eric Young's, and as such any Copyright notices in 1755714Skris * the code are not to be removed. 1855714Skris * If this package is used in a product, Eric Young should be given attribution 1955714Skris * as the author of the parts of the library used. 2055714Skris * This can be in the form of a textual message at program startup or 2155714Skris * in documentation (online or textual) provided with the package. 22280297Sjkim * 2355714Skris * Redistribution and use in source and binary forms, with or without 2455714Skris * modification, are permitted provided that the following conditions 2555714Skris * are met: 2655714Skris * 1. Redistributions of source code must retain the copyright 2755714Skris * notice, this list of conditions and the following disclaimer. 2855714Skris * 2. Redistributions in binary form must reproduce the above copyright 2955714Skris * notice, this list of conditions and the following disclaimer in the 3055714Skris * documentation and/or other materials provided with the distribution. 3155714Skris * 3. All advertising materials mentioning features or use of this software 3255714Skris * must display the following acknowledgement: 3355714Skris * "This product includes cryptographic software written by 3455714Skris * Eric Young (eay@cryptsoft.com)" 3555714Skris * The word 'cryptographic' can be left out if the rouines from the library 3655714Skris * being used are not cryptographic related :-). 37280297Sjkim * 4. If you include any Windows specific code (or a derivative thereof) from 3855714Skris * the apps directory (application code) you must include an acknowledgement: 3955714Skris * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 40280297Sjkim * 4155714Skris * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 4255714Skris * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 4355714Skris * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 4455714Skris * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 4555714Skris * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 4655714Skris * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 4755714Skris * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 4855714Skris * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 4955714Skris * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 5055714Skris * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 5155714Skris * SUCH DAMAGE. 52280297Sjkim * 5355714Skris * The licence and distribution terms for any publically available version or 5455714Skris * derivative of this code cannot be changed. i.e. this code cannot simply be 5555714Skris * copied and put under another distribution licence 5655714Skris * [including the GNU Public Licence.] 5755714Skris */ 58109998Smarkm/* ==================================================================== 59109998Smarkm * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved. 60109998Smarkm * 61109998Smarkm * Redistribution and use in source and binary forms, with or without 62109998Smarkm * modification, are permitted provided that the following conditions 63109998Smarkm * are met: 64109998Smarkm * 65109998Smarkm * 1. Redistributions of source code must retain the above copyright 66280297Sjkim * notice, this list of conditions and the following disclaimer. 67109998Smarkm * 68109998Smarkm * 2. Redistributions in binary form must reproduce the above copyright 69109998Smarkm * notice, this list of conditions and the following disclaimer in 70109998Smarkm * the documentation and/or other materials provided with the 71109998Smarkm * distribution. 72109998Smarkm * 73109998Smarkm * 3. All advertising materials mentioning features or use of this 74109998Smarkm * software must display the following acknowledgment: 75109998Smarkm * "This product includes software developed by the OpenSSL Project 76109998Smarkm * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" 77109998Smarkm * 78109998Smarkm * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 79109998Smarkm * endorse or promote products derived from this software without 80109998Smarkm * prior written permission. For written permission, please contact 81109998Smarkm * openssl-core@openssl.org. 82109998Smarkm * 83109998Smarkm * 5. Products derived from this software may not be called "OpenSSL" 84109998Smarkm * nor may "OpenSSL" appear in their names without prior written 85109998Smarkm * permission of the OpenSSL Project. 86109998Smarkm * 87109998Smarkm * 6. Redistributions of any form whatsoever must retain the following 88109998Smarkm * acknowledgment: 89109998Smarkm * "This product includes software developed by the OpenSSL Project 90109998Smarkm * for use in the OpenSSL Toolkit (http://www.openssl.org/)" 91109998Smarkm * 92109998Smarkm * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 93109998Smarkm * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 94109998Smarkm * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 95109998Smarkm * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 96109998Smarkm * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 97109998Smarkm * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 98109998Smarkm * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 99109998Smarkm * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 100109998Smarkm * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 101109998Smarkm * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 102109998Smarkm * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 103109998Smarkm * OF THE POSSIBILITY OF SUCH DAMAGE. 104109998Smarkm * ==================================================================== 105109998Smarkm * 106109998Smarkm * This product includes cryptographic software written by Eric Young 107109998Smarkm * (eay@cryptsoft.com). This product includes software written by Tim 108109998Smarkm * Hudson (tjh@cryptsoft.com). 109109998Smarkm * 110109998Smarkm */ 11155714Skris 11255714Skris#ifndef HEADER_APPS_H 113280297Sjkim# define HEADER_APPS_H 11455714Skris 115280297Sjkim# include "e_os.h" 11655714Skris 117280297Sjkim# include <openssl/bio.h> 118280297Sjkim# include <openssl/x509.h> 119280297Sjkim# include <openssl/lhash.h> 120280297Sjkim# include <openssl/conf.h> 121280297Sjkim# include <openssl/txt_db.h> 122280297Sjkim# ifndef OPENSSL_NO_ENGINE 123280297Sjkim# include <openssl/engine.h> 124280297Sjkim# endif 125280297Sjkim# ifndef OPENSSL_NO_OCSP 126280297Sjkim# include <openssl/ocsp.h> 127280297Sjkim# endif 128280297Sjkim# include <openssl/ossl_typ.h> 12955714Skris 13059191Skrisint app_RAND_load_file(const char *file, BIO *bio_e, int dont_warn); 13159191Skrisint app_RAND_write_file(const char *file, BIO *bio_e); 132280297Sjkim/* 133280297Sjkim * When `file' is NULL, use defaults. `bio_e' is for error messages. 134280297Sjkim */ 13559191Skrisvoid app_RAND_allow_write_file(void); 13659191Skrislong app_RAND_load_files(char *file); /* `file' is a list of files to read, 13759191Skris * separated by LIST_SEPARATOR_CHAR 13859191Skris * (see e_os.h). The string is 13959191Skris * destroyed! */ 14059191Skris 141280297Sjkim# ifndef MONOLITH 14255714Skris 143280297Sjkim# define MAIN(a,v) main(a,v) 14455714Skris 145280297Sjkim# ifndef NON_MAIN 146280297SjkimCONF *config = NULL; 147280297SjkimBIO *bio_err = NULL; 148280297Sjkim# else 149109998Smarkmextern CONF *config; 15055714Skrisextern BIO *bio_err; 151280297Sjkim# endif 15255714Skris 153280297Sjkim# else 15455714Skris 155280297Sjkim# define MAIN(a,v) PROG(a,v) 156109998Smarkmextern CONF *config; 15755714Skrisextern char *default_config_file; 15855714Skrisextern BIO *bio_err; 15955714Skris 160280297Sjkim# endif 16155714Skris 162280297Sjkim# ifndef OPENSSL_SYS_NETWARE 163280297Sjkim# include <signal.h> 164280297Sjkim# endif 16555714Skris 166280297Sjkim# ifdef SIGPIPE 167280297Sjkim# define do_pipe_sig() signal(SIGPIPE,SIG_IGN) 168280297Sjkim# else 169280297Sjkim# define do_pipe_sig() 170280297Sjkim# endif 17155714Skris 172280297Sjkim# ifdef OPENSSL_NO_COMP 173280297Sjkim# define zlib_cleanup() 174280297Sjkim# else 175280297Sjkim# define zlib_cleanup() COMP_zlib_cleanup() 176280297Sjkim# endif 177238405Sjkim 178280297Sjkim# if defined(MONOLITH) && !defined(OPENSSL_C) 179109998Smarkm# define apps_startup() \ 180280297Sjkim do_pipe_sig() 181109998Smarkm# define apps_shutdown() 182280297Sjkim# else 183111147Snectar# ifndef OPENSSL_NO_ENGINE 184280297Sjkim# define apps_startup() \ 185280297Sjkim do { do_pipe_sig(); CRYPTO_malloc_init(); \ 186280297Sjkim ERR_load_crypto_strings(); OpenSSL_add_all_algorithms(); \ 187280297Sjkim ENGINE_load_builtin_engines(); setup_ui_method(); } while(0) 188280297Sjkim# define apps_shutdown() \ 189280297Sjkim do { CONF_modules_unload(1); destroy_ui_method(); \ 190280297Sjkim OBJ_cleanup(); EVP_cleanup(); ENGINE_cleanup(); \ 191280297Sjkim CRYPTO_cleanup_all_ex_data(); ERR_remove_thread_state(NULL); \ 192280297Sjkim RAND_cleanup(); \ 193280297Sjkim ERR_free_strings(); zlib_cleanup();} while(0) 194111147Snectar# else 195280297Sjkim# define apps_startup() \ 196280297Sjkim do { do_pipe_sig(); CRYPTO_malloc_init(); \ 197280297Sjkim ERR_load_crypto_strings(); OpenSSL_add_all_algorithms(); \ 198280297Sjkim setup_ui_method(); } while(0) 199280297Sjkim# define apps_shutdown() \ 200280297Sjkim do { CONF_modules_unload(1); destroy_ui_method(); \ 201280297Sjkim OBJ_cleanup(); EVP_cleanup(); \ 202280297Sjkim CRYPTO_cleanup_all_ex_data(); ERR_remove_thread_state(NULL); \ 203280297Sjkim RAND_cleanup(); \ 204280297Sjkim ERR_free_strings(); zlib_cleanup(); } while(0) 20555714Skris# endif 206280297Sjkim# endif 20755714Skris 208290207Sjkim# if defined(OPENSSL_SYSNAME_WIN32) || defined(OPENSSL_SYSNAME_WINCE) 209194206Ssimon# define openssl_fdset(a,b) FD_SET((unsigned int)a, b) 210280297Sjkim# else 211194206Ssimon# define openssl_fdset(a,b) FD_SET(a, b) 212280297Sjkim# endif 213194206Ssimon 214280297Sjkimtypedef struct args_st { 215280297Sjkim char **data; 216280297Sjkim int count; 217280297Sjkim} ARGS; 218238405Sjkim 219280297Sjkim# define PW_MIN_LENGTH 4 220280297Sjkimtypedef struct pw_cb_data { 221280297Sjkim const void *password; 222280297Sjkim const char *prompt_info; 223280297Sjkim} PW_CB_DATA; 22455714Skris 225280297Sjkimint password_callback(char *buf, int bufsiz, int verify, PW_CB_DATA *cb_data); 226109998Smarkm 227109998Smarkmint setup_ui_method(void); 228109998Smarkmvoid destroy_ui_method(void); 229109998Smarkm 23055714Skrisint should_retry(int i); 23155714Skrisint args_from_file(char *file, int *argc, char **argv[]); 23255714Skrisint str2fmt(char *s); 233280297Sjkimvoid program_name(char *in, char *out, int size); 234280297Sjkimint chopup_args(ARGS *arg, char *buf, int *argc, char **argv[]); 235280297Sjkim# ifdef HEADER_X509_H 23659191Skrisint dump_cert_text(BIO *out, X509 *x); 237280297Sjkimvoid print_name(BIO *out, const char *title, X509_NAME *nm, 238280297Sjkim unsigned long lflags); 239280297Sjkim# endif 240109998Smarkmint set_cert_ex(unsigned long *flags, const char *arg); 24168651Skrisint set_name_ex(unsigned long *flags, const char *arg); 242109998Smarkmint set_ext_copy(int *copy_type, const char *arg); 243109998Smarkmint copy_extensions(X509 *x, X509_REQ *req, int copy_type); 24459191Skrisint app_passwd(BIO *err, char *arg1, char *arg2, char **pass1, char **pass2); 245109998Smarkmint add_oid_section(BIO *err, CONF *conf); 246109998SmarkmX509 *load_cert(BIO *err, const char *file, int format, 247280297Sjkim const char *pass, ENGINE *e, const char *cert_descrip); 248290207SjkimX509_CRL *load_crl(const char *infile, int format); 249290207Sjkimint load_cert_crl_http(const char *url, BIO *err, 250290207Sjkim X509 **pcert, X509_CRL **pcrl); 251109998SmarkmEVP_PKEY *load_key(BIO *err, const char *file, int format, int maybe_stdin, 252280297Sjkim const char *pass, ENGINE *e, const char *key_descrip); 253109998SmarkmEVP_PKEY *load_pubkey(BIO *err, const char *file, int format, int maybe_stdin, 254280297Sjkim const char *pass, ENGINE *e, const char *key_descrip); 255109998SmarkmSTACK_OF(X509) *load_certs(BIO *err, const char *file, int format, 256280297Sjkim const char *pass, ENGINE *e, 257280297Sjkim const char *cert_descrip); 258238405SjkimSTACK_OF(X509_CRL) *load_crls(BIO *err, const char *file, int format, 259280297Sjkim const char *pass, ENGINE *e, 260280297Sjkim const char *cert_descrip); 261109998SmarkmX509_STORE *setup_verify(BIO *bp, char *CAfile, char *CApath); 262312826Sjkim 263109998SmarkmENGINE *setup_engine(BIO *err, const char *engine, int debug); 264312826Sjkimvoid release_engine(ENGINE *e); 26568651Skris 266280297Sjkim# ifndef OPENSSL_NO_OCSP 267194206SsimonOCSP_RESPONSE *process_responder(BIO *err, OCSP_REQUEST *req, 268290207Sjkim const char *host, const char *path, 269290207Sjkim const char *port, int use_ssl, 270290207Sjkim const STACK_OF(CONF_VALUE) *headers, 271280297Sjkim int req_timeout); 272280297Sjkim# endif 273194206Ssimon 274109998Smarkmint load_config(BIO *err, CONF *cnf); 275109998Smarkmchar *make_config_name(void); 276109998Smarkm 277109998Smarkm/* Functions defined in ca.c and also used in ocsp.c */ 278109998Smarkmint unpack_revinfo(ASN1_TIME **prevtm, int *preason, ASN1_OBJECT **phold, 279280297Sjkim ASN1_GENERALIZEDTIME **pinvtm, const char *str); 280109998Smarkm 281280297Sjkim# define DB_type 0 282280297Sjkim# define DB_exp_date 1 283280297Sjkim# define DB_rev_date 2 284280297Sjkim# define DB_serial 3 /* index - unique */ 285280297Sjkim# define DB_file 4 286280297Sjkim# define DB_name 5 /* index - unique when active and not 287280297Sjkim * disabled */ 288280297Sjkim# define DB_NUMBER 6 289127128Snectar 290280297Sjkim# define DB_TYPE_REV 'R' 291280297Sjkim# define DB_TYPE_EXP 'E' 292280297Sjkim# define DB_TYPE_VAL 'V' 293127128Snectar 294280297Sjkimtypedef struct db_attr_st { 295280297Sjkim int unique_subject; 296280297Sjkim} DB_ATTR; 297280297Sjkimtypedef struct ca_db_st { 298280297Sjkim DB_ATTR attributes; 299280297Sjkim TXT_DB *db; 300280297Sjkim} CA_DB; 301127128Snectar 302127128SnectarBIGNUM *load_serial(char *serialfile, int create, ASN1_INTEGER **retai); 303280297Sjkimint save_serial(char *serialfile, char *suffix, BIGNUM *serial, 304280297Sjkim ASN1_INTEGER **retai); 305127128Snectarint rotate_serial(char *serialfile, char *new_suffix, char *old_suffix); 306142425Snectarint rand_serial(BIGNUM *b, ASN1_INTEGER *ai); 307127128SnectarCA_DB *load_index(char *dbfile, DB_ATTR *dbattr); 308127128Snectarint index_index(CA_DB *db); 309160814Ssimonint save_index(const char *dbfile, const char *suffix, CA_DB *db); 310280297Sjkimint rotate_index(const char *dbfile, const char *new_suffix, 311280297Sjkim const char *old_suffix); 312127128Snectarvoid free_index(CA_DB *db); 313280297Sjkim# define index_name_cmp_noconst(a, b) \ 314280297Sjkim index_name_cmp((const OPENSSL_CSTRING *)CHECKED_PTR_OF(OPENSSL_STRING, a), \ 315280297Sjkim (const OPENSSL_CSTRING *)CHECKED_PTR_OF(OPENSSL_STRING, b)) 316238405Sjkimint index_name_cmp(const OPENSSL_CSTRING *a, const OPENSSL_CSTRING *b); 317160814Ssimonint parse_yesno(const char *str, int def); 318127128Snectar 319160814SsimonX509_NAME *parse_name(char *str, long chtype, int multirdn); 320160814Ssimonint args_verify(char ***pargs, int *pargc, 321280297Sjkim int *badarg, BIO *err, X509_VERIFY_PARAM **pm); 322160814Ssimonvoid policies_print(BIO *out, X509_STORE_CTX *ctx); 323238405Sjkimint bio_to_mem(unsigned char **out, int maxlen, BIO *in); 324296279Sjkimint pkey_ctrl_string(EVP_PKEY_CTX *ctx, const char *value); 325238405Sjkimint init_gen_str(BIO *err, EVP_PKEY_CTX **pctx, 326280297Sjkim const char *algname, ENGINE *e, int do_param); 327238405Sjkimint do_X509_sign(BIO *err, X509 *x, EVP_PKEY *pkey, const EVP_MD *md, 328280297Sjkim STACK_OF(OPENSSL_STRING) *sigopts); 329238405Sjkimint do_X509_REQ_sign(BIO *err, X509_REQ *x, EVP_PKEY *pkey, const EVP_MD *md, 330280297Sjkim STACK_OF(OPENSSL_STRING) *sigopts); 331238405Sjkimint do_X509_CRL_sign(BIO *err, X509_CRL *x, EVP_PKEY *pkey, const EVP_MD *md, 332280297Sjkim STACK_OF(OPENSSL_STRING) *sigopts); 333280297Sjkim# ifndef OPENSSL_NO_PSK 334238405Sjkimextern char *psk_key; 335280297Sjkim# endif 336280297Sjkim# ifndef OPENSSL_NO_JPAKE 337194206Ssimonvoid jpake_client_auth(BIO *out, BIO *conn, const char *secret); 338194206Ssimonvoid jpake_server_auth(BIO *out, BIO *conn, const char *secret); 339280297Sjkim# endif 340109998Smarkm 341290207Sjkim# ifndef OPENSSL_NO_TLSEXT 342238405Sjkimunsigned char *next_protos_parse(unsigned short *outlen, const char *in); 343290207Sjkim# endif /* ndef OPENSSL_NO_TLSEXT */ 344238405Sjkim 345290207Sjkimvoid print_cert_checks(BIO *bio, X509 *x, 346290207Sjkim const char *checkhost, 347290207Sjkim const char *checkemail, const char *checkip); 348290207Sjkim 349290207Sjkimvoid store_setup_crl_download(X509_STORE *st); 350290207Sjkim 351280297Sjkim# define FORMAT_UNDEF 0 352280297Sjkim# define FORMAT_ASN1 1 353280297Sjkim# define FORMAT_TEXT 2 354280297Sjkim# define FORMAT_PEM 3 355280297Sjkim# define FORMAT_NETSCAPE 4 356280297Sjkim# define FORMAT_PKCS12 5 357280297Sjkim# define FORMAT_SMIME 6 358280297Sjkim# define FORMAT_ENGINE 7 359280297Sjkim# define FORMAT_IISSGC 8 /* XXX this stupid macro helps us to avoid 360280297Sjkim * adding yet another param to load_*key() */ 361280297Sjkim# define FORMAT_PEMRSA 9 /* PEM RSAPubicKey format */ 362280297Sjkim# define FORMAT_ASN1RSA 10 /* DER RSAPubicKey format */ 363280297Sjkim# define FORMAT_MSBLOB 11 /* MS Key blob format */ 364280297Sjkim# define FORMAT_PVK 12 /* MS PVK file format */ 365290207Sjkim# define FORMAT_HTTP 13 /* Download using HTTP */ 36655714Skris 367280297Sjkim# define EXT_COPY_NONE 0 368280297Sjkim# define EXT_COPY_ADD 1 369280297Sjkim# define EXT_COPY_ALL 2 370109998Smarkm 371280297Sjkim# define NETSCAPE_CERT_HDR "certificate" 37268651Skris 373280297Sjkim# define APP_PASS_LEN 1024 37459191Skris 375280297Sjkim# define SERIAL_RAND_BITS 64 376142425Snectar 377238405Sjkimint app_isdir(const char *); 378306195Sjkimint fileno_stdin(void); 379306195Sjkimint fileno_stdout(void); 380280297Sjkimint raw_read_stdin(void *, int); 381280297Sjkimint raw_write_stdout(const void *, int); 382238405Sjkim 383280297Sjkim# define TM_START 0 384280297Sjkim# define TM_STOP 1 385280297Sjkimdouble app_tminterval(int stop, int usertime); 386238405Sjkim 387280297Sjkim# define OPENSSL_NO_SSL_INTERN 388238405Sjkim 38955714Skris#endif 390