mirror of
https://github.com/JakubMelka/PDF4QT.git
synced 2025-06-05 21:59:17 +02:00
Issue #55: Refactoring of certificates
This commit is contained in:
@@ -315,11 +315,11 @@ void SignaturePlugin::onSignDigitally()
|
||||
// Jakub Melka: do we have certificates? If not,
|
||||
// open certificate dialog, so the user can create
|
||||
// a new one.
|
||||
if (pdf::PDFCertificateManager::getCertificates().isEmpty())
|
||||
if (pdf::PDFCertificateManager::getCertificates().empty())
|
||||
{
|
||||
onOpenCertificatesManager();
|
||||
|
||||
if (pdf::PDFCertificateManager::getCertificates().isEmpty())
|
||||
if (pdf::PDFCertificateManager::getCertificates().empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -328,9 +328,12 @@ void SignaturePlugin::onSignDigitally()
|
||||
SignDialog dialog(m_dataExchangeInterface->getMainWindow(), m_scene.isEmpty());
|
||||
if (dialog.exec() == SignDialog::Accepted)
|
||||
{
|
||||
const pdf::PDFCertificateEntry* certificate = dialog.getCertificate();
|
||||
Q_ASSERT(certificate);
|
||||
|
||||
QByteArray data = "SampleDataToBeSigned" + QByteArray::number(QDateTime::currentMSecsSinceEpoch());
|
||||
QByteArray signature;
|
||||
if (!pdf::PDFSignatureFactory::sign(dialog.getCertificatePath(), dialog.getPassword(), data, signature))
|
||||
if (!pdf::PDFSignatureFactory::sign(*certificate, dialog.getPassword(), data, signature))
|
||||
{
|
||||
QMessageBox::critical(m_widget, tr("Error"), tr("Failed to create digital signature."));
|
||||
return;
|
||||
@@ -459,7 +462,7 @@ void SignaturePlugin::onSignDigitally()
|
||||
buffer.seek(i3);
|
||||
dataToBeSigned.append(buffer.read(i4));
|
||||
|
||||
if (!pdf::PDFSignatureFactory::sign(dialog.getCertificatePath(), dialog.getPassword(), dataToBeSigned, signature))
|
||||
if (!pdf::PDFSignatureFactory::sign(*certificate, dialog.getPassword(), dataToBeSigned, signature))
|
||||
{
|
||||
QMessageBox::critical(m_widget, tr("Error"), tr("Failed to create digital signature."));
|
||||
buffer.close();
|
||||
|
@@ -108,6 +108,8 @@ private:
|
||||
|
||||
void setActive(bool active);
|
||||
|
||||
pdf::PDFWidgetTool* getActiveTool();
|
||||
|
||||
void updateActions();
|
||||
void updateGraphics();
|
||||
void updateDockWidget();
|
||||
@@ -120,7 +122,6 @@ private:
|
||||
|
||||
pdf::PDFPageContentScene m_scene;
|
||||
bool m_sceneSelectionChangeEnabled;
|
||||
pdf::PDFWidgetTool* getActiveTool();
|
||||
};
|
||||
|
||||
} // namespace pdfplugin
|
||||
|
@@ -19,6 +19,7 @@
|
||||
#include "ui_signdialog.h"
|
||||
|
||||
#include "pdfcertificatemanager.h"
|
||||
#include "pdfcertificatelisthelper.h"
|
||||
|
||||
#include <openssl/pkcs7.h>
|
||||
|
||||
@@ -41,11 +42,10 @@ SignDialog::SignDialog(QWidget* parent, bool isSceneEmpty) :
|
||||
ui->methodCombo->addItem(tr("Sign digitally (invisible signature)"), SignDigitallyInvisible);
|
||||
ui->methodCombo->setCurrentIndex(0);
|
||||
|
||||
QFileInfoList certificates = pdf::PDFCertificateManager::getCertificates();
|
||||
for (const QFileInfo& certificateFileInfo : certificates)
|
||||
{
|
||||
ui->certificateCombo->addItem(certificateFileInfo.fileName(), certificateFileInfo.absoluteFilePath());
|
||||
}
|
||||
m_certificates = pdf::PDFCertificateManager::getCertificates();
|
||||
|
||||
pdf::PDFCertificateListHelper::initComboBox(ui->certificateCombo);
|
||||
pdf::PDFCertificateListHelper::fillComboBox(ui->certificateCombo, m_certificates);
|
||||
}
|
||||
|
||||
SignDialog::~SignDialog()
|
||||
@@ -58,11 +58,6 @@ SignDialog::SignMethod SignDialog::getSignMethod() const
|
||||
return static_cast<SignMethod>(ui->methodCombo->currentData().toInt());
|
||||
}
|
||||
|
||||
QString SignDialog::getCertificatePath() const
|
||||
{
|
||||
return ui->certificateCombo->currentData().toString();
|
||||
}
|
||||
|
||||
QString SignDialog::getPassword() const
|
||||
{
|
||||
return ui->certificatePasswordEdit->text();
|
||||
@@ -78,10 +73,23 @@ QString SignDialog::getContactInfoText() const
|
||||
return ui->contactInfoEdit->text();
|
||||
}
|
||||
|
||||
const pdf::PDFCertificateEntry* SignDialog::getCertificate() const
|
||||
{
|
||||
const int index = ui->certificateCombo->currentIndex();
|
||||
if (index >= 0 && index < m_certificates.size())
|
||||
{
|
||||
return &m_certificates.at(index);
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void SignDialog::accept()
|
||||
{
|
||||
const pdf::PDFCertificateEntry* certificate = getCertificate();
|
||||
|
||||
// Check certificate
|
||||
if (!QFile::exists(getCertificatePath()))
|
||||
if (!certificate)
|
||||
{
|
||||
QMessageBox::critical(this, tr("Error"), tr("Certificate does not exist."));
|
||||
ui->certificateCombo->setFocus();
|
||||
@@ -89,7 +97,7 @@ void SignDialog::accept()
|
||||
}
|
||||
|
||||
// Check we can access the certificate
|
||||
if (!pdf::PDFCertificateManager::isCertificateValid(getCertificatePath(), ui->certificatePasswordEdit->text()))
|
||||
if (!pdf::PDFCertificateManager::isCertificateValid(*certificate, ui->certificatePasswordEdit->text()))
|
||||
{
|
||||
QMessageBox::critical(this, tr("Error"), tr("Password to open certificate is invalid."));
|
||||
ui->certificatePasswordEdit->setFocus();
|
||||
|
@@ -18,6 +18,8 @@
|
||||
#ifndef SIGNDIALOG_H
|
||||
#define SIGNDIALOG_H
|
||||
|
||||
#include "pdfcertificatemanager.h"
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
namespace Ui
|
||||
@@ -45,13 +47,14 @@ public:
|
||||
};
|
||||
|
||||
SignMethod getSignMethod() const;
|
||||
QString getCertificatePath() const;
|
||||
QString getPassword() const;
|
||||
QString getReasonText() const;
|
||||
QString getContactInfoText() const;
|
||||
const pdf::PDFCertificateEntry* getCertificate() const;
|
||||
|
||||
private:
|
||||
Ui::SignDialog* ui;
|
||||
pdf::PDFCertificateEntries m_certificates;
|
||||
};
|
||||
|
||||
} // namespace pdfplugin
|
||||
|
Reference in New Issue
Block a user