author | Edouard Tisserant |
Thu, 18 Oct 2018 11:01:14 +0200 | |
changeset 2313 | 2eaf235270f8 |
parent 2312 | 84b3cc18893b |
child 2314 | e927c101ce6d |
permissions | -rw-r--r-- |
2313
2eaf235270f8
PYRO/TLSPSK : fixed typos, used appropriate ciphers (https://github.com/drbild/sslpsk/issues/3), use PYROPSK instead of unresolvable PYROLOCPSK.
Edouard Tisserant
parents:
2312
diff
changeset
|
1 |
from __future__ import absolute_import |
2eaf235270f8
PYRO/TLSPSK : fixed typos, used appropriate ciphers (https://github.com/drbild/sslpsk/issues/3), use PYROPSK instead of unresolvable PYROLOCPSK.
Edouard Tisserant
parents:
2312
diff
changeset
|
2 |
from __future__ import print_function |
2312 | 3 |
|
2313
2eaf235270f8
PYRO/TLSPSK : fixed typos, used appropriate ciphers (https://github.com/drbild/sslpsk/issues/3), use PYROPSK instead of unresolvable PYROLOCPSK.
Edouard Tisserant
parents:
2312
diff
changeset
|
4 |
import socket |
2312 | 5 |
import sslpsk |
6 |
import Pyro |
|
7 |
from Pyro.protocol import _connect_socket,TCPConnection,PYROAdapter |
|
8 |
from Pyro.errors import ConnectionDeniedError, ProtocolError |
|
9 |
from Pyro.util import Log |
|
10 |
||
11 |
# |
|
12 |
# The TLS-PSK adapter that handles SSL connections instead of regular sockets, |
|
13 |
# but using Pre Shared Keys instead of Certificates |
|
14 |
# |
|
15 |
class PYROPSKAdapter(PYROAdapter): |
|
16 |
# This is essentialy the same as in Pyro/protocol.py |
|
17 |
# only raw_sock wrapping into sock through sslpsk.wrap_socket was added |
|
18 |
# Pyro unfortunately doesn't allow cleaner customization |
|
19 |
def bindToURI(self,URI): |
|
20 |
with self.lock: # only 1 thread at a time can bind the URI |
|
21 |
try: |
|
22 |
self.URI=URI |
|
23 |
||
24 |
# This are the statements that differ from Pyro/protocol.py |
|
25 |
raw_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
26 |
_connect_socket(raw_sock, URI.address, URI.port, self.timeout) |
|
27 |
sock = sslpsk.wrap_socket( |
|
2313
2eaf235270f8
PYRO/TLSPSK : fixed typos, used appropriate ciphers (https://github.com/drbild/sslpsk/issues/3), use PYROPSK instead of unresolvable PYROLOCPSK.
Edouard Tisserant
parents:
2312
diff
changeset
|
28 |
raw_sock, psk=Pyro.config.PYROPSK, server_side=False, |
2eaf235270f8
PYRO/TLSPSK : fixed typos, used appropriate ciphers (https://github.com/drbild/sslpsk/issues/3), use PYROPSK instead of unresolvable PYROLOCPSK.
Edouard Tisserant
parents:
2312
diff
changeset
|
29 |
ciphers="PSK-AES256-GCM-SHA384:PSK-AES256-CBC-SHA") |
2312 | 30 |
# all the rest is the same as in Pyro/protocol.py |
31 |
||
32 |
conn=TCPConnection(sock, sock.getpeername()) |
|
33 |
# receive the authentication challenge string, and use that to build the actual identification string. |
|
34 |
try: |
|
35 |
authChallenge=self.recvAuthChallenge(conn) |
|
36 |
except ProtocolError,x: |
|
37 |
# check if we were denied |
|
38 |
if hasattr(x,"partialMsg") and x.partialMsg[:len(self.denyMSG)]==self.denyMSG: |
|
39 |
raise ConnectionDeniedError(Pyro.constants.deniedReasons[int(x.partialMsg[-1])]) |
|
40 |
else: |
|
41 |
raise |
|
42 |
# reply with our ident token, generated from the ident passphrase and the challenge |
|
43 |
msg = self._sendConnect(sock,self.newConnValidator.createAuthToken(self.ident, authChallenge, conn.addr, self.URI, None) ) |
|
44 |
if msg==self.acceptMSG: |
|
45 |
self.conn=conn |
|
46 |
self.conn.connected=1 |
|
47 |
Log.msg('PYROAdapter','connected to',str(URI)) |
|
48 |
if URI.protocol=='PYROLOC': |
|
49 |
self.resolvePYROLOC_URI("PYRO") # updates self.URI |
|
50 |
elif msg[:len(self.denyMSG)]==self.denyMSG: |
|
51 |
try: |
|
52 |
raise ConnectionDeniedError(Pyro.constants.deniedReasons[int(msg[-1])]) |
|
53 |
except (KeyError,ValueError): |
|
54 |
raise ConnectionDeniedError('invalid response') |
|
55 |
except socket.error: |
|
56 |
Log.msg('PYROAdapter','connection failed to URI',str(URI)) |
|
57 |
raise ProtocolError('connection failed') |
|
58 |
||
59 |
_getProtocolAdapter = Pyro.protocol.getProtocolAdapter |
|
60 |
def getProtocolAdapter(protocol): |
|
61 |
if protocol in ('PYROPSK', 'PYROLOCPSK'): |
|
62 |
return PYROPSKAdapter() |
|
63 |
_getProtocolAdapter(protocol) |
|
64 |
||
65 |
Pyro.protocol.getProtocolAdapter = getProtocolAdapter |
|
66 |