cool stuff
parent
11667b5aa9
commit
cd887b528a
@ -1,17 +1,16 @@
|
||||
###
|
||||
# Define some basic things while we're here
|
||||
# basic config
|
||||
from .constants import *
|
||||
from .utils import *
|
||||
|
||||
class KomradeException(Exception): pass
|
||||
# common python imports
|
||||
import os,sys
|
||||
from collections import defaultdict
|
||||
from base64 import b64encode,b64decode
|
||||
|
||||
# make sure komrade is on path
|
||||
import sys,os
|
||||
sys.path.append(os.path.dirname(__file__))
|
||||
|
||||
import inspect
|
||||
class Logger(object):
|
||||
def log(self,*x):
|
||||
curframe = inspect.currentframe()
|
||||
calframe = inspect.getouterframes(curframe, 2)
|
||||
mytype = type(self).__name__
|
||||
caller = calframe[1][3]
|
||||
print(f'\n[{mytype}.{caller}()]',*x)
|
||||
# common external imports
|
||||
from pythemis.skeygen import KEY_PAIR_TYPE, GenerateKeyPair
|
||||
from pythemis.smessage import SMessage, ssign, sverify
|
||||
from pythemis.skeygen import GenerateSymmetricKey
|
||||
from pythemis.scell import SCellSeal
|
||||
from pythemis.exception import ThemisError
|
||||
import getpass
|
||||
|
@ -0,0 +1,34 @@
|
||||
# addresses
|
||||
URL_KOMRADE = '128.232.229.63' #'komrade.app'
|
||||
OPERATOR_API_URL = f'http://{URL_KOMRADE}:6999/op/'
|
||||
|
||||
|
||||
# paths
|
||||
import os
|
||||
PATH_KOMRADE = os.path.abspath(os.path.join(os.path.expanduser('~'),'.komrade'))
|
||||
PATH_OPERATOR = os.path.join(PATH_KOMRADE,'.operator')
|
||||
PATH_OPERATOR_PUBKEY = os.path.join(PATH_OPERATOR,'.op.key.pub.encr')
|
||||
PATH_OPERATOR_PRIVKEY = os.path.join(PATH_OPERATOR,'.op.key.priv.encr')
|
||||
PATH_CRYPT_KEYS = os.path.join(PATH_OPERATOR,'.op.db.keys.crypt')
|
||||
PATH_CRYPT_DATA = os.path.join(PATH_OPERATOR,'.op.db.data.encr')
|
||||
|
||||
# etc
|
||||
BSEP=b'||||||||||'
|
||||
BSEP2=b'@@@@@@@@@@'
|
||||
BSEP3=b'##########'
|
||||
|
||||
OPERATOR_PUBKEY_b64 = b'VUVDMgAAAC2uQwUQAoxUODIy1nGUKc3gnDe94XxFtsMOJMZ8MN9QMrl3nPiP'
|
||||
import base64
|
||||
OPERATOR_PUBKEY = base64.b64decode(OPERATOR_PUBKEY_b64)
|
||||
|
||||
# key names
|
||||
|
||||
KEYNAMES = [
|
||||
'pubkey','privkey','adminkey',
|
||||
'pubkey_encr','privkey_encr','adminkey_encr',
|
||||
'pubkey_decr','privkey_decr','adminkey_decr',
|
||||
'pubkey_encr_encr','privkey_encr_encr','adminkey_encr_encr',
|
||||
'pubkey_encr_decr','privkey_encr_decr','adminkey_encr_decr',
|
||||
'pubkey_decr_encr','privkey_decr_encr','adminkey_decr_encr',
|
||||
'pubkey_decr_decr','privkey_decr_decr','adminkey_decr_decr'
|
||||
]
|
@ -0,0 +1,50 @@
|
||||
log=print
|
||||
|
||||
def get_tor_python_session():
|
||||
# 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():
|
||||
import requests
|
||||
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():
|
||||
import requests_futures
|
||||
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(url,method='get',data=None):
|
||||
with get_tor_proxy_session() as s:
|
||||
if method=='get':
|
||||
return s.get(url)
|
||||
elif method=='post':
|
||||
log('data',data)
|
||||
return s.post(url,data=data)
|
||||
|
||||
|
||||
def request(Q,**kwargs):
|
||||
log('request() Q:',Q)
|
||||
res = tor_request(Q,**kwargs)
|
||||
log('reqeust() <-',res)
|
||||
return res
|
||||
|
||||
|
@ -0,0 +1,14 @@
|
||||
class KomradeException(Exception): pass
|
||||
|
||||
# make sure komrade is on path
|
||||
import sys,os
|
||||
sys.path.append(os.path.dirname(__file__))
|
||||
|
||||
import inspect
|
||||
class Logger(object):
|
||||
def log(self,*x):
|
||||
curframe = inspect.currentframe()
|
||||
calframe = inspect.getouterframes(curframe, 2)
|
||||
mytype = type(self).__name__
|
||||
caller = calframe[1][3]
|
||||
print(f'\n[{mytype}.{caller}()]',*x)
|
Loading…
Reference in New Issue