MCPcopy Create free account
hub / github.com/Bitmessage/PyBitmessage / sslHandshake

Function sslHandshake

dev/ssltest.py:43–70  ·  view source on GitHub ↗
(sock, server=False)

Source from the content-addressed store, hash-verified

41 return sock
42
43def sslHandshake(sock, server=False):
44 if sys.version_info >= (2,7,9):
45 context = ssl.SSLContext(sslProtocolVersion())
46 context.set_ciphers(sslProtocolCiphers())
47 context.set_ecdh_curve("secp256k1")
48 context.check_hostname = False
49 context.verify_mode = ssl.CERT_NONE
50 context.options = ssl.OP_ALL | ssl.OP_NO_SSLv2 | ssl.OP_NO_SSLv3 | ssl.OP_SINGLE_ECDH_USE | ssl.OP_CIPHER_SERVER_PREFERENCE
51 sslSock = context.wrap_socket(sock, server_side = server, do_handshake_on_connect=False)
52 else:
53 sslSock = ssl.wrap_socket(sock, keyfile = os.path.join('src', 'sslkeys', 'key.pem'), certfile = os.path.join('src', 'sslkeys', 'cert.pem'), server_side = server, ssl_version=sslProtocolVersion(), do_handshake_on_connect=False, ciphers='AECDH-AES256-SHA')
54
55 while True:
56 try:
57 sslSock.do_handshake()
58 break
59 except ssl.SSLWantReadError:
60 print "Waiting for SSL socket handhake read"
61 select.select([sslSock], [], [], 10)
62 except ssl.SSLWantWriteError:
63 print "Waiting for SSL socket handhake write"
64 select.select([], [sslSock], [], 10)
65 except Exception:
66 print "SSL socket handhake failed, shutting down connection"
67 traceback.print_exc()
68 return
69 print "Success!"
70 return sslSock
71
72if __name__ == "__main__":
73 if len(sys.argv) != 2:

Callers 1

ssltest.pyFile · 0.85

Calls 2

sslProtocolVersionFunction · 0.85
sslProtocolCiphersFunction · 0.85

Tested by

no test coverage detected