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