Blame SOURCES/0003-xmlsecurity-replace-XSecParser-implementation.patch

24cd51
From 4201f1be45b4567ba64655439dcc39ac403c28e0 Mon Sep 17 00:00:00 2001
24cd51
From: Michael Stahl <michael.stahl@allotropia.de>
24cd51
Date: Fri, 12 Feb 2021 16:42:51 +0100
24cd51
Subject: [PATCH 3/6] xmlsecurity: replace XSecParser implementation
24cd51
MIME-Version: 1.0
24cd51
Content-Type: text/plain; charset=UTF-8
24cd51
Content-Transfer-Encoding: 8bit
24cd51
24cd51
Implement Namespaces in XML and follow xmldsig-core and XAdES schemas.
24cd51
24cd51
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110833
24cd51
Tested-by: Jenkins
24cd51
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
24cd51
(cherry picked from commit 12b15be8f4f930a04d8056b9219ac969b42a9784)
24cd51
24cd51
xmlsecurity: move XSecParser state into contexts
24cd51
24cd51
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111158
24cd51
Tested-by: Jenkins
24cd51
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
24cd51
(cherry picked from commit 59df9e70ce1a7ec797b836bda7f9642912febc53)
24cd51
24cd51
xmlsecurity: move XSecParser Reference state into contexts
24cd51
24cd51
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111159
24cd51
Tested-by: Jenkins
24cd51
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
24cd51
(cherry picked from commit cfeb89a758b5f0ec406f0d72444e52ed2f47b85e)
24cd51
24cd51
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111907
24cd51
Tested-by: Jenkins
24cd51
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
24cd51
(cherry picked from commit ad5930e87e788780a255523f106deb1dde5d7b37)
24cd51
24cd51
Change-Id: I03537b51bb757ecbfa63a826b38de543c70ba032
24cd51
---
24cd51
 include/xmloff/xmlimp.hxx                |    6 +-
24cd51
 include/xmloff/xmlnmspe.hxx              |    7 +
24cd51
 include/xmloff/xmltoken.hxx              |   13 +
24cd51
 xmloff/source/core/xmlimp.cxx            |   26 +-
24cd51
 xmloff/source/core/xmltoken.cxx          |   13 +
24cd51
 xmloff/source/token/tokens.txt           |   10 +
24cd51
 xmlsecurity/source/helper/xsecparser.cxx | 1629 +++++++++++++++++-----
24cd51
 xmlsecurity/source/helper/xsecparser.hxx |   99 +-
24cd51
 8 files changed, 1425 insertions(+), 378 deletions(-)
24cd51
24cd51
diff --git a/include/xmloff/xmlimp.hxx b/include/xmloff/xmlimp.hxx
24cd51
index 6d0dda96596a..8d557789aa4c 100644
24cd51
--- a/include/xmloff/xmlimp.hxx
24cd51
+++ b/include/xmloff/xmlimp.hxx
24cd51
@@ -229,8 +229,12 @@ class XMLOFF_DLLPUBLIC SvXMLImport : public cppu::WeakImplHelper<
24cd51
 
24cd51
     static void initializeNamespaceMaps();
24cd51
     void registerNamespaces();
24cd51
-    std::unique_ptr<SvXMLNamespaceMap> processNSAttributes(
24cd51
+public:
24cd51
+    static std::unique_ptr<SvXMLNamespaceMap> processNSAttributes(
24cd51
+        std::unique_ptr<SvXMLNamespaceMap> & rpNamespaceMap,
24cd51
+        SvXMLImport *const pImport,
24cd51
         const css::uno::Reference< css::xml::sax::XAttributeList >& xAttrList);
24cd51
+private:
24cd51
     void Characters(const OUString& aChars);
24cd51
 
24cd51
     css::uno::Reference< css::task::XStatusIndicator > mxStatusIndicator;
24cd51
diff --git a/include/xmloff/xmlnmspe.hxx b/include/xmloff/xmlnmspe.hxx
24cd51
index b079053c38d3..302a134f92fe 100644
24cd51
--- a/include/xmloff/xmlnmspe.hxx
24cd51
+++ b/include/xmloff/xmlnmspe.hxx
24cd51
@@ -66,6 +66,13 @@ XML_NAMESPACE( XML_NAMESPACE_OF,              34U )   // OpenFormula aka ODFF
24cd51
 XML_NAMESPACE( XML_NAMESPACE_XHTML,           35U )
24cd51
 XML_NAMESPACE( XML_NAMESPACE_GRDDL,           36U )
24cd51
 XML_NAMESPACE( XML_NAMESPACE_VERSIONS_LIST,   37U )
24cd51
+// OOo extension digital signatures, used in ODF 1.1
24cd51
+XML_NAMESPACE( XML_NAMESPACE_DSIG_OOO,        38U )
24cd51
+// ODF 1.2 digital signature namespaces
24cd51
+XML_NAMESPACE( XML_NAMESPACE_DSIG,            39U )
24cd51
+XML_NAMESPACE( XML_NAMESPACE_DS,              40U )
24cd51
+XML_NAMESPACE( XML_NAMESPACE_XADES132,        41U )
24cd51
+XML_NAMESPACE( XML_NAMESPACE_XADES141,        42U )
24cd51
 
24cd51
 // namespaces for odf extended formats
24cd51
 
24cd51
diff --git a/include/xmloff/xmltoken.hxx b/include/xmloff/xmltoken.hxx
24cd51
index b5105e5da0f3..a0e52903060a 100644
24cd51
--- a/include/xmloff/xmltoken.hxx
24cd51
+++ b/include/xmloff/xmltoken.hxx
24cd51
@@ -133,6 +133,19 @@ namespace xmloff { namespace token {
24cd51
         XML_NP_GRDDL,
24cd51
         XML_N_GRDDL,
24cd51
 
24cd51
+        // OOo extension digital signatures, used in ODF 1.1
24cd51
+        XML_NP_DSIG_OOO,
24cd51
+        XML_N_DSIG_OOO,
24cd51
+        // ODF 1.2 digital signatures
24cd51
+        XML_NP_DSIG,
24cd51
+        XML_N_DSIG,
24cd51
+        XML_NP_DS,
24cd51
+        XML_N_DS,
24cd51
+        XML_NP_XADES132,
24cd51
+        XML_N_XADES132,
24cd51
+        XML_NP_XADES141,
24cd51
+        XML_N_XADES141,
24cd51
+
24cd51
         // ODF Enhanced namespaces
24cd51
         XML_NP_OFFICE_EXT,
24cd51
         XML_N_OFFICE_EXT,
24cd51
diff --git a/xmloff/source/core/xmlimp.cxx b/xmloff/source/core/xmlimp.cxx
24cd51
index ef63550ff2be..bfc9d3fe819a 100644
24cd51
--- a/xmloff/source/core/xmlimp.cxx
24cd51
+++ b/xmloff/source/core/xmlimp.cxx
24cd51
@@ -653,6 +653,8 @@ void SAL_CALL SvXMLImport::endDocument()
24cd51
 }
24cd51
 
24cd51
 std::unique_ptr<SvXMLNamespaceMap> SvXMLImport::processNSAttributes(
24cd51
+        std::unique_ptr<SvXMLNamespaceMap> & rpNamespaceMap,
24cd51
+        SvXMLImport *const pImport, // TODO???
24cd51
         const uno::Reference< xml::sax::XAttributeList >& xAttrList)
24cd51
 {
24cd51
     std::unique_ptr<SvXMLNamespaceMap> pRewindMap;
24cd51
@@ -660,12 +662,13 @@ std::unique_ptr<SvXMLNamespaceMap> SvXMLImport::processNSAttributes(
24cd51
     for( sal_Int16 i=0; i < nAttrCount; i++ )
24cd51
     {
24cd51
         const OUString& rAttrName = xAttrList->getNameByIndex( i );
24cd51
-        if ( rAttrName == "office:version" )
24cd51
+        if (pImport && rAttrName == "office:version")
24cd51
         {
24cd51
-            mpImpl->aODFVersion = xAttrList->getValueByIndex( i );
24cd51
+            pImport->mpImpl->aODFVersion = xAttrList->getValueByIndex( i );
24cd51
 
24cd51
             // the ODF version in content.xml and manifest.xml must be the same starting from ODF1.2
24cd51
-            if ( mpImpl->mStreamName == "content.xml" && !IsODFVersionConsistent( mpImpl->aODFVersion ) )
24cd51
+            if (pImport->mpImpl->mStreamName == "content.xml"
24cd51
+                && !pImport->IsODFVersionConsistent(pImport->mpImpl->aODFVersion))
24cd51
             {
24cd51
                 throw xml::sax::SAXException("Inconsistent ODF versions in content.xml and manifest.xml!",
24cd51
                         uno::Reference< uno::XInterface >(),
24cd51
@@ -679,8 +682,8 @@ std::unique_ptr<SvXMLNamespaceMap> SvXMLImport::processNSAttributes(
24cd51
         {
24cd51
             if( !pRewindMap )
24cd51
             {
24cd51
-                pRewindMap = std::move(mpNamespaceMap);
24cd51
-                mpNamespaceMap.reset(new SvXMLNamespaceMap(*pRewindMap));
24cd51
+                pRewindMap = std::move(rpNamespaceMap);
24cd51
+                rpNamespaceMap.reset(new SvXMLNamespaceMap(*pRewindMap));
24cd51
             }
24cd51
             const OUString& rAttrValue = xAttrList->getValueByIndex( i );
24cd51
 
24cd51
@@ -688,18 +691,18 @@ std::unique_ptr<SvXMLNamespaceMap> SvXMLImport::processNSAttributes(
24cd51
                                  ? OUString()
24cd51
                                  : rAttrName.copy( 6 ) );
24cd51
             // Add namespace, but only if it is known.
24cd51
-            sal_uInt16 nKey = mpNamespaceMap->AddIfKnown( aPrefix, rAttrValue );
24cd51
+            sal_uInt16 nKey = rpNamespaceMap->AddIfKnown( aPrefix, rAttrValue );
24cd51
             // If namespace is unknown, try to match a name with similar
24cd51
             // TC Id and version
24cd51
             if( XML_NAMESPACE_UNKNOWN == nKey  )
24cd51
             {
24cd51
                 OUString aTestName( rAttrValue );
24cd51
                 if( SvXMLNamespaceMap::NormalizeURI( aTestName ) )
24cd51
-                    nKey = mpNamespaceMap->AddIfKnown( aPrefix, aTestName );
24cd51
+                    nKey = rpNamespaceMap->AddIfKnown( aPrefix, aTestName );
24cd51
             }
24cd51
             // If that namespace is not known, too, add it as unknown
24cd51
             if( XML_NAMESPACE_UNKNOWN == nKey  )
24cd51
-                mpNamespaceMap->Add( aPrefix, rAttrValue );
24cd51
+                rpNamespaceMap->Add( aPrefix, rAttrValue );
24cd51
 
24cd51
         }
24cd51
     }
24cd51
@@ -712,7 +715,8 @@ void SAL_CALL SvXMLImport::startElement( const OUString& rName,
24cd51
     //    SAL_INFO("svg", "startElement " << rName);
24cd51
     // Process namespace attributes. This must happen before creating the
24cd51
     // context, because namespace declaration apply to the element name itself.
24cd51
-    std::unique_ptr<SvXMLNamespaceMap> pRewindMap(processNSAttributes(xAttrList));
24cd51
+    std::unique_ptr<SvXMLNamespaceMap> pRewindMap(
24cd51
+        processNSAttributes(mpNamespaceMap, this, xAttrList));
24cd51
 
24cd51
     // Get element's namespace and local name.
24cd51
     OUString aLocalName;
24cd51
@@ -885,7 +889,7 @@ void SAL_CALL SvXMLImport::startFastElement (sal_Int32 Element,
24cd51
 
24cd51
         maNamespaceHandler->addNSDeclAttributes( maNamespaceAttrList );
24cd51
         std::unique_ptr<SvXMLNamespaceMap> pRewindMap(
24cd51
-                processNSAttributes( maNamespaceAttrList.get() ));
24cd51
+            processNSAttributes(mpNamespaceMap, this, maNamespaceAttrList.get()));
24cd51
         assert( dynamic_cast<SvXMLImportContext*>( xContext.get() ) != nullptr );
24cd51
         SvXMLImportContext *pContext = static_cast<SvXMLImportContext*>( xContext.get() );
24cd51
         if (pRewindMap)
24cd51
@@ -2231,7 +2235,7 @@ void SAL_CALL SvXMLLegacyToFastDocHandler::endDocument()
24cd51
 void SAL_CALL SvXMLLegacyToFastDocHandler::startElement( const OUString& rName,
24cd51
                         const uno::Reference< xml::sax::XAttributeList >& xAttrList )
24cd51
 {
24cd51
-    mrImport->processNSAttributes(xAttrList);
24cd51
+    SvXMLImport::processNSAttributes(mrImport->mpNamespaceMap, mrImport.get(), xAttrList);
24cd51
     OUString aLocalName;
24cd51
     sal_uInt16 nPrefix = mrImport->mpNamespaceMap->GetKeyByAttrName( rName, &aLocalName );
24cd51
     Sequence< sal_Int8 > aLocalNameSeq( reinterpret_cast<sal_Int8 const *>(
24cd51
diff --git a/xmloff/source/core/xmltoken.cxx b/xmloff/source/core/xmltoken.cxx
24cd51
index fb760c6307c5..13f1415b8cc4 100644
24cd51
--- a/xmloff/source/core/xmltoken.cxx
24cd51
+++ b/xmloff/source/core/xmltoken.cxx
24cd51
@@ -137,6 +137,19 @@ namespace xmloff { namespace token {
24cd51
         TOKEN( "grddl",                                 XML_NP_GRDDL ),
24cd51
         TOKEN( "http://www.w3.org/2003/g/data-view#",   XML_N_GRDDL ),
24cd51
 
24cd51
+        // OOo extension digital signatures, used in ODF 1.1
24cd51
+        TOKEN( "dsigooo", XML_NP_DSIG_OOO ),
24cd51
+        TOKEN( "http://openoffice.org/2004/documentsignatures", XML_N_DSIG_OOO ),
24cd51
+        // ODF 1.2 digital signature namespaces
24cd51
+        TOKEN( "dsig", XML_NP_DSIG ),
24cd51
+        TOKEN( "urn:oasis:names:tc:opendocument:xmlns:digitalsignature:1.0", XML_N_DSIG ),
24cd51
+        TOKEN( "ds", XML_NP_DS ),
24cd51
+        TOKEN( "http://www.w3.org/2000/09/xmldsig#", XML_N_DS ),
24cd51
+        TOKEN( "xades132", XML_NP_XADES132 ),
24cd51
+        TOKEN( "http://uri.etsi.org/01903/v1.3.2#", XML_N_XADES132 ),
24cd51
+        TOKEN( "xades141", XML_NP_XADES141 ),
24cd51
+        TOKEN( "http://uri.etsi.org/01903/v1.4.1#", XML_N_XADES141 ),
24cd51
+
24cd51
         // ODF Enhanced namespaces
24cd51
         TOKEN( "officeooo", XML_NP_OFFICE_EXT ),
24cd51
         TOKEN( "http://openoffice.org/2009/office", XML_N_OFFICE_EXT ),
24cd51
diff --git a/xmloff/source/token/tokens.txt b/xmloff/source/token/tokens.txt
24cd51
index 024877e8cf45..b2b95e956bd1 100644
24cd51
--- a/xmloff/source/token/tokens.txt
24cd51
+++ b/xmloff/source/token/tokens.txt
24cd51
@@ -72,6 +72,16 @@ xhtml
24cd51
 N_XHTML_DUMMY
24cd51
 grddl
24cd51
 N_GRDDL_DUMMY
24cd51
+dsigooo
24cd51
+N_DSIG_OOO_DUMMY
24cd51
+dsig
24cd51
+N_DSIG_DUMMY
24cd51
+ds
24cd51
+N_DS_DUMMY
24cd51
+xades132
24cd51
+N_XADES132_DUMMY
24cd51
+xades141
24cd51
+N_XADES141_DUMMY
24cd51
 officeooo
24cd51
 N_OFFICE_EXT_DUMMY
24cd51
 formx
24cd51
diff --git a/xmlsecurity/source/helper/xsecparser.cxx b/xmlsecurity/source/helper/xsecparser.cxx
24cd51
index 82f347bff976..5c92e5efa104 100644
24cd51
--- a/xmlsecurity/source/helper/xsecparser.cxx
24cd51
+++ b/xmlsecurity/source/helper/xsecparser.cxx
24cd51
@@ -21,6 +21,10 @@
24cd51
 #include "xsecparser.hxx"
24cd51
 #include <xsecctl.hxx>
24cd51
 #include <xmlsignaturehelper.hxx>
24cd51
+
24cd51
+#include <xmloff/xmlnmspe.hxx>
24cd51
+#include <xmloff/xmlimp.hxx>
24cd51
+
24cd51
 #include <com/sun/star/xml/sax/SAXException.hpp>
24cd51
 #include <cppuhelper/exc_hlp.hxx>
24cd51
 #include <sal/log.hxx>
24cd51
@@ -29,471 +33,1460 @@ namespace cssu = com::sun::star::uno;
24cd51
 namespace cssxc = com::sun::star::xml::crypto;
24cd51
 namespace cssxs = com::sun::star::xml::sax;
24cd51
 
24cd51
-XSecParser::XSecParser(XMLSignatureHelper& rXMLSignatureHelper,
24cd51
-    XSecController* pXSecController)
24cd51
-    : m_bInX509IssuerName(false)
24cd51
-    , m_bInX509SerialNumber(false)
24cd51
-    , m_bInX509Certificate(false)
24cd51
-    , m_bInGpgCertificate(false)
24cd51
-    , m_bInGpgKeyID(false)
24cd51
-    , m_bInGpgOwner(false)
24cd51
-    , m_bInCertDigest(false)
24cd51
-    , m_bInEncapsulatedX509Certificate(false)
24cd51
-    , m_bInSigningTime(false)
24cd51
-    , m_bInDigestValue(false)
24cd51
-    , m_bInSignatureValue(false)
24cd51
-    , m_bInDate(false)
24cd51
-    , m_bInDescription(false)
24cd51
-    , m_bInSignatureLineId(false)
24cd51
-    , m_bInSignatureLineValidImage(false)
24cd51
-    , m_bInSignatureLineInvalidImage(false)
24cd51
-    , m_pXSecController(pXSecController)
24cd51
-    , m_bReferenceUnresolved(false)
24cd51
-    , m_nReferenceDigestID(cssxc::DigestID::SHA1)
24cd51
-    , m_rXMLSignatureHelper(rXMLSignatureHelper)
24cd51
+class XSecParser::Context
24cd51
 {
24cd51
-}
24cd51
+    protected:
24cd51
+        friend class XSecParser;
24cd51
+        XSecParser & m_rParser;
24cd51
+    private:
24cd51
+        std::unique_ptr<SvXMLNamespaceMap> m_pOldNamespaceMap;
24cd51
+
24cd51
+    public:
24cd51
+        Context(XSecParser & rParser,
24cd51
+                std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap)
24cd51
+            : m_rParser(rParser)
24cd51
+            , m_pOldNamespaceMap(std::move(pOldNamespaceMap))
24cd51
+        {
24cd51
+        }
24cd51
+
24cd51
+        virtual ~Context() = default;
24cd51
 
24cd51
-OUString XSecParser::getIdAttr(const cssu::Reference< cssxs::XAttributeList >& xAttribs )
24cd51
+        virtual void StartElement(
24cd51
+            css::uno::Reference<css::xml::sax::XAttributeList> const& /*xAttrs*/)
24cd51
+        {
24cd51
+        }
24cd51
+
24cd51
+        virtual void EndElement()
24cd51
+        {
24cd51
+        }
24cd51
+
24cd51
+        virtual std::unique_ptr<Context> CreateChildContext(
24cd51
+            std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap,
24cd51
+            sal_uInt16 const /*nNamespace*/, OUString const& /*rName*/);
24cd51
+
24cd51
+        virtual void Characters(OUString const& /*rChars*/)
24cd51
+        {
24cd51
+        }
24cd51
+};
24cd51
+
24cd51
+// it's possible that an unsupported element has an Id attribute and a
24cd51
+// ds:Reference digesting it - probably this means XSecController needs to know
24cd51
+// about it. (For known elements, the Id attribute is only processed according
24cd51
+// to the schema.)
24cd51
+class XSecParser::UnknownContext
24cd51
+    : public XSecParser::Context
24cd51
 {
24cd51
-    OUString ouIdAttr = xAttribs->getValueByName("id");
24cd51
+    public:
24cd51
+        UnknownContext(XSecParser & rParser,
24cd51
+                std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap)
24cd51
+            : XSecParser::Context(rParser, std::move(pOldNamespaceMap))
24cd51
+        {
24cd51
+        }
24cd51
 
24cd51
-    if (ouIdAttr.isEmpty())
24cd51
-    {
24cd51
-        ouIdAttr = xAttribs->getValueByName("Id");
24cd51
-    }
24cd51
+        virtual void StartElement(
24cd51
+            css::uno::Reference<css::xml::sax::XAttributeList> const& xAttrs) override
24cd51
+        {
24cd51
+            m_rParser.HandleIdAttr(xAttrs);
24cd51
+        }
24cd51
+};
24cd51
 
24cd51
-    return ouIdAttr;
24cd51
+auto XSecParser::Context::CreateChildContext(
24cd51
+    std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap,
24cd51
+    sal_uInt16 const /*nNamespace*/, OUString const& /*rName*/)
24cd51
+-> std::unique_ptr<Context>
24cd51
+{
24cd51
+    // default: create new base context
24cd51
+    return std::make_unique<UnknownContext>(m_rParser, std::move(pOldNamespaceMap));
24cd51
 }
24cd51
 
24cd51
-/*
24cd51
- * XDocumentHandler
24cd51
- */
24cd51
-void SAL_CALL XSecParser::startDocument(  )
24cd51
+class XSecParser::LoPGPOwnerContext
24cd51
+    : public XSecParser::Context
24cd51
 {
24cd51
-    m_bInX509IssuerName = false;
24cd51
-    m_bInX509SerialNumber = false;
24cd51
-    m_bInX509Certificate = false;
24cd51
-    m_bInGpgCertificate = false;
24cd51
-    m_bInGpgKeyID = false;
24cd51
-    m_bInGpgOwner = false;
24cd51
-    m_bInSignatureValue = false;
24cd51
-    m_bInDigestValue = false;
24cd51
-    m_bInDate = false;
24cd51
-    m_bInDescription = false;
24cd51
+    private:
24cd51
+        OUString m_Value;
24cd51
 
24cd51
-    if (m_xNextHandler.is())
24cd51
-    {
24cd51
-        m_xNextHandler->startDocument();
24cd51
-    }
24cd51
-}
24cd51
+    public:
24cd51
+        LoPGPOwnerContext(XSecParser & rParser,
24cd51
+                std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap)
24cd51
+            : XSecParser::Context(rParser, std::move(pOldNamespaceMap))
24cd51
+        {
24cd51
+        }
24cd51
 
24cd51
-void SAL_CALL XSecParser::endDocument(  )
24cd51
+        virtual void EndElement() override
24cd51
+        {
24cd51
+            m_rParser.m_pXSecController->setGpgOwner(m_Value);
24cd51
+        }
24cd51
+
24cd51
+        virtual void Characters(OUString const& rChars) override
24cd51
+        {
24cd51
+            m_Value += rChars;
24cd51
+        }
24cd51
+};
24cd51
+
24cd51
+class XSecParser::DsPGPKeyPacketContext
24cd51
+    : public XSecParser::Context
24cd51
 {
24cd51
-    if (m_xNextHandler.is())
24cd51
-    {
24cd51
-        m_xNextHandler->endDocument();
24cd51
-    }
24cd51
-}
24cd51
+    private:
24cd51
+        OUString m_Value;
24cd51
+
24cd51
+    public:
24cd51
+        DsPGPKeyPacketContext(XSecParser & rParser,
24cd51
+                std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap)
24cd51
+            : XSecParser::Context(rParser, std::move(pOldNamespaceMap))
24cd51
+        {
24cd51
+        }
24cd51
+
24cd51
+        virtual void EndElement() override
24cd51
+        {
24cd51
+            m_rParser.m_pXSecController->setGpgCertificate(m_Value);
24cd51
+        }
24cd51
+
24cd51
+        virtual void Characters(OUString const& rChars) override
24cd51
+        {
24cd51
+            m_Value += rChars;
24cd51
+        }
24cd51
+};
24cd51
+
24cd51
+class XSecParser::DsPGPKeyIDContext
24cd51
+    : public XSecParser::Context
24cd51
+{
24cd51
+    private:
24cd51
+        OUString m_Value;
24cd51
+
24cd51
+    public:
24cd51
+        DsPGPKeyIDContext(XSecParser & rParser,
24cd51
+                std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap)
24cd51
+            : XSecParser::Context(rParser, std::move(pOldNamespaceMap))
24cd51
+        {
24cd51
+        }
24cd51
+
24cd51
+        virtual void EndElement() override
24cd51
+        {
24cd51
+            m_rParser.m_pXSecController->setGpgKeyID(m_Value);
24cd51
+        }
24cd51
+
24cd51
+        virtual void Characters(OUString const& rChars) override
24cd51
+        {
24cd51
+            m_Value += rChars;
24cd51
+        }
24cd51
+};
24cd51
+
24cd51
+class XSecParser::DsPGPDataContext
24cd51
+    : public XSecParser::Context
24cd51
+{
24cd51
+    public:
24cd51
+        DsPGPDataContext(XSecParser & rParser,
24cd51
+                std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap)
24cd51
+            : XSecParser::Context(rParser, std::move(pOldNamespaceMap))
24cd51
+        {
24cd51
+        }
24cd51
+
24cd51
+        virtual void StartElement(
24cd51
+            css::uno::Reference<css::xml::sax::XAttributeList> const& /*xAttrs*/) override
24cd51
+        {
24cd51
+            m_rParser.m_pXSecController->switchGpgSignature();
24cd51
+        }
24cd51
+
24cd51
+        virtual std::unique_ptr<Context> CreateChildContext(
24cd51
+            std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap,
24cd51
+            sal_uInt16 const nNamespace, OUString const& rName) override
24cd51
+        {
24cd51
+            if (nNamespace == XML_NAMESPACE_DS && rName == "PGPKeyID")
24cd51
+            {
24cd51
+                return std::make_unique<DsPGPKeyIDContext>(m_rParser, std::move(pOldNamespaceMap));
24cd51
+            }
24cd51
+            if (nNamespace == XML_NAMESPACE_DS && rName == "PGPKeyPacket")
24cd51
+            {
24cd51
+                return std::make_unique<DsPGPKeyPacketContext>(m_rParser, std::move(pOldNamespaceMap));
24cd51
+            }
24cd51
+            if (nNamespace == XML_NAMESPACE_LO_EXT && rName == "PGPOwner")
24cd51
+            {
24cd51
+                return std::make_unique<LoPGPOwnerContext>(m_rParser, std::move(pOldNamespaceMap));
24cd51
+            }
24cd51
+            return XSecParser::Context::CreateChildContext(std::move(pOldNamespaceMap), nNamespace, rName);
24cd51
+        }
24cd51
+};
24cd51
+
24cd51
+class XSecParser::DsX509CertificateContext
24cd51
+    : public XSecParser::Context
24cd51
+{
24cd51
+    private:
24cd51
+        OUString m_Value;
24cd51
+
24cd51
+    public:
24cd51
+        DsX509CertificateContext(XSecParser & rParser,
24cd51
+                std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap)
24cd51
+            : XSecParser::Context(rParser, std::move(pOldNamespaceMap))
24cd51
+        {
24cd51
+        }
24cd51
+
24cd51
+        virtual void EndElement() override
24cd51
+        {
24cd51
+            m_rParser.m_pXSecController->setX509Certificate(m_Value);
24cd51
+        }
24cd51
+
24cd51
+        virtual void Characters(OUString const& rChars) override
24cd51
+        {
24cd51
+            m_Value += rChars;
24cd51
+        }
24cd51
+};
24cd51
+
24cd51
+class XSecParser::DsX509SerialNumberContext
24cd51
+    : public XSecParser::Context
24cd51
+{
24cd51
+    private:
24cd51
+        OUString m_Value;
24cd51
+
24cd51
+    public:
24cd51
+        DsX509SerialNumberContext(XSecParser & rParser,
24cd51
+                std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap)
24cd51
+            : XSecParser::Context(rParser, std::move(pOldNamespaceMap))
24cd51
+        {
24cd51
+        }
24cd51
+
24cd51
+        virtual void EndElement() override
24cd51
+        {
24cd51
+            m_rParser.m_pXSecController->setX509SerialNumber(m_Value);
24cd51
+        }
24cd51
+
24cd51
+        virtual void Characters(OUString const& rChars) override
24cd51
+        {
24cd51
+            m_Value += rChars;
24cd51
+        }
24cd51
+};
24cd51
+
24cd51
+class XSecParser::DsX509IssuerNameContext
24cd51
+    : public XSecParser::Context
24cd51
+{
24cd51
+    private:
24cd51
+        OUString m_Value;
24cd51
+
24cd51
+    public:
24cd51
+        DsX509IssuerNameContext(XSecParser & rParser,
24cd51
+                std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap)
24cd51
+            : XSecParser::Context(rParser, std::move(pOldNamespaceMap))
24cd51
+        {
24cd51
+        }
24cd51
+
24cd51
+        virtual void EndElement() override
24cd51
+        {
24cd51
+            m_rParser.m_pXSecController->setX509IssuerName(m_Value);
24cd51
+        }
24cd51
+
24cd51
+        virtual void Characters(OUString const& rChars) override
24cd51
+        {
24cd51
+            m_Value += rChars;
24cd51
+        }
24cd51
+};
24cd51
+
24cd51
+class XSecParser::DsX509IssuerSerialContext
24cd51
+    : public XSecParser::Context
24cd51
+{
24cd51
+    public:
24cd51
+        DsX509IssuerSerialContext(XSecParser & rParser,
24cd51
+                std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap)
24cd51
+            : XSecParser::Context(rParser, std::move(pOldNamespaceMap))
24cd51
+        {
24cd51
+        }
24cd51
+
24cd51
+        virtual std::unique_ptr<Context> CreateChildContext(
24cd51
+            std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap,
24cd51
+            sal_uInt16 const nNamespace, OUString const& rName) override
24cd51
+        {
24cd51
+            if (nNamespace == XML_NAMESPACE_DS && rName == "X509IssuerName")
24cd51
+            {
24cd51
+                return std::make_unique<DsX509IssuerNameContext>(m_rParser, std::move(pOldNamespaceMap));
24cd51
+            }
24cd51
+            if (nNamespace == XML_NAMESPACE_DS && rName == "X509SerialNumber")
24cd51
+            {
24cd51
+                return std::make_unique<DsX509SerialNumberContext>(m_rParser, std::move(pOldNamespaceMap));
24cd51
+            }
24cd51
+            // missing: ds:X509SKI, ds:X509SubjectName, ds:X509CRL
24cd51
+            return XSecParser::Context::CreateChildContext(std::move(pOldNamespaceMap), nNamespace, rName);
24cd51
+        }
24cd51
+};
24cd51
+
24cd51
+class XSecParser::DsX509DataContext
24cd51
+    : public XSecParser::Context
24cd51
+{
24cd51
+    public:
24cd51
+        DsX509DataContext(XSecParser & rParser,
24cd51
+                std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap)
24cd51
+            : XSecParser::Context(rParser, std::move(pOldNamespaceMap))
24cd51
+        {
24cd51
+        }
24cd51
+
24cd51
+        virtual std::unique_ptr<Context> CreateChildContext(
24cd51
+            std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap,
24cd51
+            sal_uInt16 const nNamespace, OUString const& rName) override
24cd51
+        {
24cd51
+            if (nNamespace == XML_NAMESPACE_DS && rName == "X509IssuerSerial")
24cd51
+            {
24cd51
+                return std::make_unique<DsX509IssuerSerialContext>(m_rParser, std::move(pOldNamespaceMap));
24cd51
+            }
24cd51
+            if (nNamespace == XML_NAMESPACE_DS && rName == "X509Certificate")
24cd51
+            {
24cd51
+                return std::make_unique<DsX509CertificateContext>(m_rParser, std::move(pOldNamespaceMap));
24cd51
+            }
24cd51
+            // missing: ds:X509SKI, ds:X509SubjectName, ds:X509CRL
24cd51
+            return XSecParser::Context::CreateChildContext(std::move(pOldNamespaceMap), nNamespace, rName);
24cd51
+        }
24cd51
+};
24cd51
+
24cd51
+class XSecParser::DsKeyInfoContext
24cd51
+    : public XSecParser::Context
24cd51
+{
24cd51
+    public:
24cd51
+        DsKeyInfoContext(XSecParser & rParser,
24cd51
+                std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap)
24cd51
+            : XSecParser::Context(rParser, std::move(pOldNamespaceMap))
24cd51
+        {
24cd51
+        }
24cd51
+
24cd51
+        virtual void StartElement(
24cd51
+            css::uno::Reference<css::xml::sax::XAttributeList> const& xAttrs) override
24cd51
+        {
24cd51
+            m_rParser.HandleIdAttr(xAttrs);
24cd51
+        }
24cd51
+
24cd51
+        virtual std::unique_ptr<Context> CreateChildContext(
24cd51
+            std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap,
24cd51
+            sal_uInt16 const nNamespace, OUString const& rName) override
24cd51
+        {
24cd51
+            if (nNamespace == XML_NAMESPACE_DS && rName == "X509Data")
24cd51
+            {
24cd51
+                return std::make_unique<DsX509DataContext>(m_rParser, std::move(pOldNamespaceMap));
24cd51
+            }
24cd51
+            if (nNamespace == XML_NAMESPACE_DS && rName == "PGPData")
24cd51
+            {
24cd51
+                return std::make_unique<DsPGPDataContext>(m_rParser, std::move(pOldNamespaceMap));
24cd51
+            }
24cd51
+            // missing: ds:KeyName, ds:KeyValue, ds:RetrievalMethod, ds:SPKIData, ds:MgmtData
24cd51
+            // (old code would read ds:Transform inside ds:RetrievalMethod but
24cd51
+            // presumably that was a bug)
24cd51
+            return XSecParser::Context::CreateChildContext(std::move(pOldNamespaceMap), nNamespace, rName);
24cd51
+        }
24cd51
+
24cd51
+};
24cd51
+
24cd51
+class XSecParser::DsSignatureValueContext
24cd51
+    : public XSecParser::Context
24cd51
+{
24cd51
+    private:
24cd51
+        OUString m_Value;
24cd51
+
24cd51
+    public:
24cd51
+        DsSignatureValueContext(XSecParser & rParser,
24cd51
+                std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap)
24cd51
+            : XSecParser::Context(rParser, std::move(pOldNamespaceMap))
24cd51
+        {
24cd51
+        }
24cd51
+
24cd51
+        virtual void StartElement(
24cd51
+            css::uno::Reference<css::xml::sax::XAttributeList> const& xAttrs) override
24cd51
+        {
24cd51
+            m_rParser.HandleIdAttr(xAttrs);
24cd51
+        }
24cd51
+
24cd51
+        virtual void EndElement() override
24cd51
+        {
24cd51
+            m_rParser.m_pXSecController->setSignatureValue(m_Value);
24cd51
+        }
24cd51
+
24cd51
+        virtual void Characters(OUString const& rChars) override
24cd51
+        {
24cd51
+            m_Value += rChars;
24cd51
+        }
24cd51
+};
24cd51
+
24cd51
+class XSecParser::DsDigestValueContext
24cd51
+    : public XSecParser::Context
24cd51
+{
24cd51
+    private:
24cd51
+        OUString & m_rValue;
24cd51
+
24cd51
+    public:
24cd51
+        DsDigestValueContext(XSecParser & rParser,
24cd51
+                std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap,
24cd51
+                OUString & rValue)
24cd51
+            : XSecParser::Context(rParser, std::move(pOldNamespaceMap))
24cd51
+            , m_rValue(rValue)
24cd51
+        {
24cd51
+        }
24cd51
+
24cd51
+        virtual void StartElement(
24cd51
+            css::uno::Reference<css::xml::sax::XAttributeList> const& /*xAttrs*/) override
24cd51
+        {
24cd51
+            m_rValue.clear();
24cd51
+        }
24cd51
+
24cd51
+        virtual void Characters(OUString const& rChars) override
24cd51
+        {
24cd51
+            m_rValue += rChars;
24cd51
+        }
24cd51
+};
24cd51
+
24cd51
+class XSecParser::DsDigestMethodContext
24cd51
+    : public XSecParser::Context
24cd51
+{
24cd51
+    private:
24cd51
+        sal_Int32 & m_rReferenceDigestID;
24cd51
+
24cd51
+    public:
24cd51
+        DsDigestMethodContext(XSecParser & rParser,
24cd51
+                std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap,
24cd51
+                sal_Int32 & rReferenceDigestID)
24cd51
+            : XSecParser::Context(rParser, std::move(pOldNamespaceMap))
24cd51
+            , m_rReferenceDigestID(rReferenceDigestID)
24cd51
+        {
24cd51
+        }
24cd51
+
24cd51
+        virtual void StartElement(
24cd51
+            css::uno::Reference<css::xml::sax::XAttributeList> const& xAttrs) override
24cd51
+        {
24cd51
+            OUString ouAlgorithm = xAttrs->getValueByName("Algorithm");
24cd51
+
24cd51
+            SAL_WARN_IF( ouAlgorithm.isEmpty(), "xmlsecurity.helper", "no Algorithm in Reference" );
24cd51
+            if (!ouAlgorithm.isEmpty())
24cd51
+            {
24cd51
+                SAL_WARN_IF( ouAlgorithm != ALGO_XMLDSIGSHA1
24cd51
+                             && ouAlgorithm != ALGO_XMLDSIGSHA256
24cd51
+                             && ouAlgorithm != ALGO_XMLDSIGSHA512,
24cd51
+                             "xmlsecurity.helper", "Algorithm neither SHA1, SHA256 nor SHA512");
24cd51
+                if (ouAlgorithm == ALGO_XMLDSIGSHA1)
24cd51
+                    m_rReferenceDigestID = css::xml::crypto::DigestID::SHA1;
24cd51
+                else if (ouAlgorithm == ALGO_XMLDSIGSHA256)
24cd51
+                    m_rReferenceDigestID = css::xml::crypto::DigestID::SHA256;
24cd51
+                else if (ouAlgorithm == ALGO_XMLDSIGSHA512)
24cd51
+                    m_rReferenceDigestID = css::xml::crypto::DigestID::SHA512;
24cd51
+                else
24cd51
+                    m_rReferenceDigestID = 0;
24cd51
+            }
24cd51
+        }
24cd51
+};
24cd51
+
24cd51
+class XSecParser::DsTransformContext
24cd51
+    : public XSecParser::Context
24cd51
+{
24cd51
+    private:
24cd51
+        bool & m_rIsC14N;
24cd51
+
24cd51
+    public:
24cd51
+        DsTransformContext(XSecParser & rParser,
24cd51
+                std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap,
24cd51
+                bool & rIsC14N)
24cd51
+            : XSecParser::Context(rParser, std::move(pOldNamespaceMap))
24cd51
+            , m_rIsC14N(rIsC14N)
24cd51
+        {
24cd51
+        }
24cd51
+
24cd51
+        virtual void StartElement(
24cd51
+            css::uno::Reference<css::xml::sax::XAttributeList> const& xAttrs) override
24cd51
+        {
24cd51
+            OUString ouAlgorithm = xAttrs->getValueByName("Algorithm");
24cd51
+
24cd51
+            if (ouAlgorithm == ALGO_C14N)
24cd51
+                /*
24cd51
+                 * a xml stream
24cd51
+                 */
24cd51
+            {
24cd51
+                m_rIsC14N = true;
24cd51
+            }
24cd51
+        }
24cd51
+};
24cd51
+
24cd51
+class XSecParser::DsTransformsContext
24cd51
+    : public XSecParser::Context
24cd51
+{
24cd51
+    private:
24cd51
+        bool & m_rIsC14N;
24cd51
+
24cd51
+    public:
24cd51
+        DsTransformsContext(XSecParser & rParser,
24cd51
+                std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap,
24cd51
+                bool & rIsC14N)
24cd51
+            : XSecParser::Context(rParser, std::move(pOldNamespaceMap))
24cd51
+            , m_rIsC14N(rIsC14N)
24cd51
+        {
24cd51
+        }
24cd51
+
24cd51
+        virtual std::unique_ptr<Context> CreateChildContext(
24cd51
+            std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap,
24cd51
+            sal_uInt16 const nNamespace, OUString const& rName) override
24cd51
+        {
24cd51
+            if (nNamespace == XML_NAMESPACE_DS && rName == "Transform")
24cd51
+            {
24cd51
+                return std::make_unique<DsTransformContext>(m_rParser, std::move(pOldNamespaceMap), m_rIsC14N);
24cd51
+            }
24cd51
+            return XSecParser::Context::CreateChildContext(std::move(pOldNamespaceMap), nNamespace, rName);
24cd51
+        }
24cd51
+};
24cd51
+
24cd51
+class XSecParser::DsReferenceContext
24cd51
+    : public XSecParser::Context
24cd51
+{
24cd51
+    private:
24cd51
+        OUString m_URI;
24cd51
+        OUString m_Type;
24cd51
+        OUString m_DigestValue;
24cd51
+        bool m_IsC14N = false;
24cd51
+        // Relevant for ODF. The digest algorithm selected by the DigestMethod
24cd51
+        // element's Algorithm attribute. @see css::xml::crypto::DigestID.
24cd51
+        sal_Int32 m_nReferenceDigestID = css::xml::crypto::DigestID::SHA1;
24cd51
+
24cd51
+    public:
24cd51
+        DsReferenceContext(XSecParser & rParser,
24cd51
+                std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap)
24cd51
+            : XSecParser::Context(rParser, std::move(pOldNamespaceMap))
24cd51
+        {
24cd51
+        }
24cd51
+
24cd51
+        virtual void StartElement(
24cd51
+            css::uno::Reference<css::xml::sax::XAttributeList> const& xAttrs) override
24cd51
+        {
24cd51
+            m_rParser.HandleIdAttr(xAttrs);
24cd51
+
24cd51
+            m_URI = xAttrs->getValueByName("URI");
24cd51
+            SAL_WARN_IF(m_URI.isEmpty(), "xmlsecurity.helper", "URI is empty");
24cd51
+            // Remember the type of this reference.
24cd51
+            m_Type = xAttrs->getValueByName("Type");
24cd51
+        }
24cd51
+
24cd51
+        virtual void EndElement() override
24cd51
+        {
24cd51
+            if (m_URI.startsWith("#"))
24cd51
+            {
24cd51
+                /*
24cd51
+                * remove the first character '#' from the attribute value
24cd51
+                */
24cd51
+                m_rParser.m_pXSecController->addReference(m_URI.copy(1), m_nReferenceDigestID, m_Type);
24cd51
+            }
24cd51
+            else
24cd51
+            {
24cd51
+                if (m_IsC14N) // this is determined by nested ds:Transform
24cd51
+                {
24cd51
+                    m_rParser.m_pXSecController->addStreamReference(m_URI, false, m_nReferenceDigestID);
24cd51
+                }
24cd51
+                else
24cd51
+            /*
24cd51
+            * it must be an octet stream
24cd51
+            */
24cd51
+                {
24cd51
+                    m_rParser.m_pXSecController->addStreamReference(m_URI, true, m_nReferenceDigestID);
24cd51
+                }
24cd51
+            }
24cd51
+
24cd51
+            m_rParser.m_pXSecController->setDigestValue(m_nReferenceDigestID, m_DigestValue);
24cd51
+        }
24cd51
+
24cd51
+        virtual std::unique_ptr<Context> CreateChildContext(
24cd51
+            std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap,
24cd51
+            sal_uInt16 const nNamespace, OUString const& rName) override
24cd51
+        {
24cd51
+            if (nNamespace == XML_NAMESPACE_DS && rName == "Transforms")
24cd51
+            {
24cd51
+                return std::make_unique<DsTransformsContext>(m_rParser, std::move(pOldNamespaceMap), m_IsC14N);
24cd51
+            }
24cd51
+            if (nNamespace == XML_NAMESPACE_DS && rName == "DigestMethod")
24cd51
+            {
24cd51
+                return std::make_unique<DsDigestMethodContext>(m_rParser, std::move(pOldNamespaceMap), m_nReferenceDigestID);
24cd51
+            }
24cd51
+            if (nNamespace == XML_NAMESPACE_DS && rName == "DigestValue")
24cd51
+            {
24cd51
+                return std::make_unique<DsDigestValueContext>(m_rParser, std::move(pOldNamespaceMap), m_DigestValue);
24cd51
+            }
24cd51
+            return XSecParser::Context::CreateChildContext(std::move(pOldNamespaceMap), nNamespace, rName);
24cd51
+        }
24cd51
+};
24cd51
+
24cd51
+class XSecParser::DsSignatureMethodContext
24cd51
+    : public XSecParser::Context
24cd51
+{
24cd51
+    public:
24cd51
+        DsSignatureMethodContext(XSecParser & rParser,
24cd51
+                std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap)
24cd51
+            : XSecParser::Context(rParser, std::move(pOldNamespaceMap))
24cd51
+        {
24cd51
+        }
24cd51
+
24cd51
+        virtual void StartElement(
24cd51
+            css::uno::Reference<css::xml::sax::XAttributeList> const& xAttrs) override
24cd51
+        {
24cd51
+            OUString ouAlgorithm = xAttrs->getValueByName("Algorithm");
24cd51
+            if (ouAlgorithm == ALGO_ECDSASHA1 || ouAlgorithm == ALGO_ECDSASHA256
24cd51
+                || ouAlgorithm == ALGO_ECDSASHA512)
24cd51
+            {
24cd51
+                m_rParser.m_pXSecController->setSignatureMethod(svl::crypto::SignatureMethodAlgorithm::ECDSA);
24cd51
+            }
24cd51
+        }
24cd51
+};
24cd51
+
24cd51
+class XSecParser::DsSignedInfoContext
24cd51
+    : public XSecParser::Context
24cd51
+{
24cd51
+    public:
24cd51
+        DsSignedInfoContext(XSecParser & rParser,
24cd51
+                std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap)
24cd51
+            : XSecParser::Context(rParser, std::move(pOldNamespaceMap))
24cd51
+        {
24cd51
+        }
24cd51
+
24cd51
+        virtual void StartElement(
24cd51
+            css::uno::Reference<css::xml::sax::XAttributeList> const& xAttrs) override
24cd51
+        {
24cd51
+            m_rParser.HandleIdAttr(xAttrs);
24cd51
+        }
24cd51
+
24cd51
+        virtual void EndElement() override
24cd51
+        {
24cd51
+            m_rParser.m_pXSecController->setReferenceCount();
24cd51
+        }
24cd51
+
24cd51
+        virtual std::unique_ptr<Context> CreateChildContext(
24cd51
+            std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap,
24cd51
+            sal_uInt16 const nNamespace, OUString const& rName) override
24cd51
+        {
24cd51
+            if (nNamespace == XML_NAMESPACE_DS && rName == "SignatureMethod")
24cd51
+            {
24cd51
+                return std::make_unique<DsSignatureMethodContext>(m_rParser, std::move(pOldNamespaceMap));
24cd51
+            }
24cd51
+            if (nNamespace == XML_NAMESPACE_DS && rName == "Reference")
24cd51
+            {
24cd51
+                return std::make_unique<DsReferenceContext>(m_rParser, std::move(pOldNamespaceMap));
24cd51
+            }
24cd51
+            // missing: ds:CanonicalizationMethod
24cd51
+            return XSecParser::Context::CreateChildContext(std::move(pOldNamespaceMap), nNamespace, rName);
24cd51
+        }
24cd51
+};
24cd51
+
24cd51
+class XSecParser::XadesEncapsulatedX509CertificateContext
24cd51
+    : public XSecParser::Context
24cd51
+{
24cd51
+    private:
24cd51
+        OUString m_Value;
24cd51
+
24cd51
+    public:
24cd51
+        XadesEncapsulatedX509CertificateContext(XSecParser & rParser,
24cd51
+                std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap)
24cd51
+            : XSecParser::Context(rParser, std::move(pOldNamespaceMap))
24cd51
+        {
24cd51
+        }
24cd51
+
24cd51
+        virtual void StartElement(
24cd51
+            css::uno::Reference<css::xml::sax::XAttributeList> const& xAttrs) override
24cd51
+        {
24cd51
+            m_rParser.HandleIdAttr(xAttrs);
24cd51
+        }
24cd51
+
24cd51
+        virtual void EndElement() override
24cd51
+        {
24cd51
+            m_rParser.m_pXSecController->addEncapsulatedX509Certificate(m_Value);
24cd51
+        }
24cd51
+
24cd51
+        virtual void Characters(OUString const& rChars) override
24cd51
+        {
24cd51
+            m_Value += rChars;
24cd51
+        }
24cd51
+};
24cd51
+
24cd51
+class XSecParser::XadesCertificateValuesContext
24cd51
+    : public XSecParser::Context
24cd51
+{
24cd51
+    public:
24cd51
+        XadesCertificateValuesContext(XSecParser & rParser,
24cd51
+                std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap)
24cd51
+            : XSecParser::Context(rParser, std::move(pOldNamespaceMap))
24cd51
+        {
24cd51
+        }
24cd51
+
24cd51
+        virtual void StartElement(
24cd51
+            css::uno::Reference<css::xml::sax::XAttributeList> const& xAttrs) override
24cd51
+        {
24cd51
+            m_rParser.HandleIdAttr(xAttrs);
24cd51
+        }
24cd51
+
24cd51
+        virtual std::unique_ptr<Context> CreateChildContext(
24cd51
+            std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap,
24cd51
+            sal_uInt16 const nNamespace, OUString const& rName) override
24cd51
+        {
24cd51
+            if (nNamespace == XML_NAMESPACE_XADES132 && rName == "EncapsulatedX509Certificate")
24cd51
+            {
24cd51
+                return std::make_unique<XadesEncapsulatedX509CertificateContext>(m_rParser, std::move(pOldNamespaceMap));
24cd51
+            }
24cd51
+            // missing: xades:OtherCertificate
24cd51
+            return XSecParser::Context::CreateChildContext(std::move(pOldNamespaceMap), nNamespace, rName);
24cd51
+        }
24cd51
+};
24cd51
+
24cd51
+class XSecParser::XadesUnsignedSignaturePropertiesContext
24cd51
+    : public XSecParser::Context
24cd51
+{
24cd51
+    public:
24cd51
+        XadesUnsignedSignaturePropertiesContext(XSecParser & rParser,
24cd51
+                std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap)
24cd51
+            : XSecParser::Context(rParser, std::move(pOldNamespaceMap))
24cd51
+        {
24cd51
+        }
24cd51
+
24cd51
+        virtual void StartElement(
24cd51
+            css::uno::Reference<css::xml::sax::XAttributeList> const& xAttrs) override
24cd51
+        {
24cd51
+            m_rParser.HandleIdAttr(xAttrs);
24cd51
+        }
24cd51
+
24cd51
+        virtual std::unique_ptr<Context> CreateChildContext(
24cd51
+            std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap,
24cd51
+            sal_uInt16 const nNamespace, OUString const& rName) override
24cd51
+        {
24cd51
+            if (nNamespace == XML_NAMESPACE_XADES132 && rName == "CertificateValues")
24cd51
+            {
24cd51
+                return std::make_unique<XadesCertificateValuesContext>(m_rParser, std::move(pOldNamespaceMap));
24cd51
+            }
24cd51
+            // missing:
24cd51
+            // xades:CounterSignature
24cd51
+            //  ^ old code would read a ds:Signature inside it?
24cd51
+            // xades:SignatureTimeStamp
24cd51
+            // xades:CompleteCertificateRefs
24cd51
+            // xades:CompleteRevocationRefs
24cd51
+            // xades:AttributeCertificateRefs
24cd51
+            // xades:AttributeRevocationRefs
24cd51
+            // xades:SigAndRefsTimeStamp
24cd51
+            // xades:RefsOnlyTimeStamp
24cd51
+            // xades:RevocationValues
24cd51
+            // xades:AttrAuthoritiesCertValues
24cd51
+            //  ^ old code: was equivalent to CertificateValues ???
24cd51
+            // xades:AttributeRevocationValues
24cd51
+            // xades:ArchiveTimeStamp
24cd51
+            return XSecParser::Context::CreateChildContext(std::move(pOldNamespaceMap), nNamespace, rName);
24cd51
+        }
24cd51
+};
24cd51
+
24cd51
+class XSecParser::XadesUnsignedPropertiesContext
24cd51
+    : public XSecParser::Context
24cd51
+{
24cd51
+    public:
24cd51
+        XadesUnsignedPropertiesContext(XSecParser & rParser,
24cd51
+                std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap)
24cd51
+            : XSecParser::Context(rParser, std::move(pOldNamespaceMap))
24cd51
+        {
24cd51
+        }
24cd51
+
24cd51
+        virtual void StartElement(
24cd51
+            css::uno::Reference<css::xml::sax::XAttributeList> const& xAttrs) override
24cd51
+        {
24cd51
+            m_rParser.HandleIdAttr(xAttrs);
24cd51
+        }
24cd51
+
24cd51
+        virtual std::unique_ptr<Context> CreateChildContext(
24cd51
+            std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap,
24cd51
+            sal_uInt16 const nNamespace, OUString const& rName) override
24cd51
+        {
24cd51
+            if (nNamespace == XML_NAMESPACE_XADES132 && rName == "UnsignedSignatureProperties")
24cd51
+            {
24cd51
+                return std::make_unique<XadesUnsignedSignaturePropertiesContext>(m_rParser, std::move(pOldNamespaceMap));
24cd51
+            }
24cd51
+            // missing: xades:UnsignedDataObjectProperties
24cd51
+            return XSecParser::Context::CreateChildContext(std::move(pOldNamespaceMap), nNamespace, rName);
24cd51
+        }
24cd51
+};
24cd51
+
24cd51
+class XSecParser::LoSignatureLineIdContext
24cd51
+    : public XSecParser::Context
24cd51
+{
24cd51
+    private:
24cd51
+        OUString m_Value;
24cd51
+
24cd51
+    public:
24cd51
+        LoSignatureLineIdContext(XSecParser & rParser,
24cd51
+                std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap)
24cd51
+            : XSecParser::Context(rParser, std::move(pOldNamespaceMap))
24cd51
+        {
24cd51
+        }
24cd51
+
24cd51
+        virtual void EndElement() override
24cd51
+        {
24cd51
+            m_rParser.m_pXSecController->setSignatureLineId(m_Value);
24cd51
+        }
24cd51
+
24cd51
+        virtual void Characters(OUString const& rChars) override
24cd51
+        {
24cd51
+            m_Value += rChars;
24cd51
+        }
24cd51
+};
24cd51
+
24cd51
+class XSecParser::LoSignatureLineValidImageContext
24cd51
+    : public XSecParser::Context
24cd51
+{
24cd51
+    private:
24cd51
+        OUString m_Value;
24cd51
+
24cd51
+    public:
24cd51
+        LoSignatureLineValidImageContext(XSecParser & rParser,
24cd51
+                std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap)
24cd51
+            : XSecParser::Context(rParser, std::move(pOldNamespaceMap))
24cd51
+        {
24cd51
+        }
24cd51
+
24cd51
+        virtual void EndElement() override
24cd51
+        {
24cd51
+            m_rParser.m_pXSecController->setValidSignatureImage(m_Value);
24cd51
+        }
24cd51
 
24cd51
-void SAL_CALL XSecParser::startElement(
24cd51
-    const OUString& aName,
24cd51
-    const cssu::Reference< cssxs::XAttributeList >& xAttribs )
24cd51
+        virtual void Characters(OUString const& rChars) override
24cd51
+        {
24cd51
+            m_Value += rChars;
24cd51
+        }
24cd51
+};
24cd51
+
24cd51
+class XSecParser::LoSignatureLineInvalidImageContext
24cd51
+    : public XSecParser::Context
24cd51
 {
24cd51
-    try
24cd51
-    {
24cd51
-        OUString ouIdAttr = getIdAttr(xAttribs);
24cd51
-        if (!ouIdAttr.isEmpty())
24cd51
+    private:
24cd51
+        OUString m_Value;
24cd51
+
24cd51
+    public:
24cd51
+        LoSignatureLineInvalidImageContext(XSecParser & rParser,
24cd51
+                std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap)
24cd51
+            : XSecParser::Context(rParser, std::move(pOldNamespaceMap))
24cd51
         {
24cd51
-            m_pXSecController->collectToVerify( ouIdAttr );
24cd51
         }
24cd51
 
24cd51
-        if ( aName == "Signature" )
24cd51
+        virtual void EndElement() override
24cd51
         {
24cd51
-            m_rXMLSignatureHelper.StartVerifySignatureElement();
24cd51
-            m_pXSecController->addSignature();
24cd51
-            if (!ouIdAttr.isEmpty())
24cd51
-            {
24cd51
-                m_pXSecController->setId( ouIdAttr );
24cd51
-            }
24cd51
+            m_rParser.m_pXSecController->setInvalidSignatureImage(m_Value);
24cd51
         }
24cd51
-        else if (aName == "SignatureMethod")
24cd51
+
24cd51
+        virtual void Characters(OUString const& rChars) override
24cd51
+        {
24cd51
+            m_Value += rChars;
24cd51
+        }
24cd51
+};
24cd51
+
24cd51
+class XSecParser::LoSignatureLineContext
24cd51
+    : public XSecParser::Context
24cd51
+{
24cd51
+    public:
24cd51
+        LoSignatureLineContext(XSecParser & rParser,
24cd51
+                std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap)
24cd51
+            : XSecParser::Context(rParser, std::move(pOldNamespaceMap))
24cd51
         {
24cd51
-            OUString ouAlgorithm = xAttribs->getValueByName("Algorithm");
24cd51
-            if (ouAlgorithm == ALGO_ECDSASHA1 || ouAlgorithm == ALGO_ECDSASHA256
24cd51
-                || ouAlgorithm == ALGO_ECDSASHA512)
24cd51
-                m_pXSecController->setSignatureMethod(svl::crypto::SignatureMethodAlgorithm::ECDSA);
24cd51
         }
24cd51
-        else if ( aName == "Reference" )
24cd51
+
24cd51
+        virtual std::unique_ptr<Context> CreateChildContext(
24cd51
+            std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap,
24cd51
+            sal_uInt16 const nNamespace, OUString const& rName) override
24cd51
         {
24cd51
-            OUString ouUri = xAttribs->getValueByName("URI");
24cd51
-            SAL_WARN_IF( ouUri.isEmpty(), "xmlsecurity.helper", "URI is empty" );
24cd51
-            // Remember the type of this reference.
24cd51
-            OUString ouType = xAttribs->getValueByName("Type");
24cd51
-            if (ouUri.startsWith("#"))
24cd51
+            if (nNamespace == XML_NAMESPACE_LO_EXT && rName == "SignatureLineId")
24cd51
             {
24cd51
-                /*
24cd51
-                * remove the first character '#' from the attribute value
24cd51
-                */
24cd51
-                m_pXSecController->addReference( ouUri.copy(1), m_nReferenceDigestID, ouType );
24cd51
+                return std::make_unique<LoSignatureLineIdContext>(m_rParser, std::move(pOldNamespaceMap));
24cd51
             }
24cd51
-            else
24cd51
+            if (nNamespace == XML_NAMESPACE_LO_EXT && rName == "SignatureLineValidImage")
24cd51
             {
24cd51
-                /*
24cd51
-                * remember the uri
24cd51
-                */
24cd51
-                m_currentReferenceURI = ouUri;
24cd51
-                m_bReferenceUnresolved = true;
24cd51
+                return std::make_unique<LoSignatureLineValidImageContext>(m_rParser, std::move(pOldNamespaceMap));
24cd51
             }
24cd51
-        }
24cd51
-        else if (aName == "DigestMethod")
24cd51
-        {
24cd51
-            OUString ouAlgorithm = xAttribs->getValueByName("Algorithm");
24cd51
-
24cd51
-            SAL_WARN_IF( ouAlgorithm.isEmpty(), "xmlsecurity.helper", "no Algorithm in Reference" );
24cd51
-            if (!ouAlgorithm.isEmpty())
24cd51
+            if (nNamespace == XML_NAMESPACE_LO_EXT && rName == "SignatureLineInvalidImage")
24cd51
             {
24cd51
-                SAL_WARN_IF( ouAlgorithm != ALGO_XMLDSIGSHA1
24cd51
-                             && ouAlgorithm != ALGO_XMLDSIGSHA256
24cd51
-                             && ouAlgorithm != ALGO_XMLDSIGSHA512,
24cd51
-                             "xmlsecurity.helper", "Algorithm neither SHA1, SHA256 nor SHA512");
24cd51
-                if (ouAlgorithm == ALGO_XMLDSIGSHA1)
24cd51
-                    m_nReferenceDigestID = cssxc::DigestID::SHA1;
24cd51
-                else if (ouAlgorithm == ALGO_XMLDSIGSHA256)
24cd51
-                    m_nReferenceDigestID = cssxc::DigestID::SHA256;
24cd51
-                else if (ouAlgorithm == ALGO_XMLDSIGSHA512)
24cd51
-                    m_nReferenceDigestID = cssxc::DigestID::SHA512;
24cd51
-                else
24cd51
-                    m_nReferenceDigestID = 0;
24cd51
+                return std::make_unique<LoSignatureLineInvalidImageContext>(m_rParser, std::move(pOldNamespaceMap));
24cd51
             }
24cd51
+            return XSecParser::Context::CreateChildContext(std::move(pOldNamespaceMap), nNamespace, rName);
24cd51
         }
24cd51
-        else if (aName == "Transform")
24cd51
-        {
24cd51
-            if ( m_bReferenceUnresolved )
24cd51
-            {
24cd51
-                OUString ouAlgorithm = xAttribs->getValueByName("Algorithm");
24cd51
+};
24cd51
 
24cd51
-                if (ouAlgorithm == ALGO_C14N)
24cd51
-                    /*
24cd51
-                     * a xml stream
24cd51
-                     */
24cd51
-                {
24cd51
-                    m_pXSecController->addStreamReference( m_currentReferenceURI, false, m_nReferenceDigestID );
24cd51
-                    m_bReferenceUnresolved = false;
24cd51
-                }
24cd51
-            }
24cd51
+class XSecParser::XadesCertDigestContext
24cd51
+    : public XSecParser::Context
24cd51
+{
24cd51
+    private:
24cd51
+        OUString m_Value;
24cd51
+        sal_Int32 m_nReferenceDigestID = css::xml::crypto::DigestID::SHA1;
24cd51
+
24cd51
+    public:
24cd51
+        XadesCertDigestContext(XSecParser & rParser,
24cd51
+                std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap)
24cd51
+            : XSecParser::Context(rParser, std::move(pOldNamespaceMap))
24cd51
+        {
24cd51
         }
24cd51
-        else if (aName == "X509IssuerName")
24cd51
+
24cd51
+        virtual void EndElement() override
24cd51
         {
24cd51
-            m_ouX509IssuerName.clear();
24cd51
-            m_bInX509IssuerName = true;
24cd51
+            m_rParser.m_pXSecController->setCertDigest(m_Value/* FIXME , m_nReferenceDigestID*/);
24cd51
         }
24cd51
-        else if (aName == "X509SerialNumber")
24cd51
+
24cd51
+        virtual std::unique_ptr<Context> CreateChildContext(
24cd51
+            std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap,
24cd51
+            sal_uInt16 const nNamespace, OUString const& rName) override
24cd51
         {
24cd51
-            m_ouX509SerialNumber.clear();
24cd51
-            m_bInX509SerialNumber = true;
24cd51
+            if (nNamespace == XML_NAMESPACE_DS && rName == "DigestMethod")
24cd51
+            {
24cd51
+                return std::make_unique<DsDigestMethodContext>(m_rParser, std::move(pOldNamespaceMap), m_nReferenceDigestID);
24cd51
+            }
24cd51
+            if (nNamespace == XML_NAMESPACE_DS && rName == "DigestValue")
24cd51
+            {
24cd51
+                return std::make_unique<DsDigestValueContext>(m_rParser, std::move(pOldNamespaceMap), m_Value);
24cd51
+            }
24cd51
+            return XSecParser::Context::CreateChildContext(std::move(pOldNamespaceMap), nNamespace, rName);
24cd51
         }
24cd51
-        else if (aName == "X509Certificate")
24cd51
+};
24cd51
+
24cd51
+class XSecParser::XadesCertContext
24cd51
+    : public XSecParser::Context
24cd51
+{
24cd51
+    public:
24cd51
+        XadesCertContext(XSecParser & rParser,
24cd51
+                std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap)
24cd51
+            : XSecParser::Context(rParser, std::move(pOldNamespaceMap))
24cd51
         {
24cd51
-            m_ouX509Certificate.clear();
24cd51
-            m_bInX509Certificate = true;
24cd51
         }
24cd51
-        else if (aName == "PGPData")
24cd51
+
24cd51
+        virtual std::unique_ptr<Context> CreateChildContext(
24cd51
+            std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap,
24cd51
+            sal_uInt16 const nNamespace, OUString const& rName) override
24cd51
         {
24cd51
-            m_pXSecController->switchGpgSignature();
24cd51
+            if (nNamespace == XML_NAMESPACE_XADES132 && rName == "CertDigest")
24cd51
+            {
24cd51
+                return std::make_unique<XadesCertDigestContext>(m_rParser, std::move(pOldNamespaceMap));
24cd51
+            }
24cd51
+            if (nNamespace == XML_NAMESPACE_XADES132 && rName == "IssuerSerial")
24cd51
+            {
24cd51
+                return std::make_unique<DsX509IssuerSerialContext>(m_rParser, std::move(pOldNamespaceMap));
24cd51
+            }
24cd51
+            return XSecParser::Context::CreateChildContext(std::move(pOldNamespaceMap), nNamespace, rName);
24cd51
         }
24cd51
-        else if (aName == "PGPKeyID")
24cd51
+};
24cd51
+
24cd51
+class XSecParser::XadesSigningCertificateContext
24cd51
+    : public XSecParser::Context
24cd51
+{
24cd51
+    public:
24cd51
+        XadesSigningCertificateContext(XSecParser & rParser,
24cd51
+                std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap)
24cd51
+            : XSecParser::Context(rParser, std::move(pOldNamespaceMap))
24cd51
         {
24cd51
-            m_ouGpgKeyID.clear();
24cd51
-            m_bInGpgKeyID = true;
24cd51
         }
24cd51
-        else if (aName == "PGPKeyPacket")
24cd51
+
24cd51
+        virtual std::unique_ptr<Context> CreateChildContext(
24cd51
+            std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap,
24cd51
+            sal_uInt16 const nNamespace, OUString const& rName) override
24cd51
         {
24cd51
-            m_ouGpgCertificate.clear();
24cd51
-            m_bInGpgCertificate = true;
24cd51
+            if (nNamespace == XML_NAMESPACE_XADES132 && rName == "Cert")
24cd51
+            {
24cd51
+                return std::make_unique<XadesCertContext>(m_rParser, std::move(pOldNamespaceMap));
24cd51
+            }
24cd51
+            return XSecParser::Context::CreateChildContext(std::move(pOldNamespaceMap), nNamespace, rName);
24cd51
         }
24cd51
-        else if (aName == "loext:PGPOwner")
24cd51
+};
24cd51
+
24cd51
+class XSecParser::XadesSigningTimeContext
24cd51
+    : public XSecParser::Context
24cd51
+{
24cd51
+    public:
24cd51
+        XadesSigningTimeContext(XSecParser & rParser,
24cd51
+                std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap)
24cd51
+            : XSecParser::Context(rParser, std::move(pOldNamespaceMap))
24cd51
         {
24cd51
-            m_ouGpgOwner.clear();
24cd51
-            m_bInGpgOwner = true;
24cd51
         }
24cd51
-        else if (aName == "SignatureValue")
24cd51
+
24cd51
+        virtual void StartElement(
24cd51
+            css::uno::Reference<css::xml::sax::XAttributeList> const& /*xAttrs*/) override
24cd51
         {
24cd51
-            m_ouSignatureValue.clear();
24cd51
-            m_bInSignatureValue = true;
24cd51
+            m_rParser.m_ouDate.clear();
24cd51
         }
24cd51
-        else if (aName == "DigestValue" && !m_bInCertDigest)
24cd51
+
24cd51
+        virtual void EndElement() override
24cd51
         {
24cd51
-            m_ouDigestValue.clear();
24cd51
-            m_bInDigestValue = true;
24cd51
+            m_rParser.m_pXSecController->setDate( m_rParser.m_ouDate );
24cd51
         }
24cd51
-        else if (aName == "xd:CertDigest")
24cd51
+
24cd51
+        virtual void Characters(OUString const& rChars) override
24cd51
         {
24cd51
-            m_ouCertDigest.clear();
24cd51
-            m_bInCertDigest = true;
24cd51
+            m_rParser.m_ouDate += rChars;
24cd51
         }
24cd51
-        // FIXME: Existing code here in xmlsecurity uses "xd" as the namespace prefix for XAdES,
24cd51
-        // while the sample document attached to tdf#76142 uses "xades". So accept either here. Of
24cd51
-        // course this is idiotic and wrong, the right thing would be to use a proper way to parse
24cd51
-        // XML that would handle namespaces correctly. I have no idea how substantial re-plumbing of
24cd51
-        // this code that would require.
24cd51
-        else if (aName == "xd:EncapsulatedX509Certificate" || aName == "xades:EncapsulatedX509Certificate")
24cd51
+};
24cd51
+
24cd51
+class XSecParser::XadesSignedSignaturePropertiesContext
24cd51
+    : public XSecParser::Context
24cd51
+{
24cd51
+    public:
24cd51
+        XadesSignedSignaturePropertiesContext(XSecParser & rParser,
24cd51
+                std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap)
24cd51
+            : XSecParser::Context(rParser, std::move(pOldNamespaceMap))
24cd51
         {
24cd51
-            m_ouEncapsulatedX509Certificate.clear();
24cd51
-            m_bInEncapsulatedX509Certificate = true;
24cd51
         }
24cd51
-        else if (aName == "xd:SigningTime" || aName == "xades:SigningTime")
24cd51
+
24cd51
+        virtual void StartElement(
24cd51
+            css::uno::Reference<css::xml::sax::XAttributeList> const& xAttrs) override
24cd51
         {
24cd51
-            m_ouDate.clear();
24cd51
-            m_bInSigningTime = true;
24cd51
+            m_rParser.HandleIdAttr(xAttrs);
24cd51
         }
24cd51
-        else if ( aName == "SignatureProperty" )
24cd51
+
24cd51
+        virtual std::unique_ptr<Context> CreateChildContext(
24cd51
+            std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap,
24cd51
+            sal_uInt16 const nNamespace, OUString const& rName) override
24cd51
         {
24cd51
-            if (!ouIdAttr.isEmpty())
24cd51
+            if (nNamespace == XML_NAMESPACE_XADES132 && rName == "SigningTime")
24cd51
+            {
24cd51
+                return std::make_unique<XadesSigningTimeContext>(m_rParser, std::move(pOldNamespaceMap));
24cd51
+            }
24cd51
+            if (nNamespace == XML_NAMESPACE_XADES132 && rName == "SigningCertificate")
24cd51
+            {
24cd51
+                return std::make_unique<XadesSigningCertificateContext>(m_rParser, std::move(pOldNamespaceMap));
24cd51
+            }
24cd51
+            if (nNamespace == XML_NAMESPACE_LO_EXT && rName == "SignatureLine")
24cd51
             {
24cd51
-                m_pXSecController->setPropertyId( ouIdAttr );
24cd51
+                return std::make_unique<LoSignatureLineContext>(m_rParser, std::move(pOldNamespaceMap));
24cd51
             }
24cd51
+            // missing: xades:SignaturePolicyIdentifier, xades:SignatureProductionPlace, xades:SignerRole
24cd51
+            return XSecParser::Context::CreateChildContext(std::move(pOldNamespaceMap), nNamespace, rName);
24cd51
         }
24cd51
-        else if (aName == "dc:date")
24cd51
+};
24cd51
+
24cd51
+class XSecParser::XadesSignedPropertiesContext
24cd51
+    : public XSecParser::Context
24cd51
+{
24cd51
+    public:
24cd51
+        XadesSignedPropertiesContext(XSecParser & rParser,
24cd51
+                std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap)
24cd51
+            : XSecParser::Context(rParser, std::move(pOldNamespaceMap))
24cd51
         {
24cd51
-            if (m_ouDate.isEmpty())
24cd51
-                m_bInDate = true;
24cd51
         }
24cd51
-        else if (aName == "dc:description")
24cd51
+
24cd51
+        virtual void StartElement(
24cd51
+            css::uno::Reference<css::xml::sax::XAttributeList> const& xAttrs) override
24cd51
         {
24cd51
-            m_ouDescription.clear();
24cd51
-            m_bInDescription = true;
24cd51
+            m_rParser.HandleIdAttr(xAttrs);
24cd51
         }
24cd51
-        else if (aName == "loext:SignatureLineId")
24cd51
+
24cd51
+        virtual std::unique_ptr<Context> CreateChildContext(
24cd51
+            std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap,
24cd51
+            sal_uInt16 const nNamespace, OUString const& rName) override
24cd51
         {
24cd51
-            m_ouSignatureLineId.clear();
24cd51
-            m_bInSignatureLineId = true;
24cd51
+            if (nNamespace == XML_NAMESPACE_XADES132 && rName == "SignedSignatureProperties")
24cd51
+            {
24cd51
+                return std::make_unique<XadesSignedSignaturePropertiesContext>(m_rParser, std::move(pOldNamespaceMap));
24cd51
+            }
24cd51
+            // missing: xades:SignedDataObjectProperties
24cd51
+            return XSecParser::Context::CreateChildContext(std::move(pOldNamespaceMap), nNamespace, rName);
24cd51
         }
24cd51
-        else if (aName == "loext:SignatureLineValidImage")
24cd51
+};
24cd51
+
24cd51
+class XSecParser::XadesQualifyingPropertiesContext
24cd51
+    : public XSecParser::Context
24cd51
+{
24cd51
+    public:
24cd51
+        XadesQualifyingPropertiesContext(XSecParser & rParser,
24cd51
+                std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap)
24cd51
+            : XSecParser::Context(rParser, std::move(pOldNamespaceMap))
24cd51
         {
24cd51
-            m_ouSignatureLineValidImage.clear();
24cd51
-            m_bInSignatureLineValidImage = true;
24cd51
         }
24cd51
-        else if (aName == "loext:SignatureLineInvalidImage")
24cd51
+
24cd51
+        virtual void StartElement(
24cd51
+            css::uno::Reference<css::xml::sax::XAttributeList> const& xAttrs) override
24cd51
         {
24cd51
-            m_ouSignatureLineInvalidImage.clear();
24cd51
-            m_bInSignatureLineInvalidImage = true;
24cd51
+            m_rParser.HandleIdAttr(xAttrs);
24cd51
         }
24cd51
 
24cd51
-        if (m_xNextHandler.is())
24cd51
+        virtual std::unique_ptr<Context> CreateChildContext(
24cd51
+            std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap,
24cd51
+            sal_uInt16 const nNamespace, OUString const& rName) override
24cd51
         {
24cd51
-            m_xNextHandler->startElement(aName, xAttribs);
24cd51
+            if (nNamespace == XML_NAMESPACE_XADES132 && rName == "SignedProperties")
24cd51
+            {
24cd51
+                return std::make_unique<XadesSignedPropertiesContext>(m_rParser, std::move(pOldNamespaceMap));
24cd51
+            }
24cd51
+            if (nNamespace == XML_NAMESPACE_XADES132 && rName == "UnsignedProperties")
24cd51
+            {
24cd51
+                return std::make_unique<XadesUnsignedPropertiesContext>(m_rParser, std::move(pOldNamespaceMap));
24cd51
+            }
24cd51
+            return XSecParser::Context::CreateChildContext(std::move(pOldNamespaceMap), nNamespace, rName);
24cd51
         }
24cd51
-    }
24cd51
-    catch (cssu::Exception& )
24cd51
-    {//getCaughtException MUST be the first line in the catch block
24cd51
-        cssu::Any exc =  cppu::getCaughtException();
24cd51
-        throw cssxs::SAXException(
24cd51
-            "xmlsecurity: Exception in XSecParser::startElement",
24cd51
-            nullptr, exc);
24cd51
-    }
24cd51
-    catch (...)
24cd51
-    {
24cd51
-        throw cssxs::SAXException(
24cd51
-            "xmlsecurity: unexpected exception in XSecParser::startElement", nullptr,
24cd51
-            cssu::Any());
24cd51
-    }
24cd51
-}
24cd51
+};
24cd51
 
24cd51
-void SAL_CALL XSecParser::endElement( const OUString& aName )
24cd51
+class XSecParser::DcDateContext
24cd51
+    : public XSecParser::Context
24cd51
 {
24cd51
-    try
24cd51
-    {
24cd51
-        if (aName == "DigestValue" && !m_bInCertDigest)
24cd51
+    private:
24cd51
+        bool m_isIgnore = false;
24cd51
+
24cd51
+    public:
24cd51
+        DcDateContext(XSecParser & rParser,
24cd51
+                std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap)
24cd51
+            : XSecParser::Context(rParser, std::move(pOldNamespaceMap))
24cd51
         {
24cd51
-            m_bInDigestValue = false;
24cd51
         }
24cd51
-        else if ( aName == "Reference" )
24cd51
+
24cd51
+        virtual void StartElement(
24cd51
+            css::uno::Reference<css::xml::sax::XAttributeList> const& /*xAttrs*/) override
24cd51
         {
24cd51
-            if ( m_bReferenceUnresolved )
24cd51
-            /*
24cd51
-            * it must be an octet stream
24cd51
-            */
24cd51
+            m_isIgnore = !m_rParser.m_ouDate.isEmpty();
24cd51
+        }
24cd51
+
24cd51
+        virtual void EndElement() override
24cd51
+        {
24cd51
+            if (!m_isIgnore)
24cd51
             {
24cd51
-                m_pXSecController->addStreamReference( m_currentReferenceURI, true, m_nReferenceDigestID );
24cd51
-                m_bReferenceUnresolved = false;
24cd51
+                m_rParser.m_pXSecController->setDate( m_rParser.m_ouDate );
24cd51
             }
24cd51
+        }
24cd51
 
24cd51
-            m_pXSecController->setDigestValue( m_nReferenceDigestID, m_ouDigestValue );
24cd51
+        virtual void Characters(OUString const& rChars) override
24cd51
+        {
24cd51
+            if (!m_isIgnore)
24cd51
+            {
24cd51
+                m_rParser.m_ouDate += rChars;
24cd51
+            }
24cd51
         }
24cd51
-        else if ( aName == "SignedInfo" )
24cd51
+};
24cd51
+
24cd51
+class XSecParser::DcDescriptionContext
24cd51
+    : public XSecParser::Context
24cd51
+{
24cd51
+    private:
24cd51
+        OUString m_Value;
24cd51
+
24cd51
+    public:
24cd51
+        DcDescriptionContext(XSecParser & rParser,
24cd51
+                std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap)
24cd51
+            : XSecParser::Context(rParser, std::move(pOldNamespaceMap))
24cd51
         {
24cd51
-            m_pXSecController->setReferenceCount();
24cd51
         }
24cd51
-        else if ( aName == "SignatureValue" )
24cd51
+
24cd51
+        virtual void EndElement() override
24cd51
         {
24cd51
-            m_pXSecController->setSignatureValue( m_ouSignatureValue );
24cd51
-            m_bInSignatureValue = false;
24cd51
+            m_rParser.m_pXSecController->setDescription(m_Value);
24cd51
         }
24cd51
-        else if (aName == "X509IssuerName")
24cd51
+
24cd51
+        virtual void Characters(OUString const& rChars) override
24cd51
         {
24cd51
-            m_pXSecController->setX509IssuerName( m_ouX509IssuerName );
24cd51
-            m_bInX509IssuerName = false;
24cd51
+            m_Value += rChars;
24cd51
         }
24cd51
-        else if (aName == "X509SerialNumber")
24cd51
+};
24cd51
+
24cd51
+class XSecParser::DsSignaturePropertyContext
24cd51
+    : public XSecParser::Context
24cd51
+{
24cd51
+    public:
24cd51
+        DsSignaturePropertyContext(XSecParser & rParser,
24cd51
+                std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap)
24cd51
+            : XSecParser::Context(rParser, std::move(pOldNamespaceMap))
24cd51
         {
24cd51
-            m_pXSecController->setX509SerialNumber( m_ouX509SerialNumber );
24cd51
-            m_bInX509SerialNumber = false;
24cd51
         }
24cd51
-        else if (aName == "X509Certificate")
24cd51
+
24cd51
+        virtual void StartElement(
24cd51
+            css::uno::Reference<css::xml::sax::XAttributeList> const& xAttrs) override
24cd51
         {
24cd51
-            m_pXSecController->setX509Certificate( m_ouX509Certificate );
24cd51
-            m_bInX509Certificate = false;
24cd51
+            OUString const ouIdAttr(m_rParser.HandleIdAttr(xAttrs));
24cd51
+            if (!ouIdAttr.isEmpty())
24cd51
+            {
24cd51
+                m_rParser.m_pXSecController->setPropertyId( ouIdAttr );
24cd51
+            }
24cd51
         }
24cd51
-        else if (aName == "PGPKeyID")
24cd51
+
24cd51
+        virtual std::unique_ptr<Context> CreateChildContext(
24cd51
+            std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap,
24cd51
+            sal_uInt16 const nNamespace, OUString const& rName) override
24cd51
         {
24cd51
-            m_pXSecController->setGpgKeyID( m_ouGpgKeyID );
24cd51
-            m_bInGpgKeyID = false;
24cd51
+            if (nNamespace == XML_NAMESPACE_DC && rName == "date")
24cd51
+            {
24cd51
+                return std::make_unique<DcDateContext>(m_rParser, std::move(pOldNamespaceMap));
24cd51
+            }
24cd51
+            if (nNamespace == XML_NAMESPACE_DC && rName == "description")
24cd51
+            {
24cd51
+                return std::make_unique<DcDescriptionContext>(m_rParser, std::move(pOldNamespaceMap));
24cd51
+            }
24cd51
+            return XSecParser::Context::CreateChildContext(std::move(pOldNamespaceMap), nNamespace, rName);
24cd51
         }
24cd51
-        else if (aName == "PGPKeyPacket")
24cd51
+};
24cd51
+
24cd51
+class XSecParser::DsSignaturePropertiesContext
24cd51
+    : public XSecParser::Context
24cd51
+{
24cd51
+    public:
24cd51
+        DsSignaturePropertiesContext(XSecParser & rParser,
24cd51
+                std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap)
24cd51
+            : XSecParser::Context(rParser, std::move(pOldNamespaceMap))
24cd51
         {
24cd51
-            m_pXSecController->setGpgCertificate( m_ouGpgCertificate );
24cd51
-            m_bInGpgCertificate = false;
24cd51
         }
24cd51
-        else if (aName == "loext:PGPOwner")
24cd51
+
24cd51
+        virtual void StartElement(
24cd51
+            css::uno::Reference<css::xml::sax::XAttributeList> const& xAttrs) override
24cd51
         {
24cd51
-            m_pXSecController->setGpgOwner( m_ouGpgOwner );
24cd51
-            m_bInGpgOwner = false;
24cd51
+            m_rParser.HandleIdAttr(xAttrs);
24cd51
         }
24cd51
-        else if (aName == "xd:CertDigest")
24cd51
+
24cd51
+        virtual std::unique_ptr<Context> CreateChildContext(
24cd51
+            std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap,
24cd51
+            sal_uInt16 const nNamespace, OUString const& rName) override
24cd51
         {
24cd51
-            m_pXSecController->setCertDigest( m_ouCertDigest );
24cd51
-            m_bInCertDigest = false;
24cd51
+            if (nNamespace == XML_NAMESPACE_DS && rName == "SignatureProperty")
24cd51
+            {
24cd51
+                return std::make_unique<DsSignaturePropertyContext>(m_rParser, std::move(pOldNamespaceMap));
24cd51
+            }
24cd51
+            return XSecParser::Context::CreateChildContext(std::move(pOldNamespaceMap), nNamespace, rName);
24cd51
         }
24cd51
-        else if (aName == "xd:EncapsulatedX509Certificate" || aName == "xades:EncapsulatedX509Certificate")
24cd51
+};
24cd51
+
24cd51
+class XSecParser::DsObjectContext
24cd51
+    : public XSecParser::Context
24cd51
+{
24cd51
+    public:
24cd51
+        DsObjectContext(XSecParser & rParser,
24cd51
+                std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap)
24cd51
+            : XSecParser::Context(rParser, std::move(pOldNamespaceMap))
24cd51
         {
24cd51
-            m_pXSecController->addEncapsulatedX509Certificate( m_ouEncapsulatedX509Certificate );
24cd51
-            m_bInEncapsulatedX509Certificate = false;
24cd51
         }
24cd51
-        else if (aName == "xd:SigningTime" || aName == "xades:SigningTime")
24cd51
+
24cd51
+        virtual void StartElement(
24cd51
+            css::uno::Reference<css::xml::sax::XAttributeList> const& xAttrs) override
24cd51
         {
24cd51
-            m_pXSecController->setDate( m_ouDate );
24cd51
-            m_bInSigningTime = false;
24cd51
+            m_rParser.HandleIdAttr(xAttrs);
24cd51
         }
24cd51
-        else if (aName == "dc:date")
24cd51
+
24cd51
+        virtual std::unique_ptr<Context> CreateChildContext(
24cd51
+            std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap,
24cd51
+            sal_uInt16 const nNamespace, OUString const& rName) override
24cd51
         {
24cd51
-            if (m_bInDate)
24cd51
+            if (nNamespace == XML_NAMESPACE_DS && rName == "SignatureProperties")
24cd51
             {
24cd51
-                m_pXSecController->setDate( m_ouDate );
24cd51
-                m_bInDate = false;
24cd51
+                return std::make_unique<DsSignaturePropertiesContext>(m_rParser, std::move(pOldNamespaceMap));
24cd51
             }
24cd51
+            if (nNamespace == XML_NAMESPACE_XADES132 && rName == "QualifyingProperties")
24cd51
+            {
24cd51
+                return std::make_unique<XadesQualifyingPropertiesContext>(m_rParser, std::move(pOldNamespaceMap));
24cd51
+            }
24cd51
+            // missing: ds:Manifest
24cd51
+            return XSecParser::Context::CreateChildContext(std::move(pOldNamespaceMap), nNamespace, rName);
24cd51
         }
24cd51
-        else if (aName == "dc:description")
24cd51
+};
24cd51
+
24cd51
+class XSecParser::DsSignatureContext
24cd51
+    : public XSecParser::Context
24cd51
+{
24cd51
+    public:
24cd51
+        DsSignatureContext(XSecParser & rParser,
24cd51
+                std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap)
24cd51
+            : XSecParser::Context(rParser, std::move(pOldNamespaceMap))
24cd51
         {
24cd51
-            m_pXSecController->setDescription( m_ouDescription );
24cd51
-            m_bInDescription = false;
24cd51
         }
24cd51
-        else if (aName == "loext:SignatureLineId")
24cd51
+
24cd51
+        virtual void StartElement(
24cd51
+            css::uno::Reference<css::xml::sax::XAttributeList> const& xAttrs) override
24cd51
         {
24cd51
-            m_pXSecController->setSignatureLineId( m_ouSignatureLineId );
24cd51
-            m_bInSignatureLineId = false;
24cd51
+            OUString const ouIdAttr(m_rParser.HandleIdAttr(xAttrs));
24cd51
+            m_rParser.m_rXMLSignatureHelper.StartVerifySignatureElement();
24cd51
+            m_rParser.m_pXSecController->addSignature();
24cd51
+            if (!ouIdAttr.isEmpty())
24cd51
+            {
24cd51
+                m_rParser.m_pXSecController->setId( ouIdAttr );
24cd51
+            }
24cd51
         }
24cd51
-        else if (aName == "loext:SignatureLineValidImage")
24cd51
+
24cd51
+        virtual std::unique_ptr<Context> CreateChildContext(
24cd51
+            std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap,
24cd51
+            sal_uInt16 const nNamespace, OUString const& rName) override
24cd51
         {
24cd51
-            m_pXSecController->setValidSignatureImage( m_ouSignatureLineValidImage );
24cd51
-            m_bInSignatureLineValidImage = false;
24cd51
+            if (nNamespace == XML_NAMESPACE_DS && rName == "SignedInfo")
24cd51
+            {
24cd51
+                return std::make_unique<DsSignedInfoContext>(m_rParser, std::move(pOldNamespaceMap));
24cd51
+            }
24cd51
+            if (nNamespace == XML_NAMESPACE_DS && rName == "SignatureValue")
24cd51
+            {
24cd51
+                return std::make_unique<DsSignatureValueContext>(m_rParser, std::move(pOldNamespaceMap));
24cd51
+            }
24cd51
+            if (nNamespace == XML_NAMESPACE_DS && rName == "KeyInfo")
24cd51
+            {
24cd51
+                return std::make_unique<DsKeyInfoContext>(m_rParser, std::move(pOldNamespaceMap));
24cd51
+            }
24cd51
+            if (nNamespace == XML_NAMESPACE_DS && rName == "Object")
24cd51
+            {
24cd51
+                return std::make_unique<DsObjectContext>(m_rParser, std::move(pOldNamespaceMap));
24cd51
+            }
24cd51
+            return XSecParser::Context::CreateChildContext(std::move(pOldNamespaceMap), nNamespace, rName);
24cd51
         }
24cd51
-        else if (aName == "loext:SignatureLineInvalidImage")
24cd51
+};
24cd51
+
24cd51
+class XSecParser::DsigSignaturesContext
24cd51
+    : public XSecParser::Context
24cd51
+{
24cd51
+    public:
24cd51
+        DsigSignaturesContext(XSecParser & rParser,
24cd51
+                std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap)
24cd51
+            : XSecParser::Context(rParser, std::move(pOldNamespaceMap))
24cd51
         {
24cd51
-            m_pXSecController->setInvalidSignatureImage( m_ouSignatureLineInvalidImage );
24cd51
-            m_bInSignatureLineInvalidImage = false;
24cd51
         }
24cd51
 
24cd51
-        if (m_xNextHandler.is())
24cd51
+        virtual std::unique_ptr<Context> CreateChildContext(
24cd51
+            std::unique_ptr<SvXMLNamespaceMap> pOldNamespaceMap,
24cd51
+            sal_uInt16 const nNamespace, OUString const& rName) override
24cd51
         {
24cd51
-            m_xNextHandler->endElement(aName);
24cd51
+            if (nNamespace == XML_NAMESPACE_DS && rName == "Signature")
24cd51
+            {
24cd51
+                return std::make_unique<DsSignatureContext>(m_rParser, std::move(pOldNamespaceMap));
24cd51
+            }
24cd51
+            return XSecParser::Context::CreateChildContext(std::move(pOldNamespaceMap), nNamespace, rName);
24cd51
         }
24cd51
-    }
24cd51
-    catch (cssu::Exception& )
24cd51
-    {//getCaughtException MUST be the first line in the catch block
24cd51
-        cssu::Any exc =  cppu::getCaughtException();
24cd51
-        throw cssxs::SAXException(
24cd51
-            "xmlsecurity: Exception in XSecParser::endElement",
24cd51
-            nullptr, exc);
24cd51
-    }
24cd51
-    catch (...)
24cd51
-    {
24cd51
-        throw cssxs::SAXException(
24cd51
-            "xmlsecurity: unexpected exception in XSecParser::endElement", nullptr,
24cd51
-            cssu::Any());
24cd51
-    }
24cd51
+};
24cd51
+
24cd51
+
24cd51
+XSecParser::XSecParser(XMLSignatureHelper& rXMLSignatureHelper,
24cd51
+    XSecController* pXSecController)
24cd51
+    : m_pNamespaceMap(new SvXMLNamespaceMap)
24cd51
+    , m_pXSecController(pXSecController)
24cd51
+    , m_rXMLSignatureHelper(rXMLSignatureHelper)
24cd51
+{
24cd51
+    using namespace xmloff::token;
24cd51
+    m_pNamespaceMap->Add( GetXMLToken(XML_XML), GetXMLToken(XML_N_XML), XML_NAMESPACE_XML );
24cd51
+    m_pNamespaceMap->Add( "_dsig_ooo", GetXMLToken(XML_N_DSIG_OOO), XML_NAMESPACE_DSIG_OOO );
24cd51
+    m_pNamespaceMap->Add( "_dsig", GetXMLToken(XML_N_DSIG), XML_NAMESPACE_DSIG );
24cd51
+    m_pNamespaceMap->Add( "_ds", GetXMLToken(XML_N_DS), XML_NAMESPACE_DS );
24cd51
+    m_pNamespaceMap->Add( "_xades132", GetXMLToken(XML_N_XADES132), XML_NAMESPACE_XADES132);
24cd51
+    m_pNamespaceMap->Add( "_xades141", GetXMLToken(XML_N_XADES141), XML_NAMESPACE_XADES141);
24cd51
+    m_pNamespaceMap->Add( "_dc", GetXMLToken(XML_N_DC), XML_NAMESPACE_DC );
24cd51
+    m_pNamespaceMap->Add( "_office_libo",
24cd51
+                         GetXMLToken(XML_N_LO_EXT), XML_NAMESPACE_LO_EXT);
24cd51
 }
24cd51
 
24cd51
-void SAL_CALL XSecParser::characters( const OUString& aChars )
24cd51
+OUString XSecParser::HandleIdAttr(css::uno::Reference<css::xml::sax::XAttributeList> const& xAttrs)
24cd51
 {
24cd51
-    if (m_bInX509IssuerName)
24cd51
-    {
24cd51
-        m_ouX509IssuerName += aChars;
24cd51
-    }
24cd51
-    else if (m_bInX509SerialNumber)
24cd51
+    OUString ouIdAttr = getIdAttr(xAttrs);
24cd51
+    if (!ouIdAttr.isEmpty())
24cd51
     {
24cd51
-        m_ouX509SerialNumber += aChars;
24cd51
+        m_pXSecController->collectToVerify( ouIdAttr );
24cd51
     }
24cd51
-    else if (m_bInX509Certificate)
24cd51
-    {
24cd51
-        m_ouX509Certificate += aChars;
24cd51
-    }
24cd51
-    else if (m_bInGpgCertificate)
24cd51
-    {
24cd51
-        m_ouGpgCertificate += aChars;
24cd51
-    }
24cd51
-    else if (m_bInGpgKeyID)
24cd51
+    return ouIdAttr;
24cd51
+}
24cd51
+
24cd51
+OUString XSecParser::getIdAttr(const css::uno::Reference< css::xml::sax::XAttributeList >& xAttribs )
24cd51
+{
24cd51
+    OUString ouIdAttr = xAttribs->getValueByName("id");
24cd51
+
24cd51
+    if (ouIdAttr.isEmpty())
24cd51
     {
24cd51
-        m_ouGpgKeyID += aChars;
24cd51
+        ouIdAttr = xAttribs->getValueByName("Id");
24cd51
     }
24cd51
-    else if (m_bInGpgOwner)
24cd51
+
24cd51
+    return ouIdAttr;
24cd51
+}
24cd51
+
24cd51
+/*
24cd51
+ * XDocumentHandler
24cd51
+ */
24cd51
+void SAL_CALL XSecParser::startDocument(  )
24cd51
+{
24cd51
+    if (m_xNextHandler.is())
24cd51
     {
24cd51
-        m_ouGpgOwner += aChars;
24cd51
+        m_xNextHandler->startDocument();
24cd51
     }
24cd51
-    else if (m_bInSignatureValue)
24cd51
+}
24cd51
+
24cd51
+void SAL_CALL XSecParser::endDocument(  )
24cd51
+{
24cd51
+    if (m_xNextHandler.is())
24cd51
     {
24cd51
-        m_ouSignatureValue += aChars;
24cd51
+        m_xNextHandler->endDocument();
24cd51
     }
24cd51
-    else if (m_bInDigestValue && !m_bInCertDigest)
24cd51
+}
24cd51
+
24cd51
+void SAL_CALL XSecParser::startElement(
24cd51
+    const OUString& rName,
24cd51
+    const css::uno::Reference< css::xml::sax::XAttributeList >& xAttribs )
24cd51
+{
24cd51
+    assert(m_pNamespaceMap);
24cd51
+    std::unique_ptr<SvXMLNamespaceMap> pRewindMap(
24cd51
+        SvXMLImport::processNSAttributes(m_pNamespaceMap, nullptr, xAttribs));
24cd51
+
24cd51
+    OUString localName;
24cd51
+    sal_uInt16 const nPrefix(m_pNamespaceMap->GetKeyByAttrName(rName, &localName));
24cd51
+
24cd51
+    std::unique_ptr<Context> pContext;
24cd51
+
24cd51
+    if (m_ContextStack.empty())
24cd51
     {
24cd51
-        m_ouDigestValue += aChars;
24cd51
+        if ((nPrefix == XML_NAMESPACE_DSIG || nPrefix == XML_NAMESPACE_DSIG_OOO)
24cd51
+            && localName == "document-signatures")
24cd51
+        {
24cd51
+            pContext.reset(new DsigSignaturesContext(*this, std::move(pRewindMap)));
24cd51
+        }
24cd51
+        else
24cd51
+        {
24cd51
+            throw css::xml::sax::SAXException(
24cd51
+                "xmlsecurity: unexpected root element", nullptr,
24cd51
+                css::uno::Any());
24cd51
+        }
24cd51
     }
24cd51
-    else if (m_bInDate)
24cd51
+    else
24cd51
     {
24cd51
-        m_ouDate += aChars;
24cd51
+        pContext = m_ContextStack.top()->CreateChildContext(
24cd51
+                std::move(pRewindMap), nPrefix, localName);
24cd51
     }
24cd51
-    else if (m_bInDescription)
24cd51
+
24cd51
+    m_ContextStack.push(std::move(pContext));
24cd51
+    assert(!pRewindMap);
24cd51
+
24cd51
+    try
24cd51
     {
24cd51
-        m_ouDescription += aChars;
24cd51
+        m_ContextStack.top()->StartElement(xAttribs);
24cd51
+
24cd51
+        if (m_xNextHandler.is())
24cd51
+        {
24cd51
+            m_xNextHandler->startElement(rName, xAttribs);
24cd51
+        }
24cd51
     }
24cd51
-    else if (m_bInCertDigest)
24cd51
-    {
24cd51
-        m_ouCertDigest += aChars;
24cd51
+    catch (css::uno::Exception& )
24cd51
+    {//getCaughtException MUST be the first line in the catch block
24cd51
+        css::uno::Any exc =  cppu::getCaughtException();
24cd51
+        throw css::xml::sax::SAXException(
24cd51
+            "xmlsecurity: Exception in XSecParser::startElement",
24cd51
+            nullptr, exc);
24cd51
     }
24cd51
-    else if (m_bInEncapsulatedX509Certificate)
24cd51
+    catch (...)
24cd51
     {
24cd51
-        m_ouEncapsulatedX509Certificate += aChars;
24cd51
+        throw css::xml::sax::SAXException(
24cd51
+            "xmlsecurity: unexpected exception in XSecParser::startElement", nullptr,
24cd51
+            css::uno::Any());
24cd51
     }
24cd51
-    else if (m_bInSigningTime)
24cd51
+}
24cd51
+
24cd51
+void SAL_CALL XSecParser::endElement(const OUString& rName)
24cd51
+{
24cd51
+    assert(!m_ContextStack.empty()); // this should be checked by sax parser?
24cd51
+
24cd51
+    try
24cd51
     {
24cd51
-        m_ouDate += aChars;
24cd51
+        m_ContextStack.top()->EndElement();
24cd51
+
24cd51
+        if (m_xNextHandler.is())
24cd51
+        {
24cd51
+            m_xNextHandler->endElement(rName);
24cd51
+        }
24cd51
     }
24cd51
-    else if (m_bInSignatureLineId)
24cd51
-    {
24cd51
-        m_ouSignatureLineId += aChars;
24cd51
+    catch (css::uno::Exception& )
24cd51
+    {//getCaughtException MUST be the first line in the catch block
24cd51
+        css::uno::Any exc =  cppu::getCaughtException();
24cd51
+        throw css::xml::sax::SAXException(
24cd51
+            "xmlsecurity: Exception in XSecParser::endElement",
24cd51
+            nullptr, exc);
24cd51
     }
24cd51
-    else if (m_bInSignatureLineValidImage)
24cd51
+    catch (...)
24cd51
     {
24cd51
-        m_ouSignatureLineValidImage += aChars;
24cd51
+        throw css::xml::sax::SAXException(
24cd51
+            "xmlsecurity: unexpected exception in XSecParser::endElement", nullptr,
24cd51
+            css::uno::Any());
24cd51
     }
24cd51
-    else if (m_bInSignatureLineInvalidImage)
24cd51
+
24cd51
+    if (m_ContextStack.top()->m_pOldNamespaceMap)
24cd51
     {
24cd51
-        m_ouSignatureLineInvalidImage += aChars;
24cd51
+        m_pNamespaceMap = std::move(m_ContextStack.top()->m_pOldNamespaceMap);
24cd51
     }
24cd51
+    m_ContextStack.pop();
24cd51
+}
24cd51
+
24cd51
+void SAL_CALL XSecParser::characters(const OUString& rChars)
24cd51
+{
24cd51
+    assert(!m_ContextStack.empty()); // this should be checked by sax parser?
24cd51
+    m_ContextStack.top()->Characters(rChars);
24cd51
 
24cd51
     if (m_xNextHandler.is())
24cd51
     {
24cd51
-        m_xNextHandler->characters(aChars);
24cd51
+        m_xNextHandler->characters(rChars);
24cd51
     }
24cd51
 }
24cd51
 
24cd51
diff --git a/xmlsecurity/source/helper/xsecparser.hxx b/xmlsecurity/source/helper/xsecparser.hxx
24cd51
index d9b079aa3116..93efcb766e3e 100644
24cd51
--- a/xmlsecurity/source/helper/xsecparser.hxx
24cd51
+++ b/xmlsecurity/source/helper/xsecparser.hxx
24cd51
@@ -25,6 +25,10 @@
24cd51
 
24cd51
 #include <cppuhelper/implbase.hxx>
24cd51
 
24cd51
+#include <xmloff/nmspmap.hxx>
24cd51
+
24cd51
+#include <stack>
24cd51
+
24cd51
 class XMLSignatureHelper;
24cd51
 class XSecController;
24cd51
 
24cd51
@@ -48,47 +52,59 @@ class XSecParser: public cppu::WeakImplHelper
24cd51
  ******************************************************************************/
24cd51
 {
24cd51
     friend class XSecController;
24cd51
+public:
24cd51
+    class Context;
24cd51
 private:
24cd51
+    class UnknownContext;
24cd51
+    class LoPGPOwnerContext;
24cd51
+    class DsPGPKeyPacketContext;
24cd51
+    class DsPGPKeyIDContext;
24cd51
+    class DsPGPDataContext;
24cd51
+    class DsX509CertificateContext;
24cd51
+    class DsX509SerialNumberContext;
24cd51
+    class DsX509IssuerNameContext;
24cd51
+    class DsX509IssuerSerialContext;
24cd51
+    class DsX509DataContext;
24cd51
+    class DsKeyInfoContext;
24cd51
+    class DsSignatureValueContext;
24cd51
+    class DsDigestValueContext;
24cd51
+    class DsDigestMethodContext;
24cd51
+    class DsTransformContext;
24cd51
+    class DsTransformsContext;
24cd51
+    class DsReferenceContext;
24cd51
+    class DsSignatureMethodContext;
24cd51
+    class DsSignedInfoContext;
24cd51
+    class XadesEncapsulatedX509CertificateContext;
24cd51
+    class XadesCertificateValuesContext;
24cd51
+    class XadesUnsignedSignaturePropertiesContext;
24cd51
+    class XadesUnsignedPropertiesContext;
24cd51
+    class LoSignatureLineIdContext;
24cd51
+    class LoSignatureLineValidImageContext;
24cd51
+    class LoSignatureLineInvalidImageContext;
24cd51
+    class LoSignatureLineContext;
24cd51
+    class XadesCertDigestContext;
24cd51
+    class XadesCertContext;
24cd51
+    class XadesSigningCertificateContext;
24cd51
+    class XadesSigningTimeContext;
24cd51
+    class XadesSignedSignaturePropertiesContext;
24cd51
+    class XadesSignedPropertiesContext;
24cd51
+    class XadesQualifyingPropertiesContext;
24cd51
+    class DcDateContext;
24cd51
+    class DcDescriptionContext;
24cd51
+    class DsSignaturePropertyContext;
24cd51
+    class DsSignaturePropertiesContext;
24cd51
+    class DsObjectContext;
24cd51
+    class DsSignatureContext;
24cd51
+    class DsigSignaturesContext;
24cd51
+
24cd51
     /*
24cd51
      * the following members are used to reserve the signature information,
24cd51
      * including X509IssuerName, X509SerialNumber, and X509Certificate,etc.
24cd51
      */
24cd51
-    OUString m_ouX509IssuerName;
24cd51
-    OUString m_ouX509SerialNumber;
24cd51
-    OUString m_ouX509Certificate;
24cd51
-    OUString m_ouGpgCertificate;
24cd51
-    OUString m_ouGpgKeyID;
24cd51
-    OUString m_ouGpgOwner;
24cd51
-    OUString m_ouCertDigest;
24cd51
-    OUString m_ouEncapsulatedX509Certificate;
24cd51
-    OUString m_ouDigestValue;
24cd51
-    OUString m_ouSignatureValue;
24cd51
     OUString m_ouDate;
24cd51
-    /// Characters of a <dc:description> element, as just read from XML.
24cd51
-    OUString m_ouDescription;
24cd51
-    OUString m_ouSignatureLineId;
24cd51
-    OUString m_ouSignatureLineValidImage;
24cd51
-    OUString m_ouSignatureLineInvalidImage;
24cd51
 
24cd51
-    /*
24cd51
-     * whether inside a particular element
24cd51
-     */
24cd51
-    bool m_bInX509IssuerName;
24cd51
-    bool m_bInX509SerialNumber;
24cd51
-    bool m_bInX509Certificate;
24cd51
-    bool m_bInGpgCertificate;
24cd51
-    bool m_bInGpgKeyID;
24cd51
-    bool m_bInGpgOwner;
24cd51
-    bool m_bInCertDigest;
24cd51
-    bool m_bInEncapsulatedX509Certificate;
24cd51
-    bool m_bInSigningTime;
24cd51
-    bool m_bInDigestValue;
24cd51
-    bool m_bInSignatureValue;
24cd51
-    bool m_bInDate;
24cd51
-    bool m_bInDescription;
24cd51
-    bool m_bInSignatureLineId;
24cd51
-    bool m_bInSignatureLineValidImage;
24cd51
-    bool m_bInSignatureLineInvalidImage;
24cd51
+    std::stack<std::unique_ptr<Context>> m_ContextStack;
24cd51
+    std::unique_ptr<SvXMLNamespaceMap> m_pNamespaceMap;
24cd51
 
24cd51
     /*
24cd51
      * the XSecController collaborating with XSecParser
24cd51
@@ -101,22 +117,9 @@ private:
24cd51
     css::uno::Reference<
24cd51
         css::xml::sax::XDocumentHandler > m_xNextHandler;
24cd51
 
24cd51
-    /*
24cd51
-     * this string is used to remember the current handled reference's URI,
24cd51
-     *
24cd51
-     * because it can be decided whether a stream reference is xml based or binary based
24cd51
-     * only after the Transforms element is read in, so we have to reserve the reference's
24cd51
-     * URI when the startElement event is met.
24cd51
-     */
24cd51
-    OUString m_currentReferenceURI;
24cd51
-    bool m_bReferenceUnresolved;
24cd51
-
24cd51
-    // Relevant for ODF. The digest algorithm selected by the current DigestMethod element's
24cd51
-    // Algorithm attribute in the current Reference element. From css::xml::crypto::DigestID.
24cd51
-    sal_Int32 m_nReferenceDigestID;
24cd51
     XMLSignatureHelper& m_rXMLSignatureHelper;
24cd51
 
24cd51
-private:
24cd51
+    OUString HandleIdAttr(css::uno::Reference<css::xml::sax::XAttributeList> const& xAttrs);
24cd51
     static OUString getIdAttr(const css::uno::Reference<
24cd51
             css::xml::sax::XAttributeList >& xAttribs );
24cd51
 
24cd51
-- 
24cd51
2.32.0
24cd51