0a58567c-work-with-reneg-ssl.dpatch 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #! /bin/sh -e
  2. if [ $# -lt 1 ]; then
  3. echo "`basename $0`: script expects -patch|-unpatch as argument" >&2
  4. exit 1
  5. fi
  6. [ -f debian/patches/00patch-opts ] && . debian/patches/00patch-opts
  7. patch_opts="${patch_opts:--f --no-backup-if-mismatch} ${2:+-d $2}"
  8. case "$1" in
  9. -patch) patch -p1 ${patch_opts} < $0;;
  10. -unpatch) patch -R -p1 ${patch_opts} < $0;;
  11. *)
  12. echo "`basename $0`: script expects -patch|-unpatch as argument" >&2
  13. exit 1;;
  14. esac
  15. exit 0
  16. #diff --git a/ChangeLog b/ChangeLog
  17. #index 0109ff5..679d576 100644
  18. #--- a/ChangeLog
  19. #+++ b/ChangeLog
  20. #@@ -311,6 +311,12 @@ Changes in version 0.2.2.1-alpha - 2009-08-26
  21. #
  22. #
  23. # Changes in Version 0.2.1.21 - 20??-??-??
  24. #+ o Major bugfixes:
  25. #+ - Work around a security feature in OpenSSL 0.9.8l that prevents our
  26. #+ handshake from working unless we explicitly tell OpenSSL that we are
  27. #+ using SSL renegotiation safely. We are, of course, but OpenSSL
  28. #+ 0.9.8l won't work unless we say we are.
  29. #+
  30. # o Minor bugfixes:
  31. # - Do not refuse to learn about authority certs and v2 networkstatus
  32. # documents that are older than the latest consensus. This bug might
  33. @DPATCH@
  34. diff --git a/src/common/tortls.c b/src/common/tortls.c
  35. index 6e09325..ff49ecf 100644
  36. --- a/src/common/tortls.c
  37. +++ b/src/common/tortls.c
  38. @@ -154,6 +154,7 @@ static X509* tor_tls_create_certificate(crypto_pk_env_t *rsa,
  39. const char *cname,
  40. const char *cname_sign,
  41. unsigned int lifetime);
  42. +static void tor_tls_unblock_renegotiation(tor_tls_t *tls);
  43. /** Global tls context. We keep it here because nobody else needs to
  44. * touch it. */
  45. @@ -927,6 +928,36 @@ tor_tls_set_renegotiate_callback(tor_tls_t *tls,
  46. #endif
  47. }
  48. +/** If this version of openssl requires it, turn on renegotiation on
  49. + * <b>tls</b>. (Our protocol never requires this for security, but it's nice
  50. + * to use belt-and-suspenders here.)
  51. + */
  52. +static void
  53. +tor_tls_unblock_renegotiation(tor_tls_t *tls)
  54. +{
  55. +#ifdef SSL3_FLAGS_ALLOW_UNSAFE_LEGACY_RENEGOTIATION
  56. + /* Yes, we know what we are doing here. No, we do not treat a renegotiation
  57. + * as authenticating any earlier-received data. */
  58. + tls->ssl->s3->flags |= SSL3_FLAGS_ALLOW_UNSAFE_LEGACY_RENEGOTIATION;
  59. +#else
  60. + (void)tls;
  61. +#endif
  62. +}
  63. +
  64. +/** If this version of openssl supports it, turn off renegotiation on
  65. + * <b>tls</b>. (Our protocol never requires this for security, but it's nice
  66. + * to use belt-and-suspenders here.)
  67. + */
  68. +void
  69. +tor_tls_block_renegotiation(tor_tls_t *tls)
  70. +{
  71. +#ifdef SSL3_FLAGS_ALLOW_UNSAFE_LEGACY_RENEGOTIATION
  72. + tls->ssl->s3->flags &= ~SSL3_FLAGS_ALLOW_UNSAFE_LEGACY_RENEGOTIATION;
  73. +#else
  74. + (void)tls;
  75. +#endif
  76. +}
  77. +
  78. /** Return whether this tls initiated the connect (client) or
  79. * received it (server). */
  80. int
  81. @@ -1058,6 +1089,9 @@ tor_tls_handshake(tor_tls_t *tls)
  82. if (oldstate != tls->ssl->state)
  83. log_debug(LD_HANDSHAKE, "After call, %p was in state %s",
  84. tls, ssl_state_to_string(tls->ssl->state));
  85. + /* We need to call this here and not earlier, since OpenSSL has a penchant
  86. + * for clearing its flags when you say accept or connect. */
  87. + tor_tls_unblock_renegotiation(tls);
  88. r = tor_tls_get_error(tls,r,0, "handshaking", LOG_INFO, LD_HANDSHAKE);
  89. if (ERR_peek_error() != 0) {
  90. tls_log_errors(tls, tls->isServer ? LOG_INFO : LOG_WARN, LD_HANDSHAKE,
  91. diff --git a/src/common/tortls.h b/src/common/tortls.h
  92. index d006909..871fec3 100644
  93. --- a/src/common/tortls.h
  94. +++ b/src/common/tortls.h
  95. @@ -65,6 +65,7 @@ int tor_tls_read(tor_tls_t *tls, char *cp, size_t len);
  96. int tor_tls_write(tor_tls_t *tls, const char *cp, size_t n);
  97. int tor_tls_handshake(tor_tls_t *tls);
  98. int tor_tls_renegotiate(tor_tls_t *tls);
  99. +void tor_tls_block_renegotiation(tor_tls_t *tls);
  100. int tor_tls_shutdown(tor_tls_t *tls);
  101. int tor_tls_get_pending_bytes(tor_tls_t *tls);
  102. size_t tor_tls_get_forced_write_size(tor_tls_t *tls);
  103. diff --git a/src/or/connection_or.c b/src/or/connection_or.c
  104. index c3d35e1..bbd6439 100644
  105. --- a/src/or/connection_or.c
  106. +++ b/src/or/connection_or.c
  107. @@ -799,6 +799,7 @@ connection_or_tls_renegotiated_cb(tor_tls_t *tls, void *_conn)
  108. /* Don't invoke this again. */
  109. tor_tls_set_renegotiate_callback(tls, NULL, NULL);
  110. + tor_tls_block_renegotiation(tls);
  111. if (connection_tls_finish_handshake(conn) < 0) {
  112. /* XXXX_TLS double-check that it's ok to do this from inside read. */
  113. @@ -1045,6 +1046,7 @@ connection_tls_finish_handshake(or_connection_t *conn)
  114. connection_or_init_conn_from_address(conn, &conn->_base.addr,
  115. conn->_base.port, digest_rcvd, 0);
  116. }
  117. + tor_tls_block_renegotiation(conn->tls);
  118. return connection_or_set_state_open(conn);
  119. } else {
  120. conn->_base.state = OR_CONN_STATE_OR_HANDSHAKING;