diff options
author | Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de> | 2018-05-16 16:34:35 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2018-11-08 13:55:14 +0100 |
commit | f6c5c8b14bd47aa31a37801ca27294e156d92dbb (patch) | |
tree | 2149451da6153cc792c1b8293753db85ec7009fe | |
parent | a797afa58cd441cb7de5e1fe2845c3eff2e9001b (diff) |
tdf#83877 Write SignatureLineId to ODF & OOXML signatures
Reviewed-on: https://gerrit.libreoffice.org/54432
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
(cherry picked from commit 201321f648e82ecc610e7a3324a46248a19c1704)
Conflicts:
cui/source/dialogs/SignSignatureLineDialog.cxx
xmlsecurity/source/component/documentdigitalsignatures.cxx
xmlsecurity/source/helper/documentsignaturemanager.cxx
Change-Id: I483a3b7895cdcb10ef9d6dacf167ed0f8db7e723
-rw-r--r-- | include/sfx2/docfile.hxx | 1 | ||||
-rw-r--r-- | include/sfx2/objsh.hxx | 9 | ||||
-rw-r--r-- | offapi/com/sun/star/security/XDocumentDigitalSignatures.idl | 3 | ||||
-rw-r--r-- | sfx2/source/doc/docfile.cxx | 9 | ||||
-rw-r--r-- | sfx2/source/doc/objserv.cxx | 13 | ||||
-rw-r--r-- | xmlsecurity/inc/documentsignaturemanager.hxx | 3 | ||||
-rw-r--r-- | xmlsecurity/inc/xmlsignaturehelper.hxx | 1 | ||||
-rw-r--r-- | xmlsecurity/inc/xsecctl.hxx | 1 | ||||
-rw-r--r-- | xmlsecurity/source/component/documentdigitalsignatures.cxx | 6 | ||||
-rw-r--r-- | xmlsecurity/source/component/documentdigitalsignatures.hxx | 3 | ||||
-rw-r--r-- | xmlsecurity/source/helper/documentsignaturemanager.cxx | 6 | ||||
-rw-r--r-- | xmlsecurity/source/helper/ooxmlsecexporter.cxx | 1 | ||||
-rw-r--r-- | xmlsecurity/source/helper/xmlsignaturehelper.cxx | 5 | ||||
-rw-r--r-- | xmlsecurity/source/helper/xsecctl.cxx | 22 | ||||
-rw-r--r-- | xmlsecurity/source/helper/xsecparser.cxx | 15 | ||||
-rw-r--r-- | xmlsecurity/source/helper/xsecparser.hxx | 2 | ||||
-rw-r--r-- | xmlsecurity/source/helper/xsecsign.cxx | 17 |
17 files changed, 96 insertions, 21 deletions
diff --git a/include/sfx2/docfile.hxx b/include/sfx2/docfile.hxx index 57c52b81cb95..4eb3357fa6d5 100644 --- a/include/sfx2/docfile.hxx +++ b/include/sfx2/docfile.hxx @@ -265,6 +265,7 @@ public: SAL_DLLPRIVATE bool SignContents_Impl(const css::uno::Reference<css::security::XCertificate> xCert, + const OUString& aSignatureLineId, bool bScriptingContent, const OUString& aODFVersion, bool bHasValidDocumentSignature); diff --git a/include/sfx2/objsh.hxx b/include/sfx2/objsh.hxx index 7263e78bdcbc..5208e1a58184 100644 --- a/include/sfx2/objsh.hxx +++ b/include/sfx2/objsh.hxx @@ -359,7 +359,8 @@ public: // xmlsec05, check with SFX team SignatureState GetDocumentSignatureState(); void SignDocumentContent(); - void SignDocumentContent(css::uno::Reference<css::security::XCertificate> xCert); + void SignDocumentContent(css::uno::Reference<css::security::XCertificate> xCert, + const OUString& aSignatureLineId); SignatureState GetScriptingSignatureState(); void SignScriptingContent(); DECL_LINK(SignDocumentHandler, Button*, void); @@ -742,9 +743,9 @@ public: const css::uno::Reference< css::security::XDocumentDigitalSignatures >& xSigner = css::uno::Reference< css::security::XDocumentDigitalSignatures >() ); - SAL_DLLPRIVATE void - ImplSign(const css::uno::Reference<css::security::XCertificate> xCert, - bool bScriptingContent = false); + SAL_DLLPRIVATE void ImplSign(const css::uno::Reference<css::security::XCertificate> xCert + = css::uno::Reference<css::security::XCertificate>(), + const OUString& aSignatureLineId = OUString(), bool bScriptingContent = false); SAL_DLLPRIVATE bool QuerySaveSizeExceededModules_Impl( const css::uno::Reference< css::task::XInteractionHandler >& xHandler ); SAL_DLLPRIVATE bool QueryAllowExoticFormat_Impl( const css::uno::Reference< css::task::XInteractionHandler >& xHandler, diff --git a/offapi/com/sun/star/security/XDocumentDigitalSignatures.idl b/offapi/com/sun/star/security/XDocumentDigitalSignatures.idl index 69d86af35a8a..d0bd80ca698b 100644 --- a/offapi/com/sun/star/security/XDocumentDigitalSignatures.idl +++ b/offapi/com/sun/star/security/XDocumentDigitalSignatures.idl @@ -55,7 +55,8 @@ interface XDocumentDigitalSignatures : com::sun::star::uno::XInterface */ boolean signDocumentContentWithCertificate( [in] ::com::sun::star::embed::XStorage xStorage, [in] ::com::sun::star::io::XStream xSignStream, - [in] ::com::sun::star::security::XCertificate xCertificate); + [in] ::com::sun::star::security::XCertificate xCertificate, + [in] string signatureLineId); /** checks for digital signatures and their status. diff --git a/sfx2/source/doc/docfile.cxx b/sfx2/source/doc/docfile.cxx index 2a679cd36bac..6e0b45168ba5 100644 --- a/sfx2/source/doc/docfile.cxx +++ b/sfx2/source/doc/docfile.cxx @@ -3575,8 +3575,9 @@ void SfxMedium::CreateTempFileNoCopy() CloseStorage(); } -bool SfxMedium::SignContents_Impl(const Reference<XCertificate> xCert, bool bScriptingContent, - const OUString& aODFVersion, bool bHasValidDocumentSignature) +bool SfxMedium::SignContents_Impl(const Reference<XCertificate> xCert, const OUString& aSignatureLineId, + bool bScriptingContent, const OUString& aODFVersion, + bool bHasValidDocumentSignature) { bool bChanges = false; @@ -3667,7 +3668,7 @@ bool SfxMedium::SignContents_Impl(const Reference<XCertificate> xCert, bool bScr bool bSuccess = false; if (xCert.is()) bSuccess = xSigner->signDocumentContentWithCertificate( - GetZipStorageToSign_Impl(), xStream, xCert); + GetZipStorageToSign_Impl(), xStream, xCert, aSignatureLineId); else bSuccess = xSigner->signDocumentContent(GetZipStorageToSign_Impl(), xStream); @@ -3693,7 +3694,7 @@ bool SfxMedium::SignContents_Impl(const Reference<XCertificate> xCert, bool bScr if (xCert.is()) { bSuccess = xSigner->signDocumentContentWithCertificate( - GetZipStorageToSign_Impl(), xStream, xCert); + GetZipStorageToSign_Impl(/*bReadOnly=*/false), xStream, xCert, aSignatureLineId); } else { diff --git a/sfx2/source/doc/objserv.cxx b/sfx2/source/doc/objserv.cxx index c8bc40e8bb19..e4c6b18986f0 100644 --- a/sfx2/source/doc/objserv.cxx +++ b/sfx2/source/doc/objserv.cxx @@ -1360,7 +1360,7 @@ SignatureState SfxObjectShell::ImplGetSignatureState( bool bScriptingContent ) return *pState; } -void SfxObjectShell::ImplSign(Reference<XCertificate> xCert, +void SfxObjectShell::ImplSign(Reference<XCertificate> xCert, const OUString& aSignatureLineId, bool bScriptingContent) { // Check if it is stored in OASIS format... @@ -1477,7 +1477,7 @@ void SfxObjectShell::ImplSign(Reference<XCertificate> xCert, || pImpl->nDocumentSignatureState == SignatureState::PARTIAL_OK; bool bSignSuccess = GetMedium()->SignContents_Impl( - xCert, bScriptingContent, aODFVersion, bHasValidSignatures); + xCert, aSignatureLineId, bScriptingContent, aODFVersion, bHasValidSignatures); pImpl->m_bSavingForSigning = true; DoSaveCompleted( GetMedium() ); @@ -1512,12 +1512,13 @@ SignatureState SfxObjectShell::GetDocumentSignatureState() void SfxObjectShell::SignDocumentContent() { - ImplSign(Reference<XCertificate>()); + ImplSign(); } -void SfxObjectShell::SignDocumentContent(const Reference<XCertificate> xCert) +void SfxObjectShell::SignDocumentContent(const Reference<XCertificate> xCert, + const OUString& aSignatureLineId) { - ImplSign(xCert); + ImplSign(xCert, aSignatureLineId); } SignatureState SfxObjectShell::GetScriptingSignatureState() @@ -1527,7 +1528,7 @@ SignatureState SfxObjectShell::GetScriptingSignatureState() void SfxObjectShell::SignScriptingContent() { - ImplSign( Reference<XCertificate>(), true ); + ImplSign( Reference<XCertificate>(), OUString(), true ); } namespace diff --git a/xmlsecurity/inc/documentsignaturemanager.hxx b/xmlsecurity/inc/documentsignaturemanager.hxx index f1cc8293de42..bae54619cbd5 100644 --- a/xmlsecurity/inc/documentsignaturemanager.hxx +++ b/xmlsecurity/inc/documentsignaturemanager.hxx @@ -63,7 +63,8 @@ public: /// Add a new signature, using xCert as a signing certificate, and rDescription as description. bool add(const css::uno::Reference<css::security::XCertificate>& xCert, const css::uno::Reference<css::xml::crypto::XXMLSecurityContext>& xSecurityContext, - const OUString& rDescription, sal_Int32& nSecurityId, bool bAdESCompliant); + const OUString& rDescription, sal_Int32& nSecurityId, bool bAdESCompliant, + const OUString& rSignatureLineId = OUString()); /// Remove signature at nPosition. void remove(sal_uInt16 nPosition); /// Read signatures from either a temp stream or the real storage. diff --git a/xmlsecurity/inc/xmlsignaturehelper.hxx b/xmlsecurity/inc/xmlsignaturehelper.hxx index 6f9784f4a690..c665f5a56903 100644 --- a/xmlsecurity/inc/xmlsignaturehelper.hxx +++ b/xmlsecurity/inc/xmlsignaturehelper.hxx @@ -128,6 +128,7 @@ public: void SetDateTime( sal_Int32 nSecurityId, const Date& rDate, const tools::Time& rTime ); void SetDescription(sal_Int32 nSecurityId, const OUString& rDescription); + void SetSignatureLineId(sal_Int32 nSecurityId, const OUString& rSignatureLineId); void AddForSigning( sal_Int32 securityId, const OUString& uri, bool bBinary, bool bXAdESCompliantIfODF ); bool CreateAndWriteSignature( const css::uno::Reference< css::xml::sax::XDocumentHandler >& xDocumentHandler, bool bXAdESCompliantIfODF ); diff --git a/xmlsecurity/inc/xsecctl.hxx b/xmlsecurity/inc/xsecctl.hxx index cc3b11db80a7..5d8d85f9c93e 100644 --- a/xmlsecurity/inc/xsecctl.hxx +++ b/xmlsecurity/inc/xsecctl.hxx @@ -352,6 +352,7 @@ public: sal_Int32 nSecurityId, const css::util::DateTime& rDateTime ); void setDescription(sal_Int32 nSecurityId, const OUString& rDescription); + void setSignatureLineId(sal_Int32 nSecurityId, const OUString& rSignatureLineId); bool WriteSignature( const css::uno::Reference< css::xml::sax::XDocumentHandler >& xDocumentHandler, diff --git a/xmlsecurity/source/component/documentdigitalsignatures.cxx b/xmlsecurity/source/component/documentdigitalsignatures.cxx index eee5a09952e6..5f0f2bb201f3 100644 --- a/xmlsecurity/source/component/documentdigitalsignatures.cxx +++ b/xmlsecurity/source/component/documentdigitalsignatures.cxx @@ -125,7 +125,7 @@ sal_Bool DocumentDigitalSignatures::signDocumentContent( sal_Bool DocumentDigitalSignatures::signDocumentContentWithCertificate( const Reference<css::embed::XStorage>& rxStorage, const Reference<css::io::XStream>& xSignStream, - const Reference<css::security::XCertificate>& xCertificate) + const Reference<css::security::XCertificate>& xCertificate, const OUString& aSignatureLineId) { OSL_ENSURE(!m_sODFVersion.isEmpty(), "DocumentDigitalSignatures: ODF Version not set, assuming minimum 1.2"); @@ -149,8 +149,8 @@ sal_Bool DocumentDigitalSignatures::signDocumentContentWithCertificate( sal_Int32 nSecurityId; OUString aDescription(""); - bool bSuccess - = aSignatureManager.add(xCertificate, xSecurityContext, aDescription, nSecurityId, true); + bool bSuccess = aSignatureManager.add(xCertificate, xSecurityContext, aDescription, nSecurityId, + true, aSignatureLineId); if (!bSuccess) return false; diff --git a/xmlsecurity/source/component/documentdigitalsignatures.hxx b/xmlsecurity/source/component/documentdigitalsignatures.hxx index 72ac2ced5014..8a3d0468d85b 100644 --- a/xmlsecurity/source/component/documentdigitalsignatures.hxx +++ b/xmlsecurity/source/component/documentdigitalsignatures.hxx @@ -89,7 +89,8 @@ public: sal_Bool SAL_CALL signDocumentContentWithCertificate( const css::uno::Reference<css::embed::XStorage>& Storage, const css::uno::Reference<css::io::XStream>& xSignStream, - const css::uno::Reference<css::security::XCertificate>& xCertificate) override; + const css::uno::Reference<css::security::XCertificate>& xCertificate, + const OUString& rSignatureLineId) override; css::uno::Sequence< css::security::DocumentSignatureInformation > SAL_CALL verifyDocumentContentSignatures( const css::uno::Reference< css::embed::XStorage >& xStorage, const css::uno::Reference< css::io::XInputStream >& xSignInStream ) override; void SAL_CALL showDocumentContentSignatures( const css::uno::Reference< css::embed::XStorage >& xStorage, const css::uno::Reference< css::io::XInputStream >& xSignInStream ) override; OUString SAL_CALL getDocumentContentSignatureDefaultStreamName( ) override; diff --git a/xmlsecurity/source/helper/documentsignaturemanager.cxx b/xmlsecurity/source/helper/documentsignaturemanager.cxx index 45787b190311..218360d2f60c 100644 --- a/xmlsecurity/source/helper/documentsignaturemanager.cxx +++ b/xmlsecurity/source/helper/documentsignaturemanager.cxx @@ -257,7 +257,8 @@ bool DocumentSignatureManager::add(const uno::Reference<security::XCertificate>& const uno::Reference<xml::crypto::XXMLSecurityContext>& xSecurityContext, const OUString& rDescription, sal_Int32& nSecurityId, - bool bAdESCompliant) + bool bAdESCompliant, + const OUString& rSignatureLineId) { if (!xCert.is()) { @@ -364,6 +365,9 @@ bool DocumentSignatureManager::add(const uno::Reference<security::XCertificate>& maSignatureHelper.SetDateTime(nSecurityId, Date(Date::SYSTEM), tools::Time(tools::Time::SYSTEM)); maSignatureHelper.SetDescription(nSecurityId, rDescription); + if (!rSignatureLineId.isEmpty()) + maSignatureHelper.SetSignatureLineId(nSecurityId, rSignatureLineId); + // We open a signature stream in which the existing and the new //signature is written. ImplGetSignatureInformation (later in this function) will //then read the stream an will fill maCurrentSignatureInformations. The final signature diff --git a/xmlsecurity/source/helper/ooxmlsecexporter.cxx b/xmlsecurity/source/helper/ooxmlsecexporter.cxx index 87f94958629c..9ce056d5a868 100644 --- a/xmlsecurity/source/helper/ooxmlsecexporter.cxx +++ b/xmlsecurity/source/helper/ooxmlsecexporter.cxx @@ -351,6 +351,7 @@ void OOXMLSecExporter::Impl::writeSignatureInfo() m_xDocumentHandler->startElement("SignatureInfoV1", uno::Reference<xml::sax::XAttributeList>(pAttributeList.get())); m_xDocumentHandler->startElement("SetupId", uno::Reference<xml::sax::XAttributeList>(new SvXMLAttributeList())); + m_xDocumentHandler->characters(m_rInformation.ouSignatureLineId); m_xDocumentHandler->endElement("SetupId"); m_xDocumentHandler->startElement("SignatureText", uno::Reference<xml::sax::XAttributeList>(new SvXMLAttributeList())); m_xDocumentHandler->endElement("SignatureText"); diff --git a/xmlsecurity/source/helper/xmlsignaturehelper.cxx b/xmlsecurity/source/helper/xmlsignaturehelper.cxx index 0f7630171285..33406fe2a829 100644 --- a/xmlsecurity/source/helper/xmlsignaturehelper.cxx +++ b/xmlsecurity/source/helper/xmlsignaturehelper.cxx @@ -146,6 +146,11 @@ void XMLSignatureHelper::SetDescription(sal_Int32 nSecurityId, const OUString& r mpXSecController->setDescription(nSecurityId, rDescription); } +void XMLSignatureHelper::SetSignatureLineId(sal_Int32 nSecurityId, const OUString& rSignatureLineId) +{ + mpXSecController->setSignatureLineId(nSecurityId, rSignatureLineId); +} + void XMLSignatureHelper::AddForSigning( sal_Int32 nSecurityId, const OUString& uri, bool bBinary, bool bXAdESCompliantIfODF ) { mpXSecController->signAStream( nSecurityId, uri, bBinary, bXAdESCompliantIfODF ); diff --git a/xmlsecurity/source/helper/xsecctl.cxx b/xmlsecurity/source/helper/xsecctl.cxx index 96d04436341f..cbff47dc75c3 100644 --- a/xmlsecurity/source/helper/xsecctl.cxx +++ b/xmlsecurity/source/helper/xsecctl.cxx @@ -833,6 +833,28 @@ void XSecController::exportSignature( "dc:date"); } xDocumentHandler->endElement( "SignatureProperty" ); + + if (!signatureInfo.ouSignatureLineId.isEmpty()) + { + pAttributeList = new SvXMLAttributeList(); + pAttributeList->AddAttribute( + "xmlns:loext", + "urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0"); + pAttributeList->AddAttribute("Target", "#" + signatureInfo.ouSignatureId); + + xDocumentHandler->startElement( + "SignatureProperty", + cssu::Reference<cssxs::XAttributeList>(pAttributeList)); + { + // Write SignatureLineId element + xDocumentHandler->startElement( + "loext:SignatureLineId", + cssu::Reference<cssxs::XAttributeList>(new SvXMLAttributeList())); + xDocumentHandler->characters(signatureInfo.ouSignatureLineId); + xDocumentHandler->endElement("loext:SignatureLineId"); + } + xDocumentHandler->endElement("SignatureProperty"); + } } // Write signature description. diff --git a/xmlsecurity/source/helper/xsecparser.cxx b/xmlsecurity/source/helper/xsecparser.cxx index 50c13dc95bee..b33a11f5cf36 100644 --- a/xmlsecurity/source/helper/xsecparser.cxx +++ b/xmlsecurity/source/helper/xsecparser.cxx @@ -44,6 +44,7 @@ XSecParser::XSecParser(XMLSignatureHelper& rXMLSignatureHelper, , m_bInSignatureValue(false) , m_bInDate(false) , m_bInDescription(false) + , m_bInSignatureLineId(false) , m_pXSecController(pXSecController) , m_bReferenceUnresolved(false) , m_nReferenceDigestID(cssxc::DigestID::SHA1) @@ -252,6 +253,11 @@ void SAL_CALL XSecParser::startElement( m_ouDescription.clear(); m_bInDescription = true; } + else if (aName == "loext:SignatureLineId") + { + m_ouSignatureLineId.clear(); + m_bInSignatureLineId = true; + } if (m_xNextHandler.is()) { @@ -361,6 +367,11 @@ void SAL_CALL XSecParser::endElement( const OUString& aName ) m_pXSecController->setDescription( m_ouDescription ); m_bInDescription = false; } + else if (aName == "loext:SignatureLineId") + { + m_pXSecController->setSignatureLineId( m_ouSignatureLineId ); + m_bInSignatureLineId = false; + } if (m_xNextHandler.is()) { @@ -436,6 +447,10 @@ void SAL_CALL XSecParser::characters( const OUString& aChars ) { m_ouDate += aChars; } + else if (m_bInSignatureLineId) + { + m_ouSignatureLineId += aChars; + } if (m_xNextHandler.is()) { diff --git a/xmlsecurity/source/helper/xsecparser.hxx b/xmlsecurity/source/helper/xsecparser.hxx index 8376a48b69cd..e1c4515ce941 100644 --- a/xmlsecurity/source/helper/xsecparser.hxx +++ b/xmlsecurity/source/helper/xsecparser.hxx @@ -67,6 +67,7 @@ private: OUString m_ouDate; /// Characters of a <dc:description> element, as just read from XML. OUString m_ouDescription; + OUString m_ouSignatureLineId; /* * whether inside a particular element @@ -84,6 +85,7 @@ private: bool m_bInSignatureValue; bool m_bInDate; bool m_bInDescription; + bool m_bInSignatureLineId; /* * the XSecController collaborating with XSecParser diff --git a/xmlsecurity/source/helper/xsecsign.cxx b/xmlsecurity/source/helper/xsecsign.cxx index b5e50f3c8bf0..701ce84d1989 100644 --- a/xmlsecurity/source/helper/xsecsign.cxx +++ b/xmlsecurity/source/helper/xsecsign.cxx @@ -288,6 +288,23 @@ void XSecController::setDescription(sal_Int32 nSecurityId, const OUString& rDesc } } +void XSecController::setSignatureLineId(sal_Int32 nSecurityId, const OUString& rSignatureLineId) +{ + int nIndex = findSignatureInfor(nSecurityId); + + if (nIndex == -1) + { + InternalSignatureInformation aInformation(nSecurityId, nullptr); + aInformation.signatureInfor.ouSignatureLineId = rSignatureLineId; + m_vInternalSignatureInformations.push_back(aInformation); + } + else + { + SignatureInformation& rInformation = m_vInternalSignatureInformations[nIndex].signatureInfor; + rInformation.ouSignatureLineId = rSignatureLineId; + } +} + bool XSecController::WriteSignature( const cssu::Reference<cssxs::XDocumentHandler>& xDocumentHandler, bool bXAdESCompliantIfODF ) |