Disallow multiple protocol flags to s_server and s_client
[openssl.git] / apps / apps.h
1 /*
2  * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the OpenSSL license (the "License").  You may not use
5  * this file except in compliance with the License.  You can obtain a copy
6  * in the file LICENSE in the source distribution or at
7  * https://www.openssl.org/source/license.html
8  */
9
10 #ifndef HEADER_APPS_H
11 # define HEADER_APPS_H
12
13 # include "e_os.h"
14 # if defined(__unix) || defined(__unix__)
15 #  include <sys/time.h> /* struct timeval for DTLS */
16 # endif
17 # include <assert.h>
18
19 # include <openssl/e_os2.h>
20 # include <openssl/ossl_typ.h>
21 # include <openssl/bio.h>
22 # include <openssl/x509.h>
23 # include <openssl/lhash.h>
24 # include <openssl/conf.h>
25 # include <openssl/txt_db.h>
26 # include <openssl/engine.h>
27 # include <openssl/ocsp.h>
28 # include <openssl/ossl_typ.h>
29 # include <signal.h>
30
31 # if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WINCE)
32 #  define openssl_fdset(a,b) FD_SET((unsigned int)a, b)
33 # else
34 #  define openssl_fdset(a,b) FD_SET(a, b)
35 # endif
36
37 /*
38  * quick macro when you need to pass an unsigned char instead of a char.
39  * this is true for some implementations of the is*() functions, for
40  * example.
41  */
42 #define _UC(c) ((unsigned char)(c))
43
44 int app_RAND_load_file(const char *file, int dont_warn);
45 int app_RAND_write_file(const char *file);
46 /*
47  * When `file' is NULL, use defaults. `bio_e' is for error messages.
48  */
49 void app_RAND_allow_write_file(void);
50 long app_RAND_load_files(char *file); /* `file' is a list of files to read,
51                                        * separated by LIST_SEPARATOR_CHAR
52                                        * (see e_os.h).  The string is
53                                        * destroyed! */
54
55 extern char *default_config_file;
56 extern BIO *bio_in;
57 extern BIO *bio_out;
58 extern BIO *bio_err;
59 BIO *dup_bio_in(int format);
60 BIO *dup_bio_out(int format);
61 BIO *dup_bio_err(int format);
62 BIO *bio_open_owner(const char *filename, int format, int private);
63 BIO *bio_open_default(const char *filename, char mode, int format);
64 BIO *bio_open_default_quiet(const char *filename, char mode, int format);
65 CONF *app_load_config(const char *filename);
66 CONF *app_load_config_quiet(const char *filename);
67 int app_load_modules(const CONF *config);
68 void unbuffer(FILE *fp);
69 void wait_for_async(SSL *s);
70 # if defined(OPENSSL_SYS_MSDOS)
71 int has_stdin_waiting(void);
72 # endif
73
74 /*
75  * Common verification options.
76  */
77 # define OPT_V_ENUM \
78         OPT_V__FIRST=2000, \
79         OPT_V_POLICY, OPT_V_PURPOSE, OPT_V_VERIFY_NAME, OPT_V_VERIFY_DEPTH, \
80         OPT_V_ATTIME, OPT_V_VERIFY_HOSTNAME, OPT_V_VERIFY_EMAIL, \
81         OPT_V_VERIFY_IP, OPT_V_IGNORE_CRITICAL, OPT_V_ISSUER_CHECKS, \
82         OPT_V_CRL_CHECK, OPT_V_CRL_CHECK_ALL, OPT_V_POLICY_CHECK, \
83         OPT_V_EXPLICIT_POLICY, OPT_V_INHIBIT_ANY, OPT_V_INHIBIT_MAP, \
84         OPT_V_X509_STRICT, OPT_V_EXTENDED_CRL, OPT_V_USE_DELTAS, \
85         OPT_V_POLICY_PRINT, OPT_V_CHECK_SS_SIG, OPT_V_TRUSTED_FIRST, \
86         OPT_V_SUITEB_128_ONLY, OPT_V_SUITEB_128, OPT_V_SUITEB_192, \
87         OPT_V_PARTIAL_CHAIN, OPT_V_NO_ALT_CHAINS, OPT_V_NO_CHECK_TIME, \
88         OPT_V_VERIFY_AUTH_LEVEL, OPT_V_ALLOW_PROXY_CERTS, \
89         OPT_V__LAST
90
91 # define OPT_V_OPTIONS \
92         { "policy", OPT_V_POLICY, 's', "adds policy to the acceptable policy set"}, \
93         { "purpose", OPT_V_PURPOSE, 's', \
94             "certificate chain purpose"}, \
95         { "verify_name", OPT_V_VERIFY_NAME, 's', "verification policy name"}, \
96         { "verify_depth", OPT_V_VERIFY_DEPTH, 'n', \
97             "chain depth limit" }, \
98         { "auth_level", OPT_V_VERIFY_AUTH_LEVEL, 'n', \
99             "chain authentication security level" }, \
100         { "attime", OPT_V_ATTIME, 'M', "verification epoch time" }, \
101         { "verify_hostname", OPT_V_VERIFY_HOSTNAME, 's', \
102             "expected peer hostname" }, \
103         { "verify_email", OPT_V_VERIFY_EMAIL, 's', \
104             "expected peer email" }, \
105         { "verify_ip", OPT_V_VERIFY_IP, 's', \
106             "expected peer IP address" }, \
107         { "ignore_critical", OPT_V_IGNORE_CRITICAL, '-', \
108             "permit unhandled critical extensions"}, \
109         { "issuer_checks", OPT_V_ISSUER_CHECKS, '-', "(deprecated)"}, \
110         { "crl_check", OPT_V_CRL_CHECK, '-', "check leaf certificate revocation" }, \
111         { "crl_check_all", OPT_V_CRL_CHECK_ALL, '-', "check full chain revocation" }, \
112         { "policy_check", OPT_V_POLICY_CHECK, '-', "perform rfc5280 policy checks"}, \
113         { "explicit_policy", OPT_V_EXPLICIT_POLICY, '-', \
114             "set policy variable require-explicit-policy"}, \
115         { "inhibit_any", OPT_V_INHIBIT_ANY, '-', \
116             "set policy variable inhibit-any-policy"}, \
117         { "inhibit_map", OPT_V_INHIBIT_MAP, '-', \
118             "set policy variable inhibit-policy-mapping"}, \
119         { "x509_strict", OPT_V_X509_STRICT, '-', \
120             "disable certificate compatibility work-arounds"}, \
121         { "extended_crl", OPT_V_EXTENDED_CRL, '-', \
122             "enable extended CRL features"}, \
123         { "use_deltas", OPT_V_USE_DELTAS, '-', \
124             "use delta CRLs"}, \
125         { "policy_print", OPT_V_POLICY_PRINT, '-', \
126             "print policy processing diagnostics"}, \
127         { "check_ss_sig", OPT_V_CHECK_SS_SIG, '-', \
128             "check root CA self-signatures"}, \
129         { "trusted_first", OPT_V_TRUSTED_FIRST, '-', \
130             "search trust store first (default)" }, \
131         { "suiteB_128_only", OPT_V_SUITEB_128_ONLY, '-', "Suite B 128-bit-only mode"}, \
132         { "suiteB_128", OPT_V_SUITEB_128, '-', \
133             "Suite B 128-bit mode allowing 192-bit algorithms"}, \
134         { "suiteB_192", OPT_V_SUITEB_192, '-', "Suite B 192-bit-only mode" }, \
135         { "partial_chain", OPT_V_PARTIAL_CHAIN, '-', \
136             "accept chains anchored by intermediate trust-store CAs"}, \
137         { "no_alt_chains", OPT_V_NO_ALT_CHAINS, '-', "(deprecated)" }, \
138         { "no_check_time", OPT_V_NO_CHECK_TIME, '-', "ignore certificate validity time" }, \
139         { "allow_proxy_certs", OPT_V_ALLOW_PROXY_CERTS, '-', "allow the use of proxy certificates" }
140
141 # define OPT_V_CASES \
142         OPT_V__FIRST: case OPT_V__LAST: break; \
143         case OPT_V_POLICY: \
144         case OPT_V_PURPOSE: \
145         case OPT_V_VERIFY_NAME: \
146         case OPT_V_VERIFY_DEPTH: \
147         case OPT_V_VERIFY_AUTH_LEVEL: \
148         case OPT_V_ATTIME: \
149         case OPT_V_VERIFY_HOSTNAME: \
150         case OPT_V_VERIFY_EMAIL: \
151         case OPT_V_VERIFY_IP: \
152         case OPT_V_IGNORE_CRITICAL: \
153         case OPT_V_ISSUER_CHECKS: \
154         case OPT_V_CRL_CHECK: \
155         case OPT_V_CRL_CHECK_ALL: \
156         case OPT_V_POLICY_CHECK: \
157         case OPT_V_EXPLICIT_POLICY: \
158         case OPT_V_INHIBIT_ANY: \
159         case OPT_V_INHIBIT_MAP: \
160         case OPT_V_X509_STRICT: \
161         case OPT_V_EXTENDED_CRL: \
162         case OPT_V_USE_DELTAS: \
163         case OPT_V_POLICY_PRINT: \
164         case OPT_V_CHECK_SS_SIG: \
165         case OPT_V_TRUSTED_FIRST: \
166         case OPT_V_SUITEB_128_ONLY: \
167         case OPT_V_SUITEB_128: \
168         case OPT_V_SUITEB_192: \
169         case OPT_V_PARTIAL_CHAIN: \
170         case OPT_V_NO_ALT_CHAINS: \
171         case OPT_V_NO_CHECK_TIME: \
172         case OPT_V_ALLOW_PROXY_CERTS
173
174 /*
175  * Common "extended"? options.
176  */
177 # define OPT_X_ENUM \
178         OPT_X__FIRST=1000, \
179         OPT_X_KEY, OPT_X_CERT, OPT_X_CHAIN, OPT_X_CHAIN_BUILD, \
180         OPT_X_CERTFORM, OPT_X_KEYFORM, \
181         OPT_X__LAST
182
183 # define OPT_X_OPTIONS \
184         { "xkey", OPT_X_KEY, '<', "key for Extended certificates"}, \
185         { "xcert", OPT_X_CERT, '<', "cert for Extended certificates"}, \
186         { "xchain", OPT_X_CHAIN, '<', "chain for Extended certificates"}, \
187         { "xchain_build", OPT_X_CHAIN_BUILD, '-', \
188             "build certificate chain for the extended certificates"}, \
189         { "xcertform", OPT_X_CERTFORM, 'F', \
190             "format of Extended certificate (PEM or DER) PEM default " }, \
191         { "xkeyform", OPT_X_KEYFORM, 'F', \
192             "format of Extended certificate's key (PEM or DER) PEM default"}
193
194 # define OPT_X_CASES \
195         OPT_X__FIRST: case OPT_X__LAST: break; \
196         case OPT_X_KEY: \
197         case OPT_X_CERT: \
198         case OPT_X_CHAIN: \
199         case OPT_X_CHAIN_BUILD: \
200         case OPT_X_CERTFORM: \
201         case OPT_X_KEYFORM
202
203 /*
204  * Common SSL options.
205  * Any changes here must be coordinated with ../ssl/ssl_conf.c
206  */
207 # define OPT_S_ENUM \
208         OPT_S__FIRST=3000, \
209         OPT_S_NOSSL3, OPT_S_NOTLS1, OPT_S_NOTLS1_1, OPT_S_NOTLS1_2, \
210         OPT_S_BUGS, OPT_S_NO_COMP, OPT_S_NOTICKET, \
211         OPT_S_SERVERPREF, OPT_S_LEGACYRENEG, OPT_S_LEGACYCONN, \
212         OPT_S_ONRESUMP, OPT_S_NOLEGACYCONN, OPT_S_STRICT, OPT_S_SIGALGS, \
213         OPT_S_CLIENTSIGALGS, OPT_S_CURVES, OPT_S_NAMEDCURVE, OPT_S_CIPHER, \
214         OPT_S_DHPARAM, OPT_S_DEBUGBROKE, OPT_S_COMP, \
215         OPT_S__LAST
216
217 # define OPT_S_OPTIONS \
218         {"no_ssl3", OPT_S_NOSSL3, '-',"Just disable SSLv3" }, \
219         {"no_tls1", OPT_S_NOTLS1, '-', "Just disable TLSv1"}, \
220         {"no_tls1_1", OPT_S_NOTLS1_1, '-', "Just disable TLSv1.1" }, \
221         {"no_tls1_2", OPT_S_NOTLS1_2, '-', "Just disable TLSv1.2"}, \
222         {"bugs", OPT_S_BUGS, '-', "Turn on SSL bug compatibility"}, \
223         {"no_comp", OPT_S_NO_COMP, '-', "Disable SSL/TLS compression (default)" }, \
224         {"comp", OPT_S_COMP, '-', "Use SSL/TLS-level compression" }, \
225         {"no_ticket", OPT_S_NOTICKET, '-', \
226             "Disable use of TLS session tickets"}, \
227         {"serverpref", OPT_S_SERVERPREF, '-', "Use server's cipher preferences"}, \
228         {"legacy_renegotiation", OPT_S_LEGACYRENEG, '-', \
229             "Enable use of legacy renegotiation (dangerous)"}, \
230         {"legacy_server_connect", OPT_S_LEGACYCONN, '-', \
231             "Allow initial connection to servers that don't support RI"}, \
232         {"no_resumption_on_reneg", OPT_S_ONRESUMP, '-', \
233             "Disallow session resumption on renegotiation"}, \
234         {"no_legacy_server_connect", OPT_S_NOLEGACYCONN, '-', \
235             "Disallow initial connection to servers that don't support RI"}, \
236         {"strict", OPT_S_STRICT, '-', \
237             "Enforce strict certificate checks as per TLS standard"}, \
238         {"sigalgs", OPT_S_SIGALGS, 's', \
239             "Signature algorithms to support (colon-separated list)" }, \
240         {"client_sigalgs", OPT_S_CLIENTSIGALGS, 's', \
241             "Signature algorithms to support for client certificate" \
242             " authentication (colon-separated list)" }, \
243         {"curves", OPT_S_CURVES, 's', \
244             "Elliptic curves to advertise (colon-separated list)" }, \
245         {"named_curve", OPT_S_NAMEDCURVE, 's', \
246             "Elliptic curve used for ECDHE (server-side only)" }, \
247         {"cipher", OPT_S_CIPHER, 's', "Specify cipher list to be used"}, \
248         {"dhparam", OPT_S_DHPARAM, '<', \
249             "DH parameter file to use, in cert file if not specified"}, \
250         {"debug_broken_protocol", OPT_S_DEBUGBROKE, '-', \
251             "Perform all sorts of protocol violations for testing purposes"}
252
253 # define OPT_S_CASES \
254         OPT_S__FIRST: case OPT_S__LAST: break; \
255         case OPT_S_NOSSL3: \
256         case OPT_S_NOTLS1: \
257         case OPT_S_NOTLS1_1: \
258         case OPT_S_NOTLS1_2: \
259         case OPT_S_BUGS: \
260         case OPT_S_NO_COMP: \
261         case OPT_S_COMP: \
262         case OPT_S_NOTICKET: \
263         case OPT_S_SERVERPREF: \
264         case OPT_S_LEGACYRENEG: \
265         case OPT_S_LEGACYCONN: \
266         case OPT_S_ONRESUMP: \
267         case OPT_S_NOLEGACYCONN: \
268         case OPT_S_STRICT: \
269         case OPT_S_SIGALGS: \
270         case OPT_S_CLIENTSIGALGS: \
271         case OPT_S_CURVES: \
272         case OPT_S_NAMEDCURVE: \
273         case OPT_S_CIPHER: \
274         case OPT_S_DHPARAM: \
275         case OPT_S_DEBUGBROKE
276
277 #define IS_NO_PROT_FLAG(o) \
278  (o == OPT_S_NOSSL3 || o == OPT_S_NOTLS1 || o == OPT_S_NOTLS1_1 \
279   || o == OPT_S_NOTLS1_2)
280
281 /*
282  * Option parsing.
283  */
284 extern const char OPT_HELP_STR[];
285 extern const char OPT_MORE_STR[];
286 typedef struct options_st {
287     const char *name;
288     int retval;
289     /*
290      * value type: - no value (also the value zero), n number, p positive
291      * number, u unsigned, l long, s string, < input file, > output file,
292      * f any format, F der/pem format , E der/pem/engine format identifier.
293      * l, n and u include zero; p does not.
294      */
295     int valtype;
296     const char *helpstr;
297 } OPTIONS;
298
299 /*
300  * A string/int pairing; widely use for option value lookup, hence the
301  * name OPT_PAIR. But that name is misleading in s_cb.c, so we also use
302  * the "generic" name STRINT_PAIR.
303  */
304 typedef struct string_int_pair_st {
305     const char *name;
306     int retval;
307 } OPT_PAIR, STRINT_PAIR;
308
309 /* Flags to pass into opt_format; see FORMAT_xxx, below. */
310 # define OPT_FMT_PEMDER          (1L <<  1)
311 # define OPT_FMT_PKCS12          (1L <<  2)
312 # define OPT_FMT_SMIME           (1L <<  3)
313 # define OPT_FMT_ENGINE          (1L <<  4)
314 # define OPT_FMT_MSBLOB          (1L <<  5)
315 # define OPT_FMT_NETSCAPE        (1L <<  6)
316 # define OPT_FMT_NSS             (1L <<  7)
317 # define OPT_FMT_TEXT            (1L <<  8)
318 # define OPT_FMT_HTTP            (1L <<  9)
319 # define OPT_FMT_PVK             (1L << 10)
320 # define OPT_FMT_PDE     (OPT_FMT_PEMDER | OPT_FMT_ENGINE)
321 # define OPT_FMT_PDS     (OPT_FMT_PEMDER | OPT_FMT_SMIME)
322 # define OPT_FMT_ANY     ( \
323         OPT_FMT_PEMDER | OPT_FMT_PKCS12 | OPT_FMT_SMIME | \
324         OPT_FMT_ENGINE | OPT_FMT_MSBLOB | OPT_FMT_NETSCAPE | \
325         OPT_FMT_NSS | OPT_FMT_TEXT | OPT_FMT_HTTP | OPT_FMT_PVK)
326
327 char *opt_progname(const char *argv0);
328 char *opt_getprog(void);
329 char *opt_init(int ac, char **av, const OPTIONS * o);
330 int opt_next(void);
331 int opt_format(const char *s, unsigned long flags, int *result);
332 int opt_int(const char *arg, int *result);
333 int opt_ulong(const char *arg, unsigned long *result);
334 int opt_long(const char *arg, long *result);
335 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L && \
336     defined(INTMAX_MAX) && defined(UINTMAX_MAX)
337 int opt_imax(const char *arg, intmax_t *result);
338 int opt_umax(const char *arg, uintmax_t *result);
339 #else
340 # define opt_imax opt_long
341 # define opt_umax opt_ulong
342 # define intmax_t long
343 # define uintmax_t unsigned long
344 #endif
345 int opt_pair(const char *arg, const OPT_PAIR * pairs, int *result);
346 int opt_cipher(const char *name, const EVP_CIPHER **cipherp);
347 int opt_md(const char *name, const EVP_MD **mdp);
348 char *opt_arg(void);
349 char *opt_flag(void);
350 char *opt_unknown(void);
351 char *opt_reset(void);
352 char **opt_rest(void);
353 int opt_num_rest(void);
354 int opt_verify(int i, X509_VERIFY_PARAM *vpm);
355 void opt_help(const OPTIONS * list);
356 int opt_format_error(const char *s, unsigned long flags);
357
358 typedef struct args_st {
359     int size;
360     int argc;
361     char **argv;
362 } ARGS;
363
364 /*
365  * VMS C only for now, implemented in vms_decc_init.c
366  * If other C compilers forget to terminate argv with NULL, this function
367  * can be re-used.
368  */
369 char **copy_argv(int *argc, char *argv[]);
370
371
372 # define PW_MIN_LENGTH 4
373 typedef struct pw_cb_data {
374     const void *password;
375     const char *prompt_info;
376 } PW_CB_DATA;
377
378 int password_callback(char *buf, int bufsiz, int verify, PW_CB_DATA *cb_data);
379
380 int setup_ui_method(void);
381 void destroy_ui_method(void);
382
383 int chopup_args(ARGS *arg, char *buf);
384 # ifdef HEADER_X509_H
385 int dump_cert_text(BIO *out, X509 *x);
386 void print_name(BIO *out, const char *title, X509_NAME *nm,
387                 unsigned long lflags);
388 # endif
389 void print_bignum_var(BIO *, const BIGNUM *, const char*,
390                       int, unsigned char *);
391 void print_array(BIO *, const char *, int, const unsigned char *);
392 int set_cert_ex(unsigned long *flags, const char *arg);
393 int set_name_ex(unsigned long *flags, const char *arg);
394 int set_ext_copy(int *copy_type, const char *arg);
395 int copy_extensions(X509 *x, X509_REQ *req, int copy_type);
396 int app_passwd(char *arg1, char *arg2, char **pass1, char **pass2);
397 int add_oid_section(CONF *conf);
398 X509 *load_cert(const char *file, int format, const char *cert_descrip);
399 X509_CRL *load_crl(const char *infile, int format);
400 EVP_PKEY *load_key(const char *file, int format, int maybe_stdin,
401                    const char *pass, ENGINE *e, const char *key_descrip);
402 EVP_PKEY *load_pubkey(const char *file, int format, int maybe_stdin,
403                       const char *pass, ENGINE *e, const char *key_descrip);
404 int load_certs(const char *file, STACK_OF(X509) **certs, int format,
405                const char *pass, const char *cert_descrip);
406 int load_crls(const char *file, STACK_OF(X509_CRL) **crls, int format,
407               const char *pass, const char *cert_descrip);
408 X509_STORE *setup_verify(char *CAfile, char *CApath,
409                          int noCAfile, int noCApath);
410 __owur int ctx_set_verify_locations(SSL_CTX *ctx, const char *CAfile,
411                                     const char *CApath, int noCAfile,
412                                     int noCApath);
413
414 #ifndef OPENSSL_NO_CT
415
416 /*
417  * Sets the file to load the Certificate Transparency log list from.
418  * If path is NULL, loads from the default file path.
419  * Returns 1 on success, 0 otherwise.
420  */
421 __owur int ctx_set_ctlog_list_file(SSL_CTX *ctx, const char *path);
422
423 #endif
424
425 # ifdef OPENSSL_NO_ENGINE
426 #  define setup_engine(engine, debug) NULL
427 # else
428 ENGINE *setup_engine(const char *engine, int debug);
429 # endif
430 # ifndef OPENSSL_NO_OCSP
431 OCSP_RESPONSE *process_responder(OCSP_REQUEST *req,
432                                  const char *host, const char *path,
433                                  const char *port, int use_ssl,
434                                  STACK_OF(CONF_VALUE) *headers,
435                                  int req_timeout);
436 # endif
437
438 /* Functions defined in ca.c and also used in ocsp.c */
439 int unpack_revinfo(ASN1_TIME **prevtm, int *preason, ASN1_OBJECT **phold,
440                    ASN1_GENERALIZEDTIME **pinvtm, const char *str);
441
442 # define DB_type         0
443 # define DB_exp_date     1
444 # define DB_rev_date     2
445 # define DB_serial       3      /* index - unique */
446 # define DB_file         4
447 # define DB_name         5      /* index - unique when active and not
448                                  * disabled */
449 # define DB_NUMBER       6
450
451 # define DB_TYPE_REV     'R'
452 # define DB_TYPE_EXP     'E'
453 # define DB_TYPE_VAL     'V'
454
455 typedef struct db_attr_st {
456     int unique_subject;
457 } DB_ATTR;
458 typedef struct ca_db_st {
459     DB_ATTR attributes;
460     TXT_DB *db;
461 } CA_DB;
462
463 void* app_malloc(int sz, const char *what);
464 BIGNUM *load_serial(char *serialfile, int create, ASN1_INTEGER **retai);
465 int save_serial(char *serialfile, char *suffix, BIGNUM *serial,
466                 ASN1_INTEGER **retai);
467 int rotate_serial(char *serialfile, char *new_suffix, char *old_suffix);
468 int rand_serial(BIGNUM *b, ASN1_INTEGER *ai);
469 CA_DB *load_index(char *dbfile, DB_ATTR *dbattr);
470 int index_index(CA_DB *db);
471 int save_index(const char *dbfile, const char *suffix, CA_DB *db);
472 int rotate_index(const char *dbfile, const char *new_suffix,
473                  const char *old_suffix);
474 void free_index(CA_DB *db);
475 # define index_name_cmp_noconst(a, b) \
476         index_name_cmp((const OPENSSL_CSTRING *)CHECKED_PTR_OF(OPENSSL_STRING, a), \
477         (const OPENSSL_CSTRING *)CHECKED_PTR_OF(OPENSSL_STRING, b))
478 int index_name_cmp(const OPENSSL_CSTRING *a, const OPENSSL_CSTRING *b);
479 int parse_yesno(const char *str, int def);
480
481 X509_NAME *parse_name(const char *str, long chtype, int multirdn);
482 int args_verify(char ***pargs, int *pargc,
483                 int *badarg, X509_VERIFY_PARAM **pm);
484 void policies_print(X509_STORE_CTX *ctx);
485 int bio_to_mem(unsigned char **out, int maxlen, BIO *in);
486 int pkey_ctrl_string(EVP_PKEY_CTX *ctx, const char *value);
487 int init_gen_str(EVP_PKEY_CTX **pctx,
488                  const char *algname, ENGINE *e, int do_param);
489 int do_X509_sign(X509 *x, EVP_PKEY *pkey, const EVP_MD *md,
490                  STACK_OF(OPENSSL_STRING) *sigopts);
491 int do_X509_REQ_sign(X509_REQ *x, EVP_PKEY *pkey, const EVP_MD *md,
492                      STACK_OF(OPENSSL_STRING) *sigopts);
493 int do_X509_CRL_sign(X509_CRL *x, EVP_PKEY *pkey, const EVP_MD *md,
494                      STACK_OF(OPENSSL_STRING) *sigopts);
495 # ifndef OPENSSL_NO_PSK
496 extern char *psk_key;
497 # endif
498
499 unsigned char *next_protos_parse(size_t *outlen, const char *in);
500
501 void print_cert_checks(BIO *bio, X509 *x,
502                        const char *checkhost,
503                        const char *checkemail, const char *checkip);
504
505 void store_setup_crl_download(X509_STORE *st);
506
507 /* See OPT_FMT_xxx, above. */
508 /* On some platforms, it's important to distinguish between text and binary
509  * files.  On some, there might even be specific file formats for different
510  * contents.  The FORMAT_xxx macros are meant to express an intent with the
511  * file being read or created.
512  */
513 # define B_FORMAT_TEXT   0x8000
514 # define FORMAT_UNDEF    0
515 # define FORMAT_TEXT    (1 | B_FORMAT_TEXT)     /* Generic text */
516 # define FORMAT_BINARY   2                      /* Generic binary */
517 # define FORMAT_BASE64  (3 | B_FORMAT_TEXT)     /* Base64 */
518 # define FORMAT_ASN1     4                      /* ASN.1/DER */
519 # define FORMAT_PEM     (5 | B_FORMAT_TEXT)
520 # define FORMAT_PKCS12   6
521 # define FORMAT_SMIME   (7 | B_FORMAT_TEXT)
522 # define FORMAT_ENGINE   8                      /* Not really a file format */
523 # define FORMAT_PEMRSA  (9 | B_FORMAT_TEXT)     /* PEM RSAPubicKey format */
524 # define FORMAT_ASN1RSA  10                     /* DER RSAPubicKey format */
525 # define FORMAT_MSBLOB   11                     /* MS Key blob format */
526 # define FORMAT_PVK      12                     /* MS PVK file format */
527 # define FORMAT_HTTP     13                     /* Download using HTTP */
528 # define FORMAT_NSS      14                     /* NSS keylog format */
529
530 # define EXT_COPY_NONE   0
531 # define EXT_COPY_ADD    1
532 # define EXT_COPY_ALL    2
533
534 # define NETSCAPE_CERT_HDR       "certificate"
535
536 # define APP_PASS_LEN    1024
537
538 # define SERIAL_RAND_BITS        64
539
540 int app_isdir(const char *);
541 int app_access(const char *, int flag);
542 int raw_read_stdin(void *, int);
543 int raw_write_stdout(const void *, int);
544
545 # define TM_START        0
546 # define TM_STOP         1
547 double app_tminterval(int stop, int usertime);
548
549 /* this is an accident waiting to happen (-Wshadow is your friend) */
550 extern int verify_depth;
551 extern int verify_quiet;
552 extern int verify_error;
553 extern int verify_return_error;
554
555 # include "progs.h"
556
557 #endif