apps.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. /*
  2. * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  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
  8. */
  9. #ifndef HEADER_APPS_H
  10. # define HEADER_APPS_H
  11. # include "e_os.h" /* struct timeval for DTLS */
  12. # include "internal/nelem.h"
  13. # include <assert.h>
  14. # include <sys/types.h>
  15. # ifndef OPENSSL_NO_POSIX_IO
  16. # include <sys/stat.h>
  17. # include <fcntl.h>
  18. # endif
  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/conf.h>
  24. # include <openssl/txt_db.h>
  25. # include <openssl/engine.h>
  26. # include <openssl/ocsp.h>
  27. # include <signal.h>
  28. # include "apps_ui.h"
  29. # include "opt.h"
  30. # include "fmt.h"
  31. # include "platform.h"
  32. # if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WINCE)
  33. # define openssl_fdset(a,b) FD_SET((unsigned int)a, b)
  34. # else
  35. # define openssl_fdset(a,b) FD_SET(a, b)
  36. # endif
  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. void app_RAND_load_conf(CONF *c, const char *section);
  44. void app_RAND_write(void);
  45. extern char *default_config_file;
  46. extern BIO *bio_in;
  47. extern BIO *bio_out;
  48. extern BIO *bio_err;
  49. extern const unsigned char tls13_aes128gcmsha256_id[];
  50. extern const unsigned char tls13_aes256gcmsha384_id[];
  51. extern BIO_ADDR *ourpeer;
  52. BIO_METHOD *apps_bf_prefix(void);
  53. /*
  54. * The control used to set the prefix with BIO_ctrl()
  55. * We make it high enough so the chance of ever clashing with the BIO library
  56. * remains unlikely for the foreseeable future and beyond.
  57. */
  58. #define PREFIX_CTRL_SET_PREFIX (1 << 15)
  59. /*
  60. * apps_bf_prefix() returns a dynamically created BIO_METHOD, which we
  61. * need to destroy at some point. When created internally, it's stored
  62. * in an internal pointer which can be freed with the following function
  63. */
  64. void destroy_prefix_method(void);
  65. BIO *dup_bio_in(int format);
  66. BIO *dup_bio_out(int format);
  67. BIO *dup_bio_err(int format);
  68. BIO *bio_open_owner(const char *filename, int format, int private);
  69. BIO *bio_open_default(const char *filename, char mode, int format);
  70. BIO *bio_open_default_quiet(const char *filename, char mode, int format);
  71. CONF *app_load_config_bio(BIO *in, const char *filename);
  72. CONF *app_load_config(const char *filename);
  73. CONF *app_load_config_quiet(const char *filename);
  74. int app_load_modules(const CONF *config);
  75. void unbuffer(FILE *fp);
  76. void wait_for_async(SSL *s);
  77. # if defined(OPENSSL_SYS_MSDOS)
  78. int has_stdin_waiting(void);
  79. # endif
  80. void corrupt_signature(const ASN1_STRING *signature);
  81. int set_cert_times(X509 *x, const char *startdate, const char *enddate,
  82. int days);
  83. typedef struct args_st {
  84. int size;
  85. int argc;
  86. char **argv;
  87. } ARGS;
  88. /* We need both wrap and the "real" function because libcrypto uses both. */
  89. int wrap_password_callback(char *buf, int bufsiz, int verify, void *cb_data);
  90. int chopup_args(ARGS *arg, char *buf);
  91. # ifdef HEADER_X509_H
  92. int dump_cert_text(BIO *out, X509 *x);
  93. void print_name(BIO *out, const char *title, X509_NAME *nm,
  94. unsigned long lflags);
  95. # endif
  96. void print_bignum_var(BIO *, const BIGNUM *, const char*,
  97. int, unsigned char *);
  98. void print_array(BIO *, const char *, int, const unsigned char *);
  99. int set_nameopt(const char *arg);
  100. unsigned long get_nameopt(void);
  101. int set_cert_ex(unsigned long *flags, const char *arg);
  102. int set_name_ex(unsigned long *flags, const char *arg);
  103. int set_ext_copy(int *copy_type, const char *arg);
  104. int copy_extensions(X509 *x, X509_REQ *req, int copy_type);
  105. int app_passwd(const char *arg1, const char *arg2, char **pass1, char **pass2);
  106. int add_oid_section(CONF *conf);
  107. X509 *load_cert(const char *file, int format, const char *cert_descrip);
  108. X509_CRL *load_crl(const char *infile, int format);
  109. EVP_PKEY *load_key(const char *file, int format, int maybe_stdin,
  110. const char *pass, ENGINE *e, const char *key_descrip);
  111. EVP_PKEY *load_pubkey(const char *file, int format, int maybe_stdin,
  112. const char *pass, ENGINE *e, const char *key_descrip);
  113. int load_certs(const char *file, STACK_OF(X509) **certs, int format,
  114. const char *pass, const char *cert_descrip);
  115. int load_crls(const char *file, STACK_OF(X509_CRL) **crls, int format,
  116. const char *pass, const char *cert_descrip);
  117. X509_STORE *setup_verify(const char *CAfile, const char *CApath,
  118. int noCAfile, int noCApath);
  119. __owur int ctx_set_verify_locations(SSL_CTX *ctx, const char *CAfile,
  120. const char *CApath, int noCAfile,
  121. int noCApath);
  122. #ifndef OPENSSL_NO_CT
  123. /*
  124. * Sets the file to load the Certificate Transparency log list from.
  125. * If path is NULL, loads from the default file path.
  126. * Returns 1 on success, 0 otherwise.
  127. */
  128. __owur int ctx_set_ctlog_list_file(SSL_CTX *ctx, const char *path);
  129. #endif
  130. ENGINE *setup_engine(const char *engine, int debug);
  131. void release_engine(ENGINE *e);
  132. # ifndef OPENSSL_NO_OCSP
  133. OCSP_RESPONSE *process_responder(OCSP_REQUEST *req,
  134. const char *host, const char *path,
  135. const char *port, int use_ssl,
  136. STACK_OF(CONF_VALUE) *headers,
  137. int req_timeout);
  138. # endif
  139. /* Functions defined in ca.c and also used in ocsp.c */
  140. int unpack_revinfo(ASN1_TIME **prevtm, int *preason, ASN1_OBJECT **phold,
  141. ASN1_GENERALIZEDTIME **pinvtm, const char *str);
  142. # define DB_type 0
  143. # define DB_exp_date 1
  144. # define DB_rev_date 2
  145. # define DB_serial 3 /* index - unique */
  146. # define DB_file 4
  147. # define DB_name 5 /* index - unique when active and not
  148. * disabled */
  149. # define DB_NUMBER 6
  150. # define DB_TYPE_REV 'R' /* Revoked */
  151. # define DB_TYPE_EXP 'E' /* Expired */
  152. # define DB_TYPE_VAL 'V' /* Valid ; inserted with: ca ... -valid */
  153. # define DB_TYPE_SUSP 'S' /* Suspended */
  154. typedef struct db_attr_st {
  155. int unique_subject;
  156. } DB_ATTR;
  157. typedef struct ca_db_st {
  158. DB_ATTR attributes;
  159. TXT_DB *db;
  160. char *dbfname;
  161. # ifndef OPENSSL_NO_POSIX_IO
  162. struct stat dbst;
  163. # endif
  164. } CA_DB;
  165. void* app_malloc(int sz, const char *what);
  166. BIGNUM *load_serial(const char *serialfile, int create, ASN1_INTEGER **retai);
  167. int save_serial(const char *serialfile, const char *suffix, const BIGNUM *serial,
  168. ASN1_INTEGER **retai);
  169. int rotate_serial(const char *serialfile, const char *new_suffix,
  170. const char *old_suffix);
  171. int rand_serial(BIGNUM *b, ASN1_INTEGER *ai);
  172. CA_DB *load_index(const char *dbfile, DB_ATTR *dbattr);
  173. int index_index(CA_DB *db);
  174. int save_index(const char *dbfile, const char *suffix, CA_DB *db);
  175. int rotate_index(const char *dbfile, const char *new_suffix,
  176. const char *old_suffix);
  177. void free_index(CA_DB *db);
  178. # define index_name_cmp_noconst(a, b) \
  179. index_name_cmp((const OPENSSL_CSTRING *)CHECKED_PTR_OF(OPENSSL_STRING, a), \
  180. (const OPENSSL_CSTRING *)CHECKED_PTR_OF(OPENSSL_STRING, b))
  181. int index_name_cmp(const OPENSSL_CSTRING *a, const OPENSSL_CSTRING *b);
  182. int parse_yesno(const char *str, int def);
  183. X509_NAME *parse_name(const char *str, long chtype, int multirdn);
  184. void policies_print(X509_STORE_CTX *ctx);
  185. int bio_to_mem(unsigned char **out, int maxlen, BIO *in);
  186. int pkey_ctrl_string(EVP_PKEY_CTX *ctx, const char *value);
  187. int init_gen_str(EVP_PKEY_CTX **pctx,
  188. const char *algname, ENGINE *e, int do_param);
  189. int do_X509_sign(X509 *x, EVP_PKEY *pkey, const EVP_MD *md,
  190. STACK_OF(OPENSSL_STRING) *sigopts);
  191. int do_X509_REQ_sign(X509_REQ *x, EVP_PKEY *pkey, const EVP_MD *md,
  192. STACK_OF(OPENSSL_STRING) *sigopts);
  193. int do_X509_CRL_sign(X509_CRL *x, EVP_PKEY *pkey, const EVP_MD *md,
  194. STACK_OF(OPENSSL_STRING) *sigopts);
  195. extern char *psk_key;
  196. unsigned char *next_protos_parse(size_t *outlen, const char *in);
  197. void print_cert_checks(BIO *bio, X509 *x,
  198. const char *checkhost,
  199. const char *checkemail, const char *checkip);
  200. void store_setup_crl_download(X509_STORE *st);
  201. # define EXT_COPY_NONE 0
  202. # define EXT_COPY_ADD 1
  203. # define EXT_COPY_ALL 2
  204. # define NETSCAPE_CERT_HDR "certificate"
  205. # define APP_PASS_LEN 1024
  206. /*
  207. * IETF RFC 5280 says serial number must be <= 20 bytes. Use 159 bits
  208. * so that the first bit will never be one, so that the DER encoding
  209. * rules won't force a leading octet.
  210. */
  211. # define SERIAL_RAND_BITS 159
  212. int app_isdir(const char *);
  213. int app_access(const char *, int flag);
  214. int fileno_stdin(void);
  215. int fileno_stdout(void);
  216. int raw_read_stdin(void *, int);
  217. int raw_write_stdout(const void *, int);
  218. # define TM_START 0
  219. # define TM_STOP 1
  220. double app_tminterval(int stop, int usertime);
  221. void make_uppercase(char *string);
  222. typedef struct verify_options_st {
  223. int depth;
  224. int quiet;
  225. int error;
  226. int return_error;
  227. } VERIFY_CB_ARGS;
  228. extern VERIFY_CB_ARGS verify_args;
  229. #endif