1 # Copyright 2012-2020, Damian Johnson and The Tor Project
2 # See LICENSE for licensing information
8 import stem
.util
.str_tools
9 import stem
.util
.tor_tools
12 class AuthChallengeResponse(stem
.response
.ControlMessage
):
14 AUTHCHALLENGE query response.
16 :var str server_hash: server hash provided by tor
17 :var str server_nonce: server nonce provided by tor
20 def _parse_message(self
) -> None:
22 # 250 AUTHCHALLENGE SERVERHASH=680A73C9836C4F557314EA1C4EDE54C285DB9DC89C83627401AEF9D7D27A95D5 SERVERNONCE=F8EA4B1F2C8B40EF1AF68860171605B910E3BBCABADF6FC3DB1FA064F4690E85
24 self
.server_hash
= None
25 self
.server_nonce
= None
28 raise stem
.ProtocolError("AUTHCHALLENGE response didn't have an OK status:\n%s" % self
)
30 raise stem
.ProtocolError('Received multiline AUTHCHALLENGE response:\n%s' % self
)
34 # sanity check that we're a AUTHCHALLENGE response
35 if not line
.pop() == 'AUTHCHALLENGE':
36 raise stem
.ProtocolError('Message is not an AUTHCHALLENGE response (%s)' % self
)
38 if line
.is_next_mapping('SERVERHASH'):
39 value
= line
.pop_mapping()[1]
41 if not stem
.util
.tor_tools
.is_hex_digits(value
, 64):
42 raise stem
.ProtocolError('SERVERHASH has an invalid value: %s' % value
)
44 self
.server_hash
= binascii
.unhexlify(stem
.util
.str_tools
._to
_bytes
(value
))
46 raise stem
.ProtocolError('Missing SERVERHASH mapping: %s' % line
)
48 if line
.is_next_mapping('SERVERNONCE'):
49 value
= line
.pop_mapping()[1]
51 if not stem
.util
.tor_tools
.is_hex_digits(value
, 64):
52 raise stem
.ProtocolError('SERVERNONCE has an invalid value: %s' % value
)
54 self
.server_nonce
= binascii
.unhexlify(stem
.util
.str_tools
._to
_bytes
(value
))
56 raise stem
.ProtocolError('Missing SERVERNONCE mapping: %s' % line
)