1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "xsecparser.hxx"
22 #include <xsecctl.hxx>
23 #include <xmlsignaturehelper.hxx>
25 #include <xmloff/xmlnamespace.hxx>
26 #include <xmloff/xmltoken.hxx>
27 #include <xmloff/xmlimp.hxx>
29 #include <com/sun/star/xml/sax/SAXException.hpp>
30 #include <cppuhelper/exc_hlp.hxx>
31 #include <sal/log.hxx>
33 class XSecParser::Context
36 friend class XSecParser
;
37 XSecParser
& m_rParser
;
39 std::optional
<SvXMLNamespaceMap
> m_pOldNamespaceMap
;
42 Context(XSecParser
& rParser
,
43 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
)
45 , m_pOldNamespaceMap(std::move(pOldNamespaceMap
))
49 virtual ~Context() = default;
51 virtual void StartElement(
52 css::uno::Reference
<css::xml::sax::XAttributeList
> const& /*xAttrs*/)
56 virtual void EndElement()
60 virtual std::unique_ptr
<Context
> CreateChildContext(
61 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
,
62 sal_uInt16
const /*nNamespace*/, OUString
const& /*rName*/);
64 virtual void Characters(OUString
const& /*rChars*/)
69 // it's possible that an unsupported element has an Id attribute and a
70 // ds:Reference digesting it - probably this means XSecController needs to know
71 // about it. (For known elements, the Id attribute is only processed according
73 class XSecParser::UnknownContext
74 : public XSecParser::Context
77 UnknownContext(XSecParser
& rParser
,
78 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
)
79 : XSecParser::Context(rParser
, std::move(pOldNamespaceMap
))
83 virtual void StartElement(
84 css::uno::Reference
<css::xml::sax::XAttributeList
> const& xAttrs
) override
86 m_rParser
.HandleIdAttr(xAttrs
);
90 auto XSecParser::Context::CreateChildContext(
91 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
,
92 sal_uInt16
const /*nNamespace*/, OUString
const& /*rName*/)
93 -> std::unique_ptr
<Context
>
95 // default: create new base context
96 return std::make_unique
<UnknownContext
>(m_rParser
, std::move(pOldNamespaceMap
));
100 note: anything in ds:Object should be trusted *only* if there is a ds:Reference
101 to it so it is signed (exception: the xades:EncapsulatedX509Certificate).
102 ds:SignedInfo precedes all ds:Object.
104 There may be multiple ds:Signature for purpose of counter-signatures
105 but the way XAdES describes these, only the ds:SignatureValue element
106 would be referenced, so requiring a ds:Reference for anything in
107 ds:Object shouldn't cause issues.
109 class XSecParser::ReferencedContextImpl
110 : public XSecParser::Context
116 ReferencedContextImpl(XSecParser
& rParser
,
117 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
,
118 bool const isReferenced
)
119 : XSecParser::Context(rParser
, std::move(pOldNamespaceMap
))
120 , m_isReferenced(isReferenced
)
124 OUString
CheckIdAttrReferenced(css::uno::Reference
<css::xml::sax::XAttributeList
> const& xAttrs
)
126 OUString
const id(m_rParser
.HandleIdAttr(xAttrs
));
127 if (!id
.isEmpty() && m_rParser
.m_pXSecController
->haveReferenceForId(id
))
129 m_isReferenced
= true;
135 class XSecParser::LoPGPOwnerContext
136 : public XSecParser::Context
142 LoPGPOwnerContext(XSecParser
& rParser
,
143 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
)
144 : XSecParser::Context(rParser
, std::move(pOldNamespaceMap
))
148 virtual void EndElement() override
150 m_rParser
.m_pXSecController
->setGpgOwner(m_Value
);
153 virtual void Characters(OUString
const& rChars
) override
159 class XSecParser::DsPGPKeyPacketContext
160 : public XSecParser::Context
166 DsPGPKeyPacketContext(XSecParser
& rParser
,
167 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
)
168 : XSecParser::Context(rParser
, std::move(pOldNamespaceMap
))
172 virtual void EndElement() override
174 m_rParser
.m_pXSecController
->setGpgCertificate(m_Value
);
177 virtual void Characters(OUString
const& rChars
) override
183 class XSecParser::DsPGPKeyIDContext
184 : public XSecParser::Context
190 DsPGPKeyIDContext(XSecParser
& rParser
,
191 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
)
192 : XSecParser::Context(rParser
, std::move(pOldNamespaceMap
))
196 virtual void EndElement() override
198 m_rParser
.m_pXSecController
->setGpgKeyID(m_Value
);
201 virtual void Characters(OUString
const& rChars
) override
207 class XSecParser::DsPGPDataContext
208 : public XSecParser::Context
211 DsPGPDataContext(XSecParser
& rParser
,
212 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
)
213 : XSecParser::Context(rParser
, std::move(pOldNamespaceMap
))
217 virtual void StartElement(
218 css::uno::Reference
<css::xml::sax::XAttributeList
> const& /*xAttrs*/) override
220 m_rParser
.m_pXSecController
->switchGpgSignature();
223 virtual std::unique_ptr
<Context
> CreateChildContext(
224 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
,
225 sal_uInt16
const nNamespace
, OUString
const& rName
) override
227 if (nNamespace
== XML_NAMESPACE_DS
&& rName
== "PGPKeyID")
229 return std::make_unique
<DsPGPKeyIDContext
>(m_rParser
, std::move(pOldNamespaceMap
));
231 if (nNamespace
== XML_NAMESPACE_DS
&& rName
== "PGPKeyPacket")
233 return std::make_unique
<DsPGPKeyPacketContext
>(m_rParser
, std::move(pOldNamespaceMap
));
235 if (nNamespace
== XML_NAMESPACE_LO_EXT
&& rName
== "PGPOwner")
237 return std::make_unique
<LoPGPOwnerContext
>(m_rParser
, std::move(pOldNamespaceMap
));
239 return XSecParser::Context::CreateChildContext(std::move(pOldNamespaceMap
), nNamespace
, rName
);
243 class XSecParser::DsX509CertificateContext
244 : public XSecParser::Context
250 DsX509CertificateContext(XSecParser
& rParser
,
251 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
,
253 : XSecParser::Context(rParser
, std::move(pOldNamespaceMap
))
258 virtual void Characters(OUString
const& rChars
) override
264 class XSecParser::DsX509SerialNumberContext
265 : public XSecParser::Context
271 DsX509SerialNumberContext(XSecParser
& rParser
,
272 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
,
274 : XSecParser::Context(rParser
, std::move(pOldNamespaceMap
))
279 virtual void Characters(OUString
const& rChars
) override
285 class XSecParser::DsX509IssuerNameContext
286 : public XSecParser::Context
292 DsX509IssuerNameContext(XSecParser
& rParser
,
293 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
,
295 : XSecParser::Context(rParser
, std::move(pOldNamespaceMap
))
300 virtual void Characters(OUString
const& rChars
) override
306 class XSecParser::DsX509IssuerSerialContext
307 : public XSecParser::Context
310 OUString
& m_rX509IssuerName
;
311 OUString
& m_rX509SerialNumber
;
314 DsX509IssuerSerialContext(XSecParser
& rParser
,
315 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
,
316 OUString
& rIssuerName
, OUString
& rSerialNumber
)
317 : XSecParser::Context(rParser
, std::move(pOldNamespaceMap
))
318 , m_rX509IssuerName(rIssuerName
)
319 , m_rX509SerialNumber(rSerialNumber
)
323 virtual std::unique_ptr
<Context
> CreateChildContext(
324 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
,
325 sal_uInt16
const nNamespace
, OUString
const& rName
) override
327 if (nNamespace
== XML_NAMESPACE_DS
&& rName
== "X509IssuerName")
329 return std::make_unique
<DsX509IssuerNameContext
>(m_rParser
, std::move(pOldNamespaceMap
), m_rX509IssuerName
);
331 if (nNamespace
== XML_NAMESPACE_DS
&& rName
== "X509SerialNumber")
333 return std::make_unique
<DsX509SerialNumberContext
>(m_rParser
, std::move(pOldNamespaceMap
), m_rX509SerialNumber
);
335 // missing: ds:X509SKI, ds:X509SubjectName, ds:X509CRL
336 return XSecParser::Context::CreateChildContext(std::move(pOldNamespaceMap
), nNamespace
, rName
);
340 /// can't be sure what is supposed to happen here because the spec is clear as mud
341 class XSecParser::DsX509DataContext
342 : public XSecParser::Context
345 // sigh... "No ordering is implied by the above constraints."
346 // so store the ball of mud in vectors and try to figure it out later.
347 std::vector
<std::pair
<OUString
, OUString
>> m_X509IssuerSerials
;
348 std::vector
<OUString
> m_X509Certificates
;
351 DsX509DataContext(XSecParser
& rParser
,
352 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
)
353 : XSecParser::Context(rParser
, std::move(pOldNamespaceMap
))
357 virtual void EndElement() override
359 m_rParser
.m_pXSecController
->setX509Data(m_X509IssuerSerials
, m_X509Certificates
);
362 virtual std::unique_ptr
<Context
> CreateChildContext(
363 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
,
364 sal_uInt16
const nNamespace
, OUString
const& rName
) override
366 if (nNamespace
== XML_NAMESPACE_DS
&& rName
== "X509IssuerSerial")
368 m_X509IssuerSerials
.emplace_back();
369 return std::make_unique
<DsX509IssuerSerialContext
>(m_rParser
, std::move(pOldNamespaceMap
), m_X509IssuerSerials
.back().first
, m_X509IssuerSerials
.back().second
);
371 if (nNamespace
== XML_NAMESPACE_DS
&& rName
== "X509Certificate")
373 m_X509Certificates
.emplace_back();
374 return std::make_unique
<DsX509CertificateContext
>(m_rParser
, std::move(pOldNamespaceMap
), m_X509Certificates
.back());
376 // missing: ds:X509SKI, ds:X509SubjectName, ds:X509CRL
377 return XSecParser::Context::CreateChildContext(std::move(pOldNamespaceMap
), nNamespace
, rName
);
381 class XSecParser::DsKeyInfoContext
382 : public XSecParser::Context
385 DsKeyInfoContext(XSecParser
& rParser
,
386 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
)
387 : XSecParser::Context(rParser
, std::move(pOldNamespaceMap
))
391 virtual void StartElement(
392 css::uno::Reference
<css::xml::sax::XAttributeList
> const& xAttrs
) override
394 m_rParser
.HandleIdAttr(xAttrs
);
397 virtual std::unique_ptr
<Context
> CreateChildContext(
398 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
,
399 sal_uInt16
const nNamespace
, OUString
const& rName
) override
401 if (nNamespace
== XML_NAMESPACE_DS
&& rName
== "X509Data")
403 return std::make_unique
<DsX509DataContext
>(m_rParser
, std::move(pOldNamespaceMap
));
405 if (nNamespace
== XML_NAMESPACE_DS
&& rName
== "PGPData")
407 return std::make_unique
<DsPGPDataContext
>(m_rParser
, std::move(pOldNamespaceMap
));
409 // missing: ds:KeyName, ds:KeyValue, ds:RetrievalMethod, ds:SPKIData, ds:MgmtData
410 // (old code would read ds:Transform inside ds:RetrievalMethod but
411 // presumably that was a bug)
412 return XSecParser::Context::CreateChildContext(std::move(pOldNamespaceMap
), nNamespace
, rName
);
417 class XSecParser::DsSignatureValueContext
418 : public XSecParser::Context
424 DsSignatureValueContext(XSecParser
& rParser
,
425 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
)
426 : XSecParser::Context(rParser
, std::move(pOldNamespaceMap
))
430 virtual void StartElement(
431 css::uno::Reference
<css::xml::sax::XAttributeList
> const& xAttrs
) override
433 m_rParser
.HandleIdAttr(xAttrs
);
436 virtual void EndElement() override
438 m_rParser
.m_pXSecController
->setSignatureValue(m_Value
);
441 virtual void Characters(OUString
const& rChars
) override
447 class XSecParser::DsDigestValueContext
448 : public XSecParser::Context
454 DsDigestValueContext(XSecParser
& rParser
,
455 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
,
457 : XSecParser::Context(rParser
, std::move(pOldNamespaceMap
))
462 virtual void StartElement(
463 css::uno::Reference
<css::xml::sax::XAttributeList
> const& /*xAttrs*/) override
468 virtual void Characters(OUString
const& rChars
) override
474 class XSecParser::DsDigestMethodContext
475 : public XSecParser::Context
478 sal_Int32
& m_rReferenceDigestID
;
481 DsDigestMethodContext(XSecParser
& rParser
,
482 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
,
483 sal_Int32
& rReferenceDigestID
)
484 : XSecParser::Context(rParser
, std::move(pOldNamespaceMap
))
485 , m_rReferenceDigestID(rReferenceDigestID
)
489 virtual void StartElement(
490 css::uno::Reference
<css::xml::sax::XAttributeList
> const& xAttrs
) override
492 OUString ouAlgorithm
= xAttrs
->getValueByName(u
"Algorithm"_ustr
);
494 SAL_WARN_IF( ouAlgorithm
.isEmpty(), "xmlsecurity.helper", "no Algorithm in Reference" );
495 if (ouAlgorithm
.isEmpty())
498 SAL_WARN_IF( ouAlgorithm
!= ALGO_XMLDSIGSHA1
499 && ouAlgorithm
!= ALGO_XMLDSIGSHA256
500 && ouAlgorithm
!= ALGO_XMLDSIGSHA512
,
501 "xmlsecurity.helper", "Algorithm neither SHA1, SHA256 nor SHA512");
502 if (ouAlgorithm
== ALGO_XMLDSIGSHA1
)
503 m_rReferenceDigestID
= css::xml::crypto::DigestID::SHA1
;
504 else if (ouAlgorithm
== ALGO_XMLDSIGSHA256
)
505 m_rReferenceDigestID
= css::xml::crypto::DigestID::SHA256
;
506 else if (ouAlgorithm
== ALGO_XMLDSIGSHA512
)
507 m_rReferenceDigestID
= css::xml::crypto::DigestID::SHA512
;
509 m_rReferenceDigestID
= 0;
513 class XSecParser::DsTransformContext
514 : public XSecParser::Context
520 DsTransformContext(XSecParser
& rParser
,
521 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
,
523 : XSecParser::Context(rParser
, std::move(pOldNamespaceMap
))
528 virtual void StartElement(
529 css::uno::Reference
<css::xml::sax::XAttributeList
> const& xAttrs
) override
531 OUString ouAlgorithm
= xAttrs
->getValueByName(u
"Algorithm"_ustr
);
533 if (ouAlgorithm
== ALGO_C14N
)
543 class XSecParser::DsTransformsContext
544 : public XSecParser::Context
550 DsTransformsContext(XSecParser
& rParser
,
551 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
,
553 : XSecParser::Context(rParser
, std::move(pOldNamespaceMap
))
558 virtual std::unique_ptr
<Context
> CreateChildContext(
559 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
,
560 sal_uInt16
const nNamespace
, OUString
const& rName
) override
562 if (nNamespace
== XML_NAMESPACE_DS
&& rName
== "Transform")
564 return std::make_unique
<DsTransformContext
>(m_rParser
, std::move(pOldNamespaceMap
), m_rIsC14N
);
566 return XSecParser::Context::CreateChildContext(std::move(pOldNamespaceMap
), nNamespace
, rName
);
570 class XSecParser::DsReferenceContext
571 : public XSecParser::Context
576 OUString m_DigestValue
;
577 bool m_IsC14N
= false;
578 // Relevant for ODF. The digest algorithm selected by the DigestMethod
579 // element's Algorithm attribute. @see css::xml::crypto::DigestID.
580 sal_Int32 m_nReferenceDigestID
= css::xml::crypto::DigestID::SHA1
;
583 DsReferenceContext(XSecParser
& rParser
,
584 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
)
585 : XSecParser::Context(rParser
, std::move(pOldNamespaceMap
))
589 virtual void StartElement(
590 css::uno::Reference
<css::xml::sax::XAttributeList
> const& xAttrs
) override
592 m_rParser
.HandleIdAttr(xAttrs
);
594 m_URI
= xAttrs
->getValueByName(u
"URI"_ustr
);
595 SAL_WARN_IF(m_URI
.isEmpty(), "xmlsecurity.helper", "URI is empty");
596 // Remember the type of this reference.
597 m_Type
= xAttrs
->getValueByName(u
"Type"_ustr
);
600 virtual void EndElement() override
602 if (m_URI
.startsWith("#"))
605 * remove the first character '#' from the attribute value
607 m_rParser
.m_pXSecController
->addReference(m_URI
.copy(1), m_nReferenceDigestID
, m_Type
);
611 if (m_IsC14N
) // this is determined by nested ds:Transform
613 m_rParser
.m_pXSecController
->addStreamReference(m_URI
, false, m_nReferenceDigestID
);
617 * it must be an octet stream
620 m_rParser
.m_pXSecController
->addStreamReference(m_URI
, true, m_nReferenceDigestID
);
624 m_rParser
.m_pXSecController
->setDigestValue(m_nReferenceDigestID
, m_DigestValue
);
627 virtual std::unique_ptr
<Context
> CreateChildContext(
628 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
,
629 sal_uInt16
const nNamespace
, OUString
const& rName
) override
631 if (nNamespace
== XML_NAMESPACE_DS
&& rName
== "Transforms")
633 return std::make_unique
<DsTransformsContext
>(m_rParser
, std::move(pOldNamespaceMap
), m_IsC14N
);
635 if (nNamespace
== XML_NAMESPACE_DS
&& rName
== "DigestMethod")
637 return std::make_unique
<DsDigestMethodContext
>(m_rParser
, std::move(pOldNamespaceMap
), m_nReferenceDigestID
);
639 if (nNamespace
== XML_NAMESPACE_DS
&& rName
== "DigestValue")
641 return std::make_unique
<DsDigestValueContext
>(m_rParser
, std::move(pOldNamespaceMap
), m_DigestValue
);
643 return XSecParser::Context::CreateChildContext(std::move(pOldNamespaceMap
), nNamespace
, rName
);
647 class XSecParser::DsSignatureMethodContext
648 : public XSecParser::Context
651 DsSignatureMethodContext(XSecParser
& rParser
,
652 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
)
653 : XSecParser::Context(rParser
, std::move(pOldNamespaceMap
))
657 virtual void StartElement(
658 css::uno::Reference
<css::xml::sax::XAttributeList
> const& xAttrs
) override
660 OUString ouAlgorithm
= xAttrs
->getValueByName(u
"Algorithm"_ustr
);
661 if (ouAlgorithm
== ALGO_ECDSASHA1
|| ouAlgorithm
== ALGO_ECDSASHA256
662 || ouAlgorithm
== ALGO_ECDSASHA512
)
664 m_rParser
.m_pXSecController
->setSignatureMethod(svl::crypto::SignatureMethodAlgorithm::ECDSA
);
669 class XSecParser::DsSignedInfoContext
670 : public XSecParser::Context
673 DsSignedInfoContext(XSecParser
& rParser
,
674 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
)
675 : XSecParser::Context(rParser
, std::move(pOldNamespaceMap
))
679 virtual void StartElement(
680 css::uno::Reference
<css::xml::sax::XAttributeList
> const& xAttrs
) override
682 m_rParser
.HandleIdAttr(xAttrs
);
685 virtual void EndElement() override
687 m_rParser
.m_pXSecController
->setReferenceCount();
690 virtual std::unique_ptr
<Context
> CreateChildContext(
691 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
,
692 sal_uInt16
const nNamespace
, OUString
const& rName
) override
694 if (nNamespace
== XML_NAMESPACE_DS
&& rName
== "SignatureMethod")
696 return std::make_unique
<DsSignatureMethodContext
>(m_rParser
, std::move(pOldNamespaceMap
));
698 if (nNamespace
== XML_NAMESPACE_DS
&& rName
== "Reference")
700 return std::make_unique
<DsReferenceContext
>(m_rParser
, std::move(pOldNamespaceMap
));
702 // missing: ds:CanonicalizationMethod
703 return XSecParser::Context::CreateChildContext(std::move(pOldNamespaceMap
), nNamespace
, rName
);
707 class XSecParser::XadesEncapsulatedX509CertificateContext
708 : public XSecParser::Context
714 XadesEncapsulatedX509CertificateContext(XSecParser
& rParser
,
715 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
)
716 : XSecParser::Context(rParser
, std::move(pOldNamespaceMap
))
720 virtual void StartElement(
721 css::uno::Reference
<css::xml::sax::XAttributeList
> const& xAttrs
) override
723 m_rParser
.HandleIdAttr(xAttrs
);
726 virtual void EndElement() override
728 m_rParser
.m_pXSecController
->addEncapsulatedX509Certificate(m_Value
);
731 virtual void Characters(OUString
const& rChars
) override
737 class XSecParser::XadesCertificateValuesContext
738 : public XSecParser::Context
741 XadesCertificateValuesContext(XSecParser
& rParser
,
742 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
)
743 : XSecParser::Context(rParser
, std::move(pOldNamespaceMap
))
747 virtual void StartElement(
748 css::uno::Reference
<css::xml::sax::XAttributeList
> const& xAttrs
) override
750 m_rParser
.HandleIdAttr(xAttrs
);
753 virtual std::unique_ptr
<Context
> CreateChildContext(
754 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
,
755 sal_uInt16
const nNamespace
, OUString
const& rName
) override
757 if (nNamespace
== XML_NAMESPACE_XADES132
&& rName
== "EncapsulatedX509Certificate")
759 return std::make_unique
<XadesEncapsulatedX509CertificateContext
>(m_rParser
, std::move(pOldNamespaceMap
));
761 // missing: xades:OtherCertificate
762 return XSecParser::Context::CreateChildContext(std::move(pOldNamespaceMap
), nNamespace
, rName
);
766 class XSecParser::XadesUnsignedSignaturePropertiesContext
767 : public XSecParser::Context
770 XadesUnsignedSignaturePropertiesContext(XSecParser
& rParser
,
771 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
)
772 : XSecParser::Context(rParser
, std::move(pOldNamespaceMap
))
776 virtual void StartElement(
777 css::uno::Reference
<css::xml::sax::XAttributeList
> const& xAttrs
) override
779 m_rParser
.HandleIdAttr(xAttrs
);
782 virtual std::unique_ptr
<Context
> CreateChildContext(
783 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
,
784 sal_uInt16
const nNamespace
, OUString
const& rName
) override
786 if (nNamespace
== XML_NAMESPACE_XADES132
&& rName
== "CertificateValues")
788 return std::make_unique
<XadesCertificateValuesContext
>(m_rParser
, std::move(pOldNamespaceMap
));
791 // xades:CounterSignature
792 // ^ old code would read a ds:Signature inside it?
793 // xades:SignatureTimeStamp
794 // xades:CompleteCertificateRefs
795 // xades:CompleteRevocationRefs
796 // xades:AttributeCertificateRefs
797 // xades:AttributeRevocationRefs
798 // xades:SigAndRefsTimeStamp
799 // xades:RefsOnlyTimeStamp
800 // xades:RevocationValues
801 // xades:AttrAuthoritiesCertValues
802 // ^ old code: was equivalent to CertificateValues ???
803 // xades:AttributeRevocationValues
804 // xades:ArchiveTimeStamp
805 return XSecParser::Context::CreateChildContext(std::move(pOldNamespaceMap
), nNamespace
, rName
);
809 class XSecParser::XadesUnsignedPropertiesContext
810 : public XSecParser::Context
813 XadesUnsignedPropertiesContext(XSecParser
& rParser
,
814 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
)
815 : XSecParser::Context(rParser
, std::move(pOldNamespaceMap
))
819 virtual void StartElement(
820 css::uno::Reference
<css::xml::sax::XAttributeList
> const& xAttrs
) override
822 m_rParser
.HandleIdAttr(xAttrs
);
825 virtual std::unique_ptr
<Context
> CreateChildContext(
826 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
,
827 sal_uInt16
const nNamespace
, OUString
const& rName
) override
829 if (nNamespace
== XML_NAMESPACE_XADES132
&& rName
== "UnsignedSignatureProperties")
831 return std::make_unique
<XadesUnsignedSignaturePropertiesContext
>(m_rParser
, std::move(pOldNamespaceMap
));
833 // missing: xades:UnsignedDataObjectProperties
834 return XSecParser::Context::CreateChildContext(std::move(pOldNamespaceMap
), nNamespace
, rName
);
838 class XSecParser::LoSignatureLineIdContext
839 : public XSecParser::ReferencedContextImpl
845 LoSignatureLineIdContext(XSecParser
& rParser
,
846 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
,
847 bool const isReferenced
)
848 : ReferencedContextImpl(rParser
, std::move(pOldNamespaceMap
), isReferenced
)
852 virtual void EndElement() override
856 m_rParser
.m_pXSecController
->setSignatureLineId(m_Value
);
860 SAL_INFO("xmlsecurity.helper", "ignoring unsigned SignatureLineId");
864 virtual void Characters(OUString
const& rChars
) override
870 class XSecParser::LoSignatureLineValidImageContext
871 : public XSecParser::ReferencedContextImpl
877 LoSignatureLineValidImageContext(XSecParser
& rParser
,
878 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
,
879 bool const isReferenced
)
880 : ReferencedContextImpl(rParser
, std::move(pOldNamespaceMap
), isReferenced
)
884 virtual void EndElement() override
888 m_rParser
.m_pXSecController
->setValidSignatureImage(m_Value
);
892 SAL_INFO("xmlsecurity.helper", "ignoring unsigned SignatureLineValidImage");
896 virtual void Characters(OUString
const& rChars
) override
902 class XSecParser::LoSignatureLineInvalidImageContext
903 : public XSecParser::ReferencedContextImpl
909 LoSignatureLineInvalidImageContext(XSecParser
& rParser
,
910 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
,
911 bool const isReferenced
)
912 : ReferencedContextImpl(rParser
, std::move(pOldNamespaceMap
), isReferenced
)
916 virtual void EndElement() override
920 m_rParser
.m_pXSecController
->setInvalidSignatureImage(m_Value
);
924 SAL_INFO("xmlsecurity.helper", "ignoring unsigned SignatureLineInvalidImage");
928 virtual void Characters(OUString
const& rChars
) override
934 class XSecParser::LoSignatureLineContext
935 : public XSecParser::ReferencedContextImpl
938 LoSignatureLineContext(XSecParser
& rParser
,
939 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
,
940 bool const isReferenced
)
941 : ReferencedContextImpl(rParser
, std::move(pOldNamespaceMap
), isReferenced
)
945 virtual std::unique_ptr
<Context
> CreateChildContext(
946 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
,
947 sal_uInt16
const nNamespace
, OUString
const& rName
) override
949 if (nNamespace
== XML_NAMESPACE_LO_EXT
&& rName
== "SignatureLineId")
951 return std::make_unique
<LoSignatureLineIdContext
>(m_rParser
, std::move(pOldNamespaceMap
), m_isReferenced
);
953 if (nNamespace
== XML_NAMESPACE_LO_EXT
&& rName
== "SignatureLineValidImage")
955 return std::make_unique
<LoSignatureLineValidImageContext
>(m_rParser
, std::move(pOldNamespaceMap
), m_isReferenced
);
957 if (nNamespace
== XML_NAMESPACE_LO_EXT
&& rName
== "SignatureLineInvalidImage")
959 return std::make_unique
<LoSignatureLineInvalidImageContext
>(m_rParser
, std::move(pOldNamespaceMap
), m_isReferenced
);
961 return XSecParser::Context::CreateChildContext(std::move(pOldNamespaceMap
), nNamespace
, rName
);
965 class XSecParser::XadesCertDigestContext
966 : public XSecParser::Context
969 OUString
& m_rDigestValue
;
970 sal_Int32
& m_rReferenceDigestID
;
973 XadesCertDigestContext(XSecParser
& rParser
,
974 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
,
975 OUString
& rDigestValue
, sal_Int32
& rReferenceDigestID
)
976 : XSecParser::Context(rParser
, std::move(pOldNamespaceMap
))
977 , m_rDigestValue(rDigestValue
)
978 , m_rReferenceDigestID(rReferenceDigestID
)
982 virtual std::unique_ptr
<Context
> CreateChildContext(
983 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
,
984 sal_uInt16
const nNamespace
, OUString
const& rName
) override
986 if (nNamespace
== XML_NAMESPACE_DS
&& rName
== "DigestMethod")
988 return std::make_unique
<DsDigestMethodContext
>(m_rParser
, std::move(pOldNamespaceMap
), m_rReferenceDigestID
);
990 if (nNamespace
== XML_NAMESPACE_DS
&& rName
== "DigestValue")
992 return std::make_unique
<DsDigestValueContext
>(m_rParser
, std::move(pOldNamespaceMap
), m_rDigestValue
);
994 return XSecParser::Context::CreateChildContext(std::move(pOldNamespaceMap
), nNamespace
, rName
);
998 class XSecParser::XadesCertContext
999 : public XSecParser::ReferencedContextImpl
1002 sal_Int32 m_nReferenceDigestID
= css::xml::crypto::DigestID::SHA1
;
1003 OUString m_CertDigest
;
1004 OUString m_X509IssuerName
;
1005 OUString m_X509SerialNumber
;
1008 XadesCertContext(XSecParser
& rParser
,
1009 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
,
1010 bool const isReferenced
)
1011 : ReferencedContextImpl(rParser
, std::move(pOldNamespaceMap
), isReferenced
)
1015 virtual void EndElement() override
1019 m_rParser
.m_pXSecController
->setX509CertDigest(m_CertDigest
, m_nReferenceDigestID
, m_X509IssuerName
, m_X509SerialNumber
);
1023 SAL_INFO("xmlsecurity.helper", "ignoring unsigned xades:Cert");
1027 virtual std::unique_ptr
<Context
> CreateChildContext(
1028 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
,
1029 sal_uInt16
const nNamespace
, OUString
const& rName
) override
1031 if (nNamespace
== XML_NAMESPACE_XADES132
&& rName
== "CertDigest")
1033 return std::make_unique
<XadesCertDigestContext
>(m_rParser
, std::move(pOldNamespaceMap
), m_CertDigest
, m_nReferenceDigestID
);
1035 if (nNamespace
== XML_NAMESPACE_XADES132
&& rName
== "IssuerSerial")
1037 return std::make_unique
<DsX509IssuerSerialContext
>(m_rParser
, std::move(pOldNamespaceMap
), m_X509IssuerName
, m_X509SerialNumber
);
1039 return XSecParser::Context::CreateChildContext(std::move(pOldNamespaceMap
), nNamespace
, rName
);
1043 class XSecParser::XadesSigningCertificateContext
1044 : public XSecParser::ReferencedContextImpl
1047 XadesSigningCertificateContext(XSecParser
& rParser
,
1048 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
,
1049 bool const isReferenced
)
1050 : ReferencedContextImpl(rParser
, std::move(pOldNamespaceMap
), isReferenced
)
1054 virtual std::unique_ptr
<Context
> CreateChildContext(
1055 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
,
1056 sal_uInt16
const nNamespace
, OUString
const& rName
) override
1058 if (nNamespace
== XML_NAMESPACE_XADES132
&& rName
== "Cert")
1060 return std::make_unique
<XadesCertContext
>(m_rParser
, std::move(pOldNamespaceMap
), m_isReferenced
);
1062 return XSecParser::Context::CreateChildContext(std::move(pOldNamespaceMap
), nNamespace
, rName
);
1066 class XSecParser::XadesSigningTimeContext
1067 : public XSecParser::ReferencedContextImpl
1073 XadesSigningTimeContext(XSecParser
& rParser
,
1074 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
,
1075 bool const isReferenced
)
1076 : ReferencedContextImpl(rParser
, std::move(pOldNamespaceMap
), isReferenced
)
1080 virtual void EndElement() override
1084 m_rParser
.m_pXSecController
->setDate(u
""_ustr
, m_Value
);
1088 SAL_INFO("xmlsecurity.helper", "ignoring unsigned SigningTime");
1092 virtual void Characters(OUString
const& rChars
) override
1098 class XSecParser::XadesSignedSignaturePropertiesContext
1099 : public XSecParser::ReferencedContextImpl
1102 XadesSignedSignaturePropertiesContext(XSecParser
& rParser
,
1103 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
,
1104 bool const isReferenced
)
1105 : ReferencedContextImpl(rParser
, std::move(pOldNamespaceMap
), isReferenced
)
1109 virtual void StartElement(
1110 css::uno::Reference
<css::xml::sax::XAttributeList
> const& xAttrs
) override
1112 CheckIdAttrReferenced(xAttrs
);
1115 virtual std::unique_ptr
<Context
> CreateChildContext(
1116 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
,
1117 sal_uInt16
const nNamespace
, OUString
const& rName
) override
1119 if (nNamespace
== XML_NAMESPACE_XADES132
&& rName
== "SigningTime")
1121 return std::make_unique
<XadesSigningTimeContext
>(m_rParser
, std::move(pOldNamespaceMap
), m_isReferenced
);
1123 if (nNamespace
== XML_NAMESPACE_XADES132
&& rName
== "SigningCertificate")
1125 return std::make_unique
<XadesSigningCertificateContext
>(m_rParser
, std::move(pOldNamespaceMap
), m_isReferenced
);
1127 if (nNamespace
== XML_NAMESPACE_LO_EXT
&& rName
== "SignatureLine")
1129 return std::make_unique
<LoSignatureLineContext
>(m_rParser
, std::move(pOldNamespaceMap
), m_isReferenced
);
1131 // missing: xades:SignaturePolicyIdentifier, xades:SignatureProductionPlace, xades:SignerRole
1132 return XSecParser::Context::CreateChildContext(std::move(pOldNamespaceMap
), nNamespace
, rName
);
1136 class XSecParser::XadesSignedPropertiesContext
1137 : public XSecParser::ReferencedContextImpl
1140 XadesSignedPropertiesContext(XSecParser
& rParser
,
1141 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
,
1142 bool const isReferenced
)
1143 : ReferencedContextImpl(rParser
, std::move(pOldNamespaceMap
), isReferenced
)
1147 virtual void StartElement(
1148 css::uno::Reference
<css::xml::sax::XAttributeList
> const& xAttrs
) override
1150 CheckIdAttrReferenced(xAttrs
);
1153 virtual std::unique_ptr
<Context
> CreateChildContext(
1154 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
,
1155 sal_uInt16
const nNamespace
, OUString
const& rName
) override
1157 if (nNamespace
== XML_NAMESPACE_XADES132
&& rName
== "SignedSignatureProperties")
1159 return std::make_unique
<XadesSignedSignaturePropertiesContext
>(m_rParser
, std::move(pOldNamespaceMap
), m_isReferenced
);
1161 // missing: xades:SignedDataObjectProperties
1162 return XSecParser::Context::CreateChildContext(std::move(pOldNamespaceMap
), nNamespace
, rName
);
1166 class XSecParser::XadesQualifyingPropertiesContext
1167 : public XSecParser::ReferencedContextImpl
1170 XadesQualifyingPropertiesContext(XSecParser
& rParser
,
1171 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
,
1172 bool const isReferenced
)
1173 : ReferencedContextImpl(rParser
, std::move(pOldNamespaceMap
), isReferenced
)
1177 virtual void StartElement(
1178 css::uno::Reference
<css::xml::sax::XAttributeList
> const& xAttrs
) override
1180 CheckIdAttrReferenced(xAttrs
);
1183 virtual std::unique_ptr
<Context
> CreateChildContext(
1184 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
,
1185 sal_uInt16
const nNamespace
, OUString
const& rName
) override
1187 if (nNamespace
== XML_NAMESPACE_XADES132
&& rName
== "SignedProperties")
1189 return std::make_unique
<XadesSignedPropertiesContext
>(m_rParser
, std::move(pOldNamespaceMap
), m_isReferenced
);
1191 if (nNamespace
== XML_NAMESPACE_XADES132
&& rName
== "UnsignedProperties")
1193 return std::make_unique
<XadesUnsignedPropertiesContext
>(m_rParser
, std::move(pOldNamespaceMap
));
1195 return XSecParser::Context::CreateChildContext(std::move(pOldNamespaceMap
), nNamespace
, rName
);
1199 class XSecParser::DcDateContext
1200 : public XSecParser::Context
1203 OUString
& m_rValue
;
1206 DcDateContext(XSecParser
& rParser
,
1207 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
,
1209 : XSecParser::Context(rParser
, std::move(pOldNamespaceMap
))
1214 virtual void Characters(OUString
const& rChars
) override
1220 class XSecParser::DcDescriptionContext
1221 : public XSecParser::Context
1224 OUString
& m_rValue
;
1227 DcDescriptionContext(XSecParser
& rParser
,
1228 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
,
1230 : XSecParser::Context(rParser
, std::move(pOldNamespaceMap
))
1235 virtual void Characters(OUString
const& rChars
) override
1241 class XSecParser::DsSignaturePropertyContext
1242 : public XSecParser::ReferencedContextImpl
1245 enum class SignatureProperty
{ Unknown
, Date
, Description
};
1246 SignatureProperty m_Property
= SignatureProperty::Unknown
;
1251 DsSignaturePropertyContext(XSecParser
& rParser
,
1252 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
,
1253 bool const isReferenced
)
1254 : ReferencedContextImpl(rParser
, std::move(pOldNamespaceMap
), isReferenced
)
1258 virtual void StartElement(
1259 css::uno::Reference
<css::xml::sax::XAttributeList
> const& xAttrs
) override
1261 m_Id
= CheckIdAttrReferenced(xAttrs
);
1264 virtual void EndElement() override
1270 case SignatureProperty::Unknown
:
1271 SAL_INFO("xmlsecurity.helper", "Unknown property in ds:Object ignored");
1273 case SignatureProperty::Date
:
1274 m_rParser
.m_pXSecController
->setDate(m_Id
, m_Value
);
1276 case SignatureProperty::Description
:
1277 m_rParser
.m_pXSecController
->setDescription(m_Id
, m_Value
);
1283 SAL_INFO("xmlsecurity.helper", "ignoring unsigned SignatureProperty");
1287 virtual std::unique_ptr
<Context
> CreateChildContext(
1288 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
,
1289 sal_uInt16
const nNamespace
, OUString
const& rName
) override
1291 if (nNamespace
== XML_NAMESPACE_DC
&& rName
== "date")
1293 m_Property
= SignatureProperty::Date
;
1294 return std::make_unique
<DcDateContext
>(m_rParser
, std::move(pOldNamespaceMap
), m_Value
);
1296 if (nNamespace
== XML_NAMESPACE_DC
&& rName
== "description")
1298 m_Property
= SignatureProperty::Description
;
1299 return std::make_unique
<DcDescriptionContext
>(m_rParser
, std::move(pOldNamespaceMap
), m_Value
);
1301 return XSecParser::Context::CreateChildContext(std::move(pOldNamespaceMap
), nNamespace
, rName
);
1305 class XSecParser::DsSignaturePropertiesContext
1306 : public XSecParser::ReferencedContextImpl
1309 DsSignaturePropertiesContext(XSecParser
& rParser
,
1310 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
,
1311 bool const isReferenced
)
1312 : ReferencedContextImpl(rParser
, std::move(pOldNamespaceMap
), isReferenced
)
1316 virtual void StartElement(
1317 css::uno::Reference
<css::xml::sax::XAttributeList
> const& xAttrs
) override
1319 CheckIdAttrReferenced(xAttrs
);
1322 virtual std::unique_ptr
<Context
> CreateChildContext(
1323 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
,
1324 sal_uInt16
const nNamespace
, OUString
const& rName
) override
1326 if (nNamespace
== XML_NAMESPACE_DS
&& rName
== "SignatureProperty")
1328 return std::make_unique
<DsSignaturePropertyContext
>(m_rParser
, std::move(pOldNamespaceMap
), m_isReferenced
);
1330 return XSecParser::Context::CreateChildContext(std::move(pOldNamespaceMap
), nNamespace
, rName
);
1334 class XSecParser::DsObjectContext
1335 : public XSecParser::ReferencedContextImpl
1338 DsObjectContext(XSecParser
& rParser
,
1339 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
)
1340 // init with "false" here - the Signature element can't be referenced by its child
1341 : XSecParser::ReferencedContextImpl(rParser
, std::move(pOldNamespaceMap
), false)
1345 virtual void StartElement(
1346 css::uno::Reference
<css::xml::sax::XAttributeList
> const& xAttrs
) override
1348 CheckIdAttrReferenced(xAttrs
);
1351 virtual std::unique_ptr
<Context
> CreateChildContext(
1352 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
,
1353 sal_uInt16
const nNamespace
, OUString
const& rName
) override
1355 if (nNamespace
== XML_NAMESPACE_DS
&& rName
== "SignatureProperties")
1357 return std::make_unique
<DsSignaturePropertiesContext
>(m_rParser
, std::move(pOldNamespaceMap
), m_isReferenced
);
1359 if (nNamespace
== XML_NAMESPACE_XADES132
&& rName
== "QualifyingProperties")
1361 return std::make_unique
<XadesQualifyingPropertiesContext
>(m_rParser
, std::move(pOldNamespaceMap
), m_isReferenced
);
1363 // missing: ds:Manifest
1364 return XSecParser::Context::CreateChildContext(std::move(pOldNamespaceMap
), nNamespace
, rName
);
1368 class XSecParser::DsSignatureContext
1369 : public XSecParser::Context
1372 DsSignatureContext(XSecParser
& rParser
,
1373 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
)
1374 : XSecParser::Context(rParser
, std::move(pOldNamespaceMap
))
1378 virtual void StartElement(
1379 css::uno::Reference
<css::xml::sax::XAttributeList
> const& xAttrs
) override
1381 OUString
const ouIdAttr(m_rParser
.HandleIdAttr(xAttrs
));
1382 m_rParser
.m_rXMLSignatureHelper
.StartVerifySignatureElement();
1383 m_rParser
.m_pXSecController
->addSignature();
1384 if (!ouIdAttr
.isEmpty())
1386 m_rParser
.m_pXSecController
->setId( ouIdAttr
);
1390 virtual std::unique_ptr
<Context
> CreateChildContext(
1391 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
,
1392 sal_uInt16
const nNamespace
, OUString
const& rName
) override
1394 if (nNamespace
== XML_NAMESPACE_DS
&& rName
== "SignedInfo")
1396 return std::make_unique
<DsSignedInfoContext
>(m_rParser
, std::move(pOldNamespaceMap
));
1398 if (nNamespace
== XML_NAMESPACE_DS
&& rName
== "SignatureValue")
1400 return std::make_unique
<DsSignatureValueContext
>(m_rParser
, std::move(pOldNamespaceMap
));
1402 if (nNamespace
== XML_NAMESPACE_DS
&& rName
== "KeyInfo")
1404 return std::make_unique
<DsKeyInfoContext
>(m_rParser
, std::move(pOldNamespaceMap
));
1406 if (nNamespace
== XML_NAMESPACE_DS
&& rName
== "Object")
1408 return std::make_unique
<DsObjectContext
>(m_rParser
, std::move(pOldNamespaceMap
));
1410 return XSecParser::Context::CreateChildContext(std::move(pOldNamespaceMap
), nNamespace
, rName
);
1414 class XSecParser::DsigSignaturesContext
1415 : public XSecParser::Context
1418 DsigSignaturesContext(XSecParser
& rParser
,
1419 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
)
1420 : XSecParser::Context(rParser
, std::move(pOldNamespaceMap
))
1424 virtual std::unique_ptr
<Context
> CreateChildContext(
1425 std::optional
<SvXMLNamespaceMap
>&& pOldNamespaceMap
,
1426 sal_uInt16
const nNamespace
, OUString
const& rName
) override
1428 if (nNamespace
== XML_NAMESPACE_DS
&& rName
== "Signature")
1430 return std::make_unique
<DsSignatureContext
>(m_rParser
, std::move(pOldNamespaceMap
));
1432 return XSecParser::Context::CreateChildContext(std::move(pOldNamespaceMap
), nNamespace
, rName
);
1437 XSecParser::XSecParser(XMLSignatureHelper
& rXMLSignatureHelper
,
1438 XSecController
* pXSecController
)
1439 : m_pNamespaceMap(SvXMLNamespaceMap())
1440 , m_pXSecController(pXSecController
)
1441 , m_rXMLSignatureHelper(rXMLSignatureHelper
)
1443 using namespace xmloff::token
;
1444 m_pNamespaceMap
->Add( GetXMLToken(XML_XML
), GetXMLToken(XML_N_XML
), XML_NAMESPACE_XML
);
1445 m_pNamespaceMap
->Add( u
"_dsig_ooo"_ustr
, GetXMLToken(XML_N_DSIG_OOO
), XML_NAMESPACE_DSIG_OOO
);
1446 m_pNamespaceMap
->Add( u
"_dsig"_ustr
, GetXMLToken(XML_N_DSIG
), XML_NAMESPACE_DSIG
);
1447 m_pNamespaceMap
->Add( u
"_ds"_ustr
, GetXMLToken(XML_N_DS
), XML_NAMESPACE_DS
);
1448 m_pNamespaceMap
->Add( u
"_xades132"_ustr
, GetXMLToken(XML_N_XADES132
), XML_NAMESPACE_XADES132
);
1449 m_pNamespaceMap
->Add( u
"_xades141"_ustr
, GetXMLToken(XML_N_XADES141
), XML_NAMESPACE_XADES141
);
1450 m_pNamespaceMap
->Add( u
"_dc"_ustr
, GetXMLToken(XML_N_DC
), XML_NAMESPACE_DC
);
1451 m_pNamespaceMap
->Add( u
"_office_libo"_ustr
,
1452 GetXMLToken(XML_N_LO_EXT
), XML_NAMESPACE_LO_EXT
);
1455 OUString
XSecParser::HandleIdAttr(css::uno::Reference
<css::xml::sax::XAttributeList
> const& xAttrs
)
1457 OUString ouIdAttr
= getIdAttr(xAttrs
);
1458 if (!ouIdAttr
.isEmpty())
1460 m_pXSecController
->collectToVerify( ouIdAttr
);
1465 OUString
XSecParser::getIdAttr(const css::uno::Reference
< css::xml::sax::XAttributeList
>& xAttribs
)
1467 OUString ouIdAttr
= xAttribs
->getValueByName(u
"id"_ustr
);
1469 if (ouIdAttr
.isEmpty())
1471 ouIdAttr
= xAttribs
->getValueByName(u
"Id"_ustr
);
1480 void SAL_CALL
XSecParser::startDocument( )
1482 if (m_xNextHandler
.is())
1484 m_xNextHandler
->startDocument();
1488 void SAL_CALL
XSecParser::endDocument( )
1490 if (m_xNextHandler
.is())
1492 m_xNextHandler
->endDocument();
1496 void SAL_CALL
XSecParser::startElement(
1497 const OUString
& rName
,
1498 const css::uno::Reference
< css::xml::sax::XAttributeList
>& xAttribs
)
1500 assert(m_pNamespaceMap
);
1501 std::optional
<SvXMLNamespaceMap
> pRewindMap(
1502 SvXMLImport::processNSAttributes(m_pNamespaceMap
, nullptr, xAttribs
));
1505 sal_uInt16
const nPrefix(m_pNamespaceMap
->GetKeyByAttrName(rName
, &localName
));
1507 std::unique_ptr
<Context
> pContext
;
1509 if (m_ContextStack
.empty())
1511 if ((nPrefix
!= XML_NAMESPACE_DSIG
&& nPrefix
!= XML_NAMESPACE_DSIG_OOO
)
1512 || localName
!= "document-signatures")
1514 throw css::xml::sax::SAXException(
1515 u
"xmlsecurity: unexpected root element"_ustr
, nullptr,
1519 pContext
.reset(new DsigSignaturesContext(*this, std::move(pRewindMap
)));
1524 pContext
= m_ContextStack
.top()->CreateChildContext(
1525 std::move(pRewindMap
), nPrefix
, localName
);
1528 m_ContextStack
.push(std::move(pContext
));
1532 m_ContextStack
.top()->StartElement(xAttribs
);
1534 if (m_xNextHandler
.is())
1536 m_xNextHandler
->startElement(rName
, xAttribs
);
1539 catch (css::uno::Exception
& )
1540 {//getCaughtException MUST be the first line in the catch block
1541 css::uno::Any exc
= cppu::getCaughtException();
1542 throw css::xml::sax::SAXException(
1543 u
"xmlsecurity: Exception in XSecParser::startElement"_ustr
,
1548 throw css::xml::sax::SAXException(
1549 u
"xmlsecurity: unexpected exception in XSecParser::startElement"_ustr
, nullptr,
1554 void SAL_CALL
XSecParser::endElement(const OUString
& rName
)
1556 assert(!m_ContextStack
.empty()); // this should be checked by sax parser?
1560 m_ContextStack
.top()->EndElement();
1562 if (m_xNextHandler
.is())
1564 m_xNextHandler
->endElement(rName
);
1567 catch (css::uno::Exception
& )
1568 {//getCaughtException MUST be the first line in the catch block
1569 css::uno::Any exc
= cppu::getCaughtException();
1570 throw css::xml::sax::SAXException(
1571 u
"xmlsecurity: Exception in XSecParser::endElement"_ustr
,
1576 throw css::xml::sax::SAXException(
1577 u
"xmlsecurity: unexpected exception in XSecParser::endElement"_ustr
, nullptr,
1581 if (m_ContextStack
.top()->m_pOldNamespaceMap
)
1583 m_pNamespaceMap
= std::move(m_ContextStack
.top()->m_pOldNamespaceMap
);
1585 m_ContextStack
.pop();
1588 void SAL_CALL
XSecParser::characters(const OUString
& rChars
)
1590 assert(!m_ContextStack
.empty()); // this should be checked by sax parser?
1591 m_ContextStack
.top()->Characters(rChars
);
1593 if (m_xNextHandler
.is())
1595 m_xNextHandler
->characters(rChars
);
1599 void SAL_CALL
XSecParser::ignorableWhitespace( const OUString
& aWhitespaces
)
1601 if (m_xNextHandler
.is())
1603 m_xNextHandler
->ignorableWhitespace( aWhitespaces
);
1607 void SAL_CALL
XSecParser::processingInstruction( const OUString
& aTarget
, const OUString
& aData
)
1609 if (m_xNextHandler
.is())
1611 m_xNextHandler
->processingInstruction(aTarget
, aData
);
1615 void SAL_CALL
XSecParser::setDocumentLocator( const css::uno::Reference
< css::xml::sax::XLocator
>& xLocator
)
1617 if (m_xNextHandler
.is())
1619 m_xNextHandler
->setDocumentLocator( xLocator
);
1626 void SAL_CALL
XSecParser::initialize(
1627 const css::uno::Sequence
< css::uno::Any
>& aArguments
)
1629 aArguments
[0] >>= m_xNextHandler
;
1632 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */