mirror of
https://github.com/JakubMelka/PDF4QT.git
synced 2025-06-05 21:59:17 +02:00
Signature plugin: Create certificate
This commit is contained in:
@ -32,10 +32,23 @@ DESTDIR = $$OUT_PWD/../../pdfplugins
|
|||||||
|
|
||||||
CONFIG += c++11
|
CONFIG += c++11
|
||||||
|
|
||||||
|
Pdf4Qt_OPENSSL_PATH = $$absolute_path(../../Tools, $$[QT_INSTALL_PREFIX])
|
||||||
|
|
||||||
|
# Link OpenSSL
|
||||||
|
LIBS += -L$$Pdf4Qt_OPENSSL_PATH/OpenSSL/Win_x64/bin -L$$Pdf4Qt_OPENSSL_PATH/OpenSSL/Win_x64/lib -llibcrypto -llibssl
|
||||||
|
INCLUDEPATH += $$Pdf4Qt_OPENSSL_PATH/OpenSSL/Win_x64/include
|
||||||
|
DEPENDPATH += $$Pdf4Qt_OPENSSL_PATH/OpenSSL/Win_x64/include
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
|
certificatemanager.cpp \
|
||||||
|
certificatemanagerdialog.cpp \
|
||||||
|
createcertificatedialog.cpp \
|
||||||
signatureplugin.cpp
|
signatureplugin.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
|
certificatemanager.h \
|
||||||
|
certificatemanagerdialog.h \
|
||||||
|
createcertificatedialog.h \
|
||||||
signatureplugin.h
|
signatureplugin.h
|
||||||
|
|
||||||
CONFIG += force_debug_info
|
CONFIG += force_debug_info
|
||||||
@ -46,3 +59,7 @@ DISTFILES += \
|
|||||||
RESOURCES += \
|
RESOURCES += \
|
||||||
icons.qrc
|
icons.qrc
|
||||||
|
|
||||||
|
FORMS += \
|
||||||
|
certificatemanagerdialog.ui \
|
||||||
|
createcertificatedialog.ui
|
||||||
|
|
||||||
|
112
Pdf4QtViewerPlugins/SignaturePlugin/certificatemanager.cpp
Normal file
112
Pdf4QtViewerPlugins/SignaturePlugin/certificatemanager.cpp
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
// Copyright (C) 2022 Jakub Melka
|
||||||
|
//
|
||||||
|
// This file is part of PDF4QT.
|
||||||
|
//
|
||||||
|
// PDF4QT is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// with the written consent of the copyright owner, any later version.
|
||||||
|
//
|
||||||
|
// PDF4QT is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
|
// along with PDF4QT. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "certificatemanager.h"
|
||||||
|
|
||||||
|
#include <openssl/bio.h>
|
||||||
|
#include <openssl/rsa.h>
|
||||||
|
#include <openssl/rsaerr.h>
|
||||||
|
#include <openssl/x509.h>
|
||||||
|
#include <openssl/evp.h>
|
||||||
|
#include <openssl/pem.h>
|
||||||
|
#include <openssl/x509v3.h>
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
namespace pdfplugin
|
||||||
|
{
|
||||||
|
|
||||||
|
CertificateManager::CertificateManager()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
using openssl_ptr = std::unique_ptr<T, void(*)(T*)>;
|
||||||
|
|
||||||
|
void CertificateManager::createCertificate(const NewCertificateInfo& info)
|
||||||
|
{
|
||||||
|
openssl_ptr<BIO> certificateBuffer(BIO_new(BIO_s_mem()), &BIO_free_all);
|
||||||
|
openssl_ptr<BIO> privateKeyBuffer(BIO_new(BIO_s_mem()), &BIO_free_all);
|
||||||
|
|
||||||
|
if (certificateBuffer && privateKeyBuffer)
|
||||||
|
{
|
||||||
|
openssl_ptr<BIGNUM> bignumber(BN_new(), &BN_free);
|
||||||
|
openssl_ptr<RSA> rsaKey(RSA_new(), &RSA_free);
|
||||||
|
|
||||||
|
BN_set_word(bignumber.get(), RSA_F4);
|
||||||
|
const int rsaResult = RSA_generate_key_ex(rsaKey.get(), info.rsaKeyLength, bignumber.get(), nullptr);
|
||||||
|
if (rsaResult)
|
||||||
|
{
|
||||||
|
openssl_ptr<X509> certificate(X509_new(), &X509_free);
|
||||||
|
openssl_ptr<EVP_PKEY> privateKey(EVP_PKEY_new(), &EVP_PKEY_free);
|
||||||
|
|
||||||
|
EVP_PKEY_set1_RSA(privateKey.get(), rsaKey.get());
|
||||||
|
ASN1_INTEGER* serialNumber = X509_get_serialNumber(certificate.get());
|
||||||
|
ASN1_INTEGER_set(serialNumber, info.serialNumber);
|
||||||
|
|
||||||
|
// Set validity of the certificate
|
||||||
|
X509_gmtime_adj(X509_getm_notBefore(certificate.get()), 0);
|
||||||
|
X509_gmtime_adj(X509_getm_notBefore(certificate.get()), info.validityInSeconds);
|
||||||
|
|
||||||
|
// Set name
|
||||||
|
X509_NAME* name = X509_get_subject_name(certificate.get());
|
||||||
|
|
||||||
|
auto addString = [name](const char* identifier, QString string)
|
||||||
|
{
|
||||||
|
if (string.isEmpty())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QByteArray stringUtf8 = string.toUtf8();
|
||||||
|
X509_NAME_add_entry_by_txt(name, identifier, MBSTRING_UTF8, reinterpret_cast<const unsigned char*>(stringUtf8.constData()), stringUtf8.length(), -1, 0);
|
||||||
|
};
|
||||||
|
addString("C", info.certCountryCode);
|
||||||
|
addString("O", info.certOrganization);
|
||||||
|
addString("OU", info.certOrganizationUnit);
|
||||||
|
addString("CN", info.certCommonName);
|
||||||
|
addString("E", info.certEmail);
|
||||||
|
|
||||||
|
X509_EXTENSION* extension = nullptr;
|
||||||
|
X509V3_CTX context;
|
||||||
|
X509V3_set_ctx_nodb(&context);
|
||||||
|
X509V3_set_ctx(&context, certificate.get(), certificate.get(), nullptr, nullptr, 0);
|
||||||
|
extension = X509V3_EXT_conf_nid (NULL, &context, NID_key_usage, "digitalSignature, keyAgreement");
|
||||||
|
|
||||||
|
X509_set_issuer_name(certificate.get(), name);
|
||||||
|
|
||||||
|
// Set public key
|
||||||
|
X509_set_pubkey(certificate.get(), privateKey.get());
|
||||||
|
X509_sign(certificate.get(), privateKey.get(), EVP_sha512());
|
||||||
|
|
||||||
|
// Private key password
|
||||||
|
QByteArray privateKeyPaswordUtf8 = info.privateKeyPasword.toUtf8();
|
||||||
|
|
||||||
|
// Write the data
|
||||||
|
const int retWritePrivateKey = PEM_write_bio_PKCS8PrivateKey(privateKeyBuffer.get(), privateKey.get(), EVP_aes_256_cbc(), privateKeyPaswordUtf8.data(), privateKeyPaswordUtf8.size(), nullptr, nullptr);
|
||||||
|
const int retWriteCertificate = PEM_write_bio_X509(certificateBuffer.get(), certificate.get());
|
||||||
|
|
||||||
|
if (retWritePrivateKey == 1 && retWriteCertificate == 1)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace pdfplugin
|
53
Pdf4QtViewerPlugins/SignaturePlugin/certificatemanager.h
Normal file
53
Pdf4QtViewerPlugins/SignaturePlugin/certificatemanager.h
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
// Copyright (C) 2022 Jakub Melka
|
||||||
|
//
|
||||||
|
// This file is part of PDF4QT.
|
||||||
|
//
|
||||||
|
// PDF4QT is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// with the written consent of the copyright owner, any later version.
|
||||||
|
//
|
||||||
|
// PDF4QT is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
|
// along with PDF4QT. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#ifndef CERTIFICATEMANAGER_H
|
||||||
|
#define CERTIFICATEMANAGER_H
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
namespace pdfplugin
|
||||||
|
{
|
||||||
|
|
||||||
|
class CertificateManager
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CertificateManager();
|
||||||
|
|
||||||
|
struct NewCertificateInfo
|
||||||
|
{
|
||||||
|
QString certificateFileName;
|
||||||
|
QString privateKeyFileName;
|
||||||
|
QString privateKeyPasword;
|
||||||
|
|
||||||
|
QString certCountryCode;
|
||||||
|
QString certOrganization;
|
||||||
|
QString certOrganizationUnit;
|
||||||
|
QString certCommonName;
|
||||||
|
QString certEmail;
|
||||||
|
|
||||||
|
int rsaKeyLength = 1024;
|
||||||
|
int validityInSeconds = 2 * 365 * 24 * 3600;
|
||||||
|
long serialNumber = 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
void createCertificate(const NewCertificateInfo& info);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace pdfplugin
|
||||||
|
|
||||||
|
#endif // CERTIFICATEMANAGER_H
|
@ -0,0 +1,61 @@
|
|||||||
|
// Copyright (C) 2022 Jakub Melka
|
||||||
|
//
|
||||||
|
// This file is part of PDF4QT.
|
||||||
|
//
|
||||||
|
// PDF4QT is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// with the written consent of the copyright owner, any later version.
|
||||||
|
//
|
||||||
|
// PDF4QT is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
|
// along with PDF4QT. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "certificatemanagerdialog.h"
|
||||||
|
#include "ui_certificatemanagerdialog.h"
|
||||||
|
#include "createcertificatedialog.h"
|
||||||
|
|
||||||
|
#include "pdfwidgetutils.h"
|
||||||
|
|
||||||
|
#include <QAction>
|
||||||
|
#include <QPushButton>
|
||||||
|
|
||||||
|
namespace pdfplugin
|
||||||
|
{
|
||||||
|
|
||||||
|
CertificateManagerDialog::CertificateManagerDialog(QWidget *parent) :
|
||||||
|
QDialog(parent),
|
||||||
|
ui(new Ui::CertificateManagerDialog),
|
||||||
|
m_newCertificateButton(nullptr),
|
||||||
|
m_openCertificateDirectoryButton(nullptr)
|
||||||
|
{
|
||||||
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
m_newCertificateButton = ui->buttonBox->addButton(tr("Create Certificate"), QDialogButtonBox::ActionRole);
|
||||||
|
m_openCertificateDirectoryButton = ui->buttonBox->addButton(tr("Show Certificate Directory"), QDialogButtonBox::ActionRole);
|
||||||
|
|
||||||
|
connect(m_newCertificateButton, &QPushButton::clicked, this, &CertificateManagerDialog::onNewCertificateClicked);
|
||||||
|
|
||||||
|
setMinimumSize(pdf::PDFWidgetUtils::scaleDPI(this, QSize(640, 480)));
|
||||||
|
}
|
||||||
|
|
||||||
|
CertificateManagerDialog::~CertificateManagerDialog()
|
||||||
|
{
|
||||||
|
delete ui;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CertificateManagerDialog::onNewCertificateClicked()
|
||||||
|
{
|
||||||
|
CreateCertificateDialog dialog(this);
|
||||||
|
if (dialog.exec() == CreateCertificateDialog::Accepted)
|
||||||
|
{
|
||||||
|
const CertificateManager::NewCertificateInfo info = dialog.getNewCertificateInfo();
|
||||||
|
m_certificateManager.createCertificate(info);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace pdfplugin
|
@ -0,0 +1,54 @@
|
|||||||
|
// Copyright (C) 2022 Jakub Melka
|
||||||
|
//
|
||||||
|
// This file is part of PDF4QT.
|
||||||
|
//
|
||||||
|
// PDF4QT is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// with the written consent of the copyright owner, any later version.
|
||||||
|
//
|
||||||
|
// PDF4QT is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
|
// along with PDF4QT. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#ifndef CERTIFICATEMANAGERDIALOG_H
|
||||||
|
#define CERTIFICATEMANAGERDIALOG_H
|
||||||
|
|
||||||
|
#include "certificatemanager.h"
|
||||||
|
|
||||||
|
#include <QDialog>
|
||||||
|
|
||||||
|
class QAction;
|
||||||
|
|
||||||
|
namespace Ui
|
||||||
|
{
|
||||||
|
class CertificateManagerDialog;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace pdfplugin
|
||||||
|
{
|
||||||
|
|
||||||
|
class CertificateManagerDialog : public QDialog
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit CertificateManagerDialog(QWidget* parent);
|
||||||
|
virtual ~CertificateManagerDialog() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void onNewCertificateClicked();
|
||||||
|
|
||||||
|
Ui::CertificateManagerDialog* ui;
|
||||||
|
CertificateManager m_certificateManager;
|
||||||
|
QPushButton* m_newCertificateButton;
|
||||||
|
QPushButton* m_openCertificateDirectoryButton;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace pdfplugin
|
||||||
|
|
||||||
|
#endif // CERTIFICATEMANAGERDIALOG_H
|
@ -0,0 +1,71 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>CertificateManagerDialog</class>
|
||||||
|
<widget class="QDialog" name="CertificateManagerDialog">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>789</width>
|
||||||
|
<height>511</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Certificate Manager</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QGroupBox" name="certificateGroupBox">
|
||||||
|
<property name="title">
|
||||||
|
<string>Certificates</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="standardButtons">
|
||||||
|
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>accepted()</signal>
|
||||||
|
<receiver>CertificateManagerDialog</receiver>
|
||||||
|
<slot>accept()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>248</x>
|
||||||
|
<y>254</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>157</x>
|
||||||
|
<y>274</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>rejected()</signal>
|
||||||
|
<receiver>CertificateManagerDialog</receiver>
|
||||||
|
<slot>reject()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>316</x>
|
||||||
|
<y>260</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>286</x>
|
||||||
|
<y>274</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
</connections>
|
||||||
|
</ui>
|
156
Pdf4QtViewerPlugins/SignaturePlugin/createcertificatedialog.cpp
Normal file
156
Pdf4QtViewerPlugins/SignaturePlugin/createcertificatedialog.cpp
Normal file
@ -0,0 +1,156 @@
|
|||||||
|
// Copyright (C) 2022 Jakub Melka
|
||||||
|
//
|
||||||
|
// This file is part of PDF4QT.
|
||||||
|
//
|
||||||
|
// PDF4QT is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// with the written consent of the copyright owner, any later version.
|
||||||
|
//
|
||||||
|
// PDF4QT is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
|
// along with PDF4QT. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "createcertificatedialog.h"
|
||||||
|
#include "ui_createcertificatedialog.h"
|
||||||
|
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include <QInputDialog>
|
||||||
|
#include <QDate>
|
||||||
|
#include <QCalendar>
|
||||||
|
|
||||||
|
namespace pdfplugin
|
||||||
|
{
|
||||||
|
|
||||||
|
CreateCertificateDialog::CreateCertificateDialog(QWidget *parent) :
|
||||||
|
QDialog(parent),
|
||||||
|
ui(new Ui::CreateCertificateDialog)
|
||||||
|
{
|
||||||
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
ui->keyLengthCombo->addItem(tr("1024 bits"), 1024);
|
||||||
|
ui->keyLengthCombo->addItem(tr("2048 bits"), 2048);
|
||||||
|
ui->keyLengthCombo->addItem(tr("4096 bits"), 4096);
|
||||||
|
ui->keyLengthCombo->setCurrentIndex(ui->keyLengthCombo->findData(2048));
|
||||||
|
|
||||||
|
QList<QLocale> locales = QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, QLocale::AnyCountry);
|
||||||
|
std::sort(locales.begin(), locales.end(), [](const QLocale& left, const QLocale& right) { return QString::compare(left.nativeCountryName(), right.nativeCountryName(), Qt::CaseInsensitive) < 0; });
|
||||||
|
|
||||||
|
int currentIndex = 0;
|
||||||
|
QLocale currentLocale = QLocale::system();
|
||||||
|
|
||||||
|
for (const QLocale& locale : locales)
|
||||||
|
{
|
||||||
|
if (locale.country() == QLocale::AnyCountry)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (locale.nativeCountryName().isEmpty())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString localeName = locale.name();
|
||||||
|
QString countryCode = localeName.split(QChar('_')).back();
|
||||||
|
QString text = QString("%1 | %2").arg(countryCode, locale.nativeCountryName());
|
||||||
|
|
||||||
|
if (ui->countryCombo->findText(text) >= 0)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (locale.bcp47Name() == currentLocale.bcp47Name())
|
||||||
|
{
|
||||||
|
currentIndex = ui->countryCombo->count();
|
||||||
|
}
|
||||||
|
|
||||||
|
ui->countryCombo->addItem(text, countryCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
ui->countryCombo->setCurrentIndex(currentIndex);
|
||||||
|
ui->countryCombo->setMaxVisibleItems(25);
|
||||||
|
|
||||||
|
QDate minDate = QDate::currentDate();
|
||||||
|
ui->validTillEdit->setMinimumDate(minDate);
|
||||||
|
|
||||||
|
QDate selectedDate = minDate;
|
||||||
|
selectedDate = selectedDate.addYears(5, ui->validTillEdit->calendar());
|
||||||
|
ui->validTillEdit->setSelectedDate(selectedDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
CreateCertificateDialog::~CreateCertificateDialog()
|
||||||
|
{
|
||||||
|
delete ui;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CreateCertificateDialog::accept()
|
||||||
|
{
|
||||||
|
if (validate())
|
||||||
|
{
|
||||||
|
bool ok = false;
|
||||||
|
QString password1 = QInputDialog::getText(this, tr("Certificate Protection"), tr("Enter password to protect your certificate."), QLineEdit::Password, QString(), &ok);
|
||||||
|
|
||||||
|
if (!ok)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString password2 = QInputDialog::getText(this, tr("Certificate Protection"), tr("Enter password again to verify password text."), QLineEdit::Password, QString(), &ok);
|
||||||
|
|
||||||
|
if (password1 != password2)
|
||||||
|
{
|
||||||
|
QMessageBox::critical(this, tr("Error"), tr("Reentered password is not equal to the first one!"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QDate date = ui->validTillEdit->selectedDate();
|
||||||
|
QDate currentDate = QDate::currentDate();
|
||||||
|
int days = currentDate.daysTo(date);
|
||||||
|
|
||||||
|
// Fill certificate info
|
||||||
|
m_newCertificateInfo.privateKeyPasword = password1;
|
||||||
|
m_newCertificateInfo.certCountryCode = ui->countryCombo->currentData().toString();
|
||||||
|
m_newCertificateInfo.certOrganization = ui->organizationEdit->text();
|
||||||
|
m_newCertificateInfo.certOrganizationUnit = ui->organizationUnitEdit->text();
|
||||||
|
m_newCertificateInfo.certCommonName = ui->commonNameEdit->text();
|
||||||
|
m_newCertificateInfo.certEmail = ui->emailEdit->text();
|
||||||
|
m_newCertificateInfo.rsaKeyLength = ui->keyLengthCombo->currentData().toInt();
|
||||||
|
m_newCertificateInfo.validityInSeconds = days * 24 * 3600;
|
||||||
|
|
||||||
|
BaseClass::accept();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CreateCertificateDialog::validate()
|
||||||
|
{
|
||||||
|
// validate empty text fields
|
||||||
|
if (ui->commonNameEdit->text().isEmpty())
|
||||||
|
{
|
||||||
|
QMessageBox::critical(this, tr("Error"), tr("Please enter a name!"));
|
||||||
|
ui->commonNameEdit->setFocus();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ui->organizationEdit->text().isEmpty())
|
||||||
|
{
|
||||||
|
QMessageBox::critical(this, tr("Error"), tr("Please enter an organization name!"));
|
||||||
|
ui->organizationEdit->setFocus();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ui->emailEdit->text().isEmpty())
|
||||||
|
{
|
||||||
|
QMessageBox::critical(this, tr("Error"), tr("Please enter an email address!"));
|
||||||
|
ui->emailEdit->setFocus();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace plugin
|
@ -0,0 +1,59 @@
|
|||||||
|
// Copyright (C) 2022 Jakub Melka
|
||||||
|
//
|
||||||
|
// This file is part of PDF4QT.
|
||||||
|
//
|
||||||
|
// PDF4QT is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// with the written consent of the copyright owner, any later version.
|
||||||
|
//
|
||||||
|
// PDF4QT is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
|
// along with PDF4QT. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#ifndef CREATECERTIFICATEDIALOG_H
|
||||||
|
#define CREATECERTIFICATEDIALOG_H
|
||||||
|
|
||||||
|
#include "certificatemanager.h"
|
||||||
|
|
||||||
|
#include <QDialog>
|
||||||
|
|
||||||
|
namespace Ui
|
||||||
|
{
|
||||||
|
class CreateCertificateDialog;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace pdfplugin
|
||||||
|
{
|
||||||
|
|
||||||
|
class CreateCertificateDialog : public QDialog
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
private:
|
||||||
|
using BaseClass = QDialog;
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit CreateCertificateDialog(QWidget* parent);
|
||||||
|
virtual ~CreateCertificateDialog() override;
|
||||||
|
|
||||||
|
const CertificateManager::NewCertificateInfo& getNewCertificateInfo() const { return m_newCertificateInfo; }
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
virtual void accept() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool validate();
|
||||||
|
|
||||||
|
CertificateManager::NewCertificateInfo m_newCertificateInfo;
|
||||||
|
|
||||||
|
Ui::CreateCertificateDialog* ui;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace plugin
|
||||||
|
|
||||||
|
#endif // CREATECERTIFICATEDIALOG_H
|
172
Pdf4QtViewerPlugins/SignaturePlugin/createcertificatedialog.ui
Normal file
172
Pdf4QtViewerPlugins/SignaturePlugin/createcertificatedialog.ui
Normal file
@ -0,0 +1,172 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>CreateCertificateDialog</class>
|
||||||
|
<widget class="QDialog" name="CreateCertificateDialog">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>514</width>
|
||||||
|
<height>488</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Create Certificate</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QGroupBox" name="certificateGroupBox">
|
||||||
|
<property name="title">
|
||||||
|
<string>Create Self Signed Certificate</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QFormLayout" name="formLayout">
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QLabel" name="nameLabel">
|
||||||
|
<property name="text">
|
||||||
|
<string>Name</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="1">
|
||||||
|
<widget class="QLineEdit" name="commonNameEdit">
|
||||||
|
<property name="clearButtonEnabled">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QLabel" name="organizationLabel">
|
||||||
|
<property name="text">
|
||||||
|
<string>Organization</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="0">
|
||||||
|
<widget class="QLabel" name="organizationUnitLabel">
|
||||||
|
<property name="text">
|
||||||
|
<string>Organization Unit</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="4" column="0">
|
||||||
|
<widget class="QLabel" name="emailLabel">
|
||||||
|
<property name="text">
|
||||||
|
<string>Email</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="7" column="0">
|
||||||
|
<spacer name="verticalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>20</width>
|
||||||
|
<height>40</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="QLineEdit" name="organizationEdit">
|
||||||
|
<property name="clearButtonEnabled">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="1">
|
||||||
|
<widget class="QLineEdit" name="organizationUnitEdit">
|
||||||
|
<property name="clearButtonEnabled">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="4" column="1">
|
||||||
|
<widget class="QLineEdit" name="emailEdit">
|
||||||
|
<property name="clearButtonEnabled">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="3" column="0">
|
||||||
|
<widget class="QLabel" name="countryLabel">
|
||||||
|
<property name="text">
|
||||||
|
<string>Country</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="5" column="0">
|
||||||
|
<widget class="QLabel" name="keyLengthLabel">
|
||||||
|
<property name="text">
|
||||||
|
<string>Key length</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="6" column="0">
|
||||||
|
<widget class="QLabel" name="validityLabel">
|
||||||
|
<property name="text">
|
||||||
|
<string>Valid till</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="6" column="1">
|
||||||
|
<widget class="QCalendarWidget" name="validTillEdit"/>
|
||||||
|
</item>
|
||||||
|
<item row="5" column="1">
|
||||||
|
<widget class="QComboBox" name="keyLengthCombo"/>
|
||||||
|
</item>
|
||||||
|
<item row="3" column="1">
|
||||||
|
<widget class="QComboBox" name="countryCombo"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="standardButtons">
|
||||||
|
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>accepted()</signal>
|
||||||
|
<receiver>CreateCertificateDialog</receiver>
|
||||||
|
<slot>accept()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>248</x>
|
||||||
|
<y>254</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>157</x>
|
||||||
|
<y>274</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>rejected()</signal>
|
||||||
|
<receiver>CreateCertificateDialog</receiver>
|
||||||
|
<slot>reject()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>316</x>
|
||||||
|
<y>260</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>286</x>
|
||||||
|
<y>274</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
</connections>
|
||||||
|
</ui>
|
@ -21,6 +21,7 @@
|
|||||||
#include "pdfpagecontenteditorwidget.h"
|
#include "pdfpagecontenteditorwidget.h"
|
||||||
#include "pdfpagecontenteditorstylesettings.h"
|
#include "pdfpagecontenteditorstylesettings.h"
|
||||||
#include "pdfdocumentbuilder.h"
|
#include "pdfdocumentbuilder.h"
|
||||||
|
#include "certificatemanagerdialog.h"
|
||||||
|
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
#include <QToolButton>
|
#include <QToolButton>
|
||||||
@ -155,6 +156,7 @@ void SignaturePlugin::setWidget(pdf::PDFWidget* widget)
|
|||||||
connect(clearAction, &QAction::triggered, &m_scene, &pdf::PDFPageContentScene::clear);
|
connect(clearAction, &QAction::triggered, &m_scene, &pdf::PDFPageContentScene::clear);
|
||||||
connect(activateAction, &QAction::triggered, this, &SignaturePlugin::setActive);
|
connect(activateAction, &QAction::triggered, this, &SignaturePlugin::setActive);
|
||||||
connect(signElectronicallyAction, &QAction::triggered, this, &SignaturePlugin::onSignElectronically);
|
connect(signElectronicallyAction, &QAction::triggered, this, &SignaturePlugin::onSignElectronically);
|
||||||
|
connect(certificatesAction, &QAction::triggered, this, &SignaturePlugin::onOpenCertificatesManager);
|
||||||
|
|
||||||
updateActions();
|
updateActions();
|
||||||
}
|
}
|
||||||
@ -303,6 +305,12 @@ void SignaturePlugin::onSignElectronically()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SignaturePlugin::onOpenCertificatesManager()
|
||||||
|
{
|
||||||
|
CertificateManagerDialog dialog(m_dataExchangeInterface->getMainWindow());
|
||||||
|
dialog.exec();
|
||||||
|
}
|
||||||
|
|
||||||
void SignaturePlugin::onPenChanged(const QPen& pen)
|
void SignaturePlugin::onPenChanged(const QPen& pen)
|
||||||
{
|
{
|
||||||
if (pdf::PDFCreatePCElementTool* activeTool = qobject_cast<pdf::PDFCreatePCElementTool*>(getActiveTool()))
|
if (pdf::PDFCreatePCElementTool* activeTool = qobject_cast<pdf::PDFCreatePCElementTool*>(getActiveTool()))
|
||||||
|
@ -54,6 +54,7 @@ private:
|
|||||||
void onToolActivityChanged();
|
void onToolActivityChanged();
|
||||||
void onSceneEditElement(const std::set<pdf::PDFInteger>& elements);
|
void onSceneEditElement(const std::set<pdf::PDFInteger>& elements);
|
||||||
void onSignElectronically();
|
void onSignElectronically();
|
||||||
|
void onOpenCertificatesManager();
|
||||||
|
|
||||||
void onPenChanged(const QPen& pen);
|
void onPenChanged(const QPen& pen);
|
||||||
void onBrushChanged(const QBrush& brush);
|
void onBrushChanged(const QBrush& brush);
|
||||||
|
Reference in New Issue
Block a user