]> git.ipfire.org Git - thirdparty/openssl.git/blame - apps/include/apps.h
Generalize the HTTP client so far implemented mostly in crypto/ocsp/ocsp_ht.c
[thirdparty/openssl.git] / apps / include / apps.h
CommitLineData
846e33c7 1/*
39556e63 2 * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
a661b653 3 *
dffa7520 4 * Licensed under the Apache License 2.0 (the "License"). You may not use
846e33c7
RS
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
a661b653 8 */
d02b48c6 9
ae4186b0
DMSP
10#ifndef OSSL_APPS_H
11# define OSSL_APPS_H
0f113f3e 12
4cff10dc 13# include "e_os.h" /* struct timeval for DTLS */
07016a8a 14# include "internal/nelem.h"
3b061a00 15# include <assert.h>
0f113f3e 16
3e3c7c36 17# include <sys/types.h>
c7d5ea26
VD
18# ifndef OPENSSL_NO_POSIX_IO
19# include <sys/stat.h>
20# include <fcntl.h>
21# endif
22
568b8020 23# include <openssl/e_os2.h>
50cd4768 24# include <openssl/types.h>
0f113f3e
MC
25# include <openssl/bio.h>
26# include <openssl/x509.h>
0f113f3e
MC
27# include <openssl/conf.h>
28# include <openssl/txt_db.h>
3c27208f
RS
29# include <openssl/engine.h>
30# include <openssl/ocsp.h>
29f178bd 31# include <openssl/http.h>
1fbab1dc 32# include <signal.h>
a43ce58f
SL
33# include "apps_ui.h"
34# include "opt.h"
35# include "fmt.h"
ce506d27 36# include "platform.h"
d02b48c6 37
29f178bd 38/* also in include/internal/sockets.h */
7e1b7485
RS
39# if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WINCE)
40# define openssl_fdset(a,b) FD_SET((unsigned int)a, b)
41# else
42# define openssl_fdset(a,b) FD_SET(a, b)
43# endif
44
18295f0c
RL
45/*
46 * quick macro when you need to pass an unsigned char instead of a char.
47 * this is true for some implementations of the is*() functions, for
48 * example.
49 */
50#define _UC(c) ((unsigned char)(c))
51
3ee1eac2
RS
52void app_RAND_load_conf(CONF *c, const char *section);
53void app_RAND_write(void);
a31011e8 54
d02b48c6 55extern char *default_config_file;
7e1b7485
RS
56extern BIO *bio_in;
57extern BIO *bio_out;
d02b48c6 58extern BIO *bio_err;
adfc3786
MC
59extern const unsigned char tls13_aes128gcmsha256_id[];
60extern const unsigned char tls13_aes256gcmsha384_id[];
10ee7246
MC
61extern BIO_ADDR *ourpeer;
62
a60994df
RL
63BIO *dup_bio_in(int format);
64BIO *dup_bio_out(int format);
149bd5d6 65BIO *dup_bio_err(int format);
bdd58d98
RL
66BIO *bio_open_owner(const char *filename, int format, int private);
67BIO *bio_open_default(const char *filename, char mode, int format);
68BIO *bio_open_default_quiet(const char *filename, char mode, int format);
bfa470a4 69CONF *app_load_config_bio(BIO *in, const char *filename);
296f54ee
RL
70CONF *app_load_config(const char *filename);
71CONF *app_load_config_quiet(const char *filename);
72int app_load_modules(const CONF *config);
7e1b7485 73void unbuffer(FILE *fp);
e1b9840e 74void wait_for_async(SSL *s);
75dd6c1a
MC
75# if defined(OPENSSL_SYS_MSDOS)
76int has_stdin_waiting(void);
77# endif
d02b48c6 78
a0754084 79void corrupt_signature(const ASN1_STRING *signature);
dc047d31
DSH
80int set_cert_times(X509 *x, const char *startdate, const char *enddate,
81 int days);
17ebf85a 82
0f113f3e 83typedef struct args_st {
7e1b7485
RS
84 int size;
85 int argc;
86 char **argv;
0f113f3e 87} ARGS;
7bf7333d 88
229446df
RS
89/* We need both wrap and the "real" function because libcrypto uses both. */
90int wrap_password_callback(char *buf, int bufsiz, int verify, void *cb_data);
2fe5adc3 91
7e1b7485 92int chopup_args(ARGS *arg, char *buf);
954ef7ef 93int dump_cert_text(BIO *out, X509 *x);
0f113f3e
MC
94void print_name(BIO *out, const char *title, X509_NAME *nm,
95 unsigned long lflags);
2ac6115d
RL
96void print_bignum_var(BIO *, const BIGNUM *, const char*,
97 int, unsigned char *);
7e1b7485 98void print_array(BIO *, const char *, int, const unsigned char *);
b5c4209b
DB
99int set_nameopt(const char *arg);
100unsigned long get_nameopt(void);
8ca533e3 101int set_cert_ex(unsigned long *flags, const char *arg);
a657546f 102int set_name_ex(unsigned long *flags, const char *arg);
791bd0cd
DSH
103int set_ext_copy(int *copy_type, const char *arg);
104int copy_extensions(X509 *x, X509_REQ *req, int copy_type);
cc696296 105int app_passwd(const char *arg1, const char *arg2, char **pass1, char **pass2);
7e1b7485 106int add_oid_section(CONF *conf);
a773b52a 107X509 *load_cert(const char *file, int format, const char *cert_descrip);
0090a686 108X509_CRL *load_crl(const char *infile, int format);
7e1b7485 109EVP_PKEY *load_key(const char *file, int format, int maybe_stdin,
0f113f3e 110 const char *pass, ENGINE *e, const char *key_descrip);
7e1b7485 111EVP_PKEY *load_pubkey(const char *file, int format, int maybe_stdin,
0f113f3e 112 const char *pass, ENGINE *e, const char *key_descrip);
0996dc54 113int load_certs(const char *file, STACK_OF(X509) **certs, int format,
a773b52a 114 const char *pass, const char *cert_descrip);
0996dc54 115int load_crls(const char *file, STACK_OF(X509_CRL) **crls, int format,
a773b52a 116 const char *pass, const char *cert_descrip);
fd3397fc
RL
117X509_STORE *setup_verify(const char *CAfile, int noCAfile,
118 const char *CApath, int noCApath,
119 const char *CAstore, int noCAstore);
120__owur int ctx_set_verify_locations(SSL_CTX *ctx,
121 const char *CAfile, int noCAfile,
122 const char *CApath, int noCApath,
123 const char *CAstore, int noCAstore);
ca74c38d 124
b5369582
RP
125#ifndef OPENSSL_NO_CT
126
ca74c38d
RP
127/*
128 * Sets the file to load the Certificate Transparency log list from.
129 * If path is NULL, loads from the default file path.
130 * Returns 1 on success, 0 otherwise.
131 */
5da65ef2 132__owur int ctx_set_ctlog_list_file(SSL_CTX *ctx, const char *path);
dd696a55 133
b5369582
RP
134#endif
135
7e1b7485 136ENGINE *setup_engine(const char *engine, int debug);
dd1abd44 137void release_engine(ENGINE *e);
907c6c86 138
0f113f3e 139# ifndef OPENSSL_NO_OCSP
7e1b7485 140OCSP_RESPONSE *process_responder(OCSP_REQUEST *req,
0f113f3e
MC
141 const char *host, const char *path,
142 const char *port, int use_ssl,
82c49427 143 STACK_OF(CONF_VALUE) *headers,
0f113f3e
MC
144 int req_timeout);
145# endif
67c8e7f4 146
ee306a13
DSH
147/* Functions defined in ca.c and also used in ocsp.c */
148int unpack_revinfo(ASN1_TIME **prevtm, int *preason, ASN1_OBJECT **phold,
0f113f3e
MC
149 ASN1_GENERALIZEDTIME **pinvtm, const char *str);
150
151# define DB_type 0
152# define DB_exp_date 1
153# define DB_rev_date 2
154# define DB_serial 3 /* index - unique */
155# define DB_file 4
156# define DB_name 5 /* index - unique when active and not
157 * disabled */
158# define DB_NUMBER 6
159
06a79af2
F
160# define DB_TYPE_REV 'R' /* Revoked */
161# define DB_TYPE_EXP 'E' /* Expired */
162# define DB_TYPE_VAL 'V' /* Valid ; inserted with: ca ... -valid */
163# define DB_TYPE_SUSP 'S' /* Suspended */
0f113f3e
MC
164
165typedef struct db_attr_st {
166 int unique_subject;
167} DB_ATTR;
168typedef struct ca_db_st {
169 DB_ATTR attributes;
170 TXT_DB *db;
c7d5ea26
VD
171 char *dbfname;
172# ifndef OPENSSL_NO_POSIX_IO
173 struct stat dbst;
174# endif
0f113f3e 175} CA_DB;
f85b68cd 176
68dc6824 177void* app_malloc(int sz, const char *what);
cc696296
F
178BIGNUM *load_serial(const char *serialfile, int create, ASN1_INTEGER **retai);
179int save_serial(const char *serialfile, const char *suffix, const BIGNUM *serial,
0f113f3e 180 ASN1_INTEGER **retai);
cc696296
F
181int rotate_serial(const char *serialfile, const char *new_suffix,
182 const char *old_suffix);
64674bcc 183int rand_serial(BIGNUM *b, ASN1_INTEGER *ai);
cc696296 184CA_DB *load_index(const char *dbfile, DB_ATTR *dbattr);
f85b68cd 185int index_index(CA_DB *db);
7d727231 186int save_index(const char *dbfile, const char *suffix, CA_DB *db);
0f113f3e
MC
187int rotate_index(const char *dbfile, const char *new_suffix,
188 const char *old_suffix);
f85b68cd 189void free_index(CA_DB *db);
0f113f3e
MC
190# define index_name_cmp_noconst(a, b) \
191 index_name_cmp((const OPENSSL_CSTRING *)CHECKED_PTR_OF(OPENSSL_STRING, a), \
192 (const OPENSSL_CSTRING *)CHECKED_PTR_OF(OPENSSL_STRING, b))
c869da88 193int index_name_cmp(const OPENSSL_CSTRING *a, const OPENSSL_CSTRING *b);
ff990440 194int parse_yesno(const char *str, int def);
ee306a13 195
db4c08f0 196X509_NAME *parse_name(const char *str, long chtype, int multirdn);
ecf3a1fb 197void policies_print(X509_STORE_CTX *ctx);
a9164153 198int bio_to_mem(unsigned char **out, int maxlen, BIO *in);
0c20802c 199int pkey_ctrl_string(EVP_PKEY_CTX *ctx, const char *value);
7e1b7485 200int init_gen_str(EVP_PKEY_CTX **pctx,
0f113f3e 201 const char *algname, ENGINE *e, int do_param);
7e1b7485 202int do_X509_sign(X509 *x, EVP_PKEY *pkey, const EVP_MD *md,
0f113f3e 203 STACK_OF(OPENSSL_STRING) *sigopts);
7e1b7485 204int do_X509_REQ_sign(X509_REQ *x, EVP_PKEY *pkey, const EVP_MD *md,
0f113f3e 205 STACK_OF(OPENSSL_STRING) *sigopts);
7e1b7485 206int do_X509_CRL_sign(X509_CRL *x, EVP_PKEY *pkey, const EVP_MD *md,
0f113f3e 207 STACK_OF(OPENSSL_STRING) *sigopts);
14e35350 208
f3b7bdad 209extern char *psk_key;
14e35350 210
eee6c81a 211
817cd0d5 212unsigned char *next_protos_parse(size_t *outlen, const char *in);
71fa4513 213
a70da5b3 214void print_cert_checks(BIO *bio, X509 *x,
0f113f3e
MC
215 const char *checkhost,
216 const char *checkemail, const char *checkip);
a70da5b3 217
0090a686
DSH
218void store_setup_crl_download(X509_STORE *st);
219
29f178bd
DDO
220typedef struct app_http_tls_info_st {
221 const char *server;
222 const char *port;
223 int use_proxy;
224 long timeout;
225 SSL_CTX *ssl_ctx;
226} APP_HTTP_TLS_INFO;
227BIO *app_http_tls_cb(BIO *hbio, /* APP_HTTP_TLS_INFO */ void *arg,
228 int connect, int detail);
229# ifndef OPENSSL_NO_SOCK
230ASN1_VALUE *app_http_get_asn1(const char *url, const char *proxy,
231 const char *proxy_port, SSL_CTX *ssl_ctx,
232 const STACK_OF(CONF_VALUE) *headers,
233 long timeout, const char *expected_content_type,
234 const ASN1_ITEM *it);
235ASN1_VALUE *app_http_post_asn1(const char *host, const char *port,
236 const char *path, const char *proxy,
237 const char *proxy_port, SSL_CTX *ctx,
238 const STACK_OF(CONF_VALUE) *headers,
239 const char *content_type,
240 ASN1_VALUE *req, const ASN1_ITEM *req_it,
241 long timeout, const ASN1_ITEM *rsp_it);
242# endif
243
0f113f3e
MC
244# define EXT_COPY_NONE 0
245# define EXT_COPY_ADD 1
246# define EXT_COPY_ALL 2
247
248# define NETSCAPE_CERT_HDR "certificate"
249
250# define APP_PASS_LEN 1024
251
ffb46830
RS
252/*
253 * IETF RFC 5280 says serial number must be <= 20 bytes. Use 159 bits
254 * so that the first bit will never be one, so that the DER encoding
255 * rules won't force a leading octet.
256 */
257# define SERIAL_RAND_BITS 159
64674bcc 258
ffa10187 259int app_isdir(const char *);
7e1b7485 260int app_access(const char *, int flag);
51e5133d
RL
261int fileno_stdin(void);
262int fileno_stdout(void);
0f113f3e
MC
263int raw_read_stdin(void *, int);
264int raw_write_stdout(const void *, int);
0a39d8f2 265
0f113f3e
MC
266# define TM_START 0
267# define TM_STOP 1
268double app_tminterval(int stop, int usertime);
ee2ffc27 269
20967afb
RS
270void make_uppercase(char *string);
271
acc00492
F
272typedef struct verify_options_st {
273 int depth;
274 int quiet;
275 int error;
276 int return_error;
277} VERIFY_CB_ARGS;
278
279extern VERIFY_CB_ARGS verify_args;
df2ee0e2 280
95214b43
SL
281OSSL_PARAM *app_params_new_from_opts(STACK_OF(OPENSSL_STRING) *opts,
282 const OSSL_PARAM *paramdefs);
283void app_params_free(OSSL_PARAM *params);
284
ee2ffc27 285#endif