apps.h revision 111147
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/buffer.h>
11855714Skris#include <openssl/bio.h>
11955714Skris#include <openssl/crypto.h>
12059191Skris#include <openssl/x509.h>
12168651Skris#include <openssl/lhash.h>
12268651Skris#include <openssl/conf.h>
123109998Smarkm#include <openssl/txt_db.h>
124111147Snectar#ifndef OPENSSL_NO_ENGINE
125109998Smarkm#include <openssl/engine.h>
126111147Snectar#endif
127109998Smarkm#include <openssl/ossl_typ.h>
12855714Skris
12959191Skrisint app_RAND_load_file(const char *file, BIO *bio_e, int dont_warn);
13059191Skrisint app_RAND_write_file(const char *file, BIO *bio_e);
13159191Skris/* When `file' is NULL, use defaults.
13259191Skris * `bio_e' is for error messages. */
13359191Skrisvoid app_RAND_allow_write_file(void);
13459191Skrislong app_RAND_load_files(char *file); /* `file' is a list of files to read,
13559191Skris                                       * separated by LIST_SEPARATOR_CHAR
13659191Skris                                       * (see e_os.h).  The string is
13759191Skris                                       * destroyed! */
13859191Skris
139109998Smarkm#ifdef OPENSSL_SYS_WIN32
14055714Skris#define rename(from,to) WIN32_rename((from),(to))
14155714Skrisint WIN32_rename(char *oldname,char *newname);
14255714Skris#endif
14355714Skris
144109998Smarkm/* VMS below version 7.0 doesn't have strcasecmp() */
145109998Smarkm#ifdef OPENSSL_SYS_VMS
146109998Smarkm#define strcasecmp(str1,str2) VMS_strcasecmp((str1),(str2))
147109998Smarkmint VMS_strcasecmp(const char *str1, const char *str2);
148109998Smarkm#endif
149109998Smarkm
15055714Skris#ifndef MONOLITH
15155714Skris
15255714Skris#define MAIN(a,v)	main(a,v)
15355714Skris
15455714Skris#ifndef NON_MAIN
155109998SmarkmCONF *config=NULL;
15655714SkrisBIO *bio_err=NULL;
15755714Skris#else
158109998Smarkmextern CONF *config;
15955714Skrisextern BIO *bio_err;
16055714Skris#endif
16155714Skris
16255714Skris#else
16355714Skris
16455714Skris#define MAIN(a,v)	PROG(a,v)
165109998Smarkmextern CONF *config;
16655714Skrisextern char *default_config_file;
16755714Skrisextern BIO *bio_err;
16855714Skris
16955714Skris#endif
17055714Skris
17155714Skris#include <signal.h>
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
23755714Skristypedef struct args_st
23855714Skris	{
23955714Skris	char **data;
24055714Skris	int count;
24155714Skris	} ARGS;
24255714Skris
243109998Smarkm#define PW_MIN_LENGTH 4
244109998Smarkmtypedef struct pw_cb_data
245109998Smarkm	{
246109998Smarkm	const void *password;
247109998Smarkm	const char *prompt_info;
248109998Smarkm	} PW_CB_DATA;
249109998Smarkm
250109998Smarkmint password_callback(char *buf, int bufsiz, int verify,
251109998Smarkm	PW_CB_DATA *cb_data);
252109998Smarkm
253109998Smarkmint setup_ui_method(void);
254109998Smarkmvoid destroy_ui_method(void);
255109998Smarkm
25655714Skrisint should_retry(int i);
25755714Skrisint args_from_file(char *file, int *argc, char **argv[]);
25855714Skrisint str2fmt(char *s);
25955714Skrisvoid program_name(char *in,char *out,int size);
26055714Skrisint chopup_args(ARGS *arg,char *buf, int *argc, char **argv[]);
26159191Skris#ifdef HEADER_X509_H
26259191Skrisint dump_cert_text(BIO *out, X509 *x);
26368651Skrisvoid print_name(BIO *out, char *title, X509_NAME *nm, unsigned long lflags);
26459191Skris#endif
265109998Smarkmint set_cert_ex(unsigned long *flags, const char *arg);
26668651Skrisint set_name_ex(unsigned long *flags, const char *arg);
267109998Smarkmint set_ext_copy(int *copy_type, const char *arg);
268109998Smarkmint copy_extensions(X509 *x, X509_REQ *req, int copy_type);
26959191Skrisint app_passwd(BIO *err, char *arg1, char *arg2, char **pass1, char **pass2);
270109998Smarkmint add_oid_section(BIO *err, CONF *conf);
271109998SmarkmX509 *load_cert(BIO *err, const char *file, int format,
272109998Smarkm	const char *pass, ENGINE *e, const char *cert_descrip);
273109998SmarkmEVP_PKEY *load_key(BIO *err, const char *file, int format, int maybe_stdin,
274109998Smarkm	const char *pass, ENGINE *e, const char *key_descrip);
275109998SmarkmEVP_PKEY *load_pubkey(BIO *err, const char *file, int format, int maybe_stdin,
276109998Smarkm	const char *pass, ENGINE *e, const char *key_descrip);
277109998SmarkmSTACK_OF(X509) *load_certs(BIO *err, const char *file, int format,
278109998Smarkm	const char *pass, ENGINE *e, const char *cert_descrip);
279109998SmarkmX509_STORE *setup_verify(BIO *bp, char *CAfile, char *CApath);
280111147Snectar#ifndef OPENSSL_NO_ENGINE
281109998SmarkmENGINE *setup_engine(BIO *err, const char *engine, int debug);
282111147Snectar#endif
28368651Skris
284109998Smarkmint load_config(BIO *err, CONF *cnf);
285109998Smarkmchar *make_config_name(void);
286109998Smarkm
287109998Smarkm/* Functions defined in ca.c and also used in ocsp.c */
288109998Smarkmint unpack_revinfo(ASN1_TIME **prevtm, int *preason, ASN1_OBJECT **phold,
289109998Smarkm			ASN1_GENERALIZEDTIME **pinvtm, char *str);
290109998Smarkmint make_serial_index(TXT_DB *db);
291109998Smarkm
292109998SmarkmX509_NAME *do_subject(char *str, long chtype);
293109998Smarkm
29455714Skris#define FORMAT_UNDEF    0
29555714Skris#define FORMAT_ASN1     1
29655714Skris#define FORMAT_TEXT     2
29755714Skris#define FORMAT_PEM      3
29855714Skris#define FORMAT_NETSCAPE 4
29968651Skris#define FORMAT_PKCS12   5
30068651Skris#define FORMAT_SMIME    6
301109998Smarkm#define FORMAT_ENGINE   7
302109998Smarkm#define FORMAT_IISSGC	8	/* XXX this stupid macro helps us to avoid
303109998Smarkm				 * adding yet another param to load_*key() */
30455714Skris
305109998Smarkm#define EXT_COPY_NONE	0
306109998Smarkm#define EXT_COPY_ADD	1
307109998Smarkm#define EXT_COPY_ALL	2
308109998Smarkm
30968651Skris#define NETSCAPE_CERT_HDR	"certificate"
31068651Skris
31159191Skris#define APP_PASS_LEN	1024
31259191Skris
31355714Skris#endif
314