make self.channel internal
This commit is contained in:
parent
9ead3f48a8
commit
07686f3de7
|
@ -156,6 +156,7 @@ class Wormhole:
|
||||||
side = hexlify(os.urandom(5)).decode("ascii")
|
side = hexlify(os.urandom(5)).decode("ascii")
|
||||||
self._channel_manager = ChannelManager(relay_url, appid, side,
|
self._channel_manager = ChannelManager(relay_url, appid, side,
|
||||||
self.handle_welcome)
|
self.handle_welcome)
|
||||||
|
self._channel = None
|
||||||
self.code = None
|
self.code = None
|
||||||
self.key = None
|
self.key = None
|
||||||
self.verifier = None
|
self.verifier = None
|
||||||
|
@ -212,8 +213,8 @@ class Wormhole:
|
||||||
raise ValueError("code (%s) must start with NN-" % code)
|
raise ValueError("code (%s) must start with NN-" % code)
|
||||||
self.code = code
|
self.code = code
|
||||||
channelid = int(mo.group(1))
|
channelid = int(mo.group(1))
|
||||||
self.channel = self._channel_manager.connect(channelid)
|
self._channel = self._channel_manager.connect(channelid)
|
||||||
monitor.add(self.channel)
|
monitor.add(self._channel)
|
||||||
|
|
||||||
def _start(self):
|
def _start(self):
|
||||||
# allocate the rest now too, so it can be serialized
|
# allocate the rest now too, so it can be serialized
|
||||||
|
@ -244,14 +245,14 @@ class Wormhole:
|
||||||
|
|
||||||
def _get_key(self):
|
def _get_key(self):
|
||||||
if not self.key:
|
if not self.key:
|
||||||
self.channel.send(u"pake", self.msg1)
|
self._channel.send(u"pake", self.msg1)
|
||||||
pake_msg = self.channel.get(u"pake")
|
pake_msg = self._channel.get(u"pake")
|
||||||
self.key = self.sp.finish(pake_msg)
|
self.key = self.sp.finish(pake_msg)
|
||||||
self.verifier = self.derive_key(u"wormhole:verifier")
|
self.verifier = self.derive_key(u"wormhole:verifier")
|
||||||
|
|
||||||
def get_verifier(self):
|
def get_verifier(self):
|
||||||
if self.code is None: raise UsageError
|
if self.code is None: raise UsageError
|
||||||
if self.channel is None: raise UsageError
|
if self._channel is None: raise UsageError
|
||||||
self._get_key()
|
self._get_key()
|
||||||
return self.verifier
|
return self.verifier
|
||||||
|
|
||||||
|
@ -261,7 +262,7 @@ class Wormhole:
|
||||||
if not isinstance(phase, type(u"")): raise TypeError(type(phase))
|
if not isinstance(phase, type(u"")): raise TypeError(type(phase))
|
||||||
if phase in self._sent_data: raise UsageError # only call this once
|
if phase in self._sent_data: raise UsageError # only call this once
|
||||||
if self.code is None: raise UsageError
|
if self.code is None: raise UsageError
|
||||||
if self.channel is None: raise UsageError
|
if self._channel is None: raise UsageError
|
||||||
# Without predefined roles, we can't derive predictably unique keys
|
# Without predefined roles, we can't derive predictably unique keys
|
||||||
# for each side, so we use the same key for both. We use random
|
# for each side, so we use the same key for both. We use random
|
||||||
# nonces to keep the messages distinct, and the Channel automatically
|
# nonces to keep the messages distinct, and the Channel automatically
|
||||||
|
@ -270,17 +271,17 @@ class Wormhole:
|
||||||
self._get_key()
|
self._get_key()
|
||||||
data_key = self.derive_key(u"wormhole:phase:%s" % phase)
|
data_key = self.derive_key(u"wormhole:phase:%s" % phase)
|
||||||
outbound_encrypted = self._encrypt_data(data_key, outbound_data)
|
outbound_encrypted = self._encrypt_data(data_key, outbound_data)
|
||||||
self.channel.send(phase, outbound_encrypted)
|
self._channel.send(phase, outbound_encrypted)
|
||||||
|
|
||||||
def get_data(self, phase=u"data"):
|
def get_data(self, phase=u"data"):
|
||||||
if not isinstance(phase, type(u"")): raise TypeError(type(phase))
|
if not isinstance(phase, type(u"")): raise TypeError(type(phase))
|
||||||
if phase in self._got_data: raise UsageError # only call this once
|
if phase in self._got_data: raise UsageError # only call this once
|
||||||
if self.code is None: raise UsageError
|
if self.code is None: raise UsageError
|
||||||
if self.channel is None: raise UsageError
|
if self._channel is None: raise UsageError
|
||||||
self._got_data.add(phase)
|
self._got_data.add(phase)
|
||||||
self._get_key()
|
self._get_key()
|
||||||
data_key = self.derive_key(u"wormhole:phase:%s" % phase)
|
data_key = self.derive_key(u"wormhole:phase:%s" % phase)
|
||||||
inbound_encrypted = self.channel.get(phase)
|
inbound_encrypted = self._channel.get(phase)
|
||||||
try:
|
try:
|
||||||
inbound_data = self._decrypt_data(data_key, inbound_encrypted)
|
inbound_data = self._decrypt_data(data_key, inbound_encrypted)
|
||||||
return inbound_data
|
return inbound_data
|
||||||
|
@ -288,5 +289,5 @@ class Wormhole:
|
||||||
raise WrongPasswordError
|
raise WrongPasswordError
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
monitor.close(self.channel)
|
monitor.close(self._channel)
|
||||||
self.channel.deallocate()
|
self._channel.deallocate()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user