Example #1
0
def _psh2srv(rs):
	try:
		get = urllib2.urlopen(rs)
		stream = get.read()
		try:
			return stream
		except:
			raise err.srv('unknown error')
	except urllib2.HTTPError, err:
		stream = err.read()
		try:
			return stream
		except:
			raise err.srv('unknown error')
Example #2
0
def getpub(domain='toxme.se'):
	rs = urllib2.Request('https://{}/pk'.format(domain))
	data = _psh2srv(rs)
	try:
		return json.loads(data)['key']
	except:
		raise err.srv('unable to find public key')
Example #3
0
	try:
		get = urllib2.urlopen(rs)
		stream = get.read()
		try:
			return stream
		except:
			raise err.srv('unknown error')
	except urllib2.HTTPError, err:
		stream = err.read()
		try:
			return stream
		except:
			raise err.srv('unknown error')
	except:
		import err
		raise err.srv('invalid domain')

def _pushauth(act,domain,payload,auth,r_nonce):
	nonce = nacl.encoding.Base64Encoder.encode(r_nonce).decode("utf8")
	pub = auth.public_key.encode(encoder=nacl.encoding.HexEncoder)
	post = {"action":act, "public_key":pub, "encrypted":payload, "nonce":nonce}
	rs = urllib2.Request('https://{}/api'.format(domain),data=json.dumps(post))

	return json.loads(_psh2srv(rs))

def _toxme_err(data):
	code = int(data['c'])
	if code == 0:
		return data
	else:
		raise err.toxme(data['c'])