apps.h revision 194206
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. 855714Skris * 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). 1555714Skris * 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. 2255714Skris * 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 :-). 3755714Skris * 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)" 4055714Skris * 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. 5255714Skris * 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 66109998Smarkm * 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 11355714Skris#define HEADER_APPS_H 11455714Skris 115109998Smarkm#include "e_os.h" 11655714Skris 11755714Skris#include <openssl/bio.h> 11859191Skris#include <openssl/x509.h> 11968651Skris#include <openssl/lhash.h> 12068651Skris#include <openssl/conf.h> 121109998Smarkm#include <openssl/txt_db.h> 122111147Snectar#ifndef OPENSSL_NO_ENGINE 123109998Smarkm#include <openssl/engine.h> 124111147Snectar#endif 125194206Ssimon#ifndef OPENSSL_NO_OCSP 126194206Ssimon#include <openssl/ocsp.h> 127194206Ssimon#endif 128109998Smarkm#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); 13259191Skris/* When `file' is NULL, use defaults. 13359191Skris * `bio_e' is for error messages. */ 13459191Skrisvoid app_RAND_allow_write_file(void); 13559191Skrislong app_RAND_load_files(char *file); /* `file' is a list of files to read, 13659191Skris * separated by LIST_SEPARATOR_CHAR 13759191Skris * (see e_os.h). The string is 13859191Skris * destroyed! */ 13959191Skris 140109998Smarkm#ifdef OPENSSL_SYS_WIN32 14155714Skris#define rename(from,to) WIN32_rename((from),(to)) 142160814Ssimonint WIN32_rename(const char *oldname,const char *newname); 14355714Skris#endif 14455714Skris 14555714Skris#ifndef MONOLITH 14655714Skris 14755714Skris#define MAIN(a,v) main(a,v) 14855714Skris 14955714Skris#ifndef NON_MAIN 150109998SmarkmCONF *config=NULL; 15155714SkrisBIO *bio_err=NULL; 152194206Ssimonint in_FIPS_mode=0; 15355714Skris#else 154109998Smarkmextern CONF *config; 15555714Skrisextern BIO *bio_err; 156194206Ssimonextern int in_FIPS_mode; 15755714Skris#endif 15855714Skris 15955714Skris#else 16055714Skris 16155714Skris#define MAIN(a,v) PROG(a,v) 162109998Smarkmextern CONF *config; 16355714Skrisextern char *default_config_file; 16455714Skrisextern BIO *bio_err; 165194206Ssimonextern int in_FIPS_mode; 16655714Skris 16755714Skris#endif 16855714Skris 169160814Ssimon#ifndef OPENSSL_SYS_NETWARE 17055714Skris#include <signal.h> 171160814Ssimon#endif 17255714Skris 17355714Skris#ifdef SIGPIPE 17455714Skris#define do_pipe_sig() signal(SIGPIPE,SIG_IGN) 17555714Skris#else 17655714Skris#define do_pipe_sig() 17755714Skris#endif 17855714Skris 17959191Skris#if defined(MONOLITH) && !defined(OPENSSL_C) 180109998Smarkm# define apps_startup() \ 181109998Smarkm do_pipe_sig() 182109998Smarkm# define apps_shutdown() 18355714Skris#else 184111147Snectar# ifndef OPENSSL_NO_ENGINE 185111147Snectar# if defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_WIN16) || \ 186111147Snectar defined(OPENSSL_SYS_WIN32) 187111147Snectar# ifdef _O_BINARY 188111147Snectar# define apps_startup() \ 189111147Snectar do { _fmode=_O_BINARY; do_pipe_sig(); CRYPTO_malloc_init(); \ 190111147Snectar ERR_load_crypto_strings(); OpenSSL_add_all_algorithms(); \ 191111147Snectar ENGINE_load_builtin_engines(); setup_ui_method(); } while(0) 192111147Snectar# else 193111147Snectar# define apps_startup() \ 194111147Snectar do { _fmode=O_BINARY; do_pipe_sig(); CRYPTO_malloc_init(); \ 195111147Snectar ERR_load_crypto_strings(); OpenSSL_add_all_algorithms(); \ 196111147Snectar ENGINE_load_builtin_engines(); setup_ui_method(); } while(0) 197111147Snectar# endif 198111147Snectar# else 19955714Skris# define apps_startup() \ 200111147Snectar do { do_pipe_sig(); OpenSSL_add_all_algorithms(); \ 201111147Snectar ERR_load_crypto_strings(); ENGINE_load_builtin_engines(); \ 202111147Snectar setup_ui_method(); } while(0) 203111147Snectar# endif 204111147Snectar# define apps_shutdown() \ 205111147Snectar do { CONF_modules_unload(1); destroy_ui_method(); \ 206111147Snectar EVP_cleanup(); ENGINE_cleanup(); \ 207111147Snectar CRYPTO_cleanup_all_ex_data(); ERR_remove_state(0); \ 208111147Snectar ERR_free_strings(); } while(0) 209111147Snectar# else 210111147Snectar# if defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_WIN16) || \ 211111147Snectar defined(OPENSSL_SYS_WIN32) 212111147Snectar# ifdef _O_BINARY 213111147Snectar# define apps_startup() \ 214111147Snectar do { _fmode=_O_BINARY; do_pipe_sig(); CRYPTO_malloc_init(); \ 215111147Snectar ERR_load_crypto_strings(); OpenSSL_add_all_algorithms(); \ 216111147Snectar setup_ui_method(); } while(0) 217111147Snectar# else 218111147Snectar# define apps_startup() \ 219111147Snectar do { _fmode=O_BINARY; do_pipe_sig(); CRYPTO_malloc_init(); \ 220111147Snectar ERR_load_crypto_strings(); OpenSSL_add_all_algorithms(); \ 221111147Snectar setup_ui_method(); } while(0) 222111147Snectar# endif 22355714Skris# else 22455714Skris# define apps_startup() \ 225111147Snectar do { do_pipe_sig(); OpenSSL_add_all_algorithms(); \ 226111147Snectar ERR_load_crypto_strings(); \ 227111147Snectar setup_ui_method(); } while(0) 22855714Skris# endif 229111147Snectar# define apps_shutdown() \ 230111147Snectar do { CONF_modules_unload(1); destroy_ui_method(); \ 231111147Snectar EVP_cleanup(); \ 232111147Snectar CRYPTO_cleanup_all_ex_data(); ERR_remove_state(0); \ 233111147Snectar ERR_free_strings(); } while(0) 23455714Skris# endif 23555714Skris#endif 23655714Skris 237194206Ssimon#ifdef OPENSSL_SYSNAME_WIN32 238194206Ssimon# define openssl_fdset(a,b) FD_SET((unsigned int)a, b) 239194206Ssimon#else 240194206Ssimon# define openssl_fdset(a,b) FD_SET(a, b) 241194206Ssimon#endif 242194206Ssimon 24355714Skristypedef struct args_st 24455714Skris { 24555714Skris char **data; 24655714Skris int count; 24755714Skris } ARGS; 24855714Skris 249109998Smarkm#define PW_MIN_LENGTH 4 250109998Smarkmtypedef struct pw_cb_data 251109998Smarkm { 252109998Smarkm const void *password; 253109998Smarkm const char *prompt_info; 254109998Smarkm } PW_CB_DATA; 255109998Smarkm 256109998Smarkmint password_callback(char *buf, int bufsiz, int verify, 257109998Smarkm PW_CB_DATA *cb_data); 258109998Smarkm 259109998Smarkmint setup_ui_method(void); 260109998Smarkmvoid destroy_ui_method(void); 261109998Smarkm 26255714Skrisint should_retry(int i); 26355714Skrisint args_from_file(char *file, int *argc, char **argv[]); 26455714Skrisint str2fmt(char *s); 26555714Skrisvoid program_name(char *in,char *out,int size); 26655714Skrisint chopup_args(ARGS *arg,char *buf, int *argc, char **argv[]); 26759191Skris#ifdef HEADER_X509_H 26859191Skrisint dump_cert_text(BIO *out, X509 *x); 269160814Ssimonvoid print_name(BIO *out, const char *title, X509_NAME *nm, unsigned long lflags); 27059191Skris#endif 271109998Smarkmint set_cert_ex(unsigned long *flags, const char *arg); 27268651Skrisint set_name_ex(unsigned long *flags, const char *arg); 273109998Smarkmint set_ext_copy(int *copy_type, const char *arg); 274109998Smarkmint copy_extensions(X509 *x, X509_REQ *req, int copy_type); 27559191Skrisint app_passwd(BIO *err, char *arg1, char *arg2, char **pass1, char **pass2); 276109998Smarkmint add_oid_section(BIO *err, CONF *conf); 277109998SmarkmX509 *load_cert(BIO *err, const char *file, int format, 278109998Smarkm const char *pass, ENGINE *e, const char *cert_descrip); 279109998SmarkmEVP_PKEY *load_key(BIO *err, const char *file, int format, int maybe_stdin, 280109998Smarkm const char *pass, ENGINE *e, const char *key_descrip); 281109998SmarkmEVP_PKEY *load_pubkey(BIO *err, const char *file, int format, int maybe_stdin, 282109998Smarkm const char *pass, ENGINE *e, const char *key_descrip); 283109998SmarkmSTACK_OF(X509) *load_certs(BIO *err, const char *file, int format, 284109998Smarkm const char *pass, ENGINE *e, const char *cert_descrip); 285109998SmarkmX509_STORE *setup_verify(BIO *bp, char *CAfile, char *CApath); 286111147Snectar#ifndef OPENSSL_NO_ENGINE 287109998SmarkmENGINE *setup_engine(BIO *err, const char *engine, int debug); 288111147Snectar#endif 28968651Skris 290194206Ssimon#ifndef OPENSSL_NO_OCSP 291194206SsimonOCSP_RESPONSE *process_responder(BIO *err, OCSP_REQUEST *req, 292194206Ssimon char *host, char *path, char *port, int use_ssl, 293194206Ssimon int req_timeout); 294194206Ssimon#endif 295194206Ssimon 296109998Smarkmint load_config(BIO *err, CONF *cnf); 297109998Smarkmchar *make_config_name(void); 298109998Smarkm 299109998Smarkm/* Functions defined in ca.c and also used in ocsp.c */ 300109998Smarkmint unpack_revinfo(ASN1_TIME **prevtm, int *preason, ASN1_OBJECT **phold, 301160814Ssimon ASN1_GENERALIZEDTIME **pinvtm, const char *str); 302109998Smarkm 303127128Snectar#define DB_type 0 304127128Snectar#define DB_exp_date 1 305127128Snectar#define DB_rev_date 2 306127128Snectar#define DB_serial 3 /* index - unique */ 307127128Snectar#define DB_file 4 308127128Snectar#define DB_name 5 /* index - unique when active and not disabled */ 309127128Snectar#define DB_NUMBER 6 310127128Snectar 311127128Snectar#define DB_TYPE_REV 'R' 312127128Snectar#define DB_TYPE_EXP 'E' 313127128Snectar#define DB_TYPE_VAL 'V' 314127128Snectar 315127128Snectartypedef struct db_attr_st 316127128Snectar { 317127128Snectar int unique_subject; 318127128Snectar } DB_ATTR; 319127128Snectartypedef struct ca_db_st 320127128Snectar { 321127128Snectar DB_ATTR attributes; 322127128Snectar TXT_DB *db; 323127128Snectar } CA_DB; 324127128Snectar 325127128SnectarBIGNUM *load_serial(char *serialfile, int create, ASN1_INTEGER **retai); 326127128Snectarint save_serial(char *serialfile, char *suffix, BIGNUM *serial, ASN1_INTEGER **retai); 327127128Snectarint rotate_serial(char *serialfile, char *new_suffix, char *old_suffix); 328142425Snectarint rand_serial(BIGNUM *b, ASN1_INTEGER *ai); 329127128SnectarCA_DB *load_index(char *dbfile, DB_ATTR *dbattr); 330127128Snectarint index_index(CA_DB *db); 331160814Ssimonint save_index(const char *dbfile, const char *suffix, CA_DB *db); 332160814Ssimonint rotate_index(const char *dbfile, const char *new_suffix, const char *old_suffix); 333127128Snectarvoid free_index(CA_DB *db); 334127128Snectarint index_name_cmp(const char **a, const char **b); 335160814Ssimonint parse_yesno(const char *str, int def); 336127128Snectar 337160814SsimonX509_NAME *parse_name(char *str, long chtype, int multirdn); 338160814Ssimonint args_verify(char ***pargs, int *pargc, 339160814Ssimon int *badarg, BIO *err, X509_VERIFY_PARAM **pm); 340160814Ssimonvoid policies_print(BIO *out, X509_STORE_CTX *ctx); 341194206Ssimon#ifndef OPENSSL_NO_JPAKE 342194206Ssimonvoid jpake_client_auth(BIO *out, BIO *conn, const char *secret); 343194206Ssimonvoid jpake_server_auth(BIO *out, BIO *conn, const char *secret); 344194206Ssimon#endif 345109998Smarkm 34655714Skris#define FORMAT_UNDEF 0 34755714Skris#define FORMAT_ASN1 1 34855714Skris#define FORMAT_TEXT 2 34955714Skris#define FORMAT_PEM 3 35055714Skris#define FORMAT_NETSCAPE 4 35168651Skris#define FORMAT_PKCS12 5 35268651Skris#define FORMAT_SMIME 6 353109998Smarkm#define FORMAT_ENGINE 7 354109998Smarkm#define FORMAT_IISSGC 8 /* XXX this stupid macro helps us to avoid 355109998Smarkm * adding yet another param to load_*key() */ 35655714Skris 357109998Smarkm#define EXT_COPY_NONE 0 358109998Smarkm#define EXT_COPY_ADD 1 359109998Smarkm#define EXT_COPY_ALL 2 360109998Smarkm 36168651Skris#define NETSCAPE_CERT_HDR "certificate" 36268651Skris 36359191Skris#define APP_PASS_LEN 1024 36459191Skris 365142425Snectar#define SERIAL_RAND_BITS 64 366142425Snectar 36755714Skris#endif 368