Main Page | Class List | Directories | File List | Class Members | File Members

apps.h

Go to the documentation of this file.
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 #include <openssl/ossl_typ.h>
00126 
00127 int app_RAND_load_file(const char *file, BIO *bio_e, int dont_warn);
00128 int app_RAND_write_file(const char *file, BIO *bio_e);
00129 /* When `file' is NULL, use defaults.
00130  * `bio_e' is for error messages. */
00131 void app_RAND_allow_write_file(void);
00132 long app_RAND_load_files(char *file); /* `file' is a list of files to read,
00133                                        * separated by LIST_SEPARATOR_CHAR
00134                                        * (see e_os.h).  The string is
00135                                        * destroyed! */
00136 
00137 #ifdef OPENSSL_SYS_WIN32
00138 #define rename(from,to) WIN32_rename((from),(to))
00139 int WIN32_rename(const char *oldname,const char *newname);
00140 #endif
00141 
00142 #ifndef MONOLITH
00143 
00144 #define MAIN(a,v)       main(a,v)
00145 
00146 #ifndef NON_MAIN
00147 CONF *config=NULL;
00148 BIO *bio_err=NULL;
00149 #else
00150 extern CONF *config;
00151 extern BIO *bio_err;
00152 #endif
00153 
00154 #else
00155 
00156 #define MAIN(a,v)       PROG(a,v)
00157 extern CONF *config;
00158 extern char *default_config_file;
00159 extern BIO *bio_err;
00160 
00161 #endif
00162 
00163 #ifndef OPENSSL_SYS_NETWARE
00164 #include <signal.h>
00165 #endif
00166 
00167 #ifdef SIGPIPE
00168 #define do_pipe_sig()   signal(SIGPIPE,SIG_IGN)
00169 #else
00170 #define do_pipe_sig()
00171 #endif
00172 
00173 #if defined(MONOLITH) && !defined(OPENSSL_C)
00174 #  define apps_startup() \
00175                 do_pipe_sig()
00176 #  define apps_shutdown()
00177 #else
00178 #  ifndef OPENSSL_NO_ENGINE
00179 #    if defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_WIN16) || \
00180      defined(OPENSSL_SYS_WIN32)
00181 #      ifdef _O_BINARY
00182 #        define apps_startup() \
00183                         do { _fmode=_O_BINARY; do_pipe_sig(); CRYPTO_malloc_init(); \
00184                         ERR_load_crypto_strings(); OpenSSL_add_all_algorithms(); \
00185                         ENGINE_load_builtin_engines(); setup_ui_method(); } while(0)
00186 #      else
00187 #        define apps_startup() \
00188                         do { _fmode=O_BINARY; do_pipe_sig(); CRYPTO_malloc_init(); \
00189                         ERR_load_crypto_strings(); OpenSSL_add_all_algorithms(); \
00190                         ENGINE_load_builtin_engines(); setup_ui_method(); } while(0)
00191 #      endif
00192 #    else
00193 #      define apps_startup() \
00194                         do { do_pipe_sig(); OpenSSL_add_all_algorithms(); \
00195                         ERR_load_crypto_strings(); ENGINE_load_builtin_engines(); \
00196                         setup_ui_method(); } while(0)
00197 #    endif
00198 #    define apps_shutdown() \
00199                         do { CONF_modules_unload(1); destroy_ui_method(); \
00200                         EVP_cleanup(); ENGINE_cleanup(); \
00201                         CRYPTO_cleanup_all_ex_data(); ERR_remove_state(0); \
00202                         ERR_free_strings(); } while(0)
00203 #  else
00204 #    if defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_WIN16) || \
00205      defined(OPENSSL_SYS_WIN32)
00206 #      ifdef _O_BINARY
00207 #        define apps_startup() \
00208                         do { _fmode=_O_BINARY; do_pipe_sig(); CRYPTO_malloc_init(); \
00209                         ERR_load_crypto_strings(); OpenSSL_add_all_algorithms(); \
00210                         setup_ui_method(); } while(0)
00211 #      else
00212 #        define apps_startup() \
00213                         do { _fmode=O_BINARY; do_pipe_sig(); CRYPTO_malloc_init(); \
00214                         ERR_load_crypto_strings(); OpenSSL_add_all_algorithms(); \
00215                         setup_ui_method(); } while(0)
00216 #      endif
00217 #    else
00218 #      define apps_startup() \
00219                         do { do_pipe_sig(); OpenSSL_add_all_algorithms(); \
00220                         ERR_load_crypto_strings(); \
00221                         setup_ui_method(); } while(0)
00222 #    endif
00223 #    define apps_shutdown() \
00224                         do { CONF_modules_unload(1); destroy_ui_method(); \
00225                         EVP_cleanup(); \
00226                         CRYPTO_cleanup_all_ex_data(); ERR_remove_state(0); \
00227                         ERR_free_strings(); } while(0)
00228 #  endif
00229 #endif
00230 
00231 typedef struct args_st
00232         {
00233         char **data;
00234         int count;
00235         } ARGS;
00236 
00237 #define PW_MIN_LENGTH 4
00238 typedef struct pw_cb_data
00239         {
00240         const void *password;
00241         const char *prompt_info;
00242         } PW_CB_DATA;
00243 
00244 int password_callback(char *buf, int bufsiz, int verify,
00245         PW_CB_DATA *cb_data);
00246 
00247 int setup_ui_method(void);
00248 void destroy_ui_method(void);
00249 
00250 int should_retry(int i);
00251 int args_from_file(char *file, int *argc, char **argv[]);
00252 int str2fmt(char *s);
00253 void program_name(char *in,char *out,int size);
00254 int chopup_args(ARGS *arg,char *buf, int *argc, char **argv[]);
00255 #ifdef HEADER_X509_H
00256 int dump_cert_text(BIO *out, X509 *x);
00257 void print_name(BIO *out, const char *title, X509_NAME *nm, unsigned long lflags);
00258 #endif
00259 int set_cert_ex(unsigned long *flags, const char *arg);
00260 int set_name_ex(unsigned long *flags, const char *arg);
00261 int set_ext_copy(int *copy_type, const char *arg);
00262 int copy_extensions(X509 *x, X509_REQ *req, int copy_type);
00263 int app_passwd(BIO *err, char *arg1, char *arg2, char **pass1, char **pass2);
00264 int add_oid_section(BIO *err, CONF *conf);
00265 X509 *load_cert(BIO *err, const char *file, int format,
00266         const char *pass, ENGINE *e, const char *cert_descrip);
00267 EVP_PKEY *load_key(BIO *err, const char *file, int format, int maybe_stdin,
00268         const char *pass, ENGINE *e, const char *key_descrip);
00269 EVP_PKEY *load_pubkey(BIO *err, const char *file, int format, int maybe_stdin,
00270         const char *pass, ENGINE *e, const char *key_descrip);
00271 STACK_OF(X509) *load_certs(BIO *err, const char *file, int format,
00272         const char *pass, ENGINE *e, const char *cert_descrip);
00273 X509_STORE *setup_verify(BIO *bp, char *CAfile, char *CApath);
00274 #ifndef OPENSSL_NO_ENGINE
00275 ENGINE *setup_engine(BIO *err, const char *engine, int debug);
00276 #endif
00277 
00278 int load_config(BIO *err, CONF *cnf);
00279 char *make_config_name(void);
00280 
00281 /* Functions defined in ca.c and also used in ocsp.c */
00282 int unpack_revinfo(ASN1_TIME **prevtm, int *preason, ASN1_OBJECT **phold,
00283                         ASN1_GENERALIZEDTIME **pinvtm, const char *str);
00284 
00285 #define DB_type         0
00286 #define DB_exp_date     1
00287 #define DB_rev_date     2
00288 #define DB_serial       3       /* index - unique */
00289 #define DB_file         4       
00290 #define DB_name         5       /* index - unique when active and not disabled */
00291 #define DB_NUMBER       6
00292 
00293 #define DB_TYPE_REV     'R'
00294 #define DB_TYPE_EXP     'E'
00295 #define DB_TYPE_VAL     'V'
00296 
00297 typedef struct db_attr_st
00298         {
00299         int unique_subject;
00300         } DB_ATTR;
00301 typedef struct ca_db_st
00302         {
00303         DB_ATTR attributes;
00304         TXT_DB *db;
00305         } CA_DB;
00306 
00307 BIGNUM *load_serial(char *serialfile, int create, ASN1_INTEGER **retai);
00308 int save_serial(char *serialfile, char *suffix, BIGNUM *serial, ASN1_INTEGER **retai);
00309 int rotate_serial(char *serialfile, char *new_suffix, char *old_suffix);
00310 int rand_serial(BIGNUM *b, ASN1_INTEGER *ai);
00311 CA_DB *load_index(char *dbfile, DB_ATTR *dbattr);
00312 int index_index(CA_DB *db);
00313 int save_index(const char *dbfile, const char *suffix, CA_DB *db);
00314 int rotate_index(const char *dbfile, const char *new_suffix, const char *old_suffix);
00315 void free_index(CA_DB *db);
00316 int index_name_cmp(const char **a, const char **b);
00317 int parse_yesno(const char *str, int def);
00318 
00319 X509_NAME *parse_name(char *str, long chtype, int multirdn);
00320 int args_verify(char ***pargs, int *pargc,
00321                         int *badarg, BIO *err, X509_VERIFY_PARAM **pm);
00322 void policies_print(BIO *out, X509_STORE_CTX *ctx);
00323 
00324 #define FORMAT_UNDEF    0
00325 #define FORMAT_ASN1     1
00326 #define FORMAT_TEXT     2
00327 #define FORMAT_PEM      3
00328 #define FORMAT_NETSCAPE 4
00329 #define FORMAT_PKCS12   5
00330 #define FORMAT_SMIME    6
00331 #define FORMAT_ENGINE   7
00332 #define FORMAT_IISSGC   8       /* XXX this stupid macro helps us to avoid
00333                                  * adding yet another param to load_*key() */
00334 
00335 #define EXT_COPY_NONE   0
00336 #define EXT_COPY_ADD    1
00337 #define EXT_COPY_ALL    2
00338 
00339 #define NETSCAPE_CERT_HDR       "certificate"
00340 
00341 #define APP_PASS_LEN    1024
00342 
00343 #define SERIAL_RAND_BITS        64
00344 
00345 #endif

© sourcejam.com 2005-2008