Skip to content

Commit dd6de52

Browse files
committed
SSL workaround
Python < 2.7.9 does not support anonymous SSL server through ssl.wrap_socket, so we have to disable it. Works fine as client. Try to prefer secp256k1 curve (again, requires python >= 2.7.9)
1 parent da18e4b commit dd6de52

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/class_receiveDataThread.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,10 @@ def connectionFullyEstablished(self):
265265
self.connectionIsOrWasFullyEstablished = True
266266

267267
self.sslSock = self.sock
268-
if (self.services & shared.NODE_SSL == shared.NODE_SSL):
268+
if (self.services & shared.NODE_SSL == shared.NODE_SSL and (self.initiatedConnection or sys.version_info >= (2, 7, 9))):
269269
self.sslSock = ssl.wrap_socket(self.sock, keyfile = os.path.join(shared.codePath(), 'sslkeys', 'key.pem'), certfile = os.path.join(shared.codePath(), 'sslkeys', 'cert.pem'), server_side = not self.initiatedConnection, ssl_version=ssl.PROTOCOL_TLSv1, do_handshake_on_connect=False, ciphers='AECDH-AES256-SHA')
270+
if hasattr(self.sslSock, "context"):
271+
self.sslSock.context.set_ecdh_curve("secp256k1")
270272
while True:
271273
try:
272274
self.sslSock.do_handshake()

src/shared.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ def encodeHost(host):
148148
def assembleVersionMessage(remoteHost, remotePort, myStreamNumber):
149149
payload = ''
150150
payload += pack('>L', 3) # protocol version.
151-
payload += pack('>q', NODE_NETWORK|NODE_SSL) # bitflags of the services I offer.
151+
payload += pack('>q', NODE_NETWORK|(NODE_SSL if sys.version_info >= (2, 7, 9) else 0)) # bitflags of the services I offer.
152+
# python < 2.7.9's ssl library does not support ECDSA server due to missing initialisation of available curves, but client works ok
152153
payload += pack('>q', int(time.time()))
153154

154155
payload += pack(

0 commit comments

Comments
 (0)