2 * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (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
13 # include "e_os.h" /* struct timeval for DTLS */
14 # include "internal/nelem.h"
17 # include <sys/types.h>
18 # ifndef OPENSSL_NO_POSIX_IO
19 # include <sys/stat.h>
23 # include <openssl/e_os2.h>
24 # include <openssl/types.h>
25 # include <openssl/bio.h>
26 # include <openssl/x509.h>
27 # include <openssl/conf.h>
28 # include <openssl/txt_db.h>
29 # include <openssl/engine.h>
30 # include <openssl/ocsp.h>
35 # include "platform.h"
37 # if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WINCE)
38 # define openssl_fdset(a,b) FD_SET((unsigned int)a, b)
40 # define openssl_fdset(a,b) FD_SET(a, b)
44 * quick macro when you need to pass an unsigned char instead of a char.
45 * this is true for some implementations of the is*() functions, for
48 #define _UC(c) ((unsigned char)(c))
50 void app_RAND_load_conf(CONF *c, const char *section);
51 void app_RAND_write(void);
53 extern char *default_config_file;
57 extern const unsigned char tls13_aes128gcmsha256_id[];
58 extern const unsigned char tls13_aes256gcmsha384_id[];
59 extern BIO_ADDR *ourpeer;
61 BIO *dup_bio_in(int format);
62 BIO *dup_bio_out(int format);
63 BIO *dup_bio_err(int format);
64 BIO *bio_open_owner(const char *filename, int format, int private);
65 BIO *bio_open_default(const char *filename, char mode, int format);
66 BIO *bio_open_default_quiet(const char *filename, char mode, int format);
67 CONF *app_load_config_bio(BIO *in, const char *filename);
68 CONF *app_load_config(const char *filename);
69 CONF *app_load_config_quiet(const char *filename);
70 int app_load_modules(const CONF *config);
71 void unbuffer(FILE *fp);
72 void wait_for_async(SSL *s);
73 # if defined(OPENSSL_SYS_MSDOS)
74 int has_stdin_waiting(void);
77 void corrupt_signature(const ASN1_STRING *signature);
78 int set_cert_times(X509 *x, const char *startdate, const char *enddate,
81 typedef struct args_st {
87 /* We need both wrap and the "real" function because libcrypto uses both. */
88 int wrap_password_callback(char *buf, int bufsiz, int verify, void *cb_data);
90 int chopup_args(ARGS *arg, char *buf);
91 int dump_cert_text(BIO *out, X509 *x);
92 void print_name(BIO *out, const char *title, X509_NAME *nm,
93 unsigned long lflags);
94 void print_bignum_var(BIO *, const BIGNUM *, const char*,
95 int, unsigned char *);
96 void print_array(BIO *, const char *, int, const unsigned char *);
97 int set_nameopt(const char *arg);
98 unsigned long get_nameopt(void);
99 int set_cert_ex(unsigned long *flags, const char *arg);
100 int set_name_ex(unsigned long *flags, const char *arg);
101 int set_ext_copy(int *copy_type, const char *arg);
102 int copy_extensions(X509 *x, X509_REQ *req, int copy_type);
103 int app_passwd(const char *arg1, const char *arg2, char **pass1, char **pass2);
104 int add_oid_section(CONF *conf);
105 X509 *load_cert(const char *file, int format, const char *cert_descrip);
106 X509_CRL *load_crl(const char *infile, int format);
107 EVP_PKEY *load_key(const char *file, int format, int maybe_stdin,
108 const char *pass, ENGINE *e, const char *key_descrip);
109 EVP_PKEY *load_pubkey(const char *file, int format, int maybe_stdin,
110 const char *pass, ENGINE *e, const char *key_descrip);
111 int load_certs(const char *file, STACK_OF(X509) **certs, int format,
112 const char *pass, const char *cert_descrip);
113 int load_crls(const char *file, STACK_OF(X509_CRL) **crls, int format,
114 const char *pass, const char *cert_descrip);
115 X509_STORE *setup_verify(const char *CAfile, int noCAfile,
116 const char *CApath, int noCApath,
117 const char *CAstore, int noCAstore);
118 __owur int ctx_set_verify_locations(SSL_CTX *ctx,
119 const char *CAfile, int noCAfile,
120 const char *CApath, int noCApath,
121 const char *CAstore, int noCAstore);
123 #ifndef OPENSSL_NO_CT
126 * Sets the file to load the Certificate Transparency log list from.
127 * If path is NULL, loads from the default file path.
128 * Returns 1 on success, 0 otherwise.
130 __owur int ctx_set_ctlog_list_file(SSL_CTX *ctx, const char *path);
134 ENGINE *setup_engine(const char *engine, int debug);
135 void release_engine(ENGINE *e);
137 # ifndef OPENSSL_NO_OCSP
138 OCSP_RESPONSE *process_responder(OCSP_REQUEST *req,
139 const char *host, const char *path,
140 const char *port, int use_ssl,
141 STACK_OF(CONF_VALUE) *headers,
145 /* Functions defined in ca.c and also used in ocsp.c */
146 int unpack_revinfo(ASN1_TIME **prevtm, int *preason, ASN1_OBJECT **phold,
147 ASN1_GENERALIZEDTIME **pinvtm, const char *str);
150 # define DB_exp_date 1
151 # define DB_rev_date 2
152 # define DB_serial 3 /* index - unique */
154 # define DB_name 5 /* index - unique when active and not
158 # define DB_TYPE_REV 'R' /* Revoked */
159 # define DB_TYPE_EXP 'E' /* Expired */
160 # define DB_TYPE_VAL 'V' /* Valid ; inserted with: ca ... -valid */
161 # define DB_TYPE_SUSP 'S' /* Suspended */
163 typedef struct db_attr_st {
166 typedef struct ca_db_st {
170 # ifndef OPENSSL_NO_POSIX_IO
175 void* app_malloc(int sz, const char *what);
176 BIGNUM *load_serial(const char *serialfile, int create, ASN1_INTEGER **retai);
177 int save_serial(const char *serialfile, const char *suffix, const BIGNUM *serial,
178 ASN1_INTEGER **retai);
179 int rotate_serial(const char *serialfile, const char *new_suffix,
180 const char *old_suffix);
181 int rand_serial(BIGNUM *b, ASN1_INTEGER *ai);
182 CA_DB *load_index(const char *dbfile, DB_ATTR *dbattr);
183 int index_index(CA_DB *db);
184 int save_index(const char *dbfile, const char *suffix, CA_DB *db);
185 int rotate_index(const char *dbfile, const char *new_suffix,
186 const char *old_suffix);
187 void free_index(CA_DB *db);
188 # define index_name_cmp_noconst(a, b) \
189 index_name_cmp((const OPENSSL_CSTRING *)CHECKED_PTR_OF(OPENSSL_STRING, a), \
190 (const OPENSSL_CSTRING *)CHECKED_PTR_OF(OPENSSL_STRING, b))
191 int index_name_cmp(const OPENSSL_CSTRING *a, const OPENSSL_CSTRING *b);
192 int parse_yesno(const char *str, int def);
194 X509_NAME *parse_name(const char *str, long chtype, int multirdn);
195 void policies_print(X509_STORE_CTX *ctx);
196 int bio_to_mem(unsigned char **out, int maxlen, BIO *in);
197 int pkey_ctrl_string(EVP_PKEY_CTX *ctx, const char *value);
198 int init_gen_str(EVP_PKEY_CTX **pctx,
199 const char *algname, ENGINE *e, int do_param);
200 int do_X509_sign(X509 *x, EVP_PKEY *pkey, const EVP_MD *md,
201 STACK_OF(OPENSSL_STRING) *sigopts);
202 int do_X509_REQ_sign(X509_REQ *x, EVP_PKEY *pkey, const EVP_MD *md,
203 STACK_OF(OPENSSL_STRING) *sigopts);
204 int do_X509_CRL_sign(X509_CRL *x, EVP_PKEY *pkey, const EVP_MD *md,
205 STACK_OF(OPENSSL_STRING) *sigopts);
207 extern char *psk_key;
210 unsigned char *next_protos_parse(size_t *outlen, const char *in);
212 void print_cert_checks(BIO *bio, X509 *x,
213 const char *checkhost,
214 const char *checkemail, const char *checkip);
216 void store_setup_crl_download(X509_STORE *st);
218 # define EXT_COPY_NONE 0
219 # define EXT_COPY_ADD 1
220 # define EXT_COPY_ALL 2
222 # define NETSCAPE_CERT_HDR "certificate"
224 # define APP_PASS_LEN 1024
227 * IETF RFC 5280 says serial number must be <= 20 bytes. Use 159 bits
228 * so that the first bit will never be one, so that the DER encoding
229 * rules won't force a leading octet.
231 # define SERIAL_RAND_BITS 159
233 int app_isdir(const char *);
234 int app_access(const char *, int flag);
235 int fileno_stdin(void);
236 int fileno_stdout(void);
237 int raw_read_stdin(void *, int);
238 int raw_write_stdout(const void *, int);
242 double app_tminterval(int stop, int usertime);
244 void make_uppercase(char *string);
246 typedef struct verify_options_st {
253 extern VERIFY_CB_ARGS verify_args;
255 OSSL_PARAM *app_params_new_from_opts(STACK_OF(OPENSSL_STRING) *opts,
256 const OSSL_PARAM *paramdefs);
257 void app_params_free(OSSL_PARAM *params);