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-13 14:57:06 +01:00
parent 2799034d32
commit 4c8fa594e7
6 changed files with 31 additions and 23 deletions

View File

@ -267,7 +267,7 @@ class Keymaker(Logger):
def find_name(self,pubkey_b64):
q=pubkey_b64.decode() if type(pubkey_b64)!=str else pubkey_b64
print('Q?',q)
# print('Q?',q)
res = self.crypt_keys.get(q, prefix='/name/')
# self.log('result from crypt for name:',res)
return res

View File

@ -50,22 +50,28 @@ class Komrade(Caller):
## 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=''
# if not name and not self.name: name=''
## 1) Have name?
tolog=''
if SHOW_STATUS and show_intro:
name = self.cli.status_keymaker_part1(name)
self.name = name = self.cli.status_keymaker_part1(name)
elif not name:
name = input('@Keymaker: What is the name for this new account?\n@?: ')
self.log(f'Hello, this is Komrade @{name}.\n\nI would like to sign up for the socialist network revolution.')
self.log(f'@Keymaker: To communicate with komrades securely,\n\nyou must first cut your encryption keys. ')
self.name = name = input('\nHello, this is Komrade @')
print('\nI would like to sign up for the socialist network revolution.',flush=True)
do_pause()
else:
print(f'Hello, this is Komrade @{name}.\n\nI would like to sign up for the socialist network revolution.')
do_pause()
clear_screen()
self.log(f'@Keymaker: Excellent. But to communicate with komrades securely,\nyou must first cut your public & private encryption keys. ')
# do_pause()
## 2) Make pub public/private keys
keypair = KomradeAsymmetricKey()
pubkey,privkey = keypair.pubkey_obj,keypair.privkey_obj
self.log(f'@Keymaker: I have cut for you a private and public asymmetric key pair\nusing the Elliptic Curve algorithm from Themis cryptography library:\n\n(1) {pubkey}\n\n(2) {privkey}{ART_KEY_PAIR}')
self.log(f'@Keymaker: I have cut for you a private and public asymmetric key pair\nusing the Elliptic Curve algorithm from Themis cryptography library:\n\n(1) {pubkey}\n\n(2) {privkey}{ART_KEY_PAIR}',clear=False,pause=True)
## 3) Have passphrase?
if SHOW_STATUS and not passphrase:
@ -73,7 +79,7 @@ class Komrade(Caller):
else:
if not passphrase: passphrase = DEBUG_DEFAULT_PASSPHRASE
while not passphrase:
passphrase=getpass('@Keymaker: Enter a memorable password to encrypt your private key with: \n\n')
passphrase=getpass(f'@Keymaker: Enter a memorable password to encrypt your private key with: \n\n@{self.name}: ')
clear_screen()
self.passphrase=passphrase
## 4) Get hashed password
@ -83,7 +89,7 @@ class Komrade(Caller):
privkey_decr = KomradeSymmetricKeyWithPassphrase(passphrase)
privkey_encr = privkey_decr.encrypt(privkey.data)
privkey_encr_obj = KomradeEncryptedAsymmetricPrivateKey(privkey_encr)
self.log(f"@Keymaker: Store your private key on your device hardware ONLY\nand only as it was encrypted by your password-generated key:\n\n[Encrypted Private Key]\n({make_key_discreet_str(privkey_encr_obj.data_b64)})")
self.log(f"@Keymaker: Store your private key on your device hardware ONLY\nas it was encrypted by your password-generated key:\n\n[Encrypted Private Key]\n({make_key_discreet_str(privkey_encr_obj.data_b64)})")
## 6) Test keychain works
privkey_decr2 = KomradeSymmetricKeyWithPassphrase(passphrase)

View File

@ -43,7 +43,7 @@ class Operator(Keymaker):
# print('booting opertor with ...',name,pubkey,'??')
if pubkey:
print(pubkey,'pubkey !?')
# print(pubkey,'pubkey !?')
assert type(pubkey)==bytes
if isBase64(pubkey): pubkey = b64decode(pubkey)
# print(pubkey,keychain,'??',name)

View File

@ -21,8 +21,8 @@ class CLI(Logger):
def run(self,inp='',name=''):
self.name=name
clear_screen()
# self.boot()
# self.help()
self.boot()
self.help()
if inp: self.route(inp)
@ -36,6 +36,7 @@ class CLI(Logger):
def route(self,inp):
inp=inp.strip()
# print('route got:',inp)
if not inp.startswith('/'): return
cmd=inp.split()[0]
dat=inp[len(cmd):].strip()
@ -60,10 +61,11 @@ class CLI(Logger):
def intro(self):
self.status(None,)
def register(self,dat):
self.komrade = Komrade(self.name)
self.persona.register()
def register(self,name=None):
if not name: name=self.name
self.komrade = Komrade(name)
self.komrade.register()
self.name=self.komrade.name
@ -366,7 +368,7 @@ class CLI(Logger):
def run_cli():
cli = CLI()
cli.run('/register','elon') #'/register',name='elon')
cli.run() #'/register elon') #'/register',name='elon')
if __name__=='__main__':
run_cli()

View File

@ -161,5 +161,5 @@ PAUSE_LOGGER = 1
CLI_TITLE = 'KOMRADE'
CLI_FONT = 'clr5x6'#'colossal'
CLI_WIDTH = STATUS_LINE_WIDTH = 50
CLI_WIDTH = STATUS_LINE_WIDTH = 70

View File

@ -19,8 +19,8 @@ LOG = None
def log(*x):
global LOG
if not LOG: LOG=logger().debug
#if not LOG: LOG=logger().debug
if not LOG: LOG=print
tolog=' '.join(str(_) for _ in x)
LOG(tolog)
@ -70,7 +70,7 @@ class Logger(object):
calframe = inspect.getouterframes(curframe, 2)
mytype = type(self).__name__
caller = calframe[1][3]
log(f'[{mytype}.{caller}()]\n\n',*x)
log(f'[{mytype}.{caller}()]'.center(CLI_WIDTH) + '\n\n',*x)
# try:
if pause: do_pause()