From d3440e0ebfa68ac8d2cbec9b44d0fc491162ee0e Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Thu, 23 Nov 2017 15:05:03 +0100 Subject: tdf#83877 Unit test for OOXML SignatureLine Roundtrip Change-Id: I40c116f28c0e8efe81e33e48fa05098d1dd76731 Reviewed-on: https://gerrit.libreoffice.org/45152 Reviewed-by: Samuel Mehrbrodt Tested-by: Samuel Mehrbrodt --- oox/source/vml/vmlshape.cxx | 69 +++++++++++++++++++++++++++------------------ 1 file changed, 42 insertions(+), 27 deletions(-) (limited to 'oox/source') diff --git a/oox/source/vml/vmlshape.cxx b/oox/source/vml/vmlshape.cxx index 1cec9461e2df..8079f5ef179d 100644 --- a/oox/source/vml/vmlshape.cxx +++ b/oox/source/vml/vmlshape.cxx @@ -1311,40 +1311,55 @@ Reference< XShape > ComplexShape::implConvertAndInsert( const Reference< XShapes if( getShapeModel().mbIsSignatureLine ) { - // Get the document signatures - Reference< security::XDocumentDigitalSignatures > xSignatures( - security::DocumentDigitalSignatures::createWithVersion( - comphelper::getProcessComponentContext(), "1.2" ) ); - - uno::Reference xStorage = comphelper::OStorageHelper::GetStorageOfFormatFromURL( - ZIP_STORAGE_FORMAT_STRING, mrDrawing.getFilter().getFileUrl(), embed::ElementModes::READ); - SAL_WARN_IF(!xStorage.is(), "oox.vml", "No xStorage!"); - - uno::Sequence< security::DocumentSignatureInformation > xSignatureInfo = - xSignatures->verifyScriptingContentSignatures(xStorage, uno::Reference< io::XInputStream >()); - OUString aGraphicUrl; - for (int i=0; i xSignatures( + security::DocumentDigitalSignatures::createWithVersion( + comphelper::getProcessComponentContext(), "1.2")); + + uno::Reference xStorage + = comphelper::OStorageHelper::GetStorageOfFormatFromURL( + ZIP_STORAGE_FORMAT_STRING, mrDrawing.getFilter().getFileUrl(), + embed::ElementModes::READ); + SAL_WARN_IF(!xStorage.is(), "oox.vml", "No xStorage!"); + + uno::Sequence xSignatureInfo + = xSignatures->verifyScriptingContentSignatures(xStorage, + uno::Reference()); + + for (int i = 0; i < xSignatureInfo.getLength(); i++) { - if (xSignatureInfo[i].SignatureIsValid) - { - // Signature is valid, use the 'valid' image - SAL_WARN_IF(!xSignatureInfo[i].ValidSignatureLineImage.is(), "oox.vml", "No ValidSignatureLineImage!"); - aGraphicUrl = rFilter.getGraphicHelper().createGraphicObject(xSignatureInfo[i].ValidSignatureLineImage); - } - else + // Try to find matching signature line image - if none exists that is fine, + // then the signature line is not digitally signed. + if (xSignatureInfo[i].SignatureLineId == getShapeModel().maSignatureId) { - // Signature is invalid, use the 'invalid' image - SAL_WARN_IF(!xSignatureInfo[i].InvalidSignatureLineImage.is(), "oox.vml", "No InvalidSignatureLineImage!"); - aGraphicUrl = rFilter.getGraphicHelper().createGraphicObject(xSignatureInfo[i].InvalidSignatureLineImage); + if (xSignatureInfo[i].SignatureIsValid) + { + // Signature is valid, use the 'valid' image + SAL_WARN_IF(!xSignatureInfo[i].ValidSignatureLineImage.is(), "oox.vml", + "No ValidSignatureLineImage!"); + aGraphicUrl = rFilter.getGraphicHelper().createGraphicObject( + xSignatureInfo[i].ValidSignatureLineImage); + } + else + { + // Signature is invalid, use the 'invalid' image + SAL_WARN_IF(!xSignatureInfo[i].InvalidSignatureLineImage.is(), "oox.vml", + "No InvalidSignatureLineImage!"); + aGraphicUrl = rFilter.getGraphicHelper().createGraphicObject( + xSignatureInfo[i].InvalidSignatureLineImage); + } + break; } - break; } } + catch (css::uno::Exception&) + { + // DocumentDigitalSignatures service not available. + // We continue by rendering the "unsigned" shape instead. + } Reference< XShape > xShape; if (!aGraphicUrl.isEmpty()) -- cgit