author | Edouard Tisserant |
Thu, 08 Nov 2018 09:39:06 +0100 | |
changeset 2329 | e5703dc8848e |
parent 2325 | 71593d3f880b |
child 2492 | 7dd551ac2fa0 |
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 |
2314
e927c101ce6d
PYRO/TLSPSK : must use PYROLOC* protocol scheme in pyro URI, otherwise object ID is missing. Had to use more persuasive pyro3 monkey patching to have PYROLOCPSK resolved properly
Edouard Tisserant
parents:
2313
diff
changeset
|
5 |
import re |
2312 | 6 |
import sslpsk |
2318
8925d487605a
Fixed PYRO's PSK_Adapter : monkey patching was breaking non-PSK protocol, and import ssl was missing.
Edouard Tisserant
parents:
2316
diff
changeset
|
7 |
import ssl |
2312 | 8 |
import Pyro |
2314
e927c101ce6d
PYRO/TLSPSK : must use PYROLOC* protocol scheme in pyro URI, otherwise object ID is missing. Had to use more persuasive pyro3 monkey patching to have PYROLOCPSK resolved properly
Edouard Tisserant
parents:
2313
diff
changeset
|
9 |
from Pyro.core import PyroURI |
2312 | 10 |
from Pyro.protocol import _connect_socket,TCPConnection,PYROAdapter |
11 |
from Pyro.errors import ConnectionDeniedError, ProtocolError |
|
12 |
from Pyro.util import Log |
|
13 |
||
14 |
# |
|
15 |
# The TLS-PSK adapter that handles SSL connections instead of regular sockets, |
|
16 |
# but using Pre Shared Keys instead of Certificates |
|
17 |
# |
|
18 |
class PYROPSKAdapter(PYROAdapter): |
|
19 |
# This is essentialy the same as in Pyro/protocol.py |
|
20 |
# only raw_sock wrapping into sock through sslpsk.wrap_socket was added |
|
21 |
# Pyro unfortunately doesn't allow cleaner customization |
|
22 |
def bindToURI(self,URI): |
|
23 |
with self.lock: # only 1 thread at a time can bind the URI |
|
24 |
try: |
|
25 |
self.URI=URI |
|
26 |
||
27 |
# This are the statements that differ from Pyro/protocol.py |
|
28 |
raw_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
29 |
_connect_socket(raw_sock, URI.address, URI.port, self.timeout) |
|
30 |
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
|
31 |
raw_sock, psk=Pyro.config.PYROPSK, server_side=False, |
2325
71593d3f880b
PYRO PSK: adjusted cipher and key length to be usable with openSSL 1.0.2k.
Edouard Tisserant
parents:
2318
diff
changeset
|
32 |
ciphers="PSK-AES256-CBC-SHA", # available in openssl 1.0.2 |
2316
5416c76df9e2
Fix PYROPSK protocol configuration. After a few iteration of trial and error it appears that TSLv1 and PSK ciphers needs to be specified
Edouard Tisserant
parents:
2314
diff
changeset
|
33 |
ssl_version=ssl.PROTOCOL_TLSv1) |
2312 | 34 |
# all the rest is the same as in Pyro/protocol.py |
35 |
||
36 |
conn=TCPConnection(sock, sock.getpeername()) |
|
37 |
# receive the authentication challenge string, and use that to build the actual identification string. |
|
38 |
try: |
|
39 |
authChallenge=self.recvAuthChallenge(conn) |
|
40 |
except ProtocolError,x: |
|
41 |
# check if we were denied |
|
42 |
if hasattr(x,"partialMsg") and x.partialMsg[:len(self.denyMSG)]==self.denyMSG: |
|
43 |
raise ConnectionDeniedError(Pyro.constants.deniedReasons[int(x.partialMsg[-1])]) |
|
44 |
else: |
|
45 |
raise |
|
46 |
# reply with our ident token, generated from the ident passphrase and the challenge |
|
47 |
msg = self._sendConnect(sock,self.newConnValidator.createAuthToken(self.ident, authChallenge, conn.addr, self.URI, None) ) |
|
48 |
if msg==self.acceptMSG: |
|
49 |
self.conn=conn |
|
50 |
self.conn.connected=1 |
|
51 |
Log.msg('PYROAdapter','connected to',str(URI)) |
|
2314
e927c101ce6d
PYRO/TLSPSK : must use PYROLOC* protocol scheme in pyro URI, otherwise object ID is missing. Had to use more persuasive pyro3 monkey patching to have PYROLOCPSK resolved properly
Edouard Tisserant
parents:
2313
diff
changeset
|
52 |
if URI.protocol=='PYROLOCPSK': |
e927c101ce6d
PYRO/TLSPSK : must use PYROLOC* protocol scheme in pyro URI, otherwise object ID is missing. Had to use more persuasive pyro3 monkey patching to have PYROLOCPSK resolved properly
Edouard Tisserant
parents:
2313
diff
changeset
|
53 |
self.resolvePYROLOC_URI("PYROPSK") # updates self.URI |
2312 | 54 |
elif msg[:len(self.denyMSG)]==self.denyMSG: |
55 |
try: |
|
56 |
raise ConnectionDeniedError(Pyro.constants.deniedReasons[int(msg[-1])]) |
|
57 |
except (KeyError,ValueError): |
|
58 |
raise ConnectionDeniedError('invalid response') |
|
59 |
except socket.error: |
|
60 |
Log.msg('PYROAdapter','connection failed to URI',str(URI)) |
|
61 |
raise ProtocolError('connection failed') |
|
62 |
||
63 |
_getProtocolAdapter = Pyro.protocol.getProtocolAdapter |
|
64 |
def getProtocolAdapter(protocol): |
|
65 |
if protocol in ('PYROPSK', 'PYROLOCPSK'): |
|
66 |
return PYROPSKAdapter() |
|
2318
8925d487605a
Fixed PYRO's PSK_Adapter : monkey patching was breaking non-PSK protocol, and import ssl was missing.
Edouard Tisserant
parents:
2316
diff
changeset
|
67 |
return _getProtocolAdapter(protocol) |
2312 | 68 |
|
69 |
Pyro.protocol.getProtocolAdapter = getProtocolAdapter |
|
70 |
||
2314
e927c101ce6d
PYRO/TLSPSK : must use PYROLOC* protocol scheme in pyro URI, otherwise object ID is missing. Had to use more persuasive pyro3 monkey patching to have PYROLOCPSK resolved properly
Edouard Tisserant
parents:
2313
diff
changeset
|
71 |
_processStringURI = Pyro.core.processStringURI |
e927c101ce6d
PYRO/TLSPSK : must use PYROLOC* protocol scheme in pyro URI, otherwise object ID is missing. Had to use more persuasive pyro3 monkey patching to have PYROLOCPSK resolved properly
Edouard Tisserant
parents:
2313
diff
changeset
|
72 |
def processStringURI(URI): |
e927c101ce6d
PYRO/TLSPSK : must use PYROLOC* protocol scheme in pyro URI, otherwise object ID is missing. Had to use more persuasive pyro3 monkey patching to have PYROLOCPSK resolved properly
Edouard Tisserant
parents:
2313
diff
changeset
|
73 |
x=re.match(r'(?P<protocol>PYROLOCPSK)://(?P<hostname>[^\s:]+):?(?P<port>\d+)?/(?P<name>\S*)',URI) |
e927c101ce6d
PYRO/TLSPSK : must use PYROLOC* protocol scheme in pyro URI, otherwise object ID is missing. Had to use more persuasive pyro3 monkey patching to have PYROLOCPSK resolved properly
Edouard Tisserant
parents:
2313
diff
changeset
|
74 |
if x: |
e927c101ce6d
PYRO/TLSPSK : must use PYROLOC* protocol scheme in pyro URI, otherwise object ID is missing. Had to use more persuasive pyro3 monkey patching to have PYROLOCPSK resolved properly
Edouard Tisserant
parents:
2313
diff
changeset
|
75 |
protocol=x.group('protocol') |
e927c101ce6d
PYRO/TLSPSK : must use PYROLOC* protocol scheme in pyro URI, otherwise object ID is missing. Had to use more persuasive pyro3 monkey patching to have PYROLOCPSK resolved properly
Edouard Tisserant
parents:
2313
diff
changeset
|
76 |
hostname=x.group('hostname') |
e927c101ce6d
PYRO/TLSPSK : must use PYROLOC* protocol scheme in pyro URI, otherwise object ID is missing. Had to use more persuasive pyro3 monkey patching to have PYROLOCPSK resolved properly
Edouard Tisserant
parents:
2313
diff
changeset
|
77 |
port=x.group('port') |
e927c101ce6d
PYRO/TLSPSK : must use PYROLOC* protocol scheme in pyro URI, otherwise object ID is missing. Had to use more persuasive pyro3 monkey patching to have PYROLOCPSK resolved properly
Edouard Tisserant
parents:
2313
diff
changeset
|
78 |
if port: |
e927c101ce6d
PYRO/TLSPSK : must use PYROLOC* protocol scheme in pyro URI, otherwise object ID is missing. Had to use more persuasive pyro3 monkey patching to have PYROLOCPSK resolved properly
Edouard Tisserant
parents:
2313
diff
changeset
|
79 |
port=int(port) |
e927c101ce6d
PYRO/TLSPSK : must use PYROLOC* protocol scheme in pyro URI, otherwise object ID is missing. Had to use more persuasive pyro3 monkey patching to have PYROLOCPSK resolved properly
Edouard Tisserant
parents:
2313
diff
changeset
|
80 |
else: |
e927c101ce6d
PYRO/TLSPSK : must use PYROLOC* protocol scheme in pyro URI, otherwise object ID is missing. Had to use more persuasive pyro3 monkey patching to have PYROLOCPSK resolved properly
Edouard Tisserant
parents:
2313
diff
changeset
|
81 |
port=0 |
e927c101ce6d
PYRO/TLSPSK : must use PYROLOC* protocol scheme in pyro URI, otherwise object ID is missing. Had to use more persuasive pyro3 monkey patching to have PYROLOCPSK resolved properly
Edouard Tisserant
parents:
2313
diff
changeset
|
82 |
name=x.group('name') |
e927c101ce6d
PYRO/TLSPSK : must use PYROLOC* protocol scheme in pyro URI, otherwise object ID is missing. Had to use more persuasive pyro3 monkey patching to have PYROLOCPSK resolved properly
Edouard Tisserant
parents:
2313
diff
changeset
|
83 |
return PyroURI(hostname,name,port,protocol) |
e927c101ce6d
PYRO/TLSPSK : must use PYROLOC* protocol scheme in pyro URI, otherwise object ID is missing. Had to use more persuasive pyro3 monkey patching to have PYROLOCPSK resolved properly
Edouard Tisserant
parents:
2313
diff
changeset
|
84 |
return _processStringURI(URI) |
e927c101ce6d
PYRO/TLSPSK : must use PYROLOC* protocol scheme in pyro URI, otherwise object ID is missing. Had to use more persuasive pyro3 monkey patching to have PYROLOCPSK resolved properly
Edouard Tisserant
parents:
2313
diff
changeset
|
85 |
Pyro.core.processStringURI = processStringURI |