apps.h 7.2 KB
Newer Older
1
/* apps/apps.h */
2
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
 * All rights reserved.
 *
 * This package is an SSL implementation written
 * by Eric Young (eay@cryptsoft.com).
 * The implementation was written so as to conform with Netscapes SSL.
 * 
 * This library is free for commercial and non-commercial use as long as
 * the following conditions are aheared to.  The following conditions
 * apply to all code found in this distribution, be it the RC4, RSA,
 * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
 * included with this distribution is covered by the same copyright terms
 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
 * 
 * Copyright remains Eric Young's, and as such any Copyright notices in
 * the code are not to be removed.
 * If this package is used in a product, Eric Young should be given attribution
 * as the author of the parts of the library used.
 * This can be in the form of a textual message at program startup or
 * in documentation (online or textual) provided with the package.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *    "This product includes cryptographic software written by
 *     Eric Young (eay@cryptsoft.com)"
 *    The word 'cryptographic' can be left out if the rouines from the library
 *    being used are not cryptographic related :-).
 * 4. If you include any Windows specific code (or a derivative thereof) from 
 *    the apps directory (application code) you must include an acknowledgement:
 *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
 * 
 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * 
 * The licence and distribution terms for any publically available version or
 * derivative of this code cannot be changed.  i.e. this code cannot simply be
 * copied and put under another distribution licence
 * [including the GNU Public Licence.]
 */

#ifndef HEADER_APPS_H
#define HEADER_APPS_H

62
#include "e_os.h"
63

64 65 66
#include <openssl/buffer.h>
#include <openssl/bio.h>
#include <openssl/crypto.h>
D
 
Dr. Stephen Henson 已提交
67
#include <openssl/x509.h>
68
#include <openssl/lhash.h>
69
#include <openssl/conf.h>
70
#include <openssl/engine.h>
71

72 73 74 75 76 77 78 79 80 81
int app_RAND_load_file(const char *file, BIO *bio_e, int dont_warn);
int app_RAND_write_file(const char *file, BIO *bio_e);
/* When `file' is NULL, use defaults.
 * `bio_e' is for error messages. */
void app_RAND_allow_write_file(void);
long app_RAND_load_files(char *file); /* `file' is a list of files to read,
                                       * separated by LIST_SEPARATOR_CHAR
                                       * (see e_os.h).  The string is
                                       * destroyed! */

82
#ifdef OPENSSL_NO_STDIO
83 84 85
BIO_METHOD *BIO_s_file();
#endif

86
#ifdef OPENSSL_SYS_WIN32
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
#define rename(from,to) WIN32_rename((from),(to))
int WIN32_rename(char *oldname,char *newname);
#endif

#ifndef MONOLITH

#define MAIN(a,v)	main(a,v)

#ifndef NON_MAIN
BIO *bio_err=NULL;
#else
extern BIO *bio_err;
#endif

#else

#define MAIN(a,v)	PROG(a,v)
D
 
Dr. Stephen Henson 已提交
104
extern CONF *config;
105 106 107 108 109 110 111 112 113 114 115 116 117
extern char *default_config_file;
extern BIO *bio_err;

#endif

#include <signal.h>

#ifdef SIGPIPE
#define do_pipe_sig()	signal(SIGPIPE,SIG_IGN)
#else
#define do_pipe_sig()
#endif

118
#if defined(MONOLITH) && !defined(OPENSSL_C)
119 120 121
#  define apps_startup() \
		do_pipe_sig()
#  define apps_shutdown()
122
#else
123 124
#  if defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_WIN16) || \
   defined(OPENSSL_SYS_WIN32)
125 126
#    ifdef _O_BINARY
#      define apps_startup() \
127
		do { _fmode=_O_BINARY; do_pipe_sig(); CRYPTO_malloc_init(); \
128
		OpenSSL_add_all_algorithms(); ENGINE_load_builtin_engines(); \
129
                setup_ui_method(); } while(0)
130 131
#    else
#      define apps_startup() \
132
		do { _fmode=O_BINARY; do_pipe_sig(); CRYPTO_malloc_init(); \
133
		OpenSSL_add_all_algorithms(); ENGINE_load_builtin_engines(); \
134
                setup_ui_method(); } while(0)
135 136
#    endif
#  else
137
#    define apps_startup() \
138 139
		do { do_pipe_sig(); OpenSSL_add_all_algorithms(); \
		ENGINE_load_builtin_engines(); setup_ui_method(); } while(0)
140
#  endif
141 142
#  define apps_shutdown() \
		destroy_ui_method()
143 144 145
#endif

typedef struct args_st
146 147
	{
	char **data;
148
	int count;
149
	} ARGS;
150

151 152 153 154 155 156 157 158 159 160
#define PW_MIN_LENGTH 4
typedef struct pw_cb_data
	{
	const void *password;
	const char *prompt_info;
	} PW_CB_DATA;

int password_callback(char *buf, int bufsiz, int verify,
	PW_CB_DATA *cb_data);

161
int setup_ui_method();
D
Dr. Stephen Henson 已提交
162
void destroy_ui_method();
163

164 165 166 167 168
int should_retry(int i);
int args_from_file(char *file, int *argc, char **argv[]);
int str2fmt(char *s);
void program_name(char *in,char *out,int size);
int chopup_args(ARGS *arg,char *buf, int *argc, char **argv[]);
D
 
Dr. Stephen Henson 已提交
169 170
#ifdef HEADER_X509_H
int dump_cert_text(BIO *out, X509 *x);
D
 
Dr. Stephen Henson 已提交
171
void print_name(BIO *out, char *title, X509_NAME *nm, unsigned long lflags);
D
 
Dr. Stephen Henson 已提交
172
#endif
173
int set_cert_ex(unsigned long *flags, const char *arg);
D
 
Dr. Stephen Henson 已提交
174
int set_name_ex(unsigned long *flags, const char *arg);
175 176
int set_ext_copy(int *copy_type, const char *arg);
int copy_extensions(X509 *x, X509_REQ *req, int copy_type);
D
Dr. Stephen Henson 已提交
177
int app_passwd(BIO *err, char *arg1, char *arg2, char **pass1, char **pass2);
D
 
Dr. Stephen Henson 已提交
178
int add_oid_section(BIO *err, CONF *conf);
179 180 181 182 183 184 185 186
X509 *load_cert(BIO *err, const char *file, int format,
	const char *pass, ENGINE *e, const char *cert_descrip);
EVP_PKEY *load_key(BIO *err, const char *file, int format,
	const char *pass, ENGINE *e, const char *key_descrip);
EVP_PKEY *load_pubkey(BIO *err, const char *file, int format,
	const char *pass, ENGINE *e, const char *key_descrip);
STACK_OF(X509) *load_certs(BIO *err, const char *file, int format,
	const char *pass, ENGINE *e, const char *cert_descrip);
D
 
Dr. Stephen Henson 已提交
187
X509_STORE *setup_verify(BIO *bp, char *CAfile, char *CApath);
188
ENGINE *setup_engine(BIO *err, const char *engine, int debug);
189

190 191 192 193 194
#define FORMAT_UNDEF    0
#define FORMAT_ASN1     1
#define FORMAT_TEXT     2
#define FORMAT_PEM      3
#define FORMAT_NETSCAPE 4
195
#define FORMAT_PKCS12   5
196
#define FORMAT_SMIME    6
197
#define FORMAT_ENGINE   7
198

199 200 201 202
#define EXT_COPY_NONE	0
#define EXT_COPY_ADD	1
#define EXT_COPY_ALL	2

203
#define NETSCAPE_CERT_HDR	"certificate"
204

D
Dr. Stephen Henson 已提交
205 206
#define APP_PASS_LEN	1024

207
#endif