keys-on-cli
quadrismegistus 4 years ago
parent 6c50d125f9
commit 19b3182db4

@ -3,6 +3,7 @@ from .art import *
from .constants import *
from .utils import *
# common python imports
import os,sys
from collections import defaultdict
@ -11,14 +12,31 @@ import ujson as json
import binascii,asyncio
from pprint import pprint
# 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
try:
import getch
def getpass(prompt):
"""Replacement for getpass.getpass() which prints asterisks for each character typed"""
print(prompt, end='', flush=True)
buf = ''
while True:
ch = getch.getch()
if ch == '\n':
print('')
break
else:
buf += ch
print('*', end='', flush=True)
return buf
except ImportError:
from getpass import getpass
from backend import *

@ -24,6 +24,14 @@ ART_TELEPHONE = '''
'''
ART_KEY = """
8 8 8 8 ,ooo.
8a8 8a8 oP ?b
d888a888zzzzzzzzzzzzzzzzzzzz8 8b
`""^""' ?o___oP'
"""
ART_OLDPHONE = """
__
@ -40,6 +48,24 @@ ART_OLDPHONE = """
jgs '.______.'
"""
ART_OLDPHONE2="""
_|~|/|
( | | |
/_|_|\|
| |
| |~|
| | |
| | |
| |-|
| | \
| |__|
|_|_
/ ~-_
/ ~-_
|___________|
"""
ART_ROTARY = """
_...----..._
@ -59,4 +85,101 @@ ART_ROTARY = """
`. `-' ( 0 ) ,'`
`-._ `-' _.-'
```----''' SSt
"""
ART_PHONE_DIAGRAM = """
________
.' / / )
/ /##/ /|
/ `--' / |
/__ __ __ / |
//_//_//_// / __
//_//_//_// / \`.___ Listening end
//_//_//_// /
//_//_//_// /__
/ / / \`.___ Buttons
/ .-. / /
/ /#/ / /
/ `-' / /__
/ .====. / / \`.___ Speaking end
|`--------' /
\ , .'__
`-//----' \`.___ Disconnect button
//
"""
ART_OLDPHONE3 = """
__ _
.: .' '.
/: / \_
;: ; ,-'/`:\
|: | | |():|
;: ; '-.\_:/
\: \ /`
':_'._.'
||
/__\
.---. {====}
.' _,"-,__|:: |
/ ((O)=;--.:: |
; `|: | |:: |
| |: | |:: |
| |: | |:: |
| |: | |:: |
| |: | |:: |
| |: | |:: |
| /:'__\ |:: |
| [______]|:: |
| `----` |:: |__
| _.--|:: | ''--._
; .' __{====}__ '.
\ .'_.-'._ `""` _.'-._ '.
'--'/` `''''` `\ '.__
jgs '._ _.'
`""--......--""`
"""
ART_OLDPHONE4 = """
__
/` _`\
| (_()| .-.
\_ _/_/ \
||=[_] |
|| | | |
||/ \ |
||`---' /
.--'||-.___.'
/` .-||-.
'-/`.____.`\
jgs '.______.'
"""
ART_PAYPHONE = """
_________________
/ __ \
| (__) |
| |
| .-----. .--. |
| | | / \ |
| '-----' \ / |
| | | |
| LI LI LI | | |
| LI LI LI | | |Oo
| LI LI LI | | |`Oo
| LI LI LI | | | Oo
| | | | Oo
| .------. / \ | oO
| | | \ / | Oo
| '------' '-oO | oO
| .---Oo | Oo
| || ||`Oo oO
| |'--'| | OoO
| '----' |
jgs \_________________/
"""

@ -5,7 +5,7 @@ from komrade.backend import *
class Persona(Caller):
def __init__(self, name, passphrase=DEBUG_DEFAULT_PASSPHRASE):
def __init__(self, name=None, passphrase=DEBUG_DEFAULT_PASSPHRASE):
super().__init__(name=name,passphrase=passphrase)
# self.boot(create=False)
@ -42,23 +42,66 @@ class Persona(Caller):
# def login(self):
# if keys.get('pubkey') and keys.get('privkey')
def register(self, name = None, passphrase = DEBUG_DEFAULT_PASSPHRASE, is_group=None):
def register(self, name = None, passphrase = None, is_group=None):
# defaults
if name and not self.name: self.name=name
if not name and self.name: name=self.name
if not name and not self.name: name=''
# ring ring!
ticks = ['*ring*','*ring ring*','*ring*']
self.status(None,ART_OLDPHONE3,3,pause=False,ticks = ticks)
# hello, op?
self.status(f'\n\n@{name if name else "?"}: Uh yes hello, Operator? I would like to join Komrade, the socialist network. Could you patch me through?',clear=True,pause=True)
while not name:
name=self.status(('name','@TheOperator: Of course, Komrade ...?\n@'),clear=False).get('vals',{}).get('name')
print()
self.name=name
self.status(f"@TheOperator: Of course, Komrade @{name}. A fine name. First, though, let me see if by an awkward accident someone has already taken this name.",clear=False)
# does username exist
res = self.exists_on_server()
self.status('I got this result',res,clear=False)
stop
exit()
self.status([
f'@{name}: Uh yes hello, Operator? Could I please register as Komrade @{name}?',
ART_OLDPHONE,
'''@TheOperator: Sure, but it's not safe for me to cut the keys you need. Why don't you do that yourself, and come back to me when you've cut a special "asymmetric" key in half: you can keep both halves, and I'll keep one, that way we'll always know we're talking to each other.''',
f'@{name}: Ok but how do I cut these keys?',
'''@TheOperator: I could, it's not safe yet. Your information will be exposed all over the internet. You should forge your encryption keys first.''',
f'@{name}: Fine, but how do I do that?',
'@TheOperator: Visit the Keymaker.'
])
# get needed metadata
if not name: name=self.name
if name is None:
name = input('\nWhat is the name for this account? ')
if passphrase is None:
passphrase = getpass.getpass('\nEnter a memborable password: ')
# if is_group is None:
# is_group = input('\nIs this a group account? [y/N]').strip().lower() == 'y'
# ring ring!
self.status([None,ART_KEY,2],pause=False)
# some info
res = self.status([
# ART_KEY,
f'{ART_KEY}@{name}: Dear @Keymaker, I would like to forge a new set of keys.',
f'''@Keymaker: We will make two. A matching, "asymmetric" pair:''',
'\t1) A "public key" you can share with anyone.',
'\t2) A "private key" other no one can ever, ever see.',
'With both together, you can communicate privately and securely with anyone who also has their own key pair.'
])
while not passphrase:
passphrase1 = getpass(f'What is a *memorable* pass word or phrase? Do not write it down.\n@{name}: ')
passphrase2 = getpass(f'Could you repeat that?')
if passphrase1!=passphrase2:
self.status('Those passwords didn\'t match. Please try again.',clear=False,pause=False)
else:
passphrase=passphrase1
# if not name or name=='?': self.name = name = res['vals'].get('name')
res = self.status([
('passphrase',f'\nWhat is a memorable pass word or phrase? \n@{name}: ',getpass) if not passphrase else False
('passphrase2',f'\Could you repeat that? \n@{name}: ',getpass) if not passphrase else False
],clear=False)
if not passphrase:
p1,p2=res.get('passphrase'),res.get('passphrase2')
# if p1!=p2
# passphrase = passphrase
# make and save keys locally
uri_id,keys_returned = self.forge_new_keys(
@ -101,8 +144,9 @@ class Persona(Caller):
def test_register():
import random
num = random.choice(list(range(0,1000)))
botname=f'marx{str(num).zfill(3)}'
marxbot = Persona(botname)
# botname=f'marx{str(num).zfill(3)}'
# marxbot = Persona(botname)
marxbot=Persona()
marxbot.register()
if __name__=='__main__':

@ -50,7 +50,7 @@ def dict_format(d, tab=0):
s.append('%s}' % (' '*tab))
return ''.join(s)
import inspect
import inspect,time
from komrade.constants import PAUSE_LOGGER
class Logger(object):
def log(self,*x,pause=PAUSE_LOGGER,clear=PAUSE_LOGGER):
@ -66,12 +66,44 @@ class Logger(object):
# except KeyboardInterrupt:
exit()
def status(self,status_msg):
def status(self,*msg,pause=True,clear=True,ticks=[],tab=2):
# if len(msg)==1 and type(msg[0])==str:
# msg=[x for x in msg[0].split('\n\n')]
if clear: clear_screen()
paras=[]
for para in status_msg.split('\n\n'):
self.log(para.strip(),pause=True,clear=False)
paras.append(para)
return paras
res={}
for para in msg:
plen = para if type(para)==int or type(para)==float else None
if type(para) in {int,float}:
plen=int(para)
for i in range(plen):
tick = ticks[i] if i<len(ticks) else '.'
print(tick,end=' ',flush=True)
time.sleep(1)
elif para is None:
clear_screen()
elif para is False:
pass
elif type(para) is tuple:
k=para[0]
q=para[1]
f=para[2] if len(para)>2 else input
ans=None
while not ans:
ans=f(q).strip()
res[k]=ans
elif type(para) is dict:
print(dict_format(para,tab=tab))
elif para is 0:
do_pause()
elif pause:
print(para,flush=True)
paras+=[para]
do_pause()
else:
print(para,flush=True)
paras+=[para]
return {'paras':paras, 'vals':res}
import binascii,base64
def isBase64(sb):

Loading…
Cancel
Save