Commit 3834fb2e authored by Heiko Reese's avatar Heiko Reese

Added alternative GUI

parent ff69ae30
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
from OpenSSL import crypto, SSL
from os.path import basename, dirname, isfile, splitext
from sys import exit
from tkinter import Tk, filedialog, messagebox, simpledialog, Label, Entry, Button, N, E, W, S, NORMAL, DISABLED
class PasswordEntry:
def __init__(self, master):
self.master = master
master.title("Enter Password")
infilename = ""
infile = ""
self.label = Label(master, text = "Passwort")
self.label.grid(row=0, sticky=W)
self.passentry = Entry(master)
self.passentry.grid(row=0, column=1, sticky=W)
self.toggleShow()
self.passentry.focus_set()
self.toggle = Button(master, text="⚷", command=self.toggleShow)
self.toggle.grid(row=0, column=2, sticky=W)
self.okbutton = Button(master, text="OK", command=self.reencode)
self.okbutton.grid(row=1, column=0, columnspan=3, sticky=W+E+N+S)
self.okbutton.config()
# ask for input file
self.askInputFile()
# check password while being typed in
def reencode(self):
try:
p12 = crypto.load_pkcs12(self.infile, self.passentry.get().encode('utf-8'))
except crypto.Error:
messagebox.showerror("Ok", "Falsches Passwort")
return
# write output file
outfile = filedialog.asksaveasfilename(title='PKCS12-Ausgabedatei',
initialdir=dirname(self.infilename),
initialfile=splitext(basename(self.infilename))[0] + '-repariert.p12',
defaultextension='.p12',
filetypes=(('PKCS12-Dateien', ('*.p12', '*.P12', '*.pfx', '*.PFX')),
('alle Dateien', '*.*')))
if not (outfile):
messagebox.showinfo('Abbruch', 'Die Dateiauswahl wurde abgebrochen!')
return
try:
with open(outfile, 'wb') as file:
file.write(p12.export(self.passentry.get().encode('utf-8')))
except:
messagebox.showinfo('Fehler!', 'Kann PKCS12-Datei {} nicht schreiben!'.format(outfile))
self.master.quit()
# toggle password hiding
def toggleShow(self):
if self.passentry["show"] == "":
self.passentry["show"] = "●"
else:
self.passentry["show"] = ""
# get input file
def askInputFile(self):
# Read input file
while True:
self.infilename = filedialog.askopenfilename(title='P12-Eingabedatei',
filetypes=(('PKCS12-Dateien', ('*.p12', '*.P12', '*.pfx', '*.PFX')),
('alle Dateien', '*.*')))
if not (self.infilename):
messagebox.showerror('Abbruch', 'Die Dateiauswahl wurde abgebrochen!')
self.master.quit()
# Verify file exists; if so, break
if isfile(self.infilename):
try:
with open(self.infilename, 'rb') as pkcs12file:
self.infile = pkcs12file.read()
except Exception as e:
messagebox.showerror("Ok", e)
continue
return
# Create and hide root window
root = Tk()
decodegui = PasswordEntry(root)
root.mainloop()
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