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