From: Qin Long Date: Sat, 5 Mar 2016 15:37:42 +0000 (+0800) Subject: CryptoPkg/OpensslLib: Switch to upstream fix for OpenSSL RT#3964 X-Git-Tag: edk2-stable201903~7695 X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=commitdiff_plain;h=ca6fa1fe3bdf2f3f7356530166a4f138ba537b98 CryptoPkg/OpensslLib: Switch to upstream fix for OpenSSL RT#3964 Extensive fixes for the no-stdio configuration have been merged into OpenSSL 1.1, primarily in commit 984d6c605. The backport to 1.0.2 is slightly different because we still have a mixture of no-fp-api and no-stdio in 1.0.2, although they are hopelessly intertwined. Nevertheless, drop our own original version and switch to a backported version of what went into 1.1. This includes subsequent fixes in commit c0cf5b84d for the TS code. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: David Woodhouse Reviewed-by: Laszlo Ersek Reviewed-by: Qin Long Tested-by: Qin Long --- diff --git a/CryptoPkg/Library/OpensslLib/EDKII_openssl-1.0.2f.patch b/CryptoPkg/Library/OpensslLib/EDKII_openssl-1.0.2f.patch index b93bc2c3f2..040117187e 100644 --- a/CryptoPkg/Library/OpensslLib/EDKII_openssl-1.0.2f.patch +++ b/CryptoPkg/Library/OpensslLib/EDKII_openssl-1.0.2f.patch @@ -1,47 +1,240 @@ -diff --git a/crypto/bio/bio.h b/crypto/bio/bio.h -index 6e2293b..325e5d2 100644 ---- a/crypto/bio/bio.h -+++ b/crypto/bio/bio.h -@@ -650,10 +650,10 @@ int BIO_asn1_set_suffix(BIO *b, asn1_ps_func *suffix, - int BIO_asn1_get_suffix(BIO *b, asn1_ps_func **psuffix, - asn1_ps_func **psuffix_free); - --# ifndef OPENSSL_NO_FP_API - BIO_METHOD *BIO_s_file(void); - BIO *BIO_new_file(const char *filename, const char *mode); - BIO *BIO_new_fp(FILE *stream, int close_flag); -+# ifndef OPENSSL_NO_FP_API - # define BIO_s_file_internal BIO_s_file +diff --git a/Configure b/Configure +index 4a715dc..eb61eda 100755 +--- a/Configure ++++ b/Configure +@@ -1082,7 +1082,7 @@ if (defined($disabled{"tls1"})) + } + + if (defined($disabled{"ec"}) || defined($disabled{"dsa"}) +- || defined($disabled{"dh"})) ++ || defined($disabled{"dh"}) || defined($disabled{"stdio"})) + { + $disabled{"gost"} = "forced"; + } +diff --git a/crypto/asn1/a_strex.c b/crypto/asn1/a_strex.c +index 35fd44c..9f39bff 100644 +--- a/crypto/asn1/a_strex.c ++++ b/crypto/asn1/a_strex.c +@@ -104,6 +104,7 @@ static int send_bio_chars(void *arg, const void *buf, int len) + return 1; + } + ++#ifndef OPENSSL_NO_FP_API + static int send_fp_chars(void *arg, const void *buf, int len) + { + if (!arg) +@@ -112,6 +113,7 @@ static int send_fp_chars(void *arg, const void *buf, int len) + return 0; + return 1; + } ++#endif + + typedef int char_io (void *arg, const void *buf, int len); + +diff --git a/crypto/conf/conf.h b/crypto/conf/conf.h +index 8d926d5..41cf38e 100644 +--- a/crypto/conf/conf.h ++++ b/crypto/conf/conf.h +@@ -118,8 +118,10 @@ typedef void conf_finish_func (CONF_IMODULE *md); + + int CONF_set_default_method(CONF_METHOD *meth); + void CONF_set_nconf(CONF *conf, LHASH_OF(CONF_VALUE) *hash); ++# ifndef OPENSSL_NO_STDIO + LHASH_OF(CONF_VALUE) *CONF_load(LHASH_OF(CONF_VALUE) *conf, const char *file, + long *eline); ++# endif + # ifndef OPENSSL_NO_FP_API + LHASH_OF(CONF_VALUE) *CONF_load_fp(LHASH_OF(CONF_VALUE) *conf, FILE *fp, + long *eline); +@@ -133,7 +135,9 @@ char *CONF_get_string(LHASH_OF(CONF_VALUE) *conf, const char *group, + long CONF_get_number(LHASH_OF(CONF_VALUE) *conf, const char *group, + const char *name); + void CONF_free(LHASH_OF(CONF_VALUE) *conf); ++#ifndef OPENSSL_NO_FP_API + int CONF_dump_fp(LHASH_OF(CONF_VALUE) *conf, FILE *out); ++#endif + int CONF_dump_bio(LHASH_OF(CONF_VALUE) *conf, BIO *out); + + void OPENSSL_config(const char *config_name); +@@ -160,7 +164,9 @@ CONF_METHOD *NCONF_XML(void); + void NCONF_free(CONF *conf); + void NCONF_free_data(CONF *conf); + ++# ifndef OPENSSL_NO_STDIO + int NCONF_load(CONF *conf, const char *file, long *eline); ++# endif + # ifndef OPENSSL_NO_FP_API + int NCONF_load_fp(CONF *conf, FILE *fp, long *eline); # endif - BIO *BIO_new(BIO_METHOD *type); -diff --git a/crypto/bio/bss_file.c b/crypto/bio/bss_file.c -index bfba93e..4f13d1b 100644 ---- a/crypto/bio/bss_file.c -+++ b/crypto/bio/bss_file.c -@@ -467,6 +467,23 @@ static int MS_CALLBACK file_puts(BIO *bp, const char *str) - return (ret); +@@ -170,7 +176,9 @@ STACK_OF(CONF_VALUE) *NCONF_get_section(const CONF *conf, + char *NCONF_get_string(const CONF *conf, const char *group, const char *name); + int NCONF_get_number_e(const CONF *conf, const char *group, const char *name, + long *result); ++#ifndef OPENSSL_NO_FP_API + int NCONF_dump_fp(const CONF *conf, FILE *out); ++#endif + int NCONF_dump_bio(const CONF *conf, BIO *out); + + # if 0 /* The following function has no error +@@ -184,8 +192,10 @@ long NCONF_get_number(CONF *conf, char *group, char *name); + + int CONF_modules_load(const CONF *cnf, const char *appname, + unsigned long flags); ++#ifndef OPENSSL_NO_STDIO + int CONF_modules_load_file(const char *filename, const char *appname, + unsigned long flags); ++#endif + void CONF_modules_unload(int all); + void CONF_modules_finish(void); + void CONF_modules_free(void); +diff --git a/crypto/conf/conf_def.c b/crypto/conf/conf_def.c +index 68c77ce..3d308c7 100644 +--- a/crypto/conf/conf_def.c ++++ b/crypto/conf/conf_def.c +@@ -182,6 +182,10 @@ static int def_destroy_data(CONF *conf) + + static int def_load(CONF *conf, const char *name, long *line) + { ++#ifdef OPENSSL_NO_STDIO ++ CONFerr(CONF_F_DEF_LOAD, ERR_R_SYS_LIB); ++ return 0; ++#else + int ret; + BIO *in = NULL; + +@@ -202,6 +206,7 @@ static int def_load(CONF *conf, const char *name, long *line) + BIO_free(in); + + return ret; ++#endif } -+# else -+ -+BIO_METHOD *BIO_s_file(void) -+{ -+ return NULL; -+} -+ -+BIO *BIO_new_file(const char *filename, const char *mode) -+{ -+ return NULL; -+} -+ -+BIO *BIO_new_fp(FILE *stream, int close_flag) -+{ -+ return NULL; -+} -+ - # endif /* OPENSSL_NO_STDIO */ + static int def_load_bio(CONF *conf, BIO *in, long *line) +diff --git a/crypto/conf/conf_lib.c b/crypto/conf/conf_lib.c +index 5281384..952b545 100644 +--- a/crypto/conf/conf_lib.c ++++ b/crypto/conf/conf_lib.c +@@ -90,6 +90,7 @@ int CONF_set_default_method(CONF_METHOD *meth) + return 1; + } + ++#ifndef OPENSSL_NO_STDIO + LHASH_OF(CONF_VALUE) *CONF_load(LHASH_OF(CONF_VALUE) *conf, const char *file, + long *eline) + { +@@ -111,6 +112,7 @@ LHASH_OF(CONF_VALUE) *CONF_load(LHASH_OF(CONF_VALUE) *conf, const char *file, + + return ltmp; + } ++#endif + + #ifndef OPENSSL_NO_FP_API + LHASH_OF(CONF_VALUE) *CONF_load_fp(LHASH_OF(CONF_VALUE) *conf, FILE *fp, +@@ -255,6 +257,7 @@ void NCONF_free_data(CONF *conf) + conf->meth->destroy_data(conf); + } + ++#ifndef OPENSSL_NO_STDIO + int NCONF_load(CONF *conf, const char *file, long *eline) + { + if (conf == NULL) { +@@ -264,6 +267,7 @@ int NCONF_load(CONF *conf, const char *file, long *eline) + + return conf->meth->load(conf, file, eline); + } ++#endif + + #ifndef OPENSSL_NO_FP_API + int NCONF_load_fp(CONF *conf, FILE *fp, long *eline) +diff --git a/crypto/conf/conf_mod.c b/crypto/conf/conf_mod.c +index 9acfca4..5e0a482 100644 +--- a/crypto/conf/conf_mod.c ++++ b/crypto/conf/conf_mod.c +@@ -159,6 +159,7 @@ int CONF_modules_load(const CONF *cnf, const char *appname, - #endif /* HEADER_BSS_FILE_C */ + } + ++#ifndef OPENSSL_NO_STDIO + int CONF_modules_load_file(const char *filename, const char *appname, + unsigned long flags) + { +@@ -194,6 +195,7 @@ int CONF_modules_load_file(const char *filename, const char *appname, + + return ret; + } ++#endif + + static int module_run(const CONF *cnf, char *name, char *value, + unsigned long flags) +diff --git a/crypto/conf/conf_sap.c b/crypto/conf/conf_sap.c +index c042cf2..a25b636 100644 +--- a/crypto/conf/conf_sap.c ++++ b/crypto/conf/conf_sap.c +@@ -87,9 +87,11 @@ void OPENSSL_config(const char *config_name) + ENGINE_load_builtin_engines(); + #endif + ERR_clear_error(); ++#ifndef OPENSSL_NO_STDIO + CONF_modules_load_file(NULL, config_name, + CONF_MFLAGS_DEFAULT_SECTION | + CONF_MFLAGS_IGNORE_MISSING_FILE); ++#endif + openssl_configured = 1; + } + +diff --git a/crypto/cryptlib.c b/crypto/cryptlib.c +index c9f674b..e223118 100644 +--- a/crypto/cryptlib.c ++++ b/crypto/cryptlib.c +@@ -670,6 +670,7 @@ unsigned long *OPENSSL_ia32cap_loc(void) + } + + # if defined(OPENSSL_CPUID_OBJ) && !defined(OPENSSL_NO_ASM) && !defined(I386_ONLY) ++#include + # define OPENSSL_CPUID_SETUP + # if defined(_WIN32) + typedef unsigned __int64 IA32CAP; +@@ -980,11 +981,13 @@ void OPENSSL_showfatal(const char *fmta, ...) + #else + void OPENSSL_showfatal(const char *fmta, ...) + { ++#ifndef OPENSSL_NO_STDIO + va_list ap; + + va_start(ap, fmta); + vfprintf(stderr, fmta, ap); + va_end(ap); ++#endif + } + + int OPENSSL_isservice(void) +@@ -1011,10 +1014,12 @@ void OpenSSLDie(const char *file, int line, const char *assertion) + #endif + } + ++#ifndef OPENSSL_NO_STDIO + void *OPENSSL_stderr(void) + { + return stderr; + } ++#endif + + int CRYPTO_memcmp(const void *in_a, const void *in_b, size_t len) + { +diff --git a/crypto/cryptlib.h b/crypto/cryptlib.h +index fba180a..3e3ea5e 100644 +--- a/crypto/cryptlib.h ++++ b/crypto/cryptlib.h +@@ -101,7 +101,9 @@ extern "C" { + void OPENSSL_cpuid_setup(void); + extern unsigned int OPENSSL_ia32cap_P[]; + void OPENSSL_showfatal(const char *fmta, ...); ++#ifndef OPENSSL_NO_STDIO + void *OPENSSL_stderr(void); ++#endif + extern int OPENSSL_NONPIC_relocated; + + #ifdef __cplusplus diff --git a/crypto/crypto.h b/crypto/crypto.h index c450d7a..d6e804e 100644 --- a/crypto/crypto.h @@ -128,6 +321,21 @@ index c450d7a..d6e804e 100644 "Low level API call to cipher " #alg " forbidden in FIPS mode!") # else +diff --git a/crypto/des/read2pwd.c b/crypto/des/read2pwd.c +index 01e275f..7633139 100644 +--- a/crypto/des/read2pwd.c ++++ b/crypto/des/read2pwd.c +@@ -114,6 +114,10 @@ + #include + #include + ++#ifndef BUFSIZ ++#define BUFSIZ 256 ++#endif ++ + int DES_read_password(DES_cblock *key, const char *prompt, int verify) + { + int ok; diff --git a/crypto/dh/dh_pmeth.c b/crypto/dh/dh_pmeth.c index b58e3fa..e5f345a 100644 --- a/crypto/dh/dh_pmeth.c @@ -150,8 +358,22 @@ index b58e3fa..e5f345a 100644 } return 1; } +diff --git a/crypto/engine/eng_openssl.c b/crypto/engine/eng_openssl.c +index 34b0029..cf622bb 100644 +--- a/crypto/engine/eng_openssl.c ++++ b/crypto/engine/eng_openssl.c +@@ -86,7 +86,9 @@ + * this is no longer automatic in ENGINE_load_builtin_engines(). + */ + #define TEST_ENG_OPENSSL_RC4 ++#ifndef OPENSSL_NO_FP_API + #define TEST_ENG_OPENSSL_PKEY ++#endif + /* #define TEST_ENG_OPENSSL_RC4_OTHERS */ + #define TEST_ENG_OPENSSL_RC4_P_INIT + /* #define TEST_ENG_OPENSSL_RC4_P_CIPHER */ diff --git a/crypto/pem/pem.h b/crypto/pem/pem.h -index d3b23fc..d61605b 100644 +index d3b23fc..87b0b6a 100644 --- a/crypto/pem/pem.h +++ b/crypto/pem/pem.h @@ -324,6 +324,7 @@ int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \ @@ -162,6 +384,57 @@ index d3b23fc..d61605b 100644 # define DECLARE_PEM_write_cb_fp(name, type) /**/ # else +@@ -417,6 +418,7 @@ int PEM_X509_INFO_write_bio(BIO *bp, X509_INFO *xi, EVP_CIPHER *enc, + pem_password_cb *cd, void *u); + # endif + ++#ifndef OPENSSL_NO_FP_API + int PEM_read(FILE *fp, char **name, char **header, + unsigned char **data, long *len); + int PEM_write(FILE *fp, const char *name, const char *hdr, +@@ -428,6 +430,7 @@ int PEM_ASN1_write(i2d_of_void *i2d, const char *name, FILE *fp, + int klen, pem_password_cb *callback, void *u); + STACK_OF(X509_INFO) *PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk, + pem_password_cb *cb, void *u); ++#endif + + int PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type, + EVP_MD *md_type, unsigned char **ek, int *ekl, +@@ -494,6 +497,7 @@ int i2d_PKCS8PrivateKey_nid_bio(BIO *bp, EVP_PKEY *x, int nid, + EVP_PKEY *d2i_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, + void *u); + ++#ifndef OPENSSL_NO_FP_API + int i2d_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc, + char *kstr, int klen, + pem_password_cb *cb, void *u); +@@ -510,7 +514,7 @@ EVP_PKEY *d2i_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, + int PEM_write_PKCS8PrivateKey(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc, + char *kstr, int klen, pem_password_cb *cd, + void *u); +- ++#endif + EVP_PKEY *PEM_read_bio_Parameters(BIO *bp, EVP_PKEY **x); + int PEM_write_bio_Parameters(BIO *bp, EVP_PKEY *x); + +diff --git a/crypto/pem/pem_pk8.c b/crypto/pem/pem_pk8.c +index 5747c73..fe465cc 100644 +--- a/crypto/pem/pem_pk8.c ++++ b/crypto/pem/pem_pk8.c +@@ -69,10 +69,12 @@ + static int do_pk8pkey(BIO *bp, EVP_PKEY *x, int isder, + int nid, const EVP_CIPHER *enc, + char *kstr, int klen, pem_password_cb *cb, void *u); ++ ++#ifndef OPENSSL_NO_FP_API + static int do_pk8pkey_fp(FILE *bp, EVP_PKEY *x, int isder, + int nid, const EVP_CIPHER *enc, + char *kstr, int klen, pem_password_cb *cb, void *u); +- ++#endif + /* + * These functions write a private key in PKCS#8 format: it is a "drop in" + * replacement for PEM_write_bio_PrivateKey() and friends. As usual if 'enc' diff --git a/crypto/pkcs7/pk7_smime.c b/crypto/pkcs7/pk7_smime.c index c4d3724..fd531c9 100644 --- a/crypto/pkcs7/pk7_smime.c @@ -329,6 +602,339 @@ index 4e06218..f591f0f 100644 const EVP_PKEY_ASN1_METHOD rsa_asn1_meths[] = { { +diff --git a/crypto/srp/srp.h b/crypto/srp/srp.h +index d072536..73b945f 100644 +--- a/crypto/srp/srp.h ++++ b/crypto/srp/srp.h +@@ -114,7 +114,9 @@ DECLARE_STACK_OF(SRP_gN) + + SRP_VBASE *SRP_VBASE_new(char *seed_key); + int SRP_VBASE_free(SRP_VBASE *vb); ++#ifndef OPENSSL_NO_STDIO + int SRP_VBASE_init(SRP_VBASE *vb, char *verifier_file); ++#endif + SRP_user_pwd *SRP_VBASE_get_by_user(SRP_VBASE *vb, char *username); + char *SRP_create_verifier(const char *user, const char *pass, char **salt, + char **verifier, const char *N, const char *g); +diff --git a/crypto/srp/srp_vfy.c b/crypto/srp/srp_vfy.c +index a3f1a8a..3fbb186 100644 +--- a/crypto/srp/srp_vfy.c ++++ b/crypto/srp/srp_vfy.c +@@ -225,6 +225,7 @@ static int SRP_user_pwd_set_ids(SRP_user_pwd *vinfo, const char *id, + return (info == NULL || NULL != (vinfo->info = BUF_strdup(info))); + } + ++#ifndef OPENSSL_NO_STDIO + static int SRP_user_pwd_set_sv(SRP_user_pwd *vinfo, const char *s, + const char *v) + { +@@ -239,6 +240,7 @@ static int SRP_user_pwd_set_sv(SRP_user_pwd *vinfo, const char *s, + len = t_fromb64(tmp, s); + return ((vinfo->s = BN_bin2bn(tmp, len, NULL)) != NULL); + } ++#endif + + static int SRP_user_pwd_set_sv_BN(SRP_user_pwd *vinfo, BIGNUM *s, BIGNUM *v) + { +@@ -279,6 +281,7 @@ int SRP_VBASE_free(SRP_VBASE *vb) + return 0; + } + ++#ifndef OPENSSL_NO_STDIO + static SRP_gN_cache *SRP_gN_new_init(const char *ch) + { + unsigned char tmp[MAX_LEN]; +@@ -310,6 +313,7 @@ static void SRP_gN_free(SRP_gN_cache *gN_cache) + BN_free(gN_cache->bn); + OPENSSL_free(gN_cache); + } ++#endif + + static SRP_gN *SRP_get_gN_by_id(const char *id, STACK_OF(SRP_gN) *gN_tab) + { +@@ -326,6 +330,7 @@ static SRP_gN *SRP_get_gN_by_id(const char *id, STACK_OF(SRP_gN) *gN_tab) + return SRP_get_default_gN(id); + } + ++#ifndef OPENSSL_NO_STDIO + static BIGNUM *SRP_gN_place_bn(STACK_OF(SRP_gN_cache) *gN_cache, char *ch) + { + int i; +@@ -467,6 +472,7 @@ int SRP_VBASE_init(SRP_VBASE *vb, char *verifier_file) + return error_code; + + } ++#endif + + SRP_user_pwd *SRP_VBASE_get_by_user(SRP_VBASE *vb, char *username) + { +diff --git a/crypto/ts/ts.h b/crypto/ts/ts.h +index 16eccbb..a9fe40e 100644 +--- a/crypto/ts/ts.h ++++ b/crypto/ts/ts.h +@@ -281,8 +281,10 @@ TS_REQ *d2i_TS_REQ(TS_REQ **a, const unsigned char **pp, long length); + + TS_REQ *TS_REQ_dup(TS_REQ *a); + ++#ifndef OPENSSL_NO_FP_API + TS_REQ *d2i_TS_REQ_fp(FILE *fp, TS_REQ **a); + int i2d_TS_REQ_fp(FILE *fp, TS_REQ *a); ++#endif + TS_REQ *d2i_TS_REQ_bio(BIO *fp, TS_REQ **a); + int i2d_TS_REQ_bio(BIO *fp, TS_REQ *a); + +@@ -294,10 +296,12 @@ TS_MSG_IMPRINT *d2i_TS_MSG_IMPRINT(TS_MSG_IMPRINT **a, + + TS_MSG_IMPRINT *TS_MSG_IMPRINT_dup(TS_MSG_IMPRINT *a); + ++#ifndef OPENSSL_NO_FP_API + TS_MSG_IMPRINT *d2i_TS_MSG_IMPRINT_fp(FILE *fp, TS_MSG_IMPRINT **a); + int i2d_TS_MSG_IMPRINT_fp(FILE *fp, TS_MSG_IMPRINT *a); +-TS_MSG_IMPRINT *d2i_TS_MSG_IMPRINT_bio(BIO *fp, TS_MSG_IMPRINT **a); +-int i2d_TS_MSG_IMPRINT_bio(BIO *fp, TS_MSG_IMPRINT *a); ++#endif ++TS_MSG_IMPRINT *d2i_TS_MSG_IMPRINT_bio(BIO *bio, TS_MSG_IMPRINT **a); ++int i2d_TS_MSG_IMPRINT_bio(BIO *bio, TS_MSG_IMPRINT *a); + + TS_RESP *TS_RESP_new(void); + void TS_RESP_free(TS_RESP *a); +@@ -306,10 +310,12 @@ TS_RESP *d2i_TS_RESP(TS_RESP **a, const unsigned char **pp, long length); + TS_TST_INFO *PKCS7_to_TS_TST_INFO(PKCS7 *token); + TS_RESP *TS_RESP_dup(TS_RESP *a); + ++#ifndef OPENSSL_NO_FP_API + TS_RESP *d2i_TS_RESP_fp(FILE *fp, TS_RESP **a); + int i2d_TS_RESP_fp(FILE *fp, TS_RESP *a); +-TS_RESP *d2i_TS_RESP_bio(BIO *fp, TS_RESP **a); +-int i2d_TS_RESP_bio(BIO *fp, TS_RESP *a); ++#endif ++TS_RESP *d2i_TS_RESP_bio(BIO *bio, TS_RESP **a); ++int i2d_TS_RESP_bio(BIO *bio, TS_RESP *a); + + TS_STATUS_INFO *TS_STATUS_INFO_new(void); + void TS_STATUS_INFO_free(TS_STATUS_INFO *a); +@@ -325,10 +331,12 @@ TS_TST_INFO *d2i_TS_TST_INFO(TS_TST_INFO **a, const unsigned char **pp, + long length); + TS_TST_INFO *TS_TST_INFO_dup(TS_TST_INFO *a); + ++#ifndef OPENSSL_NO_FP_API + TS_TST_INFO *d2i_TS_TST_INFO_fp(FILE *fp, TS_TST_INFO **a); + int i2d_TS_TST_INFO_fp(FILE *fp, TS_TST_INFO *a); +-TS_TST_INFO *d2i_TS_TST_INFO_bio(BIO *fp, TS_TST_INFO **a); +-int i2d_TS_TST_INFO_bio(BIO *fp, TS_TST_INFO *a); ++#endif ++TS_TST_INFO *d2i_TS_TST_INFO_bio(BIO *bio, TS_TST_INFO **a); ++int i2d_TS_TST_INFO_bio(BIO *bio, TS_TST_INFO *a); + + TS_ACCURACY *TS_ACCURACY_new(void); + void TS_ACCURACY_free(TS_ACCURACY *a); +@@ -728,15 +736,18 @@ int TS_MSG_IMPRINT_print_bio(BIO *bio, TS_MSG_IMPRINT *msg); + * ts/ts_conf.c + */ + ++#ifndef OPENSSL_NO_STDIO + X509 *TS_CONF_load_cert(const char *file); + STACK_OF(X509) *TS_CONF_load_certs(const char *file); + EVP_PKEY *TS_CONF_load_key(const char *file, const char *pass); ++#endif + const char *TS_CONF_get_tsa_section(CONF *conf, const char *section); + int TS_CONF_set_serial(CONF *conf, const char *section, TS_serial_cb cb, + TS_RESP_CTX *ctx); + int TS_CONF_set_crypto_device(CONF *conf, const char *section, + const char *device); + int TS_CONF_set_default_engine(const char *name); ++#ifndef OPENSSL_NO_STDIO + int TS_CONF_set_signer_cert(CONF *conf, const char *section, + const char *cert, TS_RESP_CTX *ctx); + int TS_CONF_set_certs(CONF *conf, const char *section, const char *certs, +@@ -744,6 +755,7 @@ int TS_CONF_set_certs(CONF *conf, const char *section, const char *certs, + int TS_CONF_set_signer_key(CONF *conf, const char *section, + const char *key, const char *pass, + TS_RESP_CTX *ctx); ++#endif + int TS_CONF_set_def_policy(CONF *conf, const char *section, + const char *policy, TS_RESP_CTX *ctx); + int TS_CONF_set_policies(CONF *conf, const char *section, TS_RESP_CTX *ctx); +@@ -784,6 +796,11 @@ void ERR_load_TS_strings(void); + # define TS_F_TS_CHECK_SIGNING_CERTS 103 + # define TS_F_TS_CHECK_STATUS_INFO 104 + # define TS_F_TS_COMPUTE_IMPRINT 145 ++# define TS_F_TS_CONF_INVALID 151 ++# define TS_F_TS_CONF_LOAD_CERT 153 ++# define TS_F_TS_CONF_LOAD_CERTS 154 ++# define TS_F_TS_CONF_LOAD_KEY 155 ++# define TS_F_TS_CONF_LOOKUP_FAIL 152 + # define TS_F_TS_CONF_SET_DEFAULT_ENGINE 146 + # define TS_F_TS_GET_STATUS_TEXT 105 + # define TS_F_TS_MSG_IMPRINT_SET_ALGO 118 +@@ -822,6 +839,8 @@ void ERR_load_TS_strings(void); + /* Reason codes. */ + # define TS_R_BAD_PKCS7_TYPE 132 + # define TS_R_BAD_TYPE 133 ++# define TS_R_CANNOT_LOAD_CERT 137 ++# define TS_R_CANNOT_LOAD_KEY 138 + # define TS_R_CERTIFICATE_VERIFY_ERROR 100 + # define TS_R_COULD_NOT_SET_ENGINE 127 + # define TS_R_COULD_NOT_SET_TIME 115 +@@ -854,6 +873,8 @@ void ERR_load_TS_strings(void); + # define TS_R_UNACCEPTABLE_POLICY 125 + # define TS_R_UNSUPPORTED_MD_ALGORITHM 126 + # define TS_R_UNSUPPORTED_VERSION 113 ++# define TS_R_VAR_BAD_VALUE 135 ++# define TS_R_VAR_LOOKUP_FAILURE 136 + # define TS_R_WRONG_CONTENT_TYPE 114 + + #ifdef __cplusplus +diff --git a/crypto/ts/ts_conf.c b/crypto/ts/ts_conf.c +index 4716b23..c4416ba 100644 +--- a/crypto/ts/ts_conf.c ++++ b/crypto/ts/ts_conf.c +@@ -92,6 +92,7 @@ + + /* Function definitions for certificate and key loading. */ + ++#ifndef OPENSSL_NO_STDIO + X509 *TS_CONF_load_cert(const char *file) + { + BIO *cert = NULL; +@@ -102,7 +103,7 @@ X509 *TS_CONF_load_cert(const char *file) + x = PEM_read_bio_X509_AUX(cert, NULL, NULL, NULL); + end: + if (x == NULL) +- fprintf(stderr, "unable to load certificate: %s\n", file); ++ TSerr(TS_F_TS_CONF_LOAD_CERT, TS_R_CANNOT_LOAD_CERT); + BIO_free(cert); + return x; + } +@@ -129,7 +130,7 @@ STACK_OF(X509) *TS_CONF_load_certs(const char *file) + } + end: + if (othercerts == NULL) +- fprintf(stderr, "unable to load certificates: %s\n", file); ++ TSerr(TS_F_TS_CONF_LOAD_CERTS, TS_R_CANNOT_LOAD_CERT); + sk_X509_INFO_pop_free(allcerts, X509_INFO_free); + BIO_free(certs); + return othercerts; +@@ -145,21 +146,24 @@ EVP_PKEY *TS_CONF_load_key(const char *file, const char *pass) + pkey = PEM_read_bio_PrivateKey(key, NULL, NULL, (char *)pass); + end: + if (pkey == NULL) +- fprintf(stderr, "unable to load private key: %s\n", file); ++ TSerr(TS_F_TS_CONF_LOAD_KEY, TS_R_CANNOT_LOAD_KEY); + BIO_free(key); + return pkey; + } ++#endif /* !OPENSSL_NO_STDIO */ + + /* Function definitions for handling configuration options. */ + + static void TS_CONF_lookup_fail(const char *name, const char *tag) + { +- fprintf(stderr, "variable lookup failed for %s::%s\n", name, tag); ++ TSerr(TS_F_TS_CONF_LOOKUP_FAIL, TS_R_VAR_LOOKUP_FAILURE); ++ ERR_add_error_data(3, name, "::", tag); + } + + static void TS_CONF_invalid(const char *name, const char *tag) + { +- fprintf(stderr, "invalid variable value for %s::%s\n", name, tag); ++ TSerr(TS_F_TS_CONF_INVALID, TS_R_VAR_BAD_VALUE); ++ ERR_add_error_data(3, name, "::", tag); + } + + const char *TS_CONF_get_tsa_section(CONF *conf, const char *section) +@@ -237,6 +241,7 @@ int TS_CONF_set_default_engine(const char *name) + + #endif + ++#ifndef OPENSSL_NO_STDIO + int TS_CONF_set_signer_cert(CONF *conf, const char *section, + const char *cert, TS_RESP_CTX *ctx) + { +@@ -302,6 +307,7 @@ int TS_CONF_set_signer_key(CONF *conf, const char *section, + EVP_PKEY_free(key_obj); + return ret; + } ++#endif /* !OPENSSL_NO_STDIO */ + + int TS_CONF_set_def_policy(CONF *conf, const char *section, + const char *policy, TS_RESP_CTX *ctx) +diff --git a/crypto/ts/ts_err.c b/crypto/ts/ts_err.c +index ff1abf4..3f5b78f 100644 +--- a/crypto/ts/ts_err.c ++++ b/crypto/ts/ts_err.c +@@ -1,6 +1,6 @@ + /* crypto/ts/ts_err.c */ + /* ==================================================================== +- * Copyright (c) 1999-2007 The OpenSSL Project. All rights reserved. ++ * Copyright (c) 1999-2015 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions +@@ -87,6 +87,11 @@ static ERR_STRING_DATA TS_str_functs[] = { + {ERR_FUNC(TS_F_TS_CHECK_SIGNING_CERTS), "TS_CHECK_SIGNING_CERTS"}, + {ERR_FUNC(TS_F_TS_CHECK_STATUS_INFO), "TS_CHECK_STATUS_INFO"}, + {ERR_FUNC(TS_F_TS_COMPUTE_IMPRINT), "TS_COMPUTE_IMPRINT"}, ++ {ERR_FUNC(TS_F_TS_CONF_INVALID), "ts_CONF_invalid"}, ++ {ERR_FUNC(TS_F_TS_CONF_LOAD_CERT), "TS_CONF_load_cert"}, ++ {ERR_FUNC(TS_F_TS_CONF_LOAD_CERTS), "TS_CONF_load_certs"}, ++ {ERR_FUNC(TS_F_TS_CONF_LOAD_KEY), "TS_CONF_load_key"}, ++ {ERR_FUNC(TS_F_TS_CONF_LOOKUP_FAIL), "ts_CONF_lookup_fail"}, + {ERR_FUNC(TS_F_TS_CONF_SET_DEFAULT_ENGINE), "TS_CONF_set_default_engine"}, + {ERR_FUNC(TS_F_TS_GET_STATUS_TEXT), "TS_GET_STATUS_TEXT"}, + {ERR_FUNC(TS_F_TS_MSG_IMPRINT_SET_ALGO), "TS_MSG_IMPRINT_set_algo"}, +@@ -132,6 +137,8 @@ static ERR_STRING_DATA TS_str_functs[] = { + static ERR_STRING_DATA TS_str_reasons[] = { + {ERR_REASON(TS_R_BAD_PKCS7_TYPE), "bad pkcs7 type"}, + {ERR_REASON(TS_R_BAD_TYPE), "bad type"}, ++ {ERR_REASON(TS_R_CANNOT_LOAD_CERT), "cannot load certificate"}, ++ {ERR_REASON(TS_R_CANNOT_LOAD_KEY), "cannot load private key"}, + {ERR_REASON(TS_R_CERTIFICATE_VERIFY_ERROR), "certificate verify error"}, + {ERR_REASON(TS_R_COULD_NOT_SET_ENGINE), "could not set engine"}, + {ERR_REASON(TS_R_COULD_NOT_SET_TIME), "could not set time"}, +@@ -170,6 +177,8 @@ static ERR_STRING_DATA TS_str_reasons[] = { + {ERR_REASON(TS_R_UNACCEPTABLE_POLICY), "unacceptable policy"}, + {ERR_REASON(TS_R_UNSUPPORTED_MD_ALGORITHM), "unsupported md algorithm"}, + {ERR_REASON(TS_R_UNSUPPORTED_VERSION), "unsupported version"}, ++ {ERR_REASON(TS_R_VAR_BAD_VALUE), "var bad value"}, ++ {ERR_REASON(TS_R_VAR_LOOKUP_FAILURE), "cannot find config variable"}, + {ERR_REASON(TS_R_WRONG_CONTENT_TYPE), "wrong content type"}, + {0, NULL} + }; +diff --git a/crypto/ui/ui_util.c b/crypto/ui/ui_util.c +index 0f29011..80dd40e 100644 +--- a/crypto/ui/ui_util.c ++++ b/crypto/ui/ui_util.c +@@ -56,6 +56,10 @@ + #include + #include "ui_locl.h" + ++#ifndef BUFSIZ ++#define BUFSIZ 256 ++#endif ++ + int UI_UTIL_read_pw_string(char *buf, int length, const char *prompt, + int verify) + { +diff --git a/crypto/x509/by_dir.c b/crypto/x509/by_dir.c +index 9ee8f8d..64b052e 100644 +--- a/crypto/x509/by_dir.c ++++ b/crypto/x509/by_dir.c +@@ -69,6 +69,8 @@ + # include + #endif + ++#ifndef OPENSSL_NO_STDIO ++ + #include + #include + +@@ -434,3 +436,5 @@ static int get_cert_by_subject(X509_LOOKUP *xl, int type, X509_NAME *name, + BUF_MEM_free(b); + return (ok); + } ++ ++#endif /* OPENSSL_NO_STDIO */ diff --git a/crypto/x509/x509_vfy.c b/crypto/x509/x509_vfy.c index 0429767..7ddc21c 100644 --- a/crypto/x509/x509_vfy.c @@ -352,7 +958,7 @@ index 0429767..7ddc21c 100644 ptime = NULL; diff --git a/crypto/x509/x509_vfy.h b/crypto/x509/x509_vfy.h -index 2663e1c..98d0b4c 100644 +index 2663e1c..3790ef5 100644 --- a/crypto/x509/x509_vfy.h +++ b/crypto/x509/x509_vfy.h @@ -438,6 +438,8 @@ void X509_STORE_CTX_set_depth(X509_STORE_CTX *ctx, int depth); @@ -364,6 +970,18 @@ index 2663e1c..98d0b4c 100644 # define X509_VP_FLAG_DEFAULT 0x1 # define X509_VP_FLAG_OVERWRITE 0x2 +@@ -490,9 +492,10 @@ void X509_STORE_CTX_cleanup(X509_STORE_CTX *ctx); + X509_STORE *X509_STORE_CTX_get0_store(X509_STORE_CTX *ctx); + + X509_LOOKUP *X509_STORE_add_lookup(X509_STORE *v, X509_LOOKUP_METHOD *m); +- ++#ifndef OPENSSL_NO_STDIO + X509_LOOKUP_METHOD *X509_LOOKUP_hash_dir(void); + X509_LOOKUP_METHOD *X509_LOOKUP_file(void); ++#endif + + int X509_STORE_add_cert(X509_STORE *ctx, X509 *x); + int X509_STORE_add_crl(X509_STORE *ctx, X509_CRL *x); diff --git a/crypto/x509v3/ext_dat.h b/crypto/x509v3/ext_dat.h index c3a6fce..01edd2a 100644 --- a/crypto/x509v3/ext_dat.h @@ -379,6 +997,41 @@ index c3a6fce..01edd2a 100644 }; /* Number of standard extensions */ +diff --git a/crypto/x509v3/v3_pci.c b/crypto/x509v3/v3_pci.c +index 34cad53..12f12a7 100644 +--- a/crypto/x509v3/v3_pci.c ++++ b/crypto/x509v3/v3_pci.c +@@ -149,6 +149,7 @@ static int process_pci_value(CONF_VALUE *val, + goto err; + } + OPENSSL_free(tmp_data2); ++#ifndef OPENSSL_NO_STDIO + } else if (strncmp(val->value, "file:", 5) == 0) { + unsigned char buf[2048]; + int n; +@@ -181,6 +182,7 @@ static int process_pci_value(CONF_VALUE *val, + X509V3_conf_err(val); + goto err; + } ++#endif /* !OPENSSL_NO_STDIO */ + } else if (strncmp(val->value, "text:", 5) == 0) { + val_len = strlen(val->value + 5); + tmp_data = OPENSSL_realloc((*policy)->data, +diff --git a/crypto/x509v3/x509v3.h b/crypto/x509v3/x509v3.h +index f5c6156..a2e78aa 100644 +--- a/crypto/x509v3/x509v3.h ++++ b/crypto/x509v3/x509v3.h +@@ -688,8 +688,9 @@ void X509V3_EXT_val_prn(BIO *out, STACK_OF(CONF_VALUE) *val, int indent, + int ml); + int X509V3_EXT_print(BIO *out, X509_EXTENSION *ext, unsigned long flag, + int indent); ++#ifndef OPENSSL_NO_FP_API + int X509V3_EXT_print_fp(FILE *out, X509_EXTENSION *ext, int flag, int indent); +- ++#endif + int X509V3_extensions_print(BIO *out, char *title, + STACK_OF(X509_EXTENSION) *exts, + unsigned long flag, int indent); diff --git a/e_os.h b/e_os.h index 1fa36c1..3e9dae2 100644 --- a/e_os.h @@ -412,3 +1065,76 @@ index 7be9989..909e22f 100644 # undef OPENSSL_SYS_UNIX # define OPENSSL_SYS_WIN32_UWIN # else +diff --git a/ssl/ssl_cert.c b/ssl/ssl_cert.c +index a73f866..d534c0a 100644 +--- a/ssl/ssl_cert.c ++++ b/ssl/ssl_cert.c +@@ -855,12 +855,13 @@ int SSL_CTX_add_client_CA(SSL_CTX *ctx, X509 *x) + return (add_client_CA(&(ctx->client_CA), x)); + } + ++#ifndef OPENSSL_NO_STDIO ++ + static int xname_cmp(const X509_NAME *const *a, const X509_NAME *const *b) + { + return (X509_NAME_cmp(*a, *b)); + } + +-#ifndef OPENSSL_NO_STDIO + /** + * Load CA certs from a file into a ::STACK. Note that it is somewhat misnamed; + * it doesn't really have anything to do with clients (except that a common use +@@ -928,7 +929,6 @@ STACK_OF(X509_NAME) *SSL_load_client_CA_file(const char *file) + ERR_clear_error(); + return (ret); + } +-#endif + + /** + * Add a file of certs to a stack. +@@ -1048,6 +1048,7 @@ int SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stack, + CRYPTO_w_unlock(CRYPTO_LOCK_READDIR); + return ret; + } ++#endif /* !OPENSSL_NO_STDIO */ + + /* Add a certificate to a BUF_MEM structure */ + +diff --git a/ssl/ssl_conf.c b/ssl/ssl_conf.c +index 5478840..c2ad7c9 100644 +--- a/ssl/ssl_conf.c ++++ b/ssl/ssl_conf.c +@@ -362,6 +362,7 @@ static int cmd_Options(SSL_CONF_CTX *cctx, const char *value) + return CONF_parse_list(value, ',', 1, ssl_set_option_list, cctx); + } + ++#ifndef OPENSSL_NO_STDIO + static int cmd_Certificate(SSL_CONF_CTX *cctx, const char *value) + { + int rv = 1; +@@ -428,7 +429,9 @@ static int cmd_DHParameters(SSL_CONF_CTX *cctx, const char *value) + BIO_free(in); + return rv > 0; + } +-#endif ++#endif /* !OPENSSL_NO_DH */ ++#endif /* !OPENSSL_NO_STDIO */ ++ + typedef struct { + int (*cmd) (SSL_CONF_CTX *cctx, const char *value); + const char *str_file; +@@ -454,12 +457,14 @@ static const ssl_conf_cmd_tbl ssl_conf_cmds[] = { + SSL_CONF_CMD_STRING(CipherString, "cipher"), + SSL_CONF_CMD_STRING(Protocol, NULL), + SSL_CONF_CMD_STRING(Options, NULL), ++#ifndef OPENSSL_NO_STDIO + SSL_CONF_CMD(Certificate, "cert", SSL_CONF_TYPE_FILE), + SSL_CONF_CMD(PrivateKey, "key", SSL_CONF_TYPE_FILE), + SSL_CONF_CMD(ServerInfoFile, NULL, SSL_CONF_TYPE_FILE), + #ifndef OPENSSL_NO_DH + SSL_CONF_CMD(DHParameters, "dhparam", SSL_CONF_TYPE_FILE) + #endif ++#endif + }; + + static int ssl_conf_cmd_skip_prefix(SSL_CONF_CTX *cctx, const char **pcmd)