Kaydet (Commit) e8499348 authored tarafından Miklos Vajna's avatar Miklos Vajna

xmlsecurity PDF verify: don't abort read on partial sign

Map it to the partially signed (not all streams) ODF concept instead.

Change-Id: I7fc931e622b9f10a1261cd475b01a2f038e37ece
Reviewed-on: https://gerrit.libreoffice.org/31497Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
üst dacd0e94
...@@ -106,6 +106,8 @@ struct SignatureInformation ...@@ -106,6 +106,8 @@ struct SignatureInformation
sal_Int32 nDigestID; sal_Int32 nDigestID;
/// For PDF: has id-aa-signingCertificateV2 as a signed attribute. /// For PDF: has id-aa-signingCertificateV2 as a signed attribute.
bool bHasSigningCertificate; bool bHasSigningCertificate;
/// For PDF: the byte range doesn't cover the whole document.
bool bPartialDocumentSignature;
SignatureInformation( sal_Int32 nId ) SignatureInformation( sal_Int32 nId )
{ {
...@@ -113,6 +115,7 @@ struct SignatureInformation ...@@ -113,6 +115,7 @@ struct SignatureInformation
nStatus = css::xml::crypto::SecurityOperationStatus_UNKNOWN; nStatus = css::xml::crypto::SecurityOperationStatus_UNKNOWN;
nDigestID = 0; nDigestID = 0;
bHasSigningCertificate = false; bHasSigningCertificate = false;
bPartialDocumentSignature = false;
} }
}; };
......
...@@ -64,6 +64,8 @@ public: ...@@ -64,6 +64,8 @@ public:
void testPDF14LOWin(); void testPDF14LOWin();
/// Test a PAdES document, signed by LO on Linux. /// Test a PAdES document, signed by LO on Linux.
void testPDFPAdESGood(); void testPDFPAdESGood();
/// Test a valid signature that does not cover the whole file.
void testPartial();
/// Test writing a PAdES signature. /// Test writing a PAdES signature.
void testSigningCertificateAttribute(); void testSigningCertificateAttribute();
/// Test that we accept files which are supposed to be good. /// Test that we accept files which are supposed to be good.
...@@ -81,6 +83,7 @@ public: ...@@ -81,6 +83,7 @@ public:
CPPUNIT_TEST(testPDF16Add); CPPUNIT_TEST(testPDF16Add);
CPPUNIT_TEST(testPDF14LOWin); CPPUNIT_TEST(testPDF14LOWin);
CPPUNIT_TEST(testPDFPAdESGood); CPPUNIT_TEST(testPDFPAdESGood);
CPPUNIT_TEST(testPartial);
CPPUNIT_TEST(testSigningCertificateAttribute); CPPUNIT_TEST(testSigningCertificateAttribute);
CPPUNIT_TEST(testGood); CPPUNIT_TEST(testGood);
CPPUNIT_TEST(testTokenize); CPPUNIT_TEST(testTokenize);
...@@ -331,6 +334,14 @@ void PDFSigningTest::testPDFPAdESGood() ...@@ -331,6 +334,14 @@ void PDFSigningTest::testPDFPAdESGood()
verify(m_directories.getURLFromSrc(DATA_DIRECTORY) + "good-pades.pdf", 1, "ETSI.CAdES.detached"); verify(m_directories.getURLFromSrc(DATA_DIRECTORY) + "good-pades.pdf", 1, "ETSI.CAdES.detached");
} }
void PDFSigningTest::testPartial()
{
std::vector<SignatureInformation> aInfos = verify(m_directories.getURLFromSrc(DATA_DIRECTORY) + "partial.pdf", 1, /*rExpectedSubFilter=*/OString());
CPPUNIT_ASSERT(!aInfos.empty());
SignatureInformation& rInformation = aInfos[0];
CPPUNIT_ASSERT(rInformation.bPartialDocumentSignature);
}
void PDFSigningTest::testSigningCertificateAttribute() void PDFSigningTest::testSigningCertificateAttribute()
{ {
// Create a new signature. // Create a new signature.
......
...@@ -82,6 +82,7 @@ uno::Sequence<security::DocumentSignatureInformation> PDFSignatureHelper::GetDoc ...@@ -82,6 +82,7 @@ uno::Sequence<security::DocumentSignatureInformation> PDFSignatureHelper::GetDoc
security::DocumentSignatureInformation& rExternal = aRet[i]; security::DocumentSignatureInformation& rExternal = aRet[i];
rExternal.SignatureIsValid = rInternal.nStatus == xml::crypto::SecurityOperationStatus_OPERATION_SUCCEEDED; rExternal.SignatureIsValid = rInternal.nStatus == xml::crypto::SecurityOperationStatus_OPERATION_SUCCEEDED;
rExternal.Signer = xSecEnv->createCertificateFromAscii(rInternal.ouX509Certificate); rExternal.Signer = xSecEnv->createCertificateFromAscii(rInternal.ouX509Certificate);
rExternal.PartialDocumentSignature = rInternal.bPartialDocumentSignature;
// Verify certificate. // Verify certificate.
if (rExternal.Signer.is()) if (rExternal.Signer.is())
......
...@@ -2212,10 +2212,8 @@ bool PDFDocument::ValidateSignature(SvStream& rStream, PDFObjectElement* pSignat ...@@ -2212,10 +2212,8 @@ bool PDFDocument::ValidateSignature(SvStream& rStream, PDFObjectElement* pSignat
rStream.Seek(STREAM_SEEK_TO_END); rStream.Seek(STREAM_SEEK_TO_END);
size_t nFileEnd = rStream.Tell(); size_t nFileEnd = rStream.Tell();
if (bLast && (aByteRanges[1].first + aByteRanges[1].second) != nFileEnd) if (bLast && (aByteRanges[1].first + aByteRanges[1].second) != nFileEnd)
{ // Second range end is not the end of the file.
SAL_WARN("xmlsecurity.pdfio", "PDFDocument::ValidateSignature: second range end is not the end of the file"); rInformation.bPartialDocumentSignature = true;
return false;
}
// At this point there is no obviously missing info to validate the // At this point there is no obviously missing info to validate the
// signature. // signature.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment