1 # Copyright 2015-2020, Damian Johnson and The Tor Project
2 # See LICENSE for licensing information
7 class AddOnionResponse(stem
.response
.ControlMessage
):
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
15 :var dict client_auth: newly generated client credentials the service accepts
18 def _parse_message(self
) -> None:
20 # 250-ServiceID=gfzprpioee3hoppz
21 # 250-PrivateKey=RSA1024:MIICXgIBAAKBgQDZvYVxv...
22 # 250-ClientAuth=bob:l4BT016McqV2Oail+Bwe6w
25 self
.service_id
= None
26 self
.private_key
= None
27 self
.private_key_type
= None
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
):
38 key
, value
= line
.split('=', 1)
40 if key
== 'ServiceID':
41 self
.service_id
= value
42 elif key
== 'PrivateKey':
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':
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