openssl.patch 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. Index: crypto/rsa/rsa_eay.c
  2. ===================================================================
  3. RCS file: /e/openssl/cvs/openssl/crypto/rsa/rsa_eay.c,v
  4. retrieving revision 1.28.2.3
  5. diff -u -r1.28.2.3 rsa_eay.c
  6. --- crypto/rsa/rsa_eay.c 30 Jan 2003 17:37:46 -0000 1.28.2.3
  7. +++ crypto/rsa/rsa_eay.c 16 Mar 2003 10:34:13 -0000
  8. @@ -195,6 +195,25 @@
  9. return(r);
  10. }
  11. +static int rsa_eay_blinding(RSA *rsa, BN_CTX *ctx)
  12. + {
  13. + int ret = 1;
  14. + CRYPTO_w_lock(CRYPTO_LOCK_RSA);
  15. + /* Check again inside the lock - the macro's check is racey */
  16. + if(rsa->blinding == NULL)
  17. + ret = RSA_blinding_on(rsa, ctx);
  18. + CRYPTO_w_unlock(CRYPTO_LOCK_RSA);
  19. + return ret;
  20. + }
  21. +
  22. +#define BLINDING_HELPER(rsa, ctx, err_instr) \
  23. + do { \
  24. + if(((rsa)->flags & RSA_FLAG_BLINDING) && \
  25. + ((rsa)->blinding == NULL) && \
  26. + !rsa_eay_blinding(rsa, ctx)) \
  27. + err_instr \
  28. + } while(0)
  29. +
  30. /* signing */
  31. static int RSA_eay_private_encrypt(int flen, const unsigned char *from,
  32. unsigned char *to, RSA *rsa, int padding)
  33. @@ -239,8 +258,8 @@
  34. goto err;
  35. }
  36. - if ((rsa->flags & RSA_FLAG_BLINDING) && (rsa->blinding == NULL))
  37. - RSA_blinding_on(rsa,ctx);
  38. + BLINDING_HELPER(rsa, ctx, goto err;);
  39. +
  40. if (rsa->flags & RSA_FLAG_BLINDING)
  41. if (!BN_BLINDING_convert(&f,rsa->blinding,ctx)) goto err;
  42. @@ -318,8 +337,8 @@
  43. goto err;
  44. }
  45. - if ((rsa->flags & RSA_FLAG_BLINDING) && (rsa->blinding == NULL))
  46. - RSA_blinding_on(rsa,ctx);
  47. + BLINDING_HELPER(rsa, ctx, goto err;);
  48. +
  49. if (rsa->flags & RSA_FLAG_BLINDING)
  50. if (!BN_BLINDING_convert(&f,rsa->blinding,ctx)) goto err;
  51. Index: crypto/rsa/rsa_lib.c
  52. ===================================================================
  53. RCS file: /e/openssl/cvs/openssl/crypto/rsa/rsa_lib.c,v
  54. retrieving revision 1.30.2.2
  55. diff -u -r1.30.2.2 rsa_lib.c
  56. --- crypto/rsa/rsa_lib.c 30 Jan 2003 17:37:46 -0000 1.30.2.2
  57. +++ crypto/rsa/rsa_lib.c 16 Mar 2003 10:34:13 -0000
  58. @@ -72,7 +72,13 @@
  59. RSA *RSA_new(void)
  60. {
  61. - return(RSA_new_method(NULL));
  62. + RSA *r=RSA_new_method(NULL);
  63. +
  64. +#ifndef OPENSSL_NO_FORCE_RSA_BLINDING
  65. + r->flags|=RSA_FLAG_BLINDING;
  66. +#endif
  67. +
  68. + return r;
  69. }
  70. void RSA_set_default_method(const RSA_METHOD *meth)
  71. Index: ssl/s3_srvr.c
  72. ============================================================================
  73. $ cvs diff -u -r1.104 -r1.105 s3_srvr.c
  74. --- ssl/s3_srvr.c 28 Feb 2003 15:37:10 -0000 1.104
  75. +++ ssl/s3_srvr.c 19 Mar 2003 19:19:53 -0000 1.105
  76. @@ -1684,7 +1684,7 @@
  77. if (i != SSL_MAX_MASTER_KEY_LENGTH)
  78. {
  79. al=SSL_AD_DECODE_ERROR;
  80. - SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_BAD_RSA_DECRYPT);
  81. + /* SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_BAD_RSA_DECRYPT); */
  82. }
  83. if ((al == -1) && !((p[0] == (s->client_version>>8)) && (p[1] == (s->client_version & 0xff))))
  84. @@ -1700,30 +1700,29 @@
  85. (p[0] == (s->version>>8)) && (p[1] == (s->version & 0xff))))
  86. {
  87. al=SSL_AD_DECODE_ERROR;
  88. - SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_BAD_PROTOCOL_VERSION_NUMBER);
  89. - goto f_err;
  90. + /* SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_BAD_PROTOCOL_VERSION_NUMBER); */
  91. +
  92. + /* The Klima-Pokorny-Rosa extension of Bleichenbacher's attack
  93. + * (http://eprint.iacr.org/2003/052/) exploits the version
  94. + * number check as a "bad version oracle" -- an alert would
  95. + * reveal that the plaintext corresponding to some ciphertext
  96. + * made up by the adversary is properly formatted except
  97. + * that the version number is wrong. To avoid such attacks,
  98. + * we should treat this just like any other decryption error. */
  99. + p[0] = (char)(int) "CAN-2003-0131 patch 2003-03-20";
  100. }
  101. }
  102. if (al != -1)
  103. {
  104. -#if 0
  105. - goto f_err;
  106. -#else
  107. /* Some decryption failure -- use random value instead as countermeasure
  108. * against Bleichenbacher's attack on PKCS #1 v1.5 RSA padding
  109. - * (see RFC 2246, section 7.4.7.1).
  110. - * But note that due to length and protocol version checking, the
  111. - * attack is impractical anyway (see section 5 in D. Bleichenbacher:
  112. - * "Chosen Ciphertext Attacks Against Protocols Based on the RSA
  113. - * Encryption Standard PKCS #1", CRYPTO '98, LNCS 1462, pp. 1-12).
  114. - */
  115. + * (see RFC 2246, section 7.4.7.1). */
  116. ERR_clear_error();
  117. i = SSL_MAX_MASTER_KEY_LENGTH;
  118. p[0] = s->client_version >> 8;
  119. p[1] = s->client_version & 0xff;
  120. RAND_pseudo_bytes(p+2, i-2); /* should be RAND_bytes, but we cannot work around a failure */
  121. -#endif
  122. }
  123. s->session->master_key_length=