mirror of
https://github.com/ComradCollective/Comrad
synced 2024-11-03 23:15:33 +00:00
got tor working on key requests
This commit is contained in:
parent
7707133330
commit
79f2996de6
46
p2p/api.py
46
p2p/api.py
@ -175,6 +175,52 @@ class Api(object):
|
|||||||
self.log(f'connect() has node {node}')
|
self.log(f'connect() has node {node}')
|
||||||
self._node = node
|
self._node = node
|
||||||
return node
|
return node
|
||||||
|
|
||||||
|
def get_tor_python_session(self):
|
||||||
|
# from torpy.http.requests import TorRequests
|
||||||
|
# with TorRequests() as tor_requests:
|
||||||
|
# with tor_requests.get_session() as s:
|
||||||
|
# # return s
|
||||||
|
# from torpy.http.requests import tor_requests_session
|
||||||
|
# with tor_requests_session() as s: # returns requests.Session() object
|
||||||
|
# return s
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def get_tor_proxy_session(self):
|
||||||
|
session = requests.session()
|
||||||
|
# Tor uses the 9050 port as the default socks port
|
||||||
|
session.proxies = {'http': 'socks5://127.0.0.1:9050',
|
||||||
|
'https': 'socks5://127.0.0.1:9050'}
|
||||||
|
return session
|
||||||
|
|
||||||
|
def get_async_tor_proxy_session(self):
|
||||||
|
from requests_futures.sessions import FuturesSession
|
||||||
|
session = FuturesSession()
|
||||||
|
# Tor uses the 9050 port as the default socks port
|
||||||
|
session.proxies = {'http': 'socks5://127.0.0.1:9050',
|
||||||
|
'https': 'socks5://127.0.0.1:9050'}
|
||||||
|
return session
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def tor_request(self,url,method='get',data=None):
|
||||||
|
with self.get_tor_proxy_session() as s:
|
||||||
|
if method=='get':
|
||||||
|
return s.get(url)
|
||||||
|
elif method=='post':
|
||||||
|
self.log('data',data)
|
||||||
|
return s.post(url,data=data)
|
||||||
|
|
||||||
|
|
||||||
|
def request(self,Q,**kwargs):
|
||||||
|
self.log('request() Q:',Q)
|
||||||
|
res = self.tor_request(Q,**kwargs)
|
||||||
|
self.log('reqeust() <-',res)
|
||||||
|
return res
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#@property
|
#@property
|
||||||
|
@ -154,8 +154,8 @@ class Persona(object):
|
|||||||
|
|
||||||
def get_keyserver_pubkey(self):
|
def get_keyserver_pubkey(self):
|
||||||
Q=f'http://{KEYSERVER_ADDR}:{KEYSERVER_PORT}/pub'
|
Q=f'http://{KEYSERVER_ADDR}:{KEYSERVER_PORT}/pub'
|
||||||
self.log('Q:',Q)
|
|
||||||
r = requests.get(Q)
|
r = self.api.request(Q)
|
||||||
return r.content
|
return r.content
|
||||||
# self.log('r =',r,b64encode(r.content))
|
# self.log('r =',r,b64encode(r.content))
|
||||||
# pubkey_b64 = b64encode(r.content)
|
# pubkey_b64 = b64encode(r.content)
|
||||||
@ -164,7 +164,7 @@ class Persona(object):
|
|||||||
def get_externally_signed_pubkey(self):
|
def get_externally_signed_pubkey(self):
|
||||||
Q=f'http://{KEYSERVER_ADDR}:{KEYSERVER_PORT}/get/{self.name}'
|
Q=f'http://{KEYSERVER_ADDR}:{KEYSERVER_PORT}/get/{self.name}'
|
||||||
self.log('Q:',Q)
|
self.log('Q:',Q)
|
||||||
r = requests.get(Q)
|
r = self.api.request(Q)
|
||||||
package_b64 = r.content
|
package_b64 = r.content
|
||||||
package = b64decode(package_b64)
|
package = b64decode(package_b64)
|
||||||
self.log('package <--',package)
|
self.log('package <--',package)
|
||||||
@ -218,13 +218,17 @@ class Persona(object):
|
|||||||
return not user_missing
|
return not user_missing
|
||||||
|
|
||||||
|
|
||||||
def meet(self):
|
def meet(self,save_loc=True):
|
||||||
pubkey_ext = b64decode(self.pubkey_keyserver_verified)
|
pubkey_ext = b64decode(self.pubkey_keyserver_verified)
|
||||||
self.log('pubkey_ext',pubkey_ext)
|
self.log('pubkey_ext',pubkey_ext)
|
||||||
self.pubkey=pubkey_ext
|
self.pubkey=pubkey_ext
|
||||||
self.log('setting self.pubkey to external value:',self.pubkey)
|
self.log('setting self.pubkey to external value:',self.pubkey)
|
||||||
self.log('self.pubkey_64',self.pubkey_b64)
|
self.log('self.pubkey_64',self.pubkey_b64)
|
||||||
self.log('keyserver_verified',self.pubkey_keyserver_verified)
|
self.log('keyserver_verified',self.pubkey_keyserver_verified)
|
||||||
|
|
||||||
|
with open(self.key_path_pub,'wb') as of:
|
||||||
|
of.write(self.pubkey_keyserver_verified)
|
||||||
|
|
||||||
return {'success':'Met person as acquaintance'}
|
return {'success':'Met person as acquaintance'}
|
||||||
|
|
||||||
def register(self):
|
def register(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user