mirror of
https://github.com/ComradCollective/Comrad
synced 2024-11-16 00:12:48 +00:00
updates
This commit is contained in:
parent
86a985e6aa
commit
6907fbc3c7
@ -1 +1 @@
|
||||
AAEBQAwAAAAQAAAAFgQAABnkCgGF78U/TuwX7wO1n/YQZAICzaxQDZSA+P9qjJMVqTrFawrIMF0DskNup6/PrJTsbXP/kfErRI/zDY+dC4s4bnLBYtcB9JLn5ngiA+kfdBqQHRXdnImVTEqFgxUYl25TB0UMqQGpqum81gZ9+wWemp7V+8+Qd4gX78aQAuQ14VcBvOMH731bM2H7vmXuOhox5rYa3IDeEiTGOwmXs7gTEaSrnIY5NB88HzA0MO/RbN6ZcuF5+xrPgVFT8AK5E1DmQendb9uVfynDUT8snsjA87HChTJMymNFKYC+mg8euIbyDss0EDwvBBz0bsfSjiWLSthjmskurXXA1tsrOCKCpYx82ZUfyQSFtMGztlDvckdTZiYEyDmS3QTC8AKEawIiK3IyNd2H3a2vRIyo6hewObl0rSIZe2msYxeVpI330pcwX6RfmQuHFtCTAFaPCqVju8eBVteuI3XcuHKTEqi7zSnJRGvcXkkXUOIfjvlA3zh9q5t0kZcngNzRb/i4sjHEYAo71iRHH0Kr3NrOi9UZhMHfT18xpUNcUGu2y5kuaM8Laka9M9APiZAOy057c2xsmpK4yXuxlydrIm5DPD9hfqGrp8pr/sXgVbtdDNm1OvGWUl4pVunDddFxn/5GgT1AY4jYJm8w7H5vTjGW1feBEr6VsasWzSPyOkyVUWyp1oKR2K0K8Gd3Jm1em3g8mbO9aY0I3nmHmNaSrJhVP8YmFTBn82wzUsivl8yqVDgqc1VOMfWUH2rRmjzWNstgm4uS3w8bprmxrx2rNtVf33zqqIu/165vsg0OsnMIPcD96GpOjdIkRsDMkQFDBOOsLrPOklP0PFHGsQVBpSQDoVFgh+/G29+otGRlZutrdrnwHbM1Wzu2Ooi12JY4bKu8awUa7fqO8UbrLxlGf5SOMp28v1BonbETg86hWJndC1T+NqvCDd/2TnjnRcYWHc7kGsbY1opWol+YTqox6bGrSyunhBXTbevNLu7j/WTGYLegyJqhZU3RKVo3h4oknRAEKoPcivYJXWpEAqn5oM0ixKrac3qyflBdOdDE1OslAwyu3DOadlPOKILMjM+3xWWF7bveJBK5k9W5YV5VsAZWU+YMFMEpq3+vDykFcnIVbR3J3LjvPIcu8iXaKqC1SGwJLJ70+c0gFDii1SI+DE+6BZXggzOHBbD/ie5PlBvwsc/BS8fcSoHEWskVNZbQ7gbiNQf4HfZrMo88IBICAW6Qh1r8YJqyHcTrZ2GIdvwFyx3/N1Ra8HZvO/rNGSl8ksVN/30BEvvQPdeGKhPWlF3clZrCrwCk+YoHei4sMONpCZDh946qzPhTpJvV0sZSs7WRrSFh2o+YOVIjdgzLNNaYWuZ8oxeunzjHEK8eqFrU9rDLryzrUrNPLH8bTRyUVqLiIadPM4tLsgdrLg58dE+aiwh2EQ==
|
||||
AAEBQAwAAAAQAAAAtgAAAAhPbtw5vfUszNGoXboVbKy5t+5dcU42Bc9OGZYZ8BdJaKABvwxQxtmzlX1cPRlwhjD39QXtt0gfAYuqvvE7BlyKkgd0KHU+UqwqtYp9QQarSGOUGitIXQcYuKEJGZ2ThuY+ygzLBUsyqvhTDqZCb4xSPHDursMo8FPMdfvzbv9BsOJ0agsNPcTkk1xm8IklnXrrJGmUvzX7APdLw3iJWpJw9xdmxLdGgS6RyTIWvmxmB6dw4UeY2Sr66DOl3RyOJfjF5u6C9Kng0H+QAJKfTrDmfw==
|
@ -91,9 +91,11 @@ class Operator(Keymaker):
|
||||
|
||||
# 2) encrypt to phone
|
||||
json_phone_encr = self.encrypt_to_send(json_phone,from_phone_privkey,to_pubkey)
|
||||
self.log('json_phone_encr',json_phone_encr)
|
||||
|
||||
# 3) to caller
|
||||
json_caller_encr = self.encrypt_to_send(json_caller,from_caller_privkey,to_pubkey)
|
||||
self.log()
|
||||
|
||||
# return
|
||||
req_data_encr = unencr_header + BSEP + json_phone_encr + BSEP + json_caller_encr
|
||||
|
@ -41,108 +41,6 @@ class TheOperator(Operator):
|
||||
self._keychain = OPERATOR_KEYCHAIN
|
||||
|
||||
|
||||
def decrypt_incoming(self,data):
|
||||
# step 1 split:
|
||||
data_unencr,data_encr_by_phone,data_encr_by_caller = data.split(BSEP)
|
||||
data_unencr_by_phone,data_unencr_by_caller = None,None
|
||||
|
||||
self.log('data_unencr =',data_unencr)
|
||||
self.log('data_encr_by_phone =',data_encr_by_phone)
|
||||
self.log('data_encr_by_caller =',data_encr_by_caller)
|
||||
|
||||
DATA = {}
|
||||
# stop1
|
||||
PHONE_PUBKEY=None
|
||||
MY_PRIVKEY=None
|
||||
|
||||
# Scan unencrypted area for half-keys
|
||||
if data_unencr:
|
||||
self.log('unencrypted data:',data_unencr)
|
||||
assert data_unencr.count(BSEP2)==1
|
||||
my_privkey_decr,phone_pubkey_decr = data_unencr.split(BSEP2)
|
||||
self.log('my_privkey_decr',my_privkey_decr)
|
||||
self.log('phone_pubkey_decr',phone_pubkey_decr)
|
||||
|
||||
# get phone pubkey
|
||||
new_phone_keychain = self.phone.keychain(extra_keys={'pubkey_decr':phone_pubkey_decr},force=True)
|
||||
new_op_keychain = self.keychain(extra_keys={'privkey_decr':my_privkey_decr},force=True)
|
||||
|
||||
PHONE_PUBKEY = new_phone_keychain.get('pubkey')
|
||||
MY_PRIVKEY = new_op_keychain.get('privkey')
|
||||
|
||||
# Scan phone-encrypted area for json dictionary
|
||||
if data_encr_by_phone:
|
||||
# then try to unwrap telephone encryption
|
||||
if not MY_PRIVKEY or not PHONE_PUBKEY:
|
||||
self.log('!! could not assemble my or phone\'s keys. failing.')
|
||||
return OPERATOR_INTERCEPT_MESSAGE
|
||||
try:
|
||||
data_unencr_by_phone = SMessage(MY_PRIVKEY, PHONE_PUBKEY).unwrap(data_encr_by_phone)
|
||||
self.log('decrypted data !!!:',data_unencr_by_phone)
|
||||
except ThemisError as e:
|
||||
self.log('not really from the telephone?',e)
|
||||
return OPERATOR_INTERCEPT_MESSAGE
|
||||
|
||||
data_unencr_by_phone_json = unpackage_from_transmission(data_unencr_by_phone)
|
||||
assert type(data_unencr_by_phone_json) == dict
|
||||
dict_merge(DATA, data_unencr_by_phone_json)
|
||||
|
||||
|
||||
if data_encr_by_caller and 'name' in data_unencr_by_phone:
|
||||
name=data_unencr_by_phone['name']
|
||||
|
||||
try:
|
||||
caller = Caller(name)
|
||||
self.log('got caller on phone',name,caller)
|
||||
data_unencr_by_caller = SMessage(MY_PRIVKEY, caller.pubkey_).unwrap(data_encr_by_caller)
|
||||
self.log('decrypted data from caller!!!:',data_unencr_by_caller)
|
||||
except ThemisError as e:
|
||||
self.log('not really from caller?',e)
|
||||
return OPERATOR_INTERCEPT_MESSAGE
|
||||
|
||||
data_unencr_by_caller_json = unpackage_from_transmission(data_unencr_by_caller)
|
||||
assert type(data_unencr_by_caller_json) == dict
|
||||
dict_merge(DATA, data_unencr_by_caller_json)
|
||||
|
||||
return DATA
|
||||
|
||||
|
||||
def encrypt_outgoing(self,json_phone={},json_caller={},caller=None):
|
||||
# 1)
|
||||
unencr_header = self.privkey_encr_ + BSEP2 + self.phone.pubkey_encr_
|
||||
self.log('unencr_header',unencr_header)
|
||||
|
||||
# 2) encrypt to phone
|
||||
if json_phone:
|
||||
json_phone_b = package_for_transmission(json_phone)
|
||||
try:
|
||||
json_phone_b_encr = SMessage(
|
||||
self.privkey_,
|
||||
self.phone.pubkey_
|
||||
).wrap(json_phone_b)
|
||||
except ThemisError as e:
|
||||
self.log('unable to send to phone!',e)
|
||||
return OPERATOR_INTERCEPT_MESSAGE
|
||||
else:
|
||||
json_phone_b=b''
|
||||
|
||||
# 3) to caller
|
||||
if json_caller and caller:
|
||||
json_caller_b = package_for_transmission(json_caller)
|
||||
try:
|
||||
json_caller_b_encr = SMessage(
|
||||
caller.privkey_,
|
||||
self.pubkey_
|
||||
).wrap(json_caller_b)
|
||||
except ThemisError as e:
|
||||
self.log('unable to send to caller!',e)
|
||||
return OPERATOR_INTERCEPT_MESSAGE
|
||||
else:
|
||||
json_caller_b_encr = b''
|
||||
|
||||
req_data_encr = unencr_header + BSEP + json_phone_b_encr + BSEP + json_caller_b_encr
|
||||
return req_data_encr
|
||||
|
||||
|
||||
def recv(self,data):
|
||||
# decrypt
|
||||
|
@ -31,9 +31,18 @@ class TheTelephone(Operator):
|
||||
|
||||
|
||||
def dial_operator(self,msg):
|
||||
msg=msg.replace('/','_')
|
||||
self.log(msg,'msg!?')
|
||||
msg_b64=b64encode(msg)
|
||||
|
||||
self.log(msg_b64,'msg_b64!?')
|
||||
|
||||
msg_b64_str = msg_b64.decode()
|
||||
self.log(msg_b64_str,'msg_b64_str!?')
|
||||
|
||||
msg=msg_b64_str.replace('/','_')
|
||||
URL = OPERATOR_API_URL + msg + '/'
|
||||
self.log("DIALING THE OPERATOR:",URL)
|
||||
# stop
|
||||
r=komrade_request(URL)
|
||||
if r.status_code==200:
|
||||
return r.text
|
||||
@ -70,7 +79,7 @@ class TheTelephone(Operator):
|
||||
|
||||
# 1) unencr header
|
||||
# telephone_pubkey_decr | op_pubkey_decr | op_privkey_decr
|
||||
unencr_header = self.pubkey_decr_ + BSEP2 + self.op.pubkey_encr_
|
||||
unencr_header = self.pubkey_encr_ + BSEP2 + self.op.pubkey_decr_
|
||||
|
||||
# 2) caller privkey?
|
||||
from_caller_privkey=caller.privkey_ if caller and json_caller else None
|
||||
@ -79,9 +88,9 @@ class TheTelephone(Operator):
|
||||
encrypted_message_to_operator = self.encrypt_outgoing(
|
||||
json_phone=json_phone,
|
||||
json_caller=json_caller,
|
||||
from_phone_privkey=phone_keychain['privkey'],
|
||||
from_phone_privkey=self.privkey_,
|
||||
from_caller_privkey=from_caller_privkey,
|
||||
to_pubkey=op_keychain['pubkey'],
|
||||
to_pubkey=self.op.pubkey_,
|
||||
unencr_header=unencr_header
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user