working on signing/verifying

macdev
quadrismegistus 4 years ago
parent a7443c0840
commit 2b4ba56c10

@ -1,4 +1,5 @@
#:import PostScreen screens.post.post.PostScreen
#:import COLOR_TEXT main.COLOR_TEXT
<AddPostTextField>
id: post_content_input
@ -13,9 +14,9 @@
size_hint: (1,None)
# size: ('300dp','300dp')
pos_hint: {'center_x': 0.5}
line_color_focus: 1,0,0,1
line_color_normal: 1,0,0,1
current_hint_text_color: 1,0,0,1
line_color_focus: rgb(*COLOR_TEXT)
line_color_normal: rgb(*COLOR_TEXT)
current_hint_text_color: rgb(*COLOR_TEXT)
# max_text_length: 1000
# mode:'fill'
font_size:'23dp'
@ -37,20 +38,20 @@
on_release: self.screen.choose()
#app.register(username.text, password.text)
theme_text_color: "Custom"
text_color: 1,0,0,1
text_color: rgb(*COLOR_TEXT)
md_bg_color: 0,0,0,1
font_size: '28sp'
# fill:1,0,0,1
# fill:rgb(*COLOR_TEXT)
font_name: 'assets/overpass-mono-regular.otf'
<PostButton>:
text: "post"
on_release: self.screen.post() #self.post_content_input.text, file_chooser_button.selection)
theme_text_color: "Custom"
text_color: 1,0,0,1
text_color: rgb(*COLOR_TEXT)
md_bg_color: 0,0,0,1
font_size: '28sp'
# fill:1,0,0,1
# fill:rgb(*COLOR_TEXT)
font_name: 'assets/overpass-mono-regular.otf'
<PostStatus>:
@ -59,10 +60,10 @@
size_hint:(None,None)
md_bg_color:0,0,0,1
pos_hint:{'center_x':.5, 'y':0.1}
text_color: 1,0,0,1
text_color: rgb(*COLOR_TEXT)
md_bg_color: 0,0,0,1
font_size: '25sp'
# fill:1,0,0,1
# fill:rgb(*COLOR_TEXT)
font_name: 'assets/overpass-mono-regular.otf'
<ProgressPopup>:
@ -83,7 +84,7 @@
# border_radius:20
canvas:
Color:
rgb: 1,0,0,1
rgb: rgb(*COLOR_TEXT)
Line:
width: 1
rectangle: (self.x, self.y, self.width, self.height)
@ -97,7 +98,7 @@
text: ''
halign: 'center'
theme_text_color: 'Custom'
text_color: 1,0,0,1
text_color: rgb(*COLOR_TEXT)
font_size: '18dp'
font_name: 'assets/overpass-mono-regular.otf'
pos_hint: {'center_x': .5, 'center_y': 0.5}
@ -108,7 +109,7 @@
size: '46dp','46dp'
pos_hint: {'center_x': .5, 'center_y': 0.5}
active: True
color:1,0,0,1
color:rgb(*COLOR_TEXT)
<MessagePopup>:
type: "custom"
@ -129,7 +130,7 @@
# border_radius:20
canvas:
Color:
rgb: 1,0,0,1
rgb: rgb(*COLOR_TEXT)
Line:
width: 1
rectangle: (self.x, self.y, self.width, self.height)
@ -144,7 +145,7 @@
halign: 'center'
# valign: 'middle'
theme_text_color: 'Custom'
text_color: 1,0,0,1
text_color: rgb(*COLOR_TEXT)
font_size: '18dp'
font_name: 'assets/overpass-mono-regular.otf'
pos_hint: {'center_x': .5, 'y': 0}

@ -12,6 +12,7 @@ from threading import Thread
from kivymd.uix.dialog import MDDialog
from kivy.core.image import Image as CoreImage
import io,shutil
from main import rgb,COLOR_TEXT
class ProgressPopup(MDDialog): pass
class MessagePopup(MDDialog): pass
@ -65,9 +66,9 @@ class PostScreen(ProtectedScreen):
post_json = {'author':self.app.username, 'timestamp':time.time()}
self.post_card = post = PostCard(post_json)
self.post_textfield = post_TextField = AddPostTextField()
post_TextField.line_color_focus=(1,0,0,1)
post_TextField.line_color_normal=(1,0,0,1)
post_TextField.current_hint_text_color=(1,0,0,1)
post_TextField.line_color_focus=rgb(*COLOR_TEXT)
post_TextField.line_color_normal=rgb(*COLOR_TEXT)
post_TextField.current_hint_text_color=rgb(*COLOR_TEXT)
post_TextField.font_name='assets/overpass-mono-regular.otf'
post_TextField.hint_text='word?'

@ -1,6 +1,6 @@
import os,time,sys,logging
from pathlib import Path
import asyncio
import asyncio,time
# handler = logging.StreamHandler()
# formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
# handler.setFormatter(formatter)
@ -129,6 +129,52 @@ class Api(object):
return res
return await _get()
def well_documented_val(self,val):
"""
What do we want to store with
1) Timestamp
2) Value
3) Public key of author
4) Signature of value by author
"""
from binascii import a2b_uu as ascii2binary
from binascii import b2a_uu as binary2ascii
timestamp=time.time()
self.log('timestamp =',timestamp)
value = str(val)
try:
value_bytes = value.encode('utf-8')
except UnicodeDecodeError:
value_bytes = value.encode('ascii')
#self.log('value =',value)
pem_public_key = save_public_key(self.public_key,return_instead=True)
#self.log('pem_public_key =',pem_public_key)
# stop
signature = sign_msg(value_bytes, self.private_key)
self.log('signature =',signature)
# value_bytes_ascii = ''.join([chr(x) for x in value_bytes])
# jsond = {'time':timestamp, 'val':value_bytes_ascii, 'pub':pem_public_key, 'sign':signature}
# jsonstr=jsonify(jsond)
sep=b'||||'
WDV = sep.join([str(timestamp).encode(), value_bytes,pem_public_key,signature])
# self.log('WDV = 'mWD)
# self.log(WDV.split(sep))
self.log('well_documented_val() =',WDV)
return WDV
async def set(self,key_or_keys,value_or_values):
async def _set():
@ -141,12 +187,12 @@ class Api(object):
keys = key_or_keys
values = value_or_values
assert len(keys)==len(values)
res = await asyncio.gather(*[node.set(key,value) for key,value in zip(keys,values)])
res = await asyncio.gather(*[node.set(key,self.well_documented_val(value)) for key,value in zip(keys,values)])
# self.log('RES?',res)
else:
key = key_or_keys
value = value_or_values
res = await node.set(key,value)
res = await node.set(key,self.well_documented_val(value))
#node.stop()
return res
@ -229,7 +275,7 @@ class Api(object):
return {'error':private_key_dat['error']}
if not 'success' in private_key_dat:
return {'error':'Incorrect password?'}
private_key = private_key_dat['success']
self._private_key = private_key = private_key_dat['success']
# see if user exists
person = await self.get_person(name)
@ -240,7 +286,7 @@ class Api(object):
# verify keys
person_public_key_pem = person['public_key']
public_key = load_public_key(person_public_key_pem.encode())
real_public_key = private_key.public_key()
self._public_key = real_public_key = private_key.public_key()
#log('PUBLIC',public_key.public_numbers())
#log('REAL PUBLIC',real_public_key.public_numbers())
@ -249,6 +295,18 @@ class Api(object):
return {'error':'Keys do not match!'}
return {'success':'Login successful', 'username':name}
@property
def public_key(self):
if not hasattr(self,'_public_key'):
self.app.root.change_screen('login')
return self._public_key
@property
def private_key(self):
if not hasattr(self,'_private_key'):
self.app.root.change_screen('login')
return self._private_key
async def append_json(self,key,data):
sofar=await self.get_json(key)
if sofar is None: sofar = []

Loading…
Cancel
Save