From 4d43eacfd07b7a4d75cdffbba3448e49244ba6a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Br=C3=B6tzmann?= Date: Tue, 2 Apr 2019 18:50:58 +0200 Subject: [PATCH] Rework Certificate dialog --- gajim/data/gui/certificate_dialog.ui | 446 +++++++++++++++++++++++++++ gajim/gtk/dialogs.py | 73 ++--- 2 files changed, 484 insertions(+), 35 deletions(-) create mode 100644 gajim/data/gui/certificate_dialog.ui diff --git a/gajim/data/gui/certificate_dialog.ui b/gajim/data/gui/certificate_dialog.ui new file mode 100644 index 000000000..61a32c633 --- /dev/null +++ b/gajim/data/gui/certificate_dialog.ui @@ -0,0 +1,446 @@ + + + + + + True + False + center + 18 + vertical + 6 + + + True + False + center + 12 + + + True + False + application-certificate-symbolic + 6 + + + False + True + 0 + + + + + True + False + <Certificate for account %s> + center + + + + False + True + 1 + + + + + False + True + 0 + + + + + True + False + 20 + 6 + 12 + + + True + False + end + Common Name (CN) + + + + 0 + 1 + + + + + True + False + start + <> + + + 1 + 1 + + + + + True + False + end + Organization (O) + + + + 0 + 2 + + + + + True + False + start + <> + + + 1 + 2 + + + + + True + False + end + Organizational Unit (OU) + + + + 0 + 3 + + + + + True + False + start + <> + + + 1 + 3 + + + + + True + False + end + Serial Number + + + + 0 + 4 + + + + + True + False + start + <> + + + 1 + 4 + + + + + True + False + end + Common Name (CN) + + + + 0 + 6 + + + + + True + False + start + <> + + + 1 + 6 + + + + + True + False + end + Organization (O) + + + + 0 + 7 + + + + + True + False + start + <> + + + 1 + 7 + + + + + True + False + end + Organizational Unit (OU) + + + + 0 + 8 + + + + + True + False + start + <> + + + 1 + 8 + + + + + True + False + end + Issued on + + + + 0 + 10 + + + + + True + False + start + <> + + + 1 + 10 + + + + + True + False + end + Expires on + + + + 0 + 11 + + + + + True + False + start + <> + + + 1 + 11 + + + + + True + False + baseline + SHA-1 + + + + 0 + 13 + 2 + + + + + True + False + baseline + 6 + SHA-256 + + + + 0 + 15 + 2 + + + + + True + False + center + <> + True + char + True + + + 0 + 14 + 2 + + + + + True + False + center + <> + True + char + True + 42 + + + 0 + 16 + 2 + + + + + True + False + baseline + 6 + Issued to + + + + 0 + 0 + 2 + + + + + True + False + baseline + 12 + Issued by + + + + 0 + 5 + 2 + + + + + True + False + baseline + 12 + Validity + + + + 0 + 9 + 2 + + + + + True + False + baseline + 12 + Fingerprints + + + + 0 + 12 + 2 + + + + + False + True + 1 + + + + diff --git a/gajim/gtk/dialogs.py b/gajim/gtk/dialogs.py index 8033d0fdc..24d636bc1 100644 --- a/gajim/gtk/dialogs.py +++ b/gajim/gtk/dialogs.py @@ -12,6 +12,8 @@ # You should have received a copy of the GNU General Public License # along with Gajim. If not, see . +from datetime import datetime + from collections import namedtuple from gi.repository import Gtk @@ -23,7 +25,6 @@ from gajim.common.i18n import _ from gajim.common.const import ButtonAction from gajim.gtk.util import get_builder -from gajim.gtk.util import load_icon class DialogButton(namedtuple('DialogButton', ('response text callback args ' @@ -880,47 +881,49 @@ class DoubleInputDialog: self.cancel_handler() -class CertificatDialog(InformationDialog): +class CertificateDialog(Gtk.ApplicationWindow): def __init__(self, transient_for, account, cert): + Gtk.ApplicationWindow.__init__(self) + self.set_name('CertificateDialog') + self.set_application(app.app) + self.set_show_menubar(False) + self.set_resizable(False) + self.set_position(Gtk.WindowPosition.CENTER) + self.set_title(_('Certificate')) + + self._ui = get_builder('certificate_dialog.ui') + self.add(self._ui.certificate_box) + issuer = cert.get_issuer() subject = cert.get_subject() - InformationDialog.__init__(self, - _('Certificate for account %s') % account, _('''Issued to: -Common Name (CN): %(scn)s -Organization (O): %(sorg)s -Organizationl Unit (OU): %(sou)s -Serial Number: %(sn)s -Issued by: -Common Name (CN): %(icn)s -Organization (O): %(iorg)s -Organizationl Unit (OU): %(iou)s + self._ui.label_cert_for_account.set_text( + _('Certificate for account\n%s') % account) -Validity: -Issued on: %(io)s -Expires on: %(eo)s + self._ui.data_it_common_name.set_text(subject.commonName) + self._ui.data_it_organization.set_text(subject.organizationName) + self._ui.data_it_organizational_unit.set_text( + subject.organizationalUnitName) + self._ui.data_it_serial_number.set_text(str(cert.get_serial_number())) -Fingerprint -SHA-1 Fingerprint: %(sha1)s + self._ui.data_ib_common_name.set_text(issuer.commonName) + self._ui.data_ib_organization.set_text(issuer.organizationName) + self._ui.data_ib_organizational_unit.set_text( + issuer.organizationalUnitName) + + issued = datetime.strptime(cert.get_notBefore().decode('ascii'), '%Y%m%d%H%M%SZ') + issued = issued.strftime('%B %d, %Y, %H:%M:%S %z') + self._ui.data_issued_on.set_text(issued) + expires = datetime.strptime(cert.get_notAfter().decode('ascii'), '%Y%m%d%H%M%SZ') + expires = expires.strftime('%B %d, %Y, %H:%M:%S %z') + self._ui.data_expires_on.set_text(expires) + + self._ui.data_sha1.set_text(cert.digest('sha1').decode('utf-8')) + self._ui.data_sha256.set_text(cert.digest('sha256').decode('utf-8')) -SHA-256 Fingerprint: %(sha256)s -''') % { - 'scn': subject.commonName, 'sorg': subject.organizationName, - 'sou': subject.organizationalUnitName, - 'sn': cert.get_serial_number(), 'icn': issuer.commonName, - 'iorg': issuer.organizationName, - 'iou': issuer.organizationalUnitName, - 'io': cert.get_notBefore().decode('utf-8'), - 'eo': cert.get_notAfter().decode('utf-8'), - 'sha1': cert.digest('sha1').decode('utf-8'), - 'sha256': cert.digest('sha256').decode('utf-8')}) - surface = load_icon('application-certificate', self, size=32) - if surface is not None: - img = Gtk.Image.new_from_surface(surface) - img.show_all() - self.set_image(img) self.set_transient_for(transient_for) - self.set_title(_('Certificate for account %s') % account) + self._ui.connect_signals(self) + self.show_all() class SSLErrorDialog(ConfirmationDialogDoubleCheck): @@ -939,7 +942,7 @@ class SSLErrorDialog(ConfirmationDialogDoubleCheck): area.pack_start(b, True, True, 0) def on_cert_clicked(self, button): - CertificatDialog(self, self.account, self.cert) + CertificateDialog(self, self.account, self.cert) class ChangePasswordDialog(Gtk.Dialog):