2
0
mirror of https://github.com/ComradCollective/Comrad synced 2024-11-05 21:20:51 +00:00
This commit is contained in:
quadrismegistus 2020-09-15 07:10:22 +01:00
parent 24867f37ad
commit e9e6910028
2 changed files with 94 additions and 16 deletions

View File

@ -347,19 +347,44 @@ class KomradeX(Caller):
self.log('inbox decrypted:',inbox)
unread = []
for post_id in inbox.split(b'\n'):
inbox = inbox.split(b'\n')
for post_id in inbox:
if not post_id: continue
print('>>',x)
already = self.crypt_keys.get(
post_id,
prefix='/post/',
)
print('>>',post_id)
if not self.crypt_keys.get(post_id,prefix='/post/'):
unread.append(post_id)
self.log(f'I {self} have {len(unread)} new messages')
# print('unread:',unread,len(unread))
return {'success':'?'}
return {
'success':True,
'status':'Inbox retrieved.',
'unread':unread,
'inbox':inbox
}
def read_msgs(self,post_ids=[],inbox=None):
if not post_ids:
# get unerad
post_ids = self.check_msgs(inbox).get('unread',[])
if not post_ids:
return {'success':False,'status':'No messages requested'}
# ask Op for them
msgs = self.ring_ring(
{
'secret_login':self.secret_login,
'name':self.name,
'pubkey':self.pubkey.data_b64,
'post_ids':post_ids,
},
route='read_msgs'
)
self.log('got back from op!',msgs)
return msgs
def test_register():
import random
@ -372,12 +397,14 @@ def test_register():
def test_msg():
z = comlink('zuck')
z.login(passphrase='eee')
b = Komrade('bez')
b.login()
print(b.check_msgs())
# z = Komrade('zuckbot')
s = comlink('sergey')
z.send_msg_to('you ssssssuck')
# b.msg(z,'you ssssssuck')
def test_loading():
@ -396,6 +423,22 @@ def test_loading():
# z1.login()
def test_sign():
from pythemis import smessage
b = Komrade('bez')
m = Komrade('marx')
z = Komrade('zuckbot')
msg = b'this is cool. --bez'
signed_msg = smessage.ssign(b.privkey.data, msg)
print(signed_msg)
verified_msg = smessage.sverify(b.pubkey.data, signed_msg)
print(verified_msg)
if __name__=='__main__':
test_loading()
test_msg()

View File

@ -387,7 +387,12 @@ from_komrade = {from_komrade}
).wrap(inbox_new)
self.log('encrypted inbox new:',inbox_new_encr)
self.crypt_keys.set(deliver_to,inbox_new_encr,prefix='/inbox/')
self.crypt_keys.set(
deliver_to,
inbox_new_encr,
prefix='/inbox/',
override=True
)
return {'status':'Message delivered.', 'success':True}
@ -417,7 +422,37 @@ from_komrade = {from_komrade}
'success':True,
'data_encr':inbox_encr
}
def read_msgs(self,
msg_to_op,
required_fields = [
'secret_login',
'name',
'pubkey',
'post_ids',
]):
# logged in?
login_res = self.login(msg_to_op)
if not login_res.get('success'):
return login_res
# ok, then find the posts?
post_ids=msg_to_op.data.get('post_ids',[])
if not post_ids: return {'success':False, 'status':'No post_ids specified'}
posts = {}
for post_id in post_ids:
post = self.crypt_keys.get(b64enc(post_id),prefix='/post/')
if post:
posts[post_id] = post
self.log(f'I {self} found {len(posts)} for {msg_to_op.from_name}')
return {
'status':'Succeeded in getting posts.',
'success':True,
'data_encr':posts
}
def test_op():
from komrade.backend.the_telephone import TheTelephone