Skip to content
This repository has been archived by the owner on May 23, 2019. It is now read-only.

Commit

Permalink
Merge pull request #37 from bilelmoussaoui/beta
Browse files Browse the repository at this point in the history
Flatpak builds
  • Loading branch information
bilelmoussaoui authored Mar 16, 2018
2 parents a460e61 + 5060a71 commit d5d376f
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 65 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ tags
# C extensions
*.so
*.po~
test/

# Distribution / packaging
builddir/
Expand Down
24 changes: 13 additions & 11 deletions Authenticator/models/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
You ould have received a copy of the GNU General Public License
along with Authenticator. If not, see <http://www.gnu.org/licenses/>.
"""
from collections import OrderedDict
import sqlite3
from os import path, makedirs

Expand Down Expand Up @@ -61,12 +62,12 @@ def insert(self, name, secret, image):
try:
self.conn.execute(query, [name, secret, image])
self.conn.commit()
return {
"id": self.latest_id,
"name": name,
"secret_id": secret,
"image": image
}
return OrderedDict([
("id", self.latest_id),
("name", name),
("secret_id", secret),
("image", image)
])
except Exception as error:
Logger.error("[SQL] Couldn't add a new account")
Logger.error(str(error))
Expand Down Expand Up @@ -139,11 +140,12 @@ def accounts(self):
try:
data = self.conn.cursor().execute(query)
accounts = data.fetchall()
return [{"id": account[0],
"name": account[1],
"secret_id": account[2],
"logo": account[3]
} for account in accounts]
return [OrderedDict([
("id", account[0]),
("name", account[1]),
("secret_id", account[2]),
("logo", account[3])
]) for account in accounts]
except Exception as error:
Logger.error("[SQL] Couldn't fetch accounts list")
Logger.error(str(error))
Expand Down
6 changes: 3 additions & 3 deletions Authenticator/models/keyring.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def get_default():
def get_by_id(id_):
"""Return the secret code"""
schema = Keyring.get_default().schema
password = Secret.password_lookup_sync(schema, { "id": id_ }, None)
password = Secret.password_lookup_sync(schema, { "id": str(id_)}, None)
return password

@staticmethod
Expand All @@ -55,7 +55,7 @@ def insert(id_, secret_code):
"""
schema = Keyring.get_default().schema
Secret.password_store_sync(schema, {
"id": id_,
"id": str(id_),
}, Secret.COLLECTION_DEFAULT, "", secret_code, None)

@staticmethod
Expand All @@ -66,5 +66,5 @@ def remove(id_):
:return: bool
"""
schema = Keyring.get_default().schema
removed = Secret.password_clear_sync(schema, { "id": id_ }, None)
removed = Secret.password_clear_sync(schema, { "id": str(id_)}, None)
return removed
20 changes: 5 additions & 15 deletions Authenticator/models/qr_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from urllib.parse import urlparse, parse_qsl

from PIL import Image
import zbarlight
from pyzbar.pyzbar import decode

from .code import Code
from .logger import Logger
Expand All @@ -34,27 +34,17 @@ def __init__(self, filename):
self._codes = None

def read(self):
with open(self.filename, 'rb') as image_file:
image = Image.open(image_file)
image.load()
self._codes = zbarlight.scan_codes('qrcode', image)
self.remove()
self._codes = decode(Image.open(self.filename))
if path.isfile(self.filename):
remove(self.filename)
if self._codes:
otpauth_url = self._codes[0].decode()
otpauth_url = self._codes[0].data.decode()
self._codes = dict(parse_qsl(urlparse(otpauth_url)[4]))
return self._codes.get("secret")
else:
Logger.error("Invalid QR image")
return None

def remove(self):
"""
remove image file for security reasons
"""
if path.isfile(self.filename):
remove(self.filename)
Logger.debug("QR code image was removed for security reasons")

def is_valid(self):
"""
Validate if the QR code is a valid tfa
Expand Down
4 changes: 3 additions & 1 deletion Authenticator/widgets/accounts/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ def _fill_data(self):
file = Gio.File.new_for_uri(uri)
content = str(file.load_contents(None)[1].decode("utf-8"))
data = json.loads(content)
for name, logo in data.items():
data = sorted([(name, logo) for name, logo in data.items()], key=lambda entry: entry[0])
for entry in data:
name, logo = entry
self._listbox.add(AccountRow(name, logo))


Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ version](https://img.shields.io/badge/python-3.3%2B-blue.svg)
- `ninja`
- `pyotp`
- `Pillow`
- `zbarlight` depends on `zbar`
- `pyzbar` depends on `zbar`
- `libzbar-dev` on Ubuntu
- `zbar` on Arch
- `libsecret`
Expand Down
44 changes: 10 additions & 34 deletions com.github.bilelmoussaoui.Authenticator.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,13 @@
/* Wayland */
"--socket=wayland",
/* Filesystem */
"--filesystem=host",
"--filesystem=~/.config/Authenticator:ro",
/* Keyring */
"--talk-name=org.freedesktop.secrets",
/* dconf */
"--filesystem=xdg-run/dconf", "--filesystem=~/.config/dconf:ro",
"--talk-name=ca.desrt.dconf", "--env=DCONF_USER_CONFIG_DIR=.config/dconf"
],
"cleanup": [
"/include",
"/lib/pkgconfig",
"/share/pkgconfig",
"/share/aclocal",
"/man",
"/share/man",
"/share/gtk-doc",
"/share/vala",
"*.la",
"*.a"
],
"build-options": {
"cflags": "-O2 -g",
"cxxflags": "-O2 -g",
Expand All @@ -37,12 +27,10 @@
"modules": [{
"name": "zbar",
"config-opts": [
"--prefix=/app",
"--without-qt",
"--without-gtk",
"--without-imagemagick",
"--disable-video",
"CFLAGS=-DNDEBUG"
"--disable-video"
],
"sources": [{
"type": "archive",
Expand Down Expand Up @@ -102,28 +90,15 @@
]
},
{
"name": "setuptools",
"name": "pyzbar",
"buildsystem": "simple",
"build-commands": [
"python3 bootstrap.py",
"python3 setup.py install --prefix=/app --root=/"
],
"sources": [{
"type": "archive",
"url": "https://github.com/pypa/setuptools/archive/38.2.5.tar.gz",
"sha256": "999acfc0f6eae7309b4a78118573e5948478cfda68061a5719cf9d475ddced0a"
}]
},
{
"name": "zbarlight",
"buildsystem": "simple",
"build-commands": [
"python3 setup.py install --prefix=/app --root=/"
],
"sources": [{
"type": "archive",
"url": "https://github.com/Polyconseil/zbarlight/archive/2.0.tar.gz",
"sha256": "92329b5496c7a86f2103f1ee15b1269dcff6011cb096948efafd349473b955a9"
"url": "https://github.com/NaturalHistoryMuseum/pyzbar/archive/v0.1.4.tar.gz",
"sha256": "7387899656e4e9564b7e507b2c26729c4863b7a79bbaf29c80c956a5654d2ee0"
}]
},
{
Expand All @@ -139,8 +114,9 @@
"buildsystem": "meson",
"sources": [{
"type": "git",
"url": "https://github.com/bilelmoussaoui/Authenticator"
- }]
"url": "https://github.com/bilelmoussaoui/Authenticator",
"branch": "beta"
}]
}
]
}

0 comments on commit d5d376f

Please sign in to comment.