Skip to content

Commit

Permalink
check p12 password before opening signature box location dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
schorschii committed Feb 25, 2024
1 parent f8d621e commit e2199b7
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions simple_signer/simple_signer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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
Expand All @@ -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()

Expand Down

0 comments on commit e2199b7

Please sign in to comment.