Skip to content

Commit

Permalink
(WIP) Backport SOCKSRandomAuth for stable aiorpcx
Browse files Browse the repository at this point in the history
TODO: Untested
  • Loading branch information
JeremyRand committed Sep 20, 2019
1 parent 2aa7b93 commit 816d9b1
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion electrum/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import sys
import traceback
import asyncio
import secrets
import socket
from typing import Tuple, Union, List, TYPE_CHECKING, Optional
from collections import defaultdict
Expand Down Expand Up @@ -62,6 +63,15 @@
BUCKET_NAME_OF_ONION_SERVERS = 'onion'


# Random authentication is useful when used with Tor for stream isolation.
class SOCKSRandomAuth(aiorpcx.socks.SOCKSUserAuth):
def __getitem__(self, key):
return secrets.token_hex(32)


SOCKSRandomAuth.__new__.__defaults__ = (None, None)


class NetworkTimeout:
# seconds
class Generic:
Expand Down Expand Up @@ -252,7 +262,7 @@ def _set_proxy(self, proxy: dict):
if proxy:
username, pw, isolate = proxy.get('user'), proxy.get('password'), proxy.get('isolate')
if isolate:
auth = aiorpcx.socks.SOCKSRandomAuth()
auth = SOCKSRandomAuth()
elif not username or not pw:
auth = None
else:
Expand Down

0 comments on commit 816d9b1

Please sign in to comment.