diff options
author | Michael Stahl <michael.stahl@allotropia.de> | 2021-02-18 19:22:31 +0100 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2021-10-19 13:57:45 +0200 |
commit | f79b73878bdb1b0cc1d37270beab1b781cfd169e (patch) | |
tree | 58af8f171516d22beeeb03c5ea27674350960a45 /xmlsecurity/source/helper/xsecparser.cxx | |
parent | xmlsecurity: replace XSecParser implementation (diff) | |
download | core-f79b73878bdb1b0cc1d37270beab1b781cfd169e.tar.gz core-f79b73878bdb1b0cc1d37270beab1b781cfd169e.zip |
xmlsecurity: XSecParser confused about multiple timestamps
LO writes timestamp both to dc:date and xades:SigningTime elements.
The parser tries to avoid reading multiple dc:date, preferring the first
one, but doesn't care about multiple xades:SigningTime, for undocumented
reasons.
Ideally something should check all read values for consistency.
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111160
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
(cherry picked from commit 4ab8d9c09a5873ca0aea56dafa1ab34758d52ef7)
xmlsecurity: remove XSecController::setPropertyId()
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111252
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
(cherry picked from commit d2a345e1163616fe3201ef1d6c758e2e819214e0)
Change-Id: Ic018ee89797a1c8a4f870ae102af48006de930ef
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111908
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
(cherry picked from commit abe77c4fcb9ea97d9fff07eaea6d8863bcba5b02)
Diffstat (limited to 'xmlsecurity/source/helper/xsecparser.cxx')
-rw-r--r-- | xmlsecurity/source/helper/xsecparser.cxx | 81 |
1 files changed, 40 insertions, 41 deletions
diff --git a/xmlsecurity/source/helper/xsecparser.cxx b/xmlsecurity/source/helper/xsecparser.cxx index 85dcbfbd968f..0c3baca5ee5d 100644 --- a/xmlsecurity/source/helper/xsecparser.cxx +++ b/xmlsecurity/source/helper/xsecparser.cxx @@ -975,6 +975,9 @@ class XSecParser::XadesSigningCertificateContext class XSecParser::XadesSigningTimeContext : public XSecParser::Context { + private: + OUString m_Value; + public: XadesSigningTimeContext(XSecParser & rParser, std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap) @@ -982,20 +985,14 @@ class XSecParser::XadesSigningTimeContext { } - virtual void StartElement( - css::uno::Reference<css::xml::sax::XAttributeList> const& /*xAttrs*/) override - { - m_rParser.m_ouDate.clear(); - } - virtual void EndElement() override { - m_rParser.m_pXSecController->setDate( m_rParser.m_ouDate ); + m_rParser.m_pXSecController->setDate("", m_Value); } virtual void Characters(OUString const& rChars) override { - m_rParser.m_ouDate += rChars; + m_Value += rChars; } }; @@ -1101,35 +1098,20 @@ class XSecParser::DcDateContext : public XSecParser::Context { private: - bool m_isIgnore = false; + OUString & m_rValue; public: DcDateContext(XSecParser & rParser, - std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap) + std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap, + OUString & rValue) : XSecParser::Context(rParser, std::move(pOldNamespaceMap)) + , m_rValue(rValue) { } - virtual void StartElement( - css::uno::Reference<css::xml::sax::XAttributeList> const& /*xAttrs*/) override - { - m_isIgnore = !m_rParser.m_ouDate.isEmpty(); - } - - virtual void EndElement() override - { - if (!m_isIgnore) - { - m_rParser.m_pXSecController->setDate( m_rParser.m_ouDate ); - } - } - virtual void Characters(OUString const& rChars) override { - if (!m_isIgnore) - { - m_rParser.m_ouDate += rChars; - } + m_rValue += rChars; } }; @@ -1137,29 +1119,32 @@ class XSecParser::DcDescriptionContext : public XSecParser::Context { private: - OUString m_Value; + OUString & m_rValue; public: DcDescriptionContext(XSecParser & rParser, - std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap) + std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap, + OUString & rValue) : XSecParser::Context(rParser, std::move(pOldNamespaceMap)) + , m_rValue(rValue) { } - virtual void EndElement() override - { - m_rParser.m_pXSecController->setDescription(m_Value); - } - virtual void Characters(OUString const& rChars) override { - m_Value += rChars; + m_rValue += rChars; } }; class XSecParser::DsSignaturePropertyContext : public XSecParser::Context { + private: + enum class SignatureProperty { Unknown, Date, Description }; + SignatureProperty m_Property = SignatureProperty::Unknown; + OUString m_Id; + OUString m_Value; + public: DsSignaturePropertyContext(XSecParser & rParser, std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap) @@ -1170,10 +1155,22 @@ class XSecParser::DsSignaturePropertyContext virtual void StartElement( css::uno::Reference<css::xml::sax::XAttributeList> const& xAttrs) override { - OUString const ouIdAttr(m_rParser.HandleIdAttr(xAttrs)); - if (!ouIdAttr.isEmpty()) + m_Id = m_rParser.HandleIdAttr(xAttrs); + } + + virtual void EndElement() override + { + switch (m_Property) { - m_rParser.m_pXSecController->setPropertyId( ouIdAttr ); + case SignatureProperty::Unknown: + SAL_INFO("xmlsecurity.helper", "Unknown property in ds:Object ignored"); + break; + case SignatureProperty::Date: + m_rParser.m_pXSecController->setDate(m_Id, m_Value); + break; + case SignatureProperty::Description: + m_rParser.m_pXSecController->setDescription(m_Id, m_Value); + break; } } @@ -1183,11 +1180,13 @@ class XSecParser::DsSignaturePropertyContext { if (nNamespace == XML_NAMESPACE_DC && rName == "date") { - return std::make_unique<DcDateContext>(m_rParser, std::move(pOldNamespaceMap)); + m_Property = SignatureProperty::Date; + return std::make_unique<DcDateContext>(m_rParser, std::move(pOldNamespaceMap), m_Value); } if (nNamespace == XML_NAMESPACE_DC && rName == "description") { - return std::make_unique<DcDescriptionContext>(m_rParser, std::move(pOldNamespaceMap)); + m_Property = SignatureProperty::Description; + return std::make_unique<DcDescriptionContext>(m_rParser, std::move(pOldNamespaceMap), m_Value); } return XSecParser::Context::CreateChildContext(std::move(pOldNamespaceMap), nNamespace, rName); } |