Skip to content

Commit 613f0f5

Browse files
committed
Remove TOFU implementation that has been proved to be buggy and cause only overhead
1 parent b780f8f commit 613f0f5

File tree

3 files changed

+5
-32
lines changed

3 files changed

+5
-32
lines changed

tor2web/t2w.py

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ def __init__(self, config):
8585
self.crawler_list = []
8686
self.hosts_map = {}
8787
self.TorExitNodes = []
88-
self.certs_tofu = LimitedSizeDict(size_limit=config.ssl_tofu_cache_size)
8988

9089
self.load_lists()
9190

@@ -143,17 +142,6 @@ def remote_get_tor_exits_list(self):
143142
def remote_get_hosts_map(self):
144143
return dict(self.hosts_map)
145144

146-
def remote_is_https(self, hostname):
147-
return hostname in self.certs_tofu
148-
149-
def remote_verify_tls_tofu(self, hostname, cert):
150-
h = hashlib.sha512(cert).hexdigest()
151-
if hostname not in self.certs_tofu:
152-
self.certs_tofu[hostname] = h
153-
return True
154-
155-
return self.certs_tofu[hostname] == h
156-
157145
def remote_update_stats(self, onion):
158146
self.stats.update(onion)
159147

@@ -323,9 +311,6 @@ def __init__(self, reactor,
323311
connectTimeout, bindAddress, pool)
324312

325313
def _getEndpoint(self, scheme, host, port):
326-
def verify_tofu(hostname, cert):
327-
return rpc("verify_tls_tofu", hostname, cert)
328-
329314
if scheme not in ('http', 'https'):
330315
raise SchemeNotSupported("Unsupported scheme: %r" % (scheme,))
331316

@@ -344,7 +329,7 @@ def verify_tofu(hostname, cert):
344329
host,
345330
port,
346331
config.socksoptimisticdata)
347-
return TLSWrapClientEndpoint(HTTPSVerifyingContextFactory(host, verify_tofu),
332+
return TLSWrapClientEndpoint(HTTPSVerifyingContextFactory(host),
348333
torSockEndpoint)
349334
else:
350335
if scheme == 'http':
@@ -365,12 +350,8 @@ def request(self, method, uri, headers, bodyProducer=None):
365350
"""
366351
parsedURI = URI.fromBytes(uri)
367352

368-
is_https = yield rpc("is_https", parsedURI.host)
369-
370-
scheme = 'https' if is_https else 'http'
371-
372353
for key, values in headers.getAllRawHeaders():
373-
fixed_values = [re_sub(rexp['w2t'], r'' + scheme + r'://\2.onion', value) for value in values]
354+
fixed_values = [re_sub(rexp['w2t'], r'http://\2.onion', value) for value in values]
374355
headers.setRawHeaders(key, fixed_values)
375356

376357
try:

tor2web/utils/config.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ def __init__(self):
7777
self.__dict__['cipher_list'] = 'ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384:' \
7878
'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-SHA256:' \
7979
'ECDHE-RSA-AES256-SHA:DHE-DSS-AES256-SHA:DHE-RSA-AES128-SHA:'
80-
self.__dict__['ssl_tofu_cache_size'] = 100
8180
self.__dict__['mode'] = 'BLOCKLIST'
8281
self.__dict__['onion'] = None
8382
self.__dict__['blockhotlinking'] = True

tor2web/utils/ssl.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616

1717
import os
1818
from OpenSSL import SSL
19-
from OpenSSL.crypto import load_certificate, dump_certificate, FILETYPE_PEM, \
20-
_raise_current_error
19+
from OpenSSL.crypto import load_certificate, FILETYPE_PEM
2120
from OpenSSL._util import lib as _lib, ffi as _ffi
2221
from pyasn1.type import univ, constraint, char, namedtype, tag
2322
from pyasn1.codec.der.decoder import decode
@@ -145,10 +144,9 @@ def getContext(self):
145144

146145

147146
class HTTPSVerifyingContextFactory(ssl.ClientContextFactory):
148-
def __init__(self, hostname, verify_tofu=None):
147+
def __init__(self, hostname):
149148
self.hostname = hostname
150-
self.verify_tofu = verify_tofu
151-
149+
152150
# read in T2WSSLContextFactory why this settings ends in enabling only TLS
153151
self.method = SSL.SSLv23_METHOD
154152

@@ -187,9 +185,4 @@ def verifyCert(self, connection, x509, errno, depth, preverifyOK):
187185
elif self.hostname in altnames(x509):
188186
verify = True
189187

190-
if verify and self.verify_tofu is not None:
191-
return self.verify_tofu(self.hostname, dump_certificate(FILETYPE_PEM, x509))
192-
193188
return verify
194-
195-
CERTS_TOFU = {}

0 commit comments

Comments
 (0)