Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verify TLS chain of trust, warn user if it fails. #165

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions electrumx/server/peers.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ async def _should_drop_peer(self, peer):

kwargs = {'family': family}
if kind == 'SSL':
kwargs['ssl'] = ssl.SSLContext(ssl.PROTOCOL_TLS)
kwargs['ssl'] = True

if self.env.force_proxy or peer.is_tor:
if not self.proxy:
Expand All @@ -283,10 +283,19 @@ async def _should_drop_peer(self, peer):

peer_text = f'[{peer}:{port} {kind}]'
try:
async with connect_rs(peer.host, port, session_factory=PeerSession,
**kwargs) as session:
session.sent_request_timeout = 120 if peer.is_tor else 30
await self._verify_peer(session, peer)
try:
async with connect_rs(peer.host, port, session_factory=PeerSession,
**kwargs) as session:
session.sent_request_timeout = 120 if peer.is_tor else 30
await self._verify_peer(session, peer)
except ssl.SSLCertVerificationError as e:
self.logger.warn(f'{peer.host} {e}')
self.logger.warn(f'Please ask {peer.host} to properly configure with a CA such as letsencrypt.org')
kwargs['ssl'] = ssl.SSLContext(ssl.PROTOCOL_TLS)
async with connect_rs(peer.host, port, session_factory=PeerSession,
**kwargs) as session:
session.sent_request_timeout = 120 if peer.is_tor else 30
await self._verify_peer(session, peer)
is_good = True
break
except BadPeerError as e:
Expand Down