Skip to content

Commit

Permalink
App successfully saves credentials in keyring.json
Browse files Browse the repository at this point in the history
  • Loading branch information
GijsTimmers committed Mar 6, 2015
1 parent b4e2a18 commit bd7261d
Show file tree
Hide file tree
Showing 3 changed files with 262 additions and 7 deletions.
19 changes: 17 additions & 2 deletions app-development/androidapp.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
#!/usr/bin/python
#!/usr/bin/env python2
# -*- coding: utf-8 -*-

## Dependencies: python-mechanize, python-keyring, curses
## Author: Gijs Timmers: https://github.com/GijsTimmers
## Contributors: Gijs Timmers: https://github.com/GijsTimmers
## Jo Van Bulck: https://github.com/jovanbulck

## Licence: CC-BY-SA-4.0
## https://creativecommons.org/licenses/by-sa/4.0/

## This work is licensed under the Creative Commons
## Attribution-ShareAlike 4.0 International License. To view a copy of
## this license, visit https://creativecommons.org/licenses/by-sa/4.0/ or
## send a letter to Creative Commons, PO Box 1866, Mountain View,
## CA 94042, USA.

from kivy.app import App
from kivy.uix.scatter import Scatter
Expand Down Expand Up @@ -32,7 +47,7 @@ def __init__(self):
self.b = BoxLayout(orientation="vertical")

bnrtitle = Label(text="kotnetcli", font_size=30, size_hint_y=None, height=60)
bnrsubtitle = Label(text="by Gijs Timmers and Jo van Bulck", font_size=14, size_hint_y=None, height=30)
bnrsubtitle = Label(text="by Gijs Timmers and Jo Van Bulck", font_size=14, size_hint_y=None, height=30)

kli = Button(text="Inloggen", font_size=40, size_hint_y = 0.4)
klo = Button(text="Uitloggen", font_size=40, size_hint_y = 0.4)
Expand Down
25 changes: 20 additions & 5 deletions app-development/labeltest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
#!/usr/bin/python
#!/usr/bin/env python2
# -*- coding: utf-8 -*-

## Dependencies: python-mechanize, python-keyring, curses
## Author: Gijs Timmers: https://github.com/GijsTimmers
## Contributors: Gijs Timmers: https://github.com/GijsTimmers
## Jo Van Bulck: https://github.com/jovanbulck

## Licence: CC-BY-SA-4.0
## https://creativecommons.org/licenses/by-sa/4.0/

## This work is licensed under the Creative Commons
## Attribution-ShareAlike 4.0 International License. To view a copy of
## this license, visit https://creativecommons.org/licenses/by-sa/4.0/ or
## send a letter to Creative Commons, PO Box 1866, Mountain View,
## CA 94042, USA.

from kivy.app import App

Expand All @@ -12,13 +27,13 @@ def scherm():
b = BoxLayout(orientation="vertical")

bnrtitle = Label(text="kotnetcli", font_size=30, size_hint_y=None, height=60)
bnrsubtitle = Label(text="by Gijs Timmers and Jo van Bulck", font_size=14, size_hint_y=None, height=30)
bnrsubtitle = Label(text="by Gijs Timmers and Jo Van Bulck", font_size=14, size_hint_y=None, height=30)

## Kopieer: cp /usr/share/fonts/truetype/droid/DroidSansMono.ttf .
outputtekst = Label(text="Netlogin openen... [ OK ]\n" + \
"Gegevens invoeren... [ OK ]\n" + \
"Gegevens opsturen... [ OK ]",
font_size=20, font_name="DroidSansMono.ttf")
"Gegevens invoeren... [ OK ]\n" + \
"Gegevens opsturen... [ OK ]",
font_size=20, font_name="DroidSansMono.ttf")

b.add_widget(bnrtitle)
b.add_widget(bnrsubtitle)
Expand Down
225 changes: 225 additions & 0 deletions app-development/meerdere_schermen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
#!/usr/bin/env python2
# -*- coding: utf-8 -*-

## Dependencies: python-mechanize, python-keyring, curses
## Author: Gijs Timmers: https://github.com/GijsTimmers
## Contributors: Gijs Timmers: https://github.com/GijsTimmers
## Jo Van Bulck: https://github.com/jovanbulck

## Licence: CC-BY-SA-4.0
## https://creativecommons.org/licenses/by-sa/4.0/

## This work is licensed under the Creative Commons
## Attribution-ShareAlike 4.0 International License. To view a copy of
## this license, visit https://creativecommons.org/licenses/by-sa/4.0/ or
## send a letter to Creative Commons, PO Box 1866, Mountain View,
## CA 94042, USA.

import re
import sys


from kivy.app import App
from kivy.lang import Builder
from kivy.storage.jsonstore import JsonStore

from kivy.uix.screenmanager import ScreenManager, Screen, NoTransition

# Create both screens. Please note the root.manager.current: this is how
# you can control the ScreenManager from kv. Each screen has by default a
# property manager that gives you the instance of the ScreenManager used.
Builder.load_string("""
<MenuScreen>:
BoxLayout:
id: hoofdbox
orientation: "vertical"
BoxLayout:
id: titelbox
orientation: "vertical"
size_hint_y: 0.15
Label:
text: "kotnetcli"
font_size: 30
size_hint_y: 0.6
Label:
text: "by Gijs Timmers and Jo Van Bulck"
font_size: 14
size_hint_y: 0.4
BoxLayout:
id: knoppenbox
orientation: "vertical"
Button:
id: inlogknop
text: "Inloggen"
on_press:
#root.manager.current = "action"
root.inloggen()
Button:
id: uitlogknop
text: "Uitloggen"
on_press:
root.manager.current = "action"
root.uitloggen()
Button:
id: instellingenknop
text: "Instellingen"
on_press: root.manager.current = "settings"
Label:
id: outputvak
text: "Netlogin openen... [ OK ]\\nGegevens invoeren... [ OK ]\\nGegevens opsturen... [ OK ]"
font_size: 20
font_name: "DroidSansMono.ttf"
Button:
id: terugknop
text: "Terug naar hoofdmenu"
#on_press: root.manager.current = "menu"
on_press: root.herteken_hoofdmenu()
Button:
id: afsluitknop
text: "Afsluiten"
on_press: root.afsluiten()
<SettingsScreen>:
BoxLayout:
orientation: "vertical"
Label:
text: "kotnetcli"
font_size: 30
size_hint_y: None
height: 60
Label:
text: "by Gijs Timmers and Jo Van Bulck"
font_size: 14
size_hint_y: None
height: 30
TextInput:
id: veld_gebruikersnaam
hint_text: "Gebruikersnaam"
multiline: False
size_hint_y: None
height: 30
keyboard_suggestions: False
password: False
write_tab: False
#on_text_validate: root.stelGebruikersnaamIn(self.text)
TextInput:
id: veld_wachtwoord
hint_text: "Wachtwoord"
multiline: False
size_hint_y: None
height: 30
keyboard_suggestions: False
password: True
write_tab: False
#on_text_validate: root.stelWachtwoordIn(self.text)
Button:
text: "Opslaan"
size_hint_y: 0.3
on_press: root.toonData()
Label:
id: toonvak
text: "Nog geen data ontvangen..."
Button:
text: "Terug naar hoofdmenu"
size_hint_y: 0.2
on_press: root.manager.current = 'menu'
""")



class MenuScreen(Screen):
def inloggen(self):
print "Wens tot inloggen ontvangen."

print self.ids

self.ids["knoppenbox"].remove_widget(self.ids["inlogknop"])
self.ids["knoppenbox"].remove_widget(self.ids["uitlogknop"])
self.ids["knoppenbox"].remove_widget(self.ids["instellingenknop"])


def uitloggen(self):
print "Wens tot uitloggen ontvangen."

def herteken_hoofdmenu(self):
self.ids["knoppenbox"].add_widget(self.ids["inlogknop"])
self.ids["knoppenbox"].add_widget(self.ids["uitlogknop"])
self.ids["knoppenbox"].add_widget(self.ids["instellingenknop"])


self.ids["knoppenbox"].remove_widget(self.ids["outputvak"])
self.ids["knoppenbox"].remove_widget(self.ids["terugknop"])
self.ids["knoppenbox"].remove_widget(self.ids["afsluitknop"])


class ActionScreen(Screen):
def inloggen(self):
print "Inloggen op actiescherm."
def afsluiten(self):
print "Sluit nu af."
sys.exit()

class SettingsScreen(Screen):
def toonData(self):
self.gebruikersnaam = self.ids["veld_gebruikersnaam"].text
self.wachtwoord = self.ids["veld_wachtwoord"].text

print "Nu ingevoerd: "
print "----------------"
print "Gebruikersnaam: " + self.gebruikersnaam
print "Wachtwoord: " + self.wachtwoord
print "----------------"

## Als de gebruikersnaam geen geldig s-/r-nummer is, of het wachtwoord
## is leeg, dan melden we dat.
if (not re.match("[a-z][0-9]+", self.gebruikersnaam)) or (self.wachtwoord == ""):
print "--> Check gegevens"
self.ids["toonvak"].text = "Controleer uw gegevens."
else:
keyring = JsonStore("keyring.json")
keyring.put("kotnetcli", \
gebruikersnaam = self.gebruikersnaam, \
wachtwoord = self.wachtwoord)

#print "gebruikersnaam in keyring: ", keyring.get("kotnetcli")["gebruikersnaam"]
#print "wachtwoord in keyring: ", keyring.get("kotnetcli")["wachtwoord"]
print "--> Opgeslagen"
self.ids["toonvak"].text = "Opgeslagen."



# Create the screen manager
sm = ScreenManager(transition=NoTransition())
sm.add_widget(MenuScreen(name="menu"))
#sm.add_widget(ActionScreen(name="action"))
sm.add_widget(SettingsScreen(name="settings"))

class TestApp(App):

def build(self):
return sm

if __name__ == '__main__':
TestApp().run()

4 comments on commit bd7261d

@GijsTimmers
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some notes here:

  • The most advanced version is meerdere_schermen.py. Please run this file.
  • meerdere_schermen.py consists of a part written in the Kivy language, and a part written in Python. The idea is to let the .kv part do most of the designing stuff, and the .py part do most of the interactions. As expected, it's a PITA to let them work together nicely.
  • Credentials are successfully saved in the unencrypted keyring.json.

@jovanbulck
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool!

@GijsTimmers
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to put the kivy layout in a separate .kv file instead of in a string as done here

That's certainly possible, but requires some work to make it load at the right time.

(...) we probably want to use this in a separate AndroidKeyring.py to implement the API of our credentials.py so that is can be passed on to a worker instance.

Absolutely, everything here is proof-of-concept. Once it works, we can start replacing code by true kotnetcli methods.

Maybe we could also use encryption

The URL you provided does not give information on how to encrypt the data. The problem here is that even if we encrypt the credentials, the encryption key would still be easy to find by looking in kotnetcli's source code.

Still, encrypting it with a known key would at least protect the credentials from being read by other apps, and it would also prevent novice users from easily reading someone's credentials by just going into kotnetcli's config directory. So maybe we should just do it.

@jovanbulck
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely, everything here is proof-of-concept. Once it works, we can start replacing code by true kotnetcli methods.

Ok, check my last post in issue #39 for a class diagram depicting the back-end integration

You're right about the encryption, I think. We'll see how we can improve security maybe...

Please sign in to comment.