apps.h

00001 /* apps/apps.h */
00002 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
00003  * All rights reserved.
00004  *
00005  * This package is an SSL implementation written
00006  * by Eric Young (eay@cryptsoft.com).
00007  * The implementation was written so as to conform with Netscapes SSL.
00008  * 
00009  * This library is free for commercial and non-commercial use as long as
00010  * the following conditions are aheared to.  The following conditions
00011  * apply to all code found in this distribution, be it the RC4, RSA,
00012  * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
00013  * included with this distribution is covered by the same copyright terms
00014  * except that the holder is Tim Hudson (tjh@cryptsoft.com).
00015  * 
00016  * Copyright remains Eric Young's, and as such any Copyright notices in
00017  * the code are not to be removed.
00018  * If this package is used in a product, Eric Young should be given attribution
00019  * as the author of the parts of the library used.
00020  * This can be in the form of a textual message at program startup or
00021  * in documentation (online or textual) provided with the package.
00022  * 
00023  * Redistribution and use in source and binary forms, with or without
00024  * modification, are permitted provided that the following conditions
00025  * are met:
00026  * 1. Redistributions of source code must retain the copyright
00027  *    notice, this list of conditions and the following disclaimer.
00028  * 2. Redistributions in binary form must reproduce the above copyright
00029  *    notice, this list of conditions and the following disclaimer in the
00030  *    documentation and/or other materials provided with the distribution.
00031  * 3. All advertising materials mentioning features or use of this software
00032  *    must display the following acknowledgement:
00033  *    "This product includes cryptographic software written by
00034  *     Eric Young (eay@cryptsoft.com)"
00035  *    The word 'cryptographic' can be left out if the rouines from the library
00036  *    being used are not cryptographic related :-).
00037  * 4. If you include any Windows specific code (or a derivative thereof) from 
00038  *    the apps directory (application code) you must include an acknowledgement:
00039  *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
00040  * 
00041  * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
00042  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00043  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00044  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
00045  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00046  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00047  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00048  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00049  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00050  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00051  * SUCH DAMAGE.
00052  * 
00053  * The licence and distribution terms for any publically available version or
00054  * derivative of this code cannot be changed.  i.e. this code cannot simply be
00055  * copied and put under another distribution licence
00056  * [including the GNU Public Licence.]
00057  */
00058 /* ====================================================================
00059  * Copyright (c) 1998-2001 The OpenSSL Project.  All rights reserved.
00060  *
00061  * Redistribution and use in source and binary forms, with or without
00062  * modification, are permitted provided that the following conditions
00063  * are met:
00064  *
00065  * 1. Redistributions of source code must retain the above copyright
00066  *    notice, this list of conditions and the following disclaimer. 
00067  *
00068  * 2. Redistributions in binary form must reproduce the above copyright
00069  *    notice, this list of conditions and the following disclaimer in
00070  *    the documentation and/or other materials provided with the
00071  *    distribution.
00072  *
00073  * 3. All advertising materials mentioning features or use of this
00074  *    software must display the following acknowledgment:
00075  *    "This product includes software developed by the OpenSSL Project
00076  *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
00077  *
00078  * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
00079  *    endorse or promote products derived from this software without
00080  *    prior written permission. For written permission, please contact
00081  *    openssl-core@openssl.org.
00082  *
00083  * 5. Products derived from this software may not be called "OpenSSL"
00084  *    nor may "OpenSSL" appear in their names without prior written
00085  *    permission of the OpenSSL Project.
00086  *
00087  * 6. Redistributions of any form whatsoever must retain the following
00088  *    acknowledgment:
00089  *    "This product includes software developed by the OpenSSL Project
00090  *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
00091  *
00092  * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
00093  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00094  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00095  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
00096  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00097  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00098  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00099  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00100  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
00101  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00102  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
00103  * OF THE POSSIBILITY OF SUCH DAMAGE.
00104  * ====================================================================
00105  *
00106  * This product includes cryptographic software written by Eric Young
00107  * (eay@cryptsoft.com).  This product includes software written by Tim
00108  * Hudson (tjh@cryptsoft.com).
00109  *
00110  */
00111 
00112 #ifndef HEADER_APPS_H
00113 #define HEADER_APPS_H
00114 
00115 #include "e_os.h"
00116 
00117 #include <openssl/bio.h>
00118 #include <openssl/x509.h>
00119 #include <openssl/lhash.h>
00120 #include <openssl/conf.h>
00121 #include <openssl/txt_db.h>
00122 #ifndef OPENSSL_NO_ENGINE
00123 #include <openssl/engine.h>
00124 #endif
00125 #ifndef OPENSSL_NO_OCSP
00126 #include <openssl/ocsp.h>
00127 #endif
00128 #include <openssl/ossl_typ.h>
00129 
00130 int app_RAND_load_file(const char *file, BIO *bio_e, int dont_warn);
00131 int app_RAND_write_file(const char *file, BIO *bio_e);
00132 /* When `file' is NULL, use defaults.
00133  * `bio_e' is for error messages. */
00134 void app_RAND_allow_write_file(void);
00135 long app_RAND_load_files(char *file); /* `file' is a list of files to read,
00136                                        * separated by LIST_SEPARATOR_CHAR
00137                                        * (see e_os.h).  The string is
00138                                        * destroyed! */
00139 
00140 #ifndef MONOLITH
00141 
00142 #define MAIN(a,v)       main(a,v)
00143 
00144 #ifndef NON_MAIN
00145 CONF *config=NULL;
00146 BIO *bio_err=NULL;
00147 #else
00148 extern CONF *config;
00149 extern BIO *bio_err;
00150 #endif
00151 
00152 #else
00153 
00154 #define MAIN(a,v)       PROG(a,v)
00155 extern CONF *config;
00156 extern char *default_config_file;
00157 extern BIO *bio_err;
00158 
00159 #endif
00160 
00161 #ifndef OPENSSL_SYS_NETWARE
00162 #include <signal.h>
00163 #endif
00164 
00165 #ifdef SIGPIPE
00166 #define do_pipe_sig()   signal(SIGPIPE,SIG_IGN)
00167 #else
00168 #define do_pipe_sig()
00169 #endif
00170 
00171 #ifdef OPENSSL_NO_COMP
00172 #define zlib_cleanup() 
00173 #else
00174 #define zlib_cleanup() COMP_zlib_cleanup()
00175 #endif
00176 
00177 #if defined(MONOLITH) && !defined(OPENSSL_C)
00178 #  define apps_startup() \
00179                 do_pipe_sig()
00180 #  define apps_shutdown()
00181 #else
00182 #  ifndef OPENSSL_NO_ENGINE
00183 #    define apps_startup() \
00184                         do { do_pipe_sig(); CRYPTO_malloc_init(); \
00185                         ERR_load_crypto_strings(); OpenSSL_add_all_algorithms(); \
00186                         ENGINE_load_builtin_engines(); setup_ui_method(); } while(0)
00187 #    define apps_shutdown() \
00188                         do { CONF_modules_unload(1); destroy_ui_method(); \
00189                         OBJ_cleanup(); EVP_cleanup(); ENGINE_cleanup(); \
00190                         CRYPTO_cleanup_all_ex_data(); ERR_remove_thread_state(NULL); \
00191                         ERR_free_strings(); zlib_cleanup();} while(0)
00192 #  else
00193 #    define apps_startup() \
00194                         do { do_pipe_sig(); CRYPTO_malloc_init(); \
00195                         ERR_load_crypto_strings(); OpenSSL_add_all_algorithms(); \
00196                         setup_ui_method(); } while(0)
00197 #    define apps_shutdown() \
00198                         do { CONF_modules_unload(1); destroy_ui_method(); \
00199                         OBJ_cleanup(); EVP_cleanup(); \
00200                         CRYPTO_cleanup_all_ex_data(); ERR_remove_thread_state(NULL); \
00201                         ERR_free_strings(); zlib_cleanup(); } while(0)
00202 #  endif
00203 #endif
00204 
00205 #ifdef OPENSSL_SYSNAME_WIN32
00206 #  define openssl_fdset(a,b) FD_SET((unsigned int)a, b)
00207 #else
00208 #  define openssl_fdset(a,b) FD_SET(a, b)
00209 #endif
00210 
00211 
00212 typedef struct args_st
00213         {
00214         char **data;
00215         int count;
00216         } ARGS;
00217 
00218 #define PW_MIN_LENGTH 4
00219 typedef struct pw_cb_data
00220         {
00221         const void *password;
00222         const char *prompt_info;
00223         } PW_CB_DATA;
00224 
00225 int password_callback(char *buf, int bufsiz, int verify,
00226         PW_CB_DATA *cb_data);
00227 
00228 int setup_ui_method(void);
00229 void destroy_ui_method(void);
00230 
00231 int should_retry(int i);
00232 int args_from_file(char *file, int *argc, char **argv[]);
00233 int str2fmt(char *s);
00234 void program_name(char *in,char *out,int size);
00235 int chopup_args(ARGS *arg,char *buf, int *argc, char **argv[]);
00236 #ifdef HEADER_X509_H
00237 int dump_cert_text(BIO *out, X509 *x);
00238 void print_name(BIO *out, const char *title, X509_NAME *nm, unsigned long lflags);
00239 #endif
00240 int set_cert_ex(unsigned long *flags, const char *arg);
00241 int set_name_ex(unsigned long *flags, const char *arg);
00242 int set_ext_copy(int *copy_type, const char *arg);
00243 int copy_extensions(X509 *x, X509_REQ *req, int copy_type);
00244 int app_passwd(BIO *err, char *arg1, char *arg2, char **pass1, char **pass2);
00245 int add_oid_section(BIO *err, CONF *conf);
00246 X509 *load_cert(BIO *err, const char *file, int format,
00247         const char *pass, ENGINE *e, const char *cert_descrip);
00248 EVP_PKEY *load_key(BIO *err, const char *file, int format, int maybe_stdin,
00249         const char *pass, ENGINE *e, const char *key_descrip);
00250 EVP_PKEY *load_pubkey(BIO *err, const char *file, int format, int maybe_stdin,
00251         const char *pass, ENGINE *e, const char *key_descrip);
00252 STACK_OF(X509) *load_certs(BIO *err, const char *file, int format,
00253         const char *pass, ENGINE *e, const char *cert_descrip);
00254 STACK_OF(X509_CRL) *load_crls(BIO *err, const char *file, int format,
00255         const char *pass, ENGINE *e, const char *cert_descrip);
00256 X509_STORE *setup_verify(BIO *bp, const char *CAfile, char *CApath);
00257 #ifndef OPENSSL_NO_ENGINE
00258 ENGINE *setup_engine(BIO *err, const char *engine, int debug);
00259 #endif
00260 
00261 #ifndef OPENSSL_NO_OCSP
00262 OCSP_RESPONSE *process_responder(BIO *err, OCSP_REQUEST *req,
00263                         char *host, char *path, char *port, int use_ssl,
00264                         STACK_OF(CONF_VALUE) *headers,
00265                         int req_timeout);
00266 #endif
00267 
00268 int load_config(BIO *err, CONF *cnf);
00269 char *make_config_name(void);
00270 
00271 /* Functions defined in ca.c and also used in ocsp.c */
00272 int unpack_revinfo(ASN1_TIME **prevtm, int *preason, ASN1_OBJECT **phold,
00273                         ASN1_GENERALIZEDTIME **pinvtm, const char *str);
00274 
00275 #define DB_type         0
00276 #define DB_exp_date     1
00277 #define DB_rev_date     2
00278 #define DB_serial       3       /* index - unique */
00279 #define DB_file         4       
00280 #define DB_name         5       /* index - unique when active and not disabled */
00281 #define DB_NUMBER       6
00282 
00283 #define DB_TYPE_REV     'R'
00284 #define DB_TYPE_EXP     'E'
00285 #define DB_TYPE_VAL     'V'
00286 
00287 typedef struct db_attr_st
00288         {
00289         int unique_subject;
00290         } DB_ATTR;
00291 typedef struct ca_db_st
00292         {
00293         DB_ATTR attributes;
00294         TXT_DB *db;
00295         } CA_DB;
00296 
00297 BIGNUM *load_serial(char *serialfile, int create, ASN1_INTEGER **retai);
00298 int save_serial(char *serialfile, char *suffix, BIGNUM *serial, ASN1_INTEGER **retai);
00299 int rotate_serial(char *serialfile, char *new_suffix, char *old_suffix);
00300 int rand_serial(BIGNUM *b, ASN1_INTEGER *ai);
00301 CA_DB *load_index(char *dbfile, DB_ATTR *dbattr);
00302 int index_index(CA_DB *db);
00303 int save_index(const char *dbfile, const char *suffix, CA_DB *db);
00304 int rotate_index(const char *dbfile, const char *new_suffix, const char *old_suffix);
00305 void free_index(CA_DB *db);
00306 #define index_name_cmp_noconst(a, b) \
00307         index_name_cmp((const OPENSSL_CSTRING *)CHECKED_PTR_OF(OPENSSL_STRING, a), \
00308         (const OPENSSL_CSTRING *)CHECKED_PTR_OF(OPENSSL_STRING, b))
00309 int index_name_cmp(const OPENSSL_CSTRING *a, const OPENSSL_CSTRING *b);
00310 int parse_yesno(const char *str, int def);
00311 
00312 X509_NAME *parse_name(char *str, long chtype, int multirdn);
00313 int args_verify(char ***pargs, int *pargc,
00314                         int *badarg, BIO *err, X509_VERIFY_PARAM **pm);
00315 void policies_print(BIO *out, X509_STORE_CTX *ctx);
00316 int bio_to_mem(unsigned char **out, int maxlen, BIO *in);
00317 int pkey_ctrl_string(EVP_PKEY_CTX *ctx, char *value);
00318 int init_gen_str(BIO *err, EVP_PKEY_CTX **pctx,
00319                         const char *algname, ENGINE *e, int do_param);
00320 #ifndef OPENSSL_NO_PSK
00321 extern char *psk_key;
00322 #endif
00323 #ifndef OPENSSL_NO_JPAKE
00324 void jpake_client_auth(BIO *out, BIO *conn, const char *secret);
00325 void jpake_server_auth(BIO *out, BIO *conn, const char *secret);
00326 #endif
00327 
00328 #define FORMAT_UNDEF    0
00329 #define FORMAT_ASN1     1
00330 #define FORMAT_TEXT     2
00331 #define FORMAT_PEM      3
00332 #define FORMAT_NETSCAPE 4
00333 #define FORMAT_PKCS12   5
00334 #define FORMAT_SMIME    6
00335 #define FORMAT_ENGINE   7
00336 #define FORMAT_IISSGC   8       /* XXX this stupid macro helps us to avoid
00337                                  * adding yet another param to load_*key() */
00338 #define FORMAT_PEMRSA   9       /* PEM RSAPubicKey format */
00339 #define FORMAT_ASN1RSA  10      /* DER RSAPubicKey format */
00340 #define FORMAT_MSBLOB   11      /* MS Key blob format */
00341 #define FORMAT_PVK      12      /* MS PVK file format */
00342 
00343 #define EXT_COPY_NONE   0
00344 #define EXT_COPY_ADD    1
00345 #define EXT_COPY_ALL    2
00346 
00347 #define NETSCAPE_CERT_HDR       "certificate"
00348 
00349 #define APP_PASS_LEN    1024
00350 
00351 #define SERIAL_RAND_BITS        64
00352 
00353 int app_isdir(const char *);
00354 int raw_read_stdin(void *,int);
00355 int raw_write_stdout(const void *,int);
00356 
00357 #define TM_START        0
00358 #define TM_STOP         1
00359 double app_tminterval (int stop,int usertime);
00360 #endif

Generated on Thu Sep 16 11:29:41 2010 for Policy Component by  doxygen 1.4.7