We need the password since in the middle of the signing process we need to reopen the document we just created to do some final modifications
@ -5516,6 +5516,7 @@ struct Okular::NewSignatureDataPrivate {
QString certNickname;
QString certSubjectCommonName;
QString password;
QString documentPassword;
int page;
NormalizedRect boundingRectangle;
};
@ -5580,6 +5581,16 @@ void NewSignatureData::setBoundingRectangle(const NormalizedRect &rect)
d->boundingRectangle = rect;
}
QString NewSignatureData::documentPassword() const
{
return d->documentPassword;
void NewSignatureData::setDocumentPassword(const QString &password)
d->documentPassword = password;
#undef foreachObserver
#undef foreachObserverD
@ -1520,6 +1520,12 @@ public:
NormalizedRect boundingRectangle() const;
void setBoundingRectangle(const NormalizedRect &rect);
/// @since 22.04
QString documentPassword() const;
void setDocumentPassword(const QString &password);
private:
NewSignatureDataPrivate *const d;
@ -55,6 +55,16 @@ int main()
" HAVE_POPPLER_21_10)
check_cxx_source_compiles("
#include <poppler-qt5.h>
#include <poppler-form.h>
int main()
Poppler::PDFConverter::NewSignatureData pData;
pData.setDocumentOwnerPassword(QByteArray());
" HAVE_POPPLER_22_02)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/config-okular-poppler.h.cmake
${CMAKE_CURRENT_BINARY_DIR}/config-okular-poppler.h
@ -13,3 +13,5 @@
/* Defined if we have the 21.10 version of the Poppler library or later */
#cmakedefine HAVE_POPPLER_21_10 1
/* Defined if we have the 22.02 version of the Poppler library or later */
#cmakedefine HAVE_POPPLER_22_02 1
@ -1469,6 +1469,14 @@ QVariant PDFGenerator::metaData(const QString &key, const QVariant &option) cons
return QStringLiteral("no");
#else
return QStringLiteral("yes");
#endif
} else if (key == QLatin1String("DocumentHasPassword")) {
return pdfdoc->isEncrypted() ? QStringLiteral("yes") : QStringLiteral("no");
} else if (key == QLatin1String("CanSignDocumentWithPassword")) {
#ifdef HAVE_POPPLER_22_02
return QVariant();
@ -1920,6 +1928,10 @@ bool PDFGenerator::sign(const Okular::NewSignatureData &oData, const QString &rF
pData.setBoundingRectangle({bRect.left, bRect.top, bRect.width(), bRect.height()});
pData.setFontColor(Qt::black);
pData.setBorderColor(Qt::black);
#if HAVE_POPPLER_22_02
pData.setDocumentOwnerPassword(oData.documentPassword().toLatin1());
pData.setDocumentUserPassword(oData.documentPassword().toLatin1());
if (!converter->sign(pData))
return false;
@ -4901,6 +4901,17 @@ void PageView::slotSignature()
return;
const bool documentHasPassword = d->document->metaData(QStringLiteral("DocumentHasPassword")).toString() == QLatin1String("yes");
if (documentHasPassword) {
if (d->document->metaData(QStringLiteral("CanSignDocumentWithPassword")).toString() == QLatin1String("no")) {
KMessageBox::information(nullptr,
i18nc("@info", "The version of the Poppler library this Okular was compiled with does not support signing documents with passwords. Please ask your provider to update it to 22.02 or later."),
i18nc("@title:window", "Poppler library is too old"),
QStringLiteral("popplerOldSignVersion"));
const Okular::CertificateStore *certStore = d->document->certificateStore();
bool userCancelled, nonDateValidCerts;
const QList<Okular::CertificateInfo *> &certs = certStore->signingCertificatesForNow(&userCancelled, &nonDateValidCerts);
@ -409,6 +409,15 @@ public:
m_aborted = true;
if (m_document->metaData(QStringLiteral("DocumentHasPassword")).toString() == QLatin1String("yes")) {
bool ok;
documentPassword = QInputDialog::getText(m_pageView, i18n("Enter document password"), i18n("Enter document password"), QLineEdit::Password, QString(), &ok);
if (!ok) {
passToUse.clear();
m_creationCompleted = false;
clicked = false;
@ -438,9 +447,11 @@ public:
data.setCertNickname(certNicknameToUse);
data.setCertSubjectCommonName(certCommonName);
data.setPassword(passToUse);
data.setDocumentPassword(documentPassword);
data.setPage(m_page->number());
data.setBoundingRectangle(rect);
documentPassword.clear();
return m_document->sign(data, newFilePath);
@ -448,6 +459,7 @@ private:
QString certNicknameToUse;
QString certCommonName;
QString passToUse;
Okular::Document *m_document;
const Okular::Page *m_page;