PDF4QT/PdfForQtLib/sources/pdfsignaturehandler_impl.h

84 lines
2.9 KiB
C
Raw Normal View History

2020-06-13 18:51:06 +02:00
// Copyright (C) 2020 Jakub Melka
//
// This file is part of PdfForQt.
//
// PdfForQt 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
// (at your option) any later version.
//
// PdfForQt 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 PDFForQt. If not, see <https://www.gnu.org/licenses/>.
#ifndef PDFSIGNATUREHANDLER_IMPL_H
#define PDFSIGNATUREHANDLER_IMPL_H
2020-06-14 18:40:42 +02:00
#include "pdfsignaturehandler.h"
#include <openssl/x509.h>
#include <openssl/x509v3.h>
#include <openssl/pkcs7.h>
2020-06-13 18:51:06 +02:00
namespace pdf
{
2020-06-14 18:40:42 +02:00
/// PKCS7 public key signature handler
class PDFPublicKeySignatureHandler : public PDFSignatureHandler
{
protected:
2020-06-27 17:28:03 +02:00
explicit PDFPublicKeySignatureHandler(const PDFFormFieldSignature* signatureField, const QByteArray& sourceData, const Parameters& parameters) :
2020-06-14 18:40:42 +02:00
m_signatureField(signatureField),
2020-06-27 17:28:03 +02:00
m_sourceData(sourceData),
m_parameters(parameters)
2020-06-14 18:40:42 +02:00
{
}
void initializeResult(PDFSignatureVerificationResult& result) const;
void verifyCertificate(PDFSignatureVerificationResult& result) const;
void verifySignature(PDFSignatureVerificationResult& result) const;
2020-06-15 19:07:01 +02:00
void addTrustedCertificates(X509_STORE* store) const;
2020-06-14 18:40:42 +02:00
2020-06-20 14:10:46 +02:00
BIO* getSignedDataBuffer(PDFSignatureVerificationResult& result, QByteArray& outputBuffer) const;
2020-06-27 17:28:03 +02:00
public:
2020-06-14 18:40:42 +02:00
/// Return a list of certificates from PKCS7 object
static STACK_OF(X509)* getCertificates(PKCS7* pkcs7);
2020-06-17 19:50:12 +02:00
/// Return certificate info for given certificate
static PDFCertificateInfo getCertificateInfo(X509* certificate);
/// Returns name converted to QString
static QString getStringFromX509Name(X509_NAME* name, int nid);
/// Converts ASN time to QDateTime. If conversion fails, then invalid
/// datetime is returned.
static QDateTime getDateTimeFromASN(const ASN1_TIME* time);
2020-06-14 18:40:42 +02:00
protected:
const PDFFormFieldSignature* m_signatureField;
QByteArray m_sourceData;
2020-06-27 17:28:03 +02:00
Parameters m_parameters;
2020-06-14 18:40:42 +02:00
};
class PDFSignatureHandler_adbe_pkcs7_detached : public PDFPublicKeySignatureHandler
{
public:
2020-06-27 17:28:03 +02:00
explicit PDFSignatureHandler_adbe_pkcs7_detached(const PDFFormFieldSignature* signatureField, const QByteArray& sourceData, const Parameters& parameters) :
PDFPublicKeySignatureHandler(signatureField, sourceData, parameters)
2020-06-14 18:40:42 +02:00
{
}
virtual PDFSignatureVerificationResult verify() const override;
};
2020-06-13 18:51:06 +02:00
} // namespace pdf
#endif // PDFSIGNATUREHANDLER_IMPL_H