apps.h revision 109998
121769Sjkh/* apps/apps.h */ 221769Sjkh/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 321769Sjkh * All rights reserved. 421769Sjkh * 521769Sjkh * This package is an SSL implementation written 621769Sjkh * by Eric Young (eay@cryptsoft.com). 721769Sjkh * The implementation was written so as to conform with Netscapes SSL. 821769Sjkh * 921769Sjkh * This library is free for commercial and non-commercial use as long as 1021769Sjkh * the following conditions are aheared to. The following conditions 1121769Sjkh * apply to all code found in this distribution, be it the RC4, RSA, 1221769Sjkh * lhash, DES, etc., code; not just the SSL code. The SSL documentation 1321769Sjkh * included with this distribution is covered by the same copyright terms 1421769Sjkh * except that the holder is Tim Hudson (tjh@cryptsoft.com). 1521769Sjkh * 1621769Sjkh * Copyright remains Eric Young's, and as such any Copyright notices in 1721769Sjkh * the code are not to be removed. 1821769Sjkh * If this package is used in a product, Eric Young should be given attribution 1921769Sjkh * as the author of the parts of the library used. 2021769Sjkh * This can be in the form of a textual message at program startup or 2121769Sjkh * in documentation (online or textual) provided with the package. 2221769Sjkh * 2321769Sjkh * Redistribution and use in source and binary forms, with or without 2421769Sjkh * modification, are permitted provided that the following conditions 2521769Sjkh * are met: 2629877Smsmith * 1. Redistributions of source code must retain the copyright 2750477Speter * notice, this list of conditions and the following disclaimer. 2852286Smdodd * 2. Redistributions in binary form must reproduce the above copyright 2952286Smdodd * notice, this list of conditions and the following disclaimer in the 3052286Smdodd * documentation and/or other materials provided with the distribution. 3121769Sjkh * 3. All advertising materials mentioning features or use of this software 3221769Sjkh * must display the following acknowledgement: 3321769Sjkh * "This product includes cryptographic software written by 3429877Smsmith * Eric Young (eay@cryptsoft.com)" 3521769Sjkh * The word 'cryptographic' can be left out if the rouines from the library 3621769Sjkh * being used are not cryptographic related :-). 3721769Sjkh * 4. If you include any Windows specific code (or a derivative thereof) from 3821769Sjkh * the apps directory (application code) you must include an acknowledgement: 3921769Sjkh * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 4021769Sjkh * 4121769Sjkh * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 4221769Sjkh * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 4321769Sjkh * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 4421769Sjkh * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 4521769Sjkh * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 4652286Smdodd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 4721769Sjkh * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 4824204Sbde * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 4921769Sjkh * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 5021769Sjkh * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 5121769Sjkh * SUCH DAMAGE. 5252286Smdodd * 5352286Smdodd * The licence and distribution terms for any publically available version or 5452286Smdodd * derivative of this code cannot be changed. i.e. this code cannot simply be 5552286Smdodd * copied and put under another distribution licence 5652286Smdodd * [including the GNU Public Licence.] 5752286Smdodd */ 5852286Smdodd/* ==================================================================== 5950026Smdodd * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved. 6021769Sjkh * 6121769Sjkh * Redistribution and use in source and binary forms, with or without 6250026Smdodd * modification, are permitted provided that the following conditions 6350026Smdodd * are met: 6450026Smdodd * 6521769Sjkh * 1. Redistributions of source code must retain the above copyright 6621769Sjkh * notice, this list of conditions and the following disclaimer. 6721769Sjkh * 6821769Sjkh * 2. Redistributions in binary form must reproduce the above copyright 6952286Smdodd * notice, this list of conditions and the following disclaimer in 7052286Smdodd * the documentation and/or other materials provided with the 7152286Smdodd * distribution. 7221769Sjkh * 7321769Sjkh * 3. All advertising materials mentioning features or use of this 7421769Sjkh * software must display the following acknowledgment: 7552286Smdodd * "This product includes software developed by the OpenSSL Project 7652286Smdodd * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" 7752286Smdodd * 7852286Smdodd * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 7921769Sjkh * endorse or promote products derived from this software without 8021769Sjkh * prior written permission. For written permission, please contact 8152286Smdodd * openssl-core@openssl.org. 8221769Sjkh * 8352286Smdodd * 5. Products derived from this software may not be called "OpenSSL" 8421769Sjkh * nor may "OpenSSL" appear in their names without prior written 8521769Sjkh * permission of the OpenSSL Project. 8621769Sjkh * 8721769Sjkh * 6. Redistributions of any form whatsoever must retain the following 8821769Sjkh * acknowledgment: 8921769Sjkh * "This product includes software developed by the OpenSSL Project 9052286Smdodd * for use in the OpenSSL Toolkit (http://www.openssl.org/)" 9152286Smdodd * 9252286Smdodd * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 9321769Sjkh * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 9452286Smdodd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 9552286Smdodd * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 9652286Smdodd * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 9752286Smdodd * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 9852286Smdodd * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 9952286Smdodd * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 10052286Smdodd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 10152286Smdodd * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 10252286Smdodd * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 10352286Smdodd * OF THE POSSIBILITY OF SUCH DAMAGE. 10452286Smdodd * ==================================================================== 10552286Smdodd * 10652286Smdodd * This product includes cryptographic software written by Eric Young 10752286Smdodd * (eay@cryptsoft.com). This product includes software written by Tim 10852286Smdodd * Hudson (tjh@cryptsoft.com). 10952286Smdodd * 11052286Smdodd */ 11152286Smdodd 11252286Smdodd#ifndef HEADER_APPS_H 11352286Smdodd#define HEADER_APPS_H 11452286Smdodd 11552286Smdodd#include "e_os.h" 11652286Smdodd 11752286Smdodd#include <openssl/buffer.h> 11852286Smdodd#include <openssl/bio.h> 11952286Smdodd#include <openssl/crypto.h> 12052286Smdodd#include <openssl/x509.h> 12152286Smdodd#include <openssl/lhash.h> 12252286Smdodd#include <openssl/conf.h> 12352286Smdodd#include <openssl/txt_db.h> 12452286Smdodd#include <openssl/engine.h> 12552286Smdodd#include <openssl/ossl_typ.h> 12652286Smdodd 12721769Sjkhint app_RAND_load_file(const char *file, BIO *bio_e, int dont_warn); 12821769Sjkhint app_RAND_write_file(const char *file, BIO *bio_e); 12952286Smdodd/* When `file' is NULL, use defaults. 13052286Smdodd * `bio_e' is for error messages. */ 13152286Smdoddvoid app_RAND_allow_write_file(void); 13252286Smdoddlong app_RAND_load_files(char *file); /* `file' is a list of files to read, 13321769Sjkh * separated by LIST_SEPARATOR_CHAR 13452286Smdodd * (see e_os.h). The string is 13552286Smdodd * destroyed! */ 13652286Smdodd 13752286Smdodd#ifdef OPENSSL_SYS_WIN32 13821769Sjkh#define rename(from,to) WIN32_rename((from),(to)) 13952286Smdoddint WIN32_rename(char *oldname,char *newname); 14055882Smdodd#endif 14152286Smdodd 14252286Smdodd/* VMS below version 7.0 doesn't have strcasecmp() */ 14321769Sjkh#ifdef OPENSSL_SYS_VMS 14452286Smdodd#define strcasecmp(str1,str2) VMS_strcasecmp((str1),(str2)) 14552286Smdoddint VMS_strcasecmp(const char *str1, const char *str2); 14652286Smdodd#endif 14752286Smdodd 14852286Smdodd#ifndef MONOLITH 14921769Sjkh 15052286Smdodd#define MAIN(a,v) main(a,v) 15152286Smdodd 15252286Smdodd#ifndef NON_MAIN 15352286SmdoddCONF *config=NULL; 15452286SmdoddBIO *bio_err=NULL; 15552286Smdodd#else 15652286Smdoddextern CONF *config; 15752286Smdoddextern BIO *bio_err; 15852286Smdodd#endif 15952286Smdodd 16052286Smdodd#else 16155882Smdodd 16252286Smdodd#define MAIN(a,v) PROG(a,v) 16352286Smdoddextern CONF *config; 16452286Smdoddextern char *default_config_file; 16552286Smdoddextern BIO *bio_err; 16652286Smdodd 16752286Smdodd#endif 16852286Smdodd 16921769Sjkh#include <signal.h> 17052286Smdodd 17152286Smdodd#ifdef SIGPIPE 17221769Sjkh#define do_pipe_sig() signal(SIGPIPE,SIG_IGN) 17321769Sjkh#else 17452286Smdodd#define do_pipe_sig() 17552286Smdodd#endif 17652286Smdodd 17752286Smdodd#if defined(MONOLITH) && !defined(OPENSSL_C) 17852286Smdodd# define apps_startup() \ 17952286Smdodd do_pipe_sig() 18052286Smdodd# define apps_shutdown() 18152286Smdodd#else 18252286Smdodd# if defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_WIN16) || \ 18352286Smdodd defined(OPENSSL_SYS_WIN32) 18421769Sjkh# ifdef _O_BINARY 18521769Sjkh# define apps_startup() \ 18621769Sjkh do { _fmode=_O_BINARY; do_pipe_sig(); CRYPTO_malloc_init(); \ 18721769Sjkh ERR_load_crypto_strings(); OpenSSL_add_all_algorithms(); \ 18821769Sjkh ENGINE_load_builtin_engines(); setup_ui_method(); } while(0) 18921769Sjkh# else 19021769Sjkh# define apps_startup() \ 19121769Sjkh do { _fmode=O_BINARY; do_pipe_sig(); CRYPTO_malloc_init(); \ 19221769Sjkh ERR_load_crypto_strings(); OpenSSL_add_all_algorithms(); \ 19321769Sjkh ENGINE_load_builtin_engines(); setup_ui_method(); } while(0) 19421769Sjkh# endif 19521769Sjkh# else 19621769Sjkh# define apps_startup() \ 19752286Smdodd do { do_pipe_sig(); OpenSSL_add_all_algorithms(); \ 19821769Sjkh ERR_load_crypto_strings(); ENGINE_load_builtin_engines(); \ 19921769Sjkh setup_ui_method(); } while(0) 20021769Sjkh# endif 20152286Smdodd# define apps_shutdown() \ 20252286Smdodd do { CONF_modules_unload(1); destroy_ui_method(); \ 20352286Smdodd EVP_cleanup(); ENGINE_cleanup(); \ 20452286Smdodd CRYPTO_cleanup_all_ex_data(); ERR_remove_state(0); \ 20521769Sjkh ERR_free_strings(); } while(0) 20652286Smdodd#endif 20752286Smdodd 20852286Smdoddtypedef struct args_st 20952286Smdodd { 21052286Smdodd char **data; 21152286Smdodd int count; 21252286Smdodd } ARGS; 21352286Smdodd 21452286Smdodd#define PW_MIN_LENGTH 4 21552286Smdoddtypedef struct pw_cb_data 21652286Smdodd { 21752286Smdodd const void *password; 21852286Smdodd const char *prompt_info; 21952286Smdodd } PW_CB_DATA; 22021769Sjkh 22152286Smdoddint password_callback(char *buf, int bufsiz, int verify, 22221769Sjkh PW_CB_DATA *cb_data); 22352286Smdodd 22452286Smdoddint setup_ui_method(void); 22552286Smdoddvoid destroy_ui_method(void); 22652286Smdodd 22752286Smdoddint should_retry(int i); 22852286Smdoddint args_from_file(char *file, int *argc, char **argv[]); 22952286Smdoddint str2fmt(char *s); 23052286Smdoddvoid program_name(char *in,char *out,int size); 23152286Smdoddint chopup_args(ARGS *arg,char *buf, int *argc, char **argv[]); 23252286Smdodd#ifdef HEADER_X509_H 23352286Smdoddint dump_cert_text(BIO *out, X509 *x); 23452286Smdoddvoid print_name(BIO *out, char *title, X509_NAME *nm, unsigned long lflags); 23521769Sjkh#endif 23652286Smdoddint set_cert_ex(unsigned long *flags, const char *arg); 23752286Smdoddint set_name_ex(unsigned long *flags, const char *arg); 23852286Smdoddint set_ext_copy(int *copy_type, const char *arg); 23952286Smdoddint copy_extensions(X509 *x, X509_REQ *req, int copy_type); 24052286Smdoddint app_passwd(BIO *err, char *arg1, char *arg2, char **pass1, char **pass2); 24152286Smdoddint add_oid_section(BIO *err, CONF *conf); 24252286SmdoddX509 *load_cert(BIO *err, const char *file, int format, 24352286Smdodd const char *pass, ENGINE *e, const char *cert_descrip); 24452286SmdoddEVP_PKEY *load_key(BIO *err, const char *file, int format, int maybe_stdin, 24555882Smdodd const char *pass, ENGINE *e, const char *key_descrip); 24655882SmdoddEVP_PKEY *load_pubkey(BIO *err, const char *file, int format, int maybe_stdin, 24755882Smdodd const char *pass, ENGINE *e, const char *key_descrip); 24855882SmdoddSTACK_OF(X509) *load_certs(BIO *err, const char *file, int format, 24955882Smdodd const char *pass, ENGINE *e, const char *cert_descrip); 25055882SmdoddX509_STORE *setup_verify(BIO *bp, char *CAfile, char *CApath); 25155882SmdoddENGINE *setup_engine(BIO *err, const char *engine, int debug); 25255882Smdodd 25355882Smdoddint load_config(BIO *err, CONF *cnf); 25455882Smdoddchar *make_config_name(void); 25555882Smdodd 25655882Smdodd/* Functions defined in ca.c and also used in ocsp.c */ 25755882Smdoddint unpack_revinfo(ASN1_TIME **prevtm, int *preason, ASN1_OBJECT **phold, 25855882Smdodd ASN1_GENERALIZEDTIME **pinvtm, char *str); 25955882Smdoddint make_serial_index(TXT_DB *db); 26055882Smdodd 26155882SmdoddX509_NAME *do_subject(char *str, long chtype); 26255882Smdodd 26355882Smdodd#define FORMAT_UNDEF 0 26455882Smdodd#define FORMAT_ASN1 1 26555882Smdodd#define FORMAT_TEXT 2 26655882Smdodd#define FORMAT_PEM 3 26755882Smdodd#define FORMAT_NETSCAPE 4 26855882Smdodd#define FORMAT_PKCS12 5 26955882Smdodd#define FORMAT_SMIME 6 27055882Smdodd#define FORMAT_ENGINE 7 27155882Smdodd#define FORMAT_IISSGC 8 /* XXX this stupid macro helps us to avoid 27255882Smdodd * adding yet another param to load_*key() */ 27355882Smdodd 27455882Smdodd#define EXT_COPY_NONE 0 27555882Smdodd#define EXT_COPY_ADD 1 27655882Smdodd#define EXT_COPY_ALL 2 27755882Smdodd 27855882Smdodd#define NETSCAPE_CERT_HDR "certificate" 27955882Smdodd 28055882Smdodd#define APP_PASS_LEN 1024 28155882Smdodd 28255882Smdodd#endif 28355882Smdodd