Replace tpo git repository URL by gitlab
[stem.git] / stem / response / add_onion.py
blob3f52f9f21dd1cfd5bdeaaf6dd7cbeb034226e416
1 # Copyright 2015-2020, Damian Johnson and The Tor Project
2 # See LICENSE for licensing information
4 import stem.response
7 class AddOnionResponse(stem.response.ControlMessage):
8 """
9 ADD_ONION response.
11 :var str service_id: hidden service address without the '.onion' suffix
12 :var str private_key: base64 encoded hidden service private key
13 :var str private_key_type: crypto used to generate the hidden service private
14 key (such as RSA1024)
15 :var dict client_auth: newly generated client credentials the service accepts
16 """
18 def _parse_message(self) -> None:
19 # Example:
20 # 250-ServiceID=gfzprpioee3hoppz
21 # 250-PrivateKey=RSA1024:MIICXgIBAAKBgQDZvYVxv...
22 # 250-ClientAuth=bob:l4BT016McqV2Oail+Bwe6w
23 # 250 OK
25 self.service_id = None
26 self.private_key = None
27 self.private_key_type = None
28 self.client_auth = {}
30 if not self.is_ok():
31 raise stem.ProtocolError("ADD_ONION response didn't have an OK status: %s" % self)
33 if not str(self).startswith('ServiceID='):
34 raise stem.ProtocolError('ADD_ONION response should start with the service id: %s' % self)
36 for line in list(self):
37 if '=' in line:
38 key, value = line.split('=', 1)
40 if key == 'ServiceID':
41 self.service_id = value
42 elif key == 'PrivateKey':
43 if ':' not in value:
44 raise stem.ProtocolError("ADD_ONION PrivateKey lines should be of the form 'PrivateKey=[type]:[key]: %s" % self)
46 self.private_key_type, self.private_key = value.split(':', 1)
47 elif key == 'ClientAuth':
48 if ':' not in value:
49 raise stem.ProtocolError("ADD_ONION ClientAuth lines should be of the form 'ClientAuth=[username]:[credential]: %s" % self)
51 username, credential = value.split(':', 1)
52 self.client_auth[username] = credential