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.
8296465Sdelphij *
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).
15296465Sdelphij *
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.
22296465Sdelphij *
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 :-).
37296465Sdelphij * 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)"
40296465Sdelphij *
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.
52296465Sdelphij *
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
66296465Sdelphij *    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
113296465Sdelphij# define HEADER_APPS_H
11455714Skris
115296465Sdelphij# include "e_os.h"
11655714Skris
117296465Sdelphij# include <openssl/bio.h>
118296465Sdelphij# include <openssl/x509.h>
119296465Sdelphij# include <openssl/lhash.h>
120296465Sdelphij# include <openssl/conf.h>
121296465Sdelphij# include <openssl/txt_db.h>
122296465Sdelphij# ifndef OPENSSL_NO_ENGINE
123296465Sdelphij#  include <openssl/engine.h>
124296465Sdelphij# endif
125296465Sdelphij# ifndef OPENSSL_NO_OCSP
126296465Sdelphij#  include <openssl/ocsp.h>
127296465Sdelphij# endif
128296465Sdelphij# 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);
132296465Sdelphij/*
133296465Sdelphij * When `file' is NULL, use defaults. `bio_e' is for error messages.
134296465Sdelphij */
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
141296465Sdelphij# ifdef OPENSSL_SYS_WIN32
142296465Sdelphij#  define rename(from,to) WIN32_rename((from),(to))
143296465Sdelphijint WIN32_rename(const char *oldname, const char *newname);
144296465Sdelphij# endif
14555714Skris
146296465Sdelphij# ifndef MONOLITH
14755714Skris
148296465Sdelphij#  define MAIN(a,v)       main(a,v)
14955714Skris
150296465Sdelphij#  ifndef NON_MAIN
151296465SdelphijCONF *config = NULL;
152296465SdelphijBIO *bio_err = NULL;
153296465Sdelphijint in_FIPS_mode = 0;
154296465Sdelphij#  else
155109998Smarkmextern CONF *config;
15655714Skrisextern BIO *bio_err;
157194206Ssimonextern int in_FIPS_mode;
158296465Sdelphij#  endif
15955714Skris
160296465Sdelphij# else
16155714Skris
162296465Sdelphij#  define MAIN(a,v)       PROG(a,v)
163109998Smarkmextern CONF *config;
16455714Skrisextern char *default_config_file;
16555714Skrisextern BIO *bio_err;
166194206Ssimonextern int in_FIPS_mode;
16755714Skris
168296465Sdelphij# endif
16955714Skris
170296465Sdelphij# ifndef OPENSSL_SYS_NETWARE
171296465Sdelphij#  include <signal.h>
172296465Sdelphij# endif
17355714Skris
174296465Sdelphij# ifdef SIGPIPE
175296465Sdelphij#  define do_pipe_sig()   signal(SIGPIPE,SIG_IGN)
176296465Sdelphij# else
177296465Sdelphij#  define do_pipe_sig()
178296465Sdelphij# endif
17955714Skris
180296465Sdelphij# if defined(MONOLITH) && !defined(OPENSSL_C)
181109998Smarkm#  define apps_startup() \
182296465Sdelphij                do_pipe_sig()
183109998Smarkm#  define apps_shutdown()
184296465Sdelphij# else
185111147Snectar#  ifndef OPENSSL_NO_ENGINE
186296465Sdelphij#   if defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_WIN16) || \
187111147Snectar     defined(OPENSSL_SYS_WIN32)
188296465Sdelphij#    ifdef _O_BINARY
189296465Sdelphij#     define apps_startup() \
190296465Sdelphij                        do { _fmode=_O_BINARY; do_pipe_sig(); CRYPTO_malloc_init(); \
191296465Sdelphij                        ERR_load_crypto_strings(); OpenSSL_add_all_algorithms(); \
192296465Sdelphij                        ENGINE_load_builtin_engines(); setup_ui_method(); } while(0)
193111147Snectar#    else
194296465Sdelphij#     define apps_startup() \
195296465Sdelphij                        do { _fmode=O_BINARY; do_pipe_sig(); CRYPTO_malloc_init(); \
196296465Sdelphij                        ERR_load_crypto_strings(); OpenSSL_add_all_algorithms(); \
197296465Sdelphij                        ENGINE_load_builtin_engines(); setup_ui_method(); } while(0)
198111147Snectar#    endif
199296465Sdelphij#   else
200296465Sdelphij#    define apps_startup() \
201296465Sdelphij                        do { do_pipe_sig(); OpenSSL_add_all_algorithms(); \
202296465Sdelphij                        ERR_load_crypto_strings(); ENGINE_load_builtin_engines(); \
203296465Sdelphij                        setup_ui_method(); } while(0)
204296465Sdelphij#   endif
205296465Sdelphij#   define apps_shutdown() \
206296465Sdelphij                        do { CONF_modules_unload(1); destroy_ui_method(); \
207296465Sdelphij                        EVP_cleanup(); ENGINE_cleanup(); \
208296465Sdelphij                        CRYPTO_cleanup_all_ex_data(); ERR_remove_state(0); \
209296465Sdelphij                        ERR_free_strings(); } while(0)
210111147Snectar#  else
211296465Sdelphij#   if defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_WIN16) || \
212111147Snectar     defined(OPENSSL_SYS_WIN32)
213296465Sdelphij#    ifdef _O_BINARY
214296465Sdelphij#     define apps_startup() \
215296465Sdelphij                        do { _fmode=_O_BINARY; do_pipe_sig(); CRYPTO_malloc_init(); \
216296465Sdelphij                        ERR_load_crypto_strings(); OpenSSL_add_all_algorithms(); \
217296465Sdelphij                        setup_ui_method(); } while(0)
21855714Skris#    else
219296465Sdelphij#     define apps_startup() \
220296465Sdelphij                        do { _fmode=O_BINARY; do_pipe_sig(); CRYPTO_malloc_init(); \
221296465Sdelphij                        ERR_load_crypto_strings(); OpenSSL_add_all_algorithms(); \
222296465Sdelphij                        setup_ui_method(); } while(0)
22355714Skris#    endif
224296465Sdelphij#   else
225296465Sdelphij#    define apps_startup() \
226296465Sdelphij                        do { do_pipe_sig(); OpenSSL_add_all_algorithms(); \
227296465Sdelphij                        ERR_load_crypto_strings(); \
228296465Sdelphij                        setup_ui_method(); } while(0)
229296465Sdelphij#   endif
230296465Sdelphij#   define apps_shutdown() \
231296465Sdelphij                        do { CONF_modules_unload(1); destroy_ui_method(); \
232296465Sdelphij                        EVP_cleanup(); \
233296465Sdelphij                        CRYPTO_cleanup_all_ex_data(); ERR_remove_state(0); \
234296465Sdelphij                        ERR_free_strings(); } while(0)
23555714Skris#  endif
236296465Sdelphij# endif
23755714Skris
238296465Sdelphij# ifdef OPENSSL_SYSNAME_WIN32
239194206Ssimon#  define openssl_fdset(a,b) FD_SET((unsigned int)a, b)
240296465Sdelphij# else
241194206Ssimon#  define openssl_fdset(a,b) FD_SET(a, b)
242296465Sdelphij# endif
243194206Ssimon
244296465Sdelphijtypedef struct args_st {
245296465Sdelphij    char **data;
246296465Sdelphij    int count;
247296465Sdelphij} ARGS;
24855714Skris
249296465Sdelphij# define PW_MIN_LENGTH 4
250296465Sdelphijtypedef struct pw_cb_data {
251296465Sdelphij    const void *password;
252296465Sdelphij    const char *prompt_info;
253296465Sdelphij} PW_CB_DATA;
254109998Smarkm
255296465Sdelphijint password_callback(char *buf, int bufsiz, int verify, PW_CB_DATA *cb_data);
256109998Smarkm
257109998Smarkmint setup_ui_method(void);
258109998Smarkmvoid destroy_ui_method(void);
259109998Smarkm
26055714Skrisint should_retry(int i);
26155714Skrisint args_from_file(char *file, int *argc, char **argv[]);
26255714Skrisint str2fmt(char *s);
263296465Sdelphijvoid program_name(char *in, char *out, int size);
264296465Sdelphijint chopup_args(ARGS *arg, char *buf, int *argc, char **argv[]);
265296465Sdelphij# ifdef HEADER_X509_H
26659191Skrisint dump_cert_text(BIO *out, X509 *x);
267296465Sdelphijvoid print_name(BIO *out, const char *title, X509_NAME *nm,
268296465Sdelphij                unsigned long lflags);
269296465Sdelphij# endif
270109998Smarkmint set_cert_ex(unsigned long *flags, const char *arg);
27168651Skrisint set_name_ex(unsigned long *flags, const char *arg);
272109998Smarkmint set_ext_copy(int *copy_type, const char *arg);
273109998Smarkmint copy_extensions(X509 *x, X509_REQ *req, int copy_type);
27459191Skrisint app_passwd(BIO *err, char *arg1, char *arg2, char **pass1, char **pass2);
275109998Smarkmint add_oid_section(BIO *err, CONF *conf);
276109998SmarkmX509 *load_cert(BIO *err, const char *file, int format,
277296465Sdelphij                const char *pass, ENGINE *e, const char *cert_descrip);
278109998SmarkmEVP_PKEY *load_key(BIO *err, const char *file, int format, int maybe_stdin,
279296465Sdelphij                   const char *pass, ENGINE *e, const char *key_descrip);
280109998SmarkmEVP_PKEY *load_pubkey(BIO *err, const char *file, int format, int maybe_stdin,
281296465Sdelphij                      const char *pass, ENGINE *e, const char *key_descrip);
282109998SmarkmSTACK_OF(X509) *load_certs(BIO *err, const char *file, int format,
283296465Sdelphij                           const char *pass, ENGINE *e,
284296465Sdelphij                           const char *cert_descrip);
285109998SmarkmX509_STORE *setup_verify(BIO *bp, char *CAfile, char *CApath);
286296465Sdelphij# ifndef OPENSSL_NO_ENGINE
287109998SmarkmENGINE *setup_engine(BIO *err, const char *engine, int debug);
288296465Sdelphij# endif
28968651Skris
290296465Sdelphij# ifndef OPENSSL_NO_OCSP
291194206SsimonOCSP_RESPONSE *process_responder(BIO *err, OCSP_REQUEST *req,
292296465Sdelphij                                 char *host, char *path, char *port,
293296465Sdelphij                                 int use_ssl, int req_timeout);
294296465Sdelphij# 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,
301296465Sdelphij                   ASN1_GENERALIZEDTIME **pinvtm, const char *str);
302109998Smarkm
303296465Sdelphij# define DB_type         0
304296465Sdelphij# define DB_exp_date     1
305296465Sdelphij# define DB_rev_date     2
306296465Sdelphij# define DB_serial       3      /* index - unique */
307296465Sdelphij# define DB_file         4
308296465Sdelphij# define DB_name         5      /* index - unique when active and not
309296465Sdelphij                                 * disabled */
310296465Sdelphij# define DB_NUMBER       6
311127128Snectar
312296465Sdelphij# define DB_TYPE_REV     'R'
313296465Sdelphij# define DB_TYPE_EXP     'E'
314296465Sdelphij# define DB_TYPE_VAL     'V'
315127128Snectar
316296465Sdelphijtypedef struct db_attr_st {
317296465Sdelphij    int unique_subject;
318296465Sdelphij} DB_ATTR;
319296465Sdelphijtypedef struct ca_db_st {
320296465Sdelphij    DB_ATTR attributes;
321296465Sdelphij    TXT_DB *db;
322296465Sdelphij} CA_DB;
323127128Snectar
324127128SnectarBIGNUM *load_serial(char *serialfile, int create, ASN1_INTEGER **retai);
325296465Sdelphijint save_serial(char *serialfile, char *suffix, BIGNUM *serial,
326296465Sdelphij                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);
332296465Sdelphijint rotate_index(const char *dbfile, const char *new_suffix,
333296465Sdelphij                 const char *old_suffix);
334127128Snectarvoid free_index(CA_DB *db);
335127128Snectarint index_name_cmp(const char **a, const char **b);
336160814Ssimonint parse_yesno(const char *str, int def);
337127128Snectar
338160814SsimonX509_NAME *parse_name(char *str, long chtype, int multirdn);
339160814Ssimonint args_verify(char ***pargs, int *pargc,
340296465Sdelphij                int *badarg, BIO *err, X509_VERIFY_PARAM **pm);
341160814Ssimonvoid policies_print(BIO *out, X509_STORE_CTX *ctx);
342296465Sdelphij# ifndef OPENSSL_NO_JPAKE
343194206Ssimonvoid jpake_client_auth(BIO *out, BIO *conn, const char *secret);
344194206Ssimonvoid jpake_server_auth(BIO *out, BIO *conn, const char *secret);
345296465Sdelphij# endif
346109998Smarkm
347296465Sdelphij# define FORMAT_UNDEF    0
348296465Sdelphij# define FORMAT_ASN1     1
349296465Sdelphij# define FORMAT_TEXT     2
350296465Sdelphij# define FORMAT_PEM      3
351296465Sdelphij# define FORMAT_NETSCAPE 4
352296465Sdelphij# define FORMAT_PKCS12   5
353296465Sdelphij# define FORMAT_SMIME    6
354296465Sdelphij# define FORMAT_ENGINE   7
355296465Sdelphij# define FORMAT_IISSGC   8      /* XXX this stupid macro helps us to avoid
356296465Sdelphij                                 * adding yet another param to load_*key() */
35755714Skris
358296465Sdelphij# define EXT_COPY_NONE   0
359296465Sdelphij# define EXT_COPY_ADD    1
360296465Sdelphij# define EXT_COPY_ALL    2
361109998Smarkm
362296465Sdelphij# define NETSCAPE_CERT_HDR       "certificate"
36368651Skris
364296465Sdelphij# define APP_PASS_LEN    1024
36559191Skris
366296465Sdelphij# define SERIAL_RAND_BITS        64
367142425Snectar
36855714Skris#endif
369