Filtr pro adbe.pkcs7.sha1

This commit is contained in:
Jakub Melka 2020-06-29 20:17:35 +02:00
parent 6fb32613f3
commit 515a8184d4
2 changed files with 47 additions and 1 deletions

View File

@ -23,6 +23,7 @@
#include "pdfsignaturehandler_impl.h"
#include <openssl/err.h>
#include <openssl/sha.h>
#include <QMutex>
#include <QMutexLocker>
@ -149,6 +150,10 @@ PDFSignatureHandler* PDFSignatureHandler::createHandler(const PDFFormFieldSignat
{
return new PDFSignatureHandler_adbe_pkcs7_detached(signatureField, sourceData, parameters);
}
else if (subfilter == "adbe.pkcs7.sha1")
{
return new PDFSignatureHandler_adbe_pkcs7_sha1(signatureField, sourceData, parameters);
}
return nullptr;
}
@ -670,6 +675,32 @@ PDFSignatureVerificationResult PDFSignatureHandler_adbe_pkcs7_detached::verify()
return result;
}
PDFSignatureVerificationResult PDFSignatureHandler_adbe_pkcs7_sha1::verify() const
{
PDFSignatureVerificationResult result;
initializeResult(result);
verifyCertificate(result);
verifySignature(result);
result.validate();
return result;
}
BIO* PDFSignatureHandler_adbe_pkcs7_sha1::getSignedDataBuffer(PDFSignatureVerificationResult& result, QByteArray& outputBuffer) const
{
QByteArray temporaryBuffer;
if (BIO* bio = PDFPublicKeySignatureHandler::getSignedDataBuffer(result, temporaryBuffer))
{
// Calculate SHA1
outputBuffer.resize(SHA_DIGEST_LENGTH);
SHA1(reinterpret_cast<const unsigned char*>(temporaryBuffer.data()), temporaryBuffer.length(), reinterpret_cast<unsigned char*>(outputBuffer.data()));
BIO_free(bio);
return BIO_new_mem_buf(outputBuffer.data(), outputBuffer.length());
}
return nullptr;
}
PDFCertificateInfo PDFPublicKeySignatureHandler::getCertificateInfo(X509* certificate)
{
PDFCertificateInfo info;

View File

@ -44,7 +44,7 @@ protected:
void verifySignature(PDFSignatureVerificationResult& result) const;
void addTrustedCertificates(X509_STORE* store) const;
BIO* getSignedDataBuffer(PDFSignatureVerificationResult& result, QByteArray& outputBuffer) const;
virtual BIO* getSignedDataBuffer(PDFSignatureVerificationResult& result, QByteArray& outputBuffer) const;
public:
/// Return a list of certificates from PKCS7 object
@ -78,6 +78,21 @@ public:
virtual PDFSignatureVerificationResult verify() const override;
};
class PDFSignatureHandler_adbe_pkcs7_sha1 : public PDFPublicKeySignatureHandler
{
public:
explicit PDFSignatureHandler_adbe_pkcs7_sha1(const PDFFormFieldSignature* signatureField, const QByteArray& sourceData, const Parameters& parameters) :
PDFPublicKeySignatureHandler(signatureField, sourceData, parameters)
{
}
virtual PDFSignatureVerificationResult verify() const override;
protected:
virtual BIO* getSignedDataBuffer(PDFSignatureVerificationResult& result, QByteArray& outputBuffer) const override;
};
} // namespace pdf
#endif // PDFSIGNATUREHANDLER_IMPL_H