Commit 661e375b authored by tobias.dussa's avatar tobias.dussa

Added script.

parents
*.exe
*.pyc
__pycache__
RecodeCertificate
=================
This is a minimal Python script designed to recode a PKCS12 file using OpenSSL.
A Firefox-generated PKCS12 file cannot be imported into Windows under certain
circumstances. Recoding it with this tool should help.
Windows Binary
==============
A 32-bit stand-alone Windows binary with the script is provided in [the
release notes](https://git.scc.kit.edu/KIT-CA/RecodeCertificate/tags). To
use the Windows binary, simply double-click the executable file.
If you want to roll the Windows EXE file yourself, check out the [Windows
branch](https://git.scc.kit.edu/KIT-CA/RecodeCertificate/tree/Windows). A
Windows system with a working Python 3 installation and the `pyinstaller`
package is required. After checking out the Windows branch, run
`Windows\roll_executable.bat`. The resulting binary will be located in
`dist\RecodeCertificate.exe`.
#! /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
# Create and hide root window
root = Tk()
root.withdraw()
# Read input file
while True:
infile = filedialog.askopenfilename(title='P12-Eingabedatei',
filetypes=(('PKCS12-Dateien', ('*.p12', '*.P12', '*.pfx', '*.PFX')),
('alle Dateien', '*.*')))
if not(infile):
messagebox.showinfo('Abbruch', 'Die Dateiauswahl wurde abgebrochen!')
exit(0)
# Verify file exists; if so, break
if isfile(infile):
break
# Read password
while True:
password = simpledialog.askstring('Passworteingabe', 'Passwort des geheimen Schlüssels:')
if password is None:
messagebox.showinfo('Abbruch', 'Die Passworteingabe wurde abgebrochen!')
exit(0)
# Break the loop if the password decrypts the private key, shout out
# otherwise
try:
with open(infile, 'rb') as pkcs12file:
p12 = crypto.load_pkcs12(pkcs12file.read(), password.encode('ascii'))
break
except crypto.Error:
messagebox.showinfo('Fehler!', 'Zertifikat konnte nicht geöffnet werden!')
# Read and write output file
while True:
outfile = filedialog.asksaveasfilename(title='PKCS12-Ausgabedatei',
initialdir=dirname(infile),
initialfile=splitext(basename(infile))[0]+'-neu.p12',
defaultextension='.p12',
filetypes=(('PKCS12-Dateien', ('*.p12', '*.P12', '*.pfx', '*.PFX')),
('alle Dateien', '*.*')))
if not(outfile):
messagebox.showinfo('Abbruch', 'Die Dateiauswahl wurde abgebrochen!')
exit(0)
try:
with open(outfile, 'wb') as file:
file.write(p12.export(password.encode('utf-8')))
break
except:
messagebox.showinfo('Fehler!', 'Kann PKCS12-Datei {} nicht schreiben!'.format(outfile))
# All done
messagebox.showinfo('Zertifikat exportiert!', 'Zertifikat erfolgreich in PKCS12-Datei {} exportiert!'.format(outfile))
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