From e2199b72c7cbe319fa7d0c9efa80318ae8075858 Mon Sep 17 00:00:00 2001 From: Georg Sieber Date: Sun, 25 Feb 2024 19:35:06 +0100 Subject: [PATCH] check p12 password before opening signature box location dialog --- simple_signer/simple_signer.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/simple_signer/simple_signer.py b/simple_signer/simple_signer.py index f26d638..36e9499 100755 --- a/simple_signer/simple_signer.py +++ b/simple_signer/simple_signer.py @@ -431,6 +431,19 @@ def OnClickCertify(self, e): def Sign(self, certify): try: + # load certificate + certData = open(self.txtCertPath.text(), 'rb').read() + p12Data = pkcs12.load_key_and_certificates(certData, str.encode(self.txtCertPassword.text()), backends.default_backend()) + + # check certificate + if(p12Data[1] != None and p12Data[1].not_valid_after < datetime.datetime.now()): + msg = QMessageBox() + msg.setIcon(QMessageBox.Warning) + msg.setWindowTitle(QApplication.translate('SimpleSigner', 'Certificate Warning')) + msg.setText(QApplication.translate('SimpleSigner', 'Your certificate expired on %s. Continue?') % str(p12Data[1].not_valid_after)) + msg.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel) + if(msg.exec_() == QMessageBox.Cancel): return + # get source path pdfPath = self.txtPdfPath.text() @@ -497,7 +510,7 @@ def Sign(self, certify): if not self.signedPdfPath: return # do it - self.DoSign(pdfPath, dct) + self.DoSign(pdfPath, dct, p12Data) except Exception as e: # error message @@ -509,21 +522,8 @@ def Sign(self, certify): msg.setStandardButtons(QMessageBox.Ok) retval = msg.exec_() - def DoSign(self, pdfPath, dct): + def DoSign(self, pdfPath, dct, p12Data): try: - # load certificate - certData = open(self.txtCertPath.text(), 'rb').read() - p12Data = pkcs12.load_key_and_certificates(certData, str.encode(self.txtCertPassword.text()), backends.default_backend()) - - # check certificate - if(p12Data[1] != None and p12Data[1].not_valid_after < datetime.datetime.now()): - msg = QMessageBox() - msg.setIcon(QMessageBox.Warning) - msg.setWindowTitle(QApplication.translate('SimpleSigner', 'Certificate Warning')) - msg.setText(QApplication.translate('SimpleSigner', 'Your certificate expired on %s. Continue?') % str(p12Data[1].not_valid_after)) - msg.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel) - if(msg.exec_() == QMessageBox.Cancel): return - # load source PDF pdfData = open(pdfPath, 'rb').read()