Commit a56896ae authored by Danish Prakash's avatar Danish Prakash

Formatting and other pep8 fixes

parent 8ca1b358
......@@ -55,7 +55,7 @@ class Application(Gtk.Application):
quit_action = Gio.SimpleAction.new("quit", None)
quit_action.connect("activate", self.on_quit_menu_clicked)
shortcuts_action = Gio.SimpleAction.new("shortcuts", None)
shortcuts_action.connect("activate", self.on_shortcuts_menu_clicked)
......@@ -78,7 +78,7 @@ class Application(Gtk.Application):
def on_quit_menu_clicked(self, action, param):
self.quit()
def on_shortcuts_menu_clicked(self, action, param):
builder = Gtk.Builder()
builder.add_from_resource("/org/gnome/PasswordSafe/shortcuts_overview.ui")
......@@ -114,6 +114,7 @@ class Application(Gtk.Application):
self.set_accels_for_action("app.db.add_entry", ["<Control>e"])
self.set_accels_for_action("app.db.add_group", ["<Control>g"])
if __name__ == "__main__":
app = Application()
app.run(sys.argv)
......
import os
from os.path import exists, join
from gi.repository import GLib, Gio
setting = Gio.Settings.new("org.gnome.PasswordSafe")
......
from gi.repository import Gtk
import gi
class ContainerPage(Gtk.Box):
......
from gi.repository import Gtk, GLib
from passwordsafe.created_database import CreatedDatabase
from gettext import gettext as _
import gi
import threading
import passwordsafe.keyfile_generator
......
from gi.repository import Gtk
from passwordsafe.unlock_database import UnlockDatabase
import gi
class CreatedDatabase:
......
from pykeepass import PyKeePass
from passwordsafe.logging_manager import LoggingManager
import passwordsafe.config_manager
import re
import hashlib
......@@ -66,7 +64,7 @@ class DatabaseManager:
else:
return group.notes
# Return the belonging icon for a group object
# Return the belonging icon for a group object
def get_group_icon_from_group_object(self, group):
return group.icon
......@@ -467,7 +465,7 @@ class DatabaseManager:
return True
else:
return False
# Search for an entry or a group by (part of) name, username, url and notes, returns list of uuid's, search fulltext optionally
def global_search(self, string, fulltext):
lstring = str.lower(string)
......@@ -480,16 +478,16 @@ class DatabaseManager:
if lstring in str.lower(self.get_group_notes_from_group_object(group)):
if group.is_root_group is False:
uuid_list.append(group.uuid)
for entry in self.db.entries:
if lstring in str.lower(self.get_entry_name_from_entry_object(entry)):
uuid_list.append(entry.uuid)
if fulltext is True:
if lstring in str.lower(self.get_entry_username_from_entry_object(entry)) or string in str.lower(self.get_entry_url_from_entry_object(entry)) or string in str.lower(self.get_entry_notes_from_entry_object(entry)):
uuid_list.append(entry.uuid)
return uuid_list
# Search one group for a string, search fulltext optionally, returns list of uuid's of groups and entries
def local_search(self, group, string, fulltext):
lstring = str.lower(string)
......@@ -502,16 +500,15 @@ class DatabaseManager:
if lstring in str.lower(self.get_group_notes_from_group_object(group)):
if group.is_root_group is False:
uuid_list.append(group.uuid)
for entry in group.entries:
if lstring in str.lower(self.get_entry_name_from_entry_object(entry)):
uuid_list.append(entry.uuid)
if fulltext is True:
if lstring in str.lower(self.get_entry_username_from_entry_object(entry)) or string in str.lower(self.get_entry_url_from_entry_object(entry)) or string in str.lower(self.get_entry_notes_from_entry_object(entry)):
uuid_list.append(entry.uuid)
return uuid_list
return uuid_list
# Check if object is group
def check_is_group(self, uuid):
......
from gettext import gettext as _
from gi.repository import Gtk, GLib, Gio
from gi.repository import Gtk, GLib
from random import randint
from threading import Timer
import gi
import ntpath
import passwordsafe.config_manager
import passwordsafe.keyfile_generator
......@@ -394,7 +392,7 @@ class DatabaseSettingsDialog():
# Derivation Algorithm
der_alg = "Argon2"
if version == (3,1):
if version == (3, 1):
der_alg = "AES-KDF"
self.builder.get_object("label_der_alg").set_text(der_alg)
......@@ -416,7 +414,7 @@ class DatabaseSettingsDialog():
self.groups_number = len(self.database_manager.db.groups)
self.passwords_number = 0
for entry in self.database_manager.db.entries:
if entry.password != None and entry.password != "":
if entry.password is not None and entry.password != "":
self.passwords_number = self.passwords_number + 1
GLib.idle_add(self.set_stats_values)
......@@ -436,9 +434,9 @@ class DatabaseSettingsDialog():
der_alg_list = self.builder.get_object("der_alg_list_box")
if self.database_manager.db.version == (4,0):
if self.database_manager.db.version == (4, 0):
der_alg_list.select_row(der_alg_list.get_row_at_index(0))
elif self.database_manager.db.version == (3,1):
elif self.database_manager.db.version == (3, 1):
der_alg_list.select_row(der_alg_list.get_row_at_index(1))
enc_alg_list.connect("row-activated", self.on_encryption_changed)
......@@ -453,9 +451,9 @@ class DatabaseSettingsDialog():
self.new_encryption_algorithm = row.get_name()
if self.builder.get_object("der_alg_list_box").get_selected_row().get_name() == "argon2":
version_tuple = (4,0)
version_tuple = (4, 0)
elif self.builder.get_object("der_alg_list_box").get_selected_row().get_name() == "aeskdf":
version_tuple = (3,1)
version_tuple = (3, 1)
if self.database_manager.db.encryption_algorithm == row.get_name() and self.database_manager.db.version == version_tuple:
self.encryption_apply_button.set_sensitive(False)
......@@ -471,9 +469,9 @@ class DatabaseSettingsDialog():
version_tuple = NotImplemented
if row.get_name() == "argon2":
version_tuple = (4,0)
version_tuple = (4, 0)
elif row.get_name() == "aeskdf":
version_tuple = (3,1)
version_tuple = (3, 1)
if version_tuple == NotImplemented:
return
......
from gettext import gettext as _
from gi.repository import Gtk, Gdk
from gi.repository import Gtk
from threading import Timer
import gi
import passwordsafe.config_manager
import passwordsafe.icon
import threading
class EntryRow(Gtk.ListBoxRow):
......
from gi.repository import Gtk, Gdk
import gi
from gi.repository import Gtk
from gettext import gettext as _
......
icon_list = {"0" : "dialog-password-symbolic",
"1" : "network-wired-symbolic",
"2" : "dialog-warning-symbolic",
"3" : "network-server-symbolic",
"4" : "document-edit-symbolic",
"5" : "media-view-subtitles-symbolic",
"6" : "application-x-addon-symbolic",
"7" : "accessories-text-editor-symbolic",
"8" : "network-wired-symbolic",
"9" : "mail-send-symbolic",
"10" : "text-x-generic-symbolic",
"11" : "camera-photo-symbolic",
"12" : "network-wireless-signal-excellent-symbolic",
"13" : "dialog-password-symbolic",
"14" : "colorimeter-colorhug-symbolic",
"15" : "scanner-symbolic",
"16" : "network-wired-symbolic",
"17" : "media-optical-cd-audio-symbolic",
"18" : "video-display-symbolic",
"19" : "mail-unread-symbolic",
"20" : "emblem-system-symbolic",
"21" : "edit-paste-symbolic",
"22" : "edit-paste-symbolic",
"23" : "preferences-desktop-remote-desktop-symbolic",
"24" : "uninterruptible-power-supply-symbolic",
"25" : "mail-unread-symbolic",
"26" : "media-floppy-symbolic",
"27" : "drive-harddisk-symbolic",
"28" : "dialog-password-symbolic",
"29" : "dialog-password-symbolic",
"30" : "utilities-terminal-symbolic",
"31" : "printer-symbolic",
"32" : "image-x-generic-symbolic",
"33" : "edit-select-all-symbolic",
"34" : "preferences-system-symbolic",
"35" : "network-workgroup-symbolic",
"36" : "dialog-password-symbolic",
"37" : "dialog-password-symbolic",
"38" : "drive-harddisk-symbolic",
"39" : "document-open-recent-symbolic",
"40" : "system-search-symbolic",
"41" : "dialog-password-symbolic",
"42" : "media-flash-symbolic",
"43" : "user-trash-symbolic",
"44" : "accessories-text-editor-symbolic",
"45" : "edit-delete-symbolic",
"46" : "dialog-question-symbolic",
"47" : "package-x-generic-symbolic",
"48" : "folder-symbolic",
"49" : "folder-open-symbolic",
"50" : "document-open-symbolic",
"51" : "system-lock-screen-symbolic",
"52" : "rotation-locked-symbolic",
"53" : "object-select-symbolic",
"54" : "document-edit-symbolic",
"55" : "image-x-generic-symbolic",
"56" : "accessories-dictionary-symbolic",
"57" : "view-list-symbolic",
"58" : "avatar-default-symbolic",
"59" : "applications-engineering-symbolic",
"60" : "go-home-symbolic",
"61" : "starred-symbolic",
"62" : "start-here-symbolic",
"63" : "dialog-password-symbolic",
"64" : "start-here-symbolic",
"65" : "accessories-dictionary-symbolic",
"66" : "dialog-password-symbolic",
"67" : "application-certificate-symbolic",
"68" : "phone-apple-iphone-symbolic" }
icon_list = {"0": "dialog-password-symbolic",
"1": "network-wired-symbolic",
"2": "dialog-warning-symbolic",
"3": "network-server-symbolic",
"4": "document-edit-symbolic",
"5": "media-view-subtitles-symbolic",
"6": "application-x-addon-symbolic",
"7": "accessories-text-editor-symbolic",
"8": "network-wired-symbolic",
"9": "mail-send-symbolic",
"10": "text-x-generic-symbolic",
"11": "camera-photo-symbolic",
"12": "network-wireless-signal-excellent-symbolic",
"13": "dialog-password-symbolic",
"14": "colorimeter-colorhug-symbolic",
"15": "scanner-symbolic",
"16": "network-wired-symbolic",
"17": "media-optical-cd-audio-symbolic",
"18": "video-display-symbolic",
"19": "mail-unread-symbolic",
"20": "emblem-system-symbolic",
"21": "edit-paste-symbolic",
"22": "edit-paste-symbolic",
"23": "preferences-desktop-remote-desktop-symbolic",
"24": "uninterruptible-power-supply-symbolic",
"25": "mail-unread-symbolic",
"26": "media-floppy-symbolic",
"27": "drive-harddisk-symbolic",
"28": "dialog-password-symbolic",
"29": "dialog-password-symbolic",
"30": "utilities-terminal-symbolic",
"31": "printer-symbolic",
"32": "image-x-generic-symbolic",
"33": "edit-select-all-symbolic",
"34": "preferences-system-symbolic",
"35": "network-workgroup-symbolic",
"36": "dialog-password-symbolic",
"37": "dialog-password-symbolic",
"38": "drive-harddisk-symbolic",
"39": "document-open-recent-symbolic",
"40": "system-search-symbolic",
"41": "dialog-password-symbolic",
"42": "media-flash-symbolic",
"43": "user-trash-symbolic",
"44": "accessories-text-editor-symbolic",
"45": "edit-delete-symbolic",
"46": "dialog-question-symbolic",
"47": "package-x-generic-symbolic",
"48": "folder-symbolic",
"49": "folder-open-symbolic",
"50": "document-open-symbolic",
"51": "system-lock-screen-symbolic",
"52": "rotation-locked-symbolic",
"53": "object-select-symbolic",
"54": "document-edit-symbolic",
"55": "image-x-generic-symbolic",
"56": "accessories-dictionary-symbolic",
"57": "view-list-symbolic",
"58": "avatar-default-symbolic",
"59": "applications-engineering-symbolic",
"60": "go-home-symbolic",
"61": "starred-symbolic",
"62": "start-here-symbolic",
"63": "dialog-password-symbolic",
"64": "start-here-symbolic",
"65": "accessories-dictionary-symbolic",
"66": "dialog-password-symbolic",
"67": "application-certificate-symbolic",
"68": "phone-apple-iphone-symbolic"}
def get_icon(number):
return icon_list[number]
......@@ -3,16 +3,18 @@ from Crypto.Cipher import AES
from Crypto.Random import get_random_bytes
import secrets
def create_random_data(bytes):
return secrets.token_bytes(bytes)
def generate_keyfile(filepath, database_creation, instance, composite):
key = get_random_bytes(32)
cipher = AES.new(key, AES.MODE_EAX)
ciphertext, tag = cipher.encrypt_and_digest(create_random_data(96))
keyfile = open(filepath, "wb")
[ keyfile.write(x) for x in (cipher.nonce, tag, ciphertext) ]
[keyfile.write(x) for x in (cipher.nonce, tag, ciphertext)]
keyfile.close()
if database_creation is True:
......@@ -25,4 +27,3 @@ def generate_keyfile(filepath, database_creation, instance, composite):
else:
GLib.idle_add(instance.keyfile_generated)
......@@ -32,4 +32,4 @@ class LoggingManager:
def log_debug(self, message):
if(self.debug):
print("( " + self.date + " ):" + "\033[1m DEBUG: \033[0m" + message)
\ No newline at end of file
print("( " + self.date + " ):" + "\033[1m DEBUG: \033[0m" + message)
......@@ -8,8 +8,6 @@ from passwordsafe.unlock_database import UnlockDatabase
import passwordsafe.config_manager
import os
import ntpath
import gi
import signal
import threading
from gettext import gettext as _
......@@ -39,7 +37,7 @@ class MainWindow(Gtk.ApplicationWindow):
def assemble_window(self):
window_size = passwordsafe.config_manager.get_window_size()
self.set_default_size(window_size[0], window_size[1])
self.create_headerbar()
self.first_start_screen()
......@@ -217,7 +215,6 @@ class MainWindow(Gtk.ApplicationWindow):
path_label.set_text(path)
last_opened_row.set_name(path)
entry_list.append(last_opened_row)
else:
invalid = invalid + 1
......@@ -248,7 +245,6 @@ class MainWindow(Gtk.ApplicationWindow):
self.first_start_grid = builder.get_object("first_start_grid")
self.add(self.first_start_grid)
#
# Container Methods (Gtk Notebook holds tabs)
#
......@@ -551,7 +547,7 @@ class MainWindow(Gtk.ApplicationWindow):
quit_button.connect("clicked", self.on_quit_button_clicked)
unsaved_databases_list_box = builder.get_object("unsaved_databases_list_box")
for db in unsaved_databases_list:
unsaved_database_row = Gtk.ListBoxRow()
check_button = Gtk.CheckButton()
......
from gi.repository import Gio, GLib
import gi
from gi.repository import Gio
import re
import secrets
word_dict = {}
def generate(words, separator):
words_file = Gio.File.new_for_uri("resource:///org/gnome/PasswordSafe/crypto/eff_large_wordlist.txt")
file_buffer = Gio.InputStream.read_bytes(words_file.read(), 108800)
......@@ -26,9 +26,11 @@ def generate(words, separator):
return passphrase
def dice():
return "".join([secrets.choice("123456") for _ in range(0, 5)])
def get_word(number):
return word_dict[number]
......@@ -3,9 +3,10 @@ import secrets
import string
import re
def generate(digits, high_letter, low_letter, numbers, special):
characters = ""
if high_letter is True:
characters += string.ascii_uppercase
......@@ -23,6 +24,7 @@ def generate(digits, high_letter, low_letter, numbers, special):
return "".join([secrets.choice(characters) for _ in range(0, digits)])
def strength(password):
di = diversity(password)
en = entropy(password)
......@@ -30,11 +32,12 @@ def strength(password):
strength = int(round((di + en) / 2, 0))
if strength <= 6:
return strength
elif strenth > 6:
elif strength > 6:
return 6
else:
return 0
def diversity(password):
if len(password) <= 3:
return 0
......@@ -57,7 +60,7 @@ def diversity(password):
count += 2
else:
count += 1
if(re.compile('[@_!#$%^&*()<>?/\|}{~:]').search(password) != None):
if(re.compile('[@_!#$%^&*()<>?/\|}{~:]').search(password) is not None):
count += 1
return count
......
from gi.repository import Gtk
from passwordsafe.pathbar_button import PathbarButton
from passwordsafe.logging_manager import LoggingManager
import gi
class Pathbar(Gtk.HBox):
......
from gi.repository import Gtk
import gi
class PathbarButton(Gtk.Button):
......
from gi.repository import Gtk
import gi
class ScrolledPage(Gtk.ScrolledWindow):
edit_page = False
made_database_changes = False
all_properties_revealed = False
show_all_properties_button = NotImplemented
......
from gi.repository import Gtk
from gi.repository.GdkPixbuf import Pixbuf
import passwordsafe.config_manager
import gi
class SettingsDialog():
......@@ -14,7 +13,7 @@ class SettingsDialog():
self.builder.add_from_resource("/org/gnome/PasswordSafe/settings_dialog.ui")
def on_settings_menu_clicked(self, action, param):
settings_dialog = self.builder.get_object("settings_dialog")
settings_dialog = self.builder.get_object("settings_dialog")
settings_dialog.set_modal(True)
settings_dialog.set_transient_for(self.window)
......@@ -71,7 +70,6 @@ class SettingsDialog():
settings_remember_method_switch_value = passwordsafe.config_manager.get_remember_unlock_method()
settings_remember_method_switch.set_active(settings_remember_method_switch_value)
def on_settings_theme_switch_switched(self, switch_button, gparam):
gtk_settings = Gtk.Settings.get_default()
......
......@@ -3,13 +3,11 @@ from passwordsafe.database_manager import DatabaseManager
from passwordsafe.unlocked_database import UnlockedDatabase
import passwordsafe.config_manager
from passwordsafe.logging_manager import LoggingManager
import gi
import ntpath
import os
import threading
import time
import datetime
import construct
from gettext import gettext as _
from construct import core
......
from gi.repository import Gio, Gdk, Gtk, GLib, Handy
from gi.repository.GdkPixbuf import Pixbuf
from gi.repository import Notify
from passwordsafe.logging_manager import LoggingManager
from passwordsafe.pathbar import Pathbar
......@@ -14,7 +13,6 @@ import passwordsafe.password_generator
import passwordsafe.config_manager
import os
import threading
import gi
import ntpath
import datetime
import time
......@@ -650,7 +648,6 @@ class UnlockedDatabase:
else:
self.set_entry_page_headerbar()
def update_current_stack_page(self):
self.stack.set_transition_type(Gtk.StackTransitionType.NONE)
stack_page_name = self.database_manager.get_group_uuid_from_group_object(self.current_group)
......@@ -745,7 +742,7 @@ class UnlockedDatabase:
page.destroy()
self.show_page_of_new_directory(False, False)
#
# Create Property Rows
#
......@@ -1604,7 +1601,7 @@ class UnlockedDatabase:
key = scrolled_page.attributes_key_entry.get_text()
value = scrolled_page.attributes_value_entry.get_text()
if key == "" or key == None:
if key == "" or key is None:
scrolled_page.attributes_key_entry.get_style_context().add_class("error")
return
......@@ -1797,7 +1794,7 @@ class UnlockedDatabase:
row.selection_checkbox.set_active(False)
def on_session_lock(self, connection, unique_name, object_path, interface, signal, state):
if state[0] == True and self.database_locked is False:
if state[0] is True and self.database_locked is False:
self.lock_timeout_database()
def on_back_button_mobile_clicked(self, button):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment