]> git.proxmox.com Git - mirror_edk2.git/blobdiff - CryptoPkg/Library/OpensslLib/EDKII_openssl-1.0.2f.patch
CryptoPkg/OpensslLib: Switch to upstream fix for OpenSSL RT#3951
[mirror_edk2.git] / CryptoPkg / Library / OpensslLib / EDKII_openssl-1.0.2f.patch
index ec54de5725e23725da2f67361f987c0354341253..82fa8dddf0594887fc2861a099a27ff828224375 100644 (file)
@@ -11,6 +11,19 @@ index 4a715dc..eb61eda 100755
        {\r
        $disabled{"gost"} = "forced";\r
        }\r
+diff --git a/apps/apps.c b/apps/apps.c\r
+index 2e77805..e21e759 100644\r
+--- a/apps/apps.c\r
++++ b/apps/apps.c\r
+@@ -2374,6 +2374,8 @@ int args_verify(char ***pargs, int *pargc,\r
+         flags |= X509_V_FLAG_PARTIAL_CHAIN;\r
+     else if (!strcmp(arg, "-no_alt_chains"))\r
+         flags |= X509_V_FLAG_NO_ALT_CHAINS;\r
++    else if (!strcmp(arg, "-no_check_time"))\r
++        flags |= X509_V_FLAG_NO_CHECK_TIME;\r
+     else\r
+         return 0;\r
\r
 diff --git a/crypto/asn1/a_strex.c b/crypto/asn1/a_strex.c\r
 index 35fd44c..9f39bff 100644\r
 --- a/crypto/asn1/a_strex.c\r
@@ -201,6 +214,63 @@ index abc6dc3..3a672e9 100644
  \r
  # define M_ASN1_New(arg,func) \\r
          if (((arg)=func()) == NULL) return(NULL)\r
+diff --git a/crypto/bn/bn_prime.c b/crypto/bn/bn_prime.c\r
+index 1d25687..e933ead 100644\r
+--- a/crypto/bn/bn_prime.c\r
++++ b/crypto/bn/bn_prime.c\r
+@@ -131,7 +131,7 @@\r
+ static int witness(BIGNUM *w, const BIGNUM *a, const BIGNUM *a1,\r
+                    const BIGNUM *a1_odd, int k, BN_CTX *ctx,\r
+                    BN_MONT_CTX *mont);\r
+-static int probable_prime(BIGNUM *rnd, int bits);\r
++static int probable_prime(BIGNUM *rnd, int bits, prime_t *mods);\r
+ static int probable_prime_dh(BIGNUM *rnd, int bits,\r
+                              const BIGNUM *add, const BIGNUM *rem,\r
+                              BN_CTX *ctx);\r
+@@ -166,9 +166,13 @@ int BN_generate_prime_ex(BIGNUM *ret, int bits, int safe,\r
+     BIGNUM *t;\r
+     int found = 0;\r
+     int i, j, c1 = 0;\r
+-    BN_CTX *ctx;\r
++    BN_CTX *ctx = NULL;\r
++    prime_t *mods = NULL;\r
+     int checks = BN_prime_checks_for_size(bits);\r
\r
++    mods = OPENSSL_malloc(sizeof(*mods) * NUMPRIMES);\r
++    if (mods == NULL)\r
++          goto err;\r
+     ctx = BN_CTX_new();\r
+     if (ctx == NULL)\r
+         goto err;\r
+@@ -179,7 +183,7 @@ int BN_generate_prime_ex(BIGNUM *ret, int bits, int safe,\r
+  loop:\r
+     /* make a random number and set the top and bottom bits */\r
+     if (add == NULL) {\r
+-        if (!probable_prime(ret, bits))\r
++        if (!probable_prime(ret, bits, mods))\r
+             goto err;\r
+     } else {\r
+         if (safe) {\r
+@@ -230,6 +234,7 @@ int BN_generate_prime_ex(BIGNUM *ret, int bits, int safe,\r
+     /* we have a prime :-) */\r
+     found = 1;\r
+  err:\r
++    OPENSSL_free(mods);\r
+     if (ctx != NULL) {\r
+         BN_CTX_end(ctx);\r
+         BN_CTX_free(ctx);\r
+@@ -375,10 +380,9 @@ static int witness(BIGNUM *w, const BIGNUM *a, const BIGNUM *a1,\r
+     return 1;\r
+ }\r
\r
+-static int probable_prime(BIGNUM *rnd, int bits)\r
++static int probable_prime(BIGNUM *rnd, int bits, prime_t *mods)\r
+ {\r
+     int i;\r
+-    prime_t mods[NUMPRIMES];\r
+     BN_ULONG delta, maxdelta;\r
\r
+  again:\r
 diff --git a/crypto/conf/conf.h b/crypto/conf/conf.h\r
 index 8d926d5..41cf38e 100644\r
 --- a/crypto/conf/conf.h\r
@@ -533,28 +603,128 @@ index 01e275f..7633139 100644
  int DES_read_password(DES_cblock *key, const char *prompt, int verify)\r
  {\r
      int ok;\r
+diff --git a/crypto/dh/Makefile b/crypto/dh/Makefile\r
+index 46fa5ac..cc366ec 100644\r
+--- a/crypto/dh/Makefile\r
++++ b/crypto/dh/Makefile\r
+@@ -134,7 +134,7 @@ dh_gen.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h\r
+ dh_gen.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h\r
+ dh_gen.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h\r
+ dh_gen.o: ../cryptlib.h dh_gen.c\r
+-dh_kdf.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h\r
++dh_kdf.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h\r
+ dh_kdf.o: ../../include/openssl/buffer.h ../../include/openssl/cms.h\r
+ dh_kdf.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h\r
+ dh_kdf.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h\r
+diff --git a/crypto/dh/dh.h b/crypto/dh/dh.h\r
+index 5498a9d..4a5c665 100644\r
+--- a/crypto/dh/dh.h\r
++++ b/crypto/dh/dh.h\r
+@@ -240,11 +240,13 @@ DH *DH_get_1024_160(void);\r
+ DH *DH_get_2048_224(void);\r
+ DH *DH_get_2048_256(void);\r
\r
++# ifndef OPENSSL_NO_CMS\r
+ /* RFC2631 KDF */\r
+ int DH_KDF_X9_42(unsigned char *out, size_t outlen,\r
+                  const unsigned char *Z, size_t Zlen,\r
+                  ASN1_OBJECT *key_oid,\r
+                  const unsigned char *ukm, size_t ukmlen, const EVP_MD *md);\r
++# endif\r
\r
+ # define EVP_PKEY_CTX_set_dh_paramgen_prime_len(ctx, len) \\r
+         EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DH, EVP_PKEY_OP_PARAMGEN, \\r
+@@ -337,7 +339,9 @@ int DH_KDF_X9_42(unsigned char *out, size_t outlen,\r
\r
+ /* KDF types */\r
+ # define EVP_PKEY_DH_KDF_NONE                            1\r
++# ifndef OPENSSL_NO_CMS\r
+ # define EVP_PKEY_DH_KDF_X9_42                           2\r
++# endif\r
\r
+ /* BEGIN ERROR CODES */\r
+ /*\r
+diff --git a/crypto/dh/dh_kdf.c b/crypto/dh/dh_kdf.c\r
+index a882cb2..4eddb9a 100644\r
+--- a/crypto/dh/dh_kdf.c\r
++++ b/crypto/dh/dh_kdf.c\r
+@@ -51,13 +51,18 @@\r
+  * ====================================================================\r
+  */\r
\r
++#include <e_os.h>\r
++\r
++#ifndef OPENSSL_NO_CMS\r
+ #include <string.h>\r
+ #include <openssl/dh.h>\r
+ #include <openssl/evp.h>\r
+ #include <openssl/asn1.h>\r
+ #include <openssl/cms.h>\r
\r
++\r
+ /* Key derivation from X9.42/RFC2631 */\r
++/* Uses CMS functions, hence the #ifdef wrapper. */\r
\r
+ #define DH_KDF_MAX      (1L << 30)\r
\r
+@@ -185,3 +190,4 @@ int DH_KDF_X9_42(unsigned char *out, size_t outlen,\r
+     EVP_MD_CTX_cleanup(&mctx);\r
+     return rv;\r
+ }\r
++#endif\r
 diff --git a/crypto/dh/dh_pmeth.c b/crypto/dh/dh_pmeth.c\r
-index b58e3fa..e5f345a 100644\r
+index b58e3fa..c6288f6 100644\r
 --- a/crypto/dh/dh_pmeth.c\r
 +++ b/crypto/dh/dh_pmeth.c\r
-@@ -449,6 +449,9 @@ static int pkey_dh_derive(EVP_PKEY_CTX *ctx, unsigned char *key,\r
-         *keylen = ret;\r
-         return 1;\r
-     } else if (dctx->kdf_type == EVP_PKEY_DH_KDF_X9_42) {\r
+@@ -207,7 +207,11 @@ static int pkey_dh_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)\r
+     case EVP_PKEY_CTRL_DH_KDF_TYPE:\r
+         if (p1 == -2)\r
+             return dctx->kdf_type;\r
 +#ifdef OPENSSL_NO_CMS\r
-+        return 0;\r
++        if (p1 != EVP_PKEY_DH_KDF_NONE)\r
 +#else\r
+         if (p1 != EVP_PKEY_DH_KDF_NONE && p1 != EVP_PKEY_DH_KDF_X9_42)\r
++#endif\r
+             return -2;\r
+         dctx->kdf_type = p1;\r
+         return 1;\r
+@@ -448,7 +452,10 @@ static int pkey_dh_derive(EVP_PKEY_CTX *ctx, unsigned char *key,\r
+             return ret;\r
+         *keylen = ret;\r
+         return 1;\r
+-    } else if (dctx->kdf_type == EVP_PKEY_DH_KDF_X9_42) {\r
++    }\r
++#ifndef OPENSSL_NO_CMS\r
++    else if (dctx->kdf_type == EVP_PKEY_DH_KDF_X9_42) {\r
++\r
          unsigned char *Z = NULL;\r
          size_t Zlen = 0;\r
          if (!dctx->kdf_outlen || !dctx->kdf_oid)\r
-@@ -478,6 +481,7 @@ static int pkey_dh_derive(EVP_PKEY_CTX *ctx, unsigned char *key,\r
-             OPENSSL_free(Z);\r
+@@ -479,7 +486,8 @@ static int pkey_dh_derive(EVP_PKEY_CTX *ctx, unsigned char *key,\r
          }\r
          return ret;\r
-+#endif\r
      }\r
-     return 1;\r
+-    return 1;\r
++#endif\r
++    return 0;\r
  }\r
\r
+ const EVP_PKEY_METHOD dh_pkey_meth = {\r
+diff --git a/crypto/ec/ec_ameth.c b/crypto/ec/ec_ameth.c\r
+index 83e208c..4869098 100644\r
+--- a/crypto/ec/ec_ameth.c\r
++++ b/crypto/ec/ec_ameth.c\r
+@@ -67,8 +67,10 @@\r
+ #include <openssl/asn1t.h>\r
+ #include "asn1_locl.h"\r
\r
++#ifndef OPENSSL_NO_CMS\r
+ static int ecdh_cms_decrypt(CMS_RecipientInfo *ri);\r
+ static int ecdh_cms_encrypt(CMS_RecipientInfo *ri);\r
++#endif\r
\r
+ static int eckey_param2type(int *pptype, void **ppval, EC_KEY *ec_key)\r
+ {\r
 diff --git a/crypto/engine/eng_int.h b/crypto/engine/eng_int.h\r
 index 46f163b..b4a72a0 100644\r
 --- a/crypto/engine/eng_int.h\r
@@ -752,20 +922,29 @@ index 5747c73..fe465cc 100644
   * These functions write a private key in PKCS#8 format: it is a "drop in"\r
   * replacement for PEM_write_bio_PrivateKey() and friends. As usual if 'enc'\r
 diff --git a/crypto/pkcs7/pk7_smime.c b/crypto/pkcs7/pk7_smime.c\r
-index c4d3724..fd531c9 100644\r
+index c4d3724..0bc3d43 100644\r
 --- a/crypto/pkcs7/pk7_smime.c\r
 +++ b/crypto/pkcs7/pk7_smime.c\r
-@@ -254,7 +254,8 @@ int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store,\r
+@@ -64,6 +64,9 @@\r
+ #include <openssl/x509.h>\r
+ #include <openssl/x509v3.h>\r
\r
++\r
++#define BUFFERSIZE 4096\r
++\r
+ static int pkcs7_copy_existing_digest(PKCS7 *p7, PKCS7_SIGNER_INFO *si);\r
\r
+ PKCS7 *PKCS7_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs,\r
+@@ -254,7 +257,7 @@ int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store,\r
      STACK_OF(PKCS7_SIGNER_INFO) *sinfos;\r
      PKCS7_SIGNER_INFO *si;\r
      X509_STORE_CTX cert_ctx;\r
 -    char buf[4096];\r
 +    char *buf = NULL;\r
-+    int bufsiz;\r
      int i, j = 0, k, ret = 0;\r
      BIO *p7bio = NULL;\r
      BIO *tmpin = NULL, *tmpout = NULL;\r
-@@ -274,12 +275,29 @@ int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store,\r
+@@ -274,12 +277,29 @@ int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store,\r
          PKCS7err(PKCS7_F_PKCS7_VERIFY, PKCS7_R_NO_CONTENT);\r
          return 0;\r
      }\r
@@ -795,32 +974,84 @@ index c4d3724..fd531c9 100644
  \r
      sinfos = PKCS7_get_signer_info(p7);\r
  \r
-@@ -355,9 +373,14 @@ int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store,\r
-     } else\r
+@@ -356,8 +376,12 @@ int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store,\r
          tmpout = out;\r
  \r
-+    bufsiz = 4096;\r
-+    buf = OPENSSL_malloc(bufsiz);\r
-+    if (buf == NULL) {\r
+     /* We now have to 'read' from p7bio to calculate digests etc. */\r
++    if ((buf = OPENSSL_malloc(BUFFERSIZE)) == NULL) {\r
++        PKCS7err(PKCS7_F_PKCS7_VERIFY, ERR_R_MALLOC_FAILURE);\r
 +        goto err;\r
 +    }\r
-     /* We now have to 'read' from p7bio to calculate digests etc. */\r
      for (;;) {\r
 -        i = BIO_read(p7bio, buf, sizeof(buf));\r
-+        i = BIO_read(p7bio, buf, bufsiz);\r
++        i = BIO_read(p7bio, buf, BUFFERSIZE);\r
          if (i <= 0)\r
              break;\r
          if (tmpout)\r
-@@ -394,6 +417,9 @@ int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store,\r
-     }\r
-     BIO_free_all(p7bio);\r
-     sk_X509_free(signers);\r
-+    if (buf != NULL) {\r
-+        OPENSSL_free(buf);\r
+@@ -388,6 +412,7 @@ int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store,\r
+     ret = 1;\r
\r
+  err:\r
++    OPENSSL_free(buf);\r
+     if (tmpin == indata) {\r
+         if (indata)\r
+             BIO_pop(p7bio);\r
+@@ -506,7 +531,7 @@ int PKCS7_decrypt(PKCS7 *p7, EVP_PKEY *pkey, X509 *cert, BIO *data, int flags)\r
+ {\r
+     BIO *tmpmem;\r
+     int ret, i;\r
+-    char buf[4096];\r
++    char *buf = NULL;\r
\r
+     if (!p7) {\r
+         PKCS7err(PKCS7_F_PKCS7_DECRYPT, PKCS7_R_INVALID_NULL_POINTER);\r
+@@ -550,24 +575,29 @@ int PKCS7_decrypt(PKCS7 *p7, EVP_PKEY *pkey, X509 *cert, BIO *data, int flags)\r
+         }\r
+         BIO_free_all(bread);\r
+         return ret;\r
+-    } else {\r
+-        for (;;) {\r
+-            i = BIO_read(tmpmem, buf, sizeof(buf));\r
+-            if (i <= 0) {\r
+-                ret = 1;\r
+-                if (BIO_method_type(tmpmem) == BIO_TYPE_CIPHER) {\r
+-                    if (!BIO_get_cipher_status(tmpmem))\r
+-                        ret = 0;\r
+-                }\r
+-\r
+-                break;\r
+-            }\r
+-            if (BIO_write(data, buf, i) != i) {\r
+-                ret = 0;\r
+-                break;\r
 +    }\r
-     return ret;\r
++    if ((buf = OPENSSL_malloc(BUFFERSIZE)) == NULL) {\r
++        PKCS7err(PKCS7_F_PKCS7_DECRYPT, ERR_R_MALLOC_FAILURE);\r
++        goto err;\r
++    }\r
++    for (;;) {\r
++        i = BIO_read(tmpmem, buf, BUFFERSIZE);\r
++        if (i <= 0) {\r
++            ret = 1;\r
++            if (BIO_method_type(tmpmem) == BIO_TYPE_CIPHER) {\r
++                if (!BIO_get_cipher_status(tmpmem))\r
++                    ret = 0;\r
+             }\r
++\r
++            break;\r
++        }\r
++        if (BIO_write(data, buf, i) != i) {\r
++            ret = 0;\r
++            break;\r
+         }\r
+-        BIO_free_all(tmpmem);\r
+-        return ret;\r
+     }\r
++err:\r
++    OPENSSL_free(buf);\r
++    BIO_free_all(tmpmem);\r
++    return ret;\r
  }\r
\r
 diff --git a/crypto/rand/rand_unix.c b/crypto/rand/rand_unix.c\r
 index 266111e..f60fac6 100644\r
 --- a/crypto/rand/rand_unix.c\r
@@ -844,7 +1075,7 @@ index 266111e..f60fac6 100644
  {\r
      return 0;\r
 diff --git a/crypto/rsa/rsa_ameth.c b/crypto/rsa/rsa_ameth.c\r
-index 4e06218..f591f0f 100644\r
+index 4e06218..ddead3d 100644\r
 --- a/crypto/rsa/rsa_ameth.c\r
 +++ b/crypto/rsa/rsa_ameth.c\r
 @@ -68,10 +68,12 @@\r
@@ -892,25 +1123,15 @@ index 4e06218..f591f0f 100644
  \r
  static int rsa_item_sign(EVP_MD_CTX *ctx, const ASN1_ITEM *it, void *asn,\r
                           X509_ALGOR *alg1, X509_ALGOR *alg2,\r
-@@ -785,6 +791,7 @@ static RSA_OAEP_PARAMS *rsa_oaep_decode(const X509_ALGOR *alg,\r
-     return pss;\r
+@@ -762,6 +768,7 @@ static int rsa_item_sign(EVP_MD_CTX *ctx, const ASN1_ITEM *it, void *asn,\r
+     return 2;\r
  }\r
  \r
 +#ifndef OPENSSL_NO_CMS\r
- static int rsa_cms_decrypt(CMS_RecipientInfo *ri)\r
+ static RSA_OAEP_PARAMS *rsa_oaep_decode(const X509_ALGOR *alg,\r
+                                         X509_ALGOR **pmaskHash)\r
  {\r
-     EVP_PKEY_CTX *pkctx;\r
-@@ -857,7 +864,9 @@ static int rsa_cms_decrypt(CMS_RecipientInfo *ri)\r
-         X509_ALGOR_free(maskHash);\r
-     return rv;\r
- }\r
-+#endif\r
\r
-+#ifndef OPENSSL_NO_CMS\r
- static int rsa_cms_encrypt(CMS_RecipientInfo *ri)\r
- {\r
-     const EVP_MD *md, *mgf1md;\r
-@@ -920,6 +929,7 @@ static int rsa_cms_encrypt(CMS_RecipientInfo *ri)\r
+@@ -920,6 +927,7 @@ static int rsa_cms_encrypt(CMS_RecipientInfo *ri)\r
          ASN1_STRING_free(os);\r
      return rv;\r
  }\r
@@ -1400,6 +1621,21 @@ index f4a8358..94d3293 100644
  \r
  /* Error codes for the ZENCOD functions. */\r
  \r
+diff --git a/doc/crypto/X509_VERIFY_PARAM_set_flags.pod b/doc/crypto/X509_VERIFY_PARAM_set_flags.pod\r
+index 44792f9..7f95d58 100644\r
+--- a/doc/crypto/X509_VERIFY_PARAM_set_flags.pod\r
++++ b/doc/crypto/X509_VERIFY_PARAM_set_flags.pod\r
+@@ -203,6 +203,10 @@ chain found is not trusted, then OpenSSL will continue to check to see if an\r
+ alternative chain can be found that is trusted. With this flag set the behaviour\r
+ will match that of OpenSSL versions prior to 1.0.2b.\r
\r
++The B<X509_V_FLAG_NO_CHECK_TIME> flag suppresses checking the validity period\r
++of certificates and CRLs against the current time. If X509_VERIFY_PARAM_set_time()\r
++is used to specify a verification time, the check is not suppressed.\r
++\r
+ =head1 NOTES\r
\r
+ The above functions should be used to manipulate verification parameters\r
 diff --git a/doc/crypto/threads.pod b/doc/crypto/threads.pod\r
 index dc0e939..fe123bb 100644\r
 --- a/doc/crypto/threads.pod\r
@@ -1741,6 +1977,37 @@ index 514fcb3..2a54cc9 100644
                  else if (RAND_bytes(rec->input, ivlen) <= 0)\r
                      return -1;\r
              }\r
+diff --git a/test/cms-test.pl b/test/cms-test.pl\r
+index baa3b59..1ee3f02 100644\r
+--- a/test/cms-test.pl\r
++++ b/test/cms-test.pl\r
+@@ -100,6 +100,13 @@ my $no_ec2m;\r
+ my $no_ecdh;\r
+ my $ossl8 = `$ossl_path version -v` =~ /0\.9\.8/;\r
\r
++system ("$ossl_path no-cms > $null_path");\r
++if ($? == 0)\r
++        {\r
++        print "CMS disabled\n";\r
++        exit 0;\r
++        }\r
++\r
+ system ("$ossl_path no-ec > $null_path");\r
+ if ($? == 0)\r
+       {\r
+diff --git a/util/libeay.num b/util/libeay.num\r
+index 7f7487d..13b2e3a 100755\r
+--- a/util/libeay.num\r
++++ b/util/libeay.num\r
+@@ -4368,7 +4368,7 @@ DH_compute_key_padded                   4732     EXIST::FUNCTION:DH\r
+ ECDSA_METHOD_set_sign                   4733  EXIST::FUNCTION:ECDSA\r
+ CMS_RecipientEncryptedKey_cert_cmp      4734  EXIST:!VMS:FUNCTION:CMS\r
+ CMS_RecipEncryptedKey_cert_cmp          4734  EXIST:VMS:FUNCTION:CMS\r
+-DH_KDF_X9_42                            4735  EXIST::FUNCTION:DH\r
++DH_KDF_X9_42                            4735  EXIST::FUNCTION:CMS,DH\r
+ RSA_OAEP_PARAMS_free                    4736  EXIST::FUNCTION:RSA\r
+ EVP_des_ede3_wrap                       4737  EXIST::FUNCTION:DES\r
+ RSA_OAEP_PARAMS_it                      4738  EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:RSA\r
 diff --git a/util/mkerr.pl b/util/mkerr.pl\r
 index 09ebebe..cd57ade 100644\r
 --- a/util/mkerr.pl\r