1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <documentsignaturehelper.hxx>
25 #include <string_view>
27 #include <com/sun/star/io/IOException.hpp>
28 #include <com/sun/star/embed/XStorage.hpp>
29 #include <com/sun/star/embed/StorageFormats.hpp>
30 #include <com/sun/star/embed/ElementModes.hpp>
31 #include <com/sun/star/beans/StringPair.hpp>
32 #include <com/sun/star/beans/XPropertySet.hpp>
33 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
35 #include <comphelper/attributelist.hxx>
36 #include <comphelper/documentconstants.hxx>
37 #include <comphelper/ofopxmlhelper.hxx>
38 #include <comphelper/processfactory.hxx>
39 #include <osl/diagnose.h>
40 #include <rtl/ref.hxx>
41 #include <rtl/uri.hxx>
42 #include <sal/log.hxx>
43 #include <svx/xoutbmp.hxx>
44 #include <comphelper/diagnose_ex.hxx>
45 #include <o3tl/string_view.hxx>
47 #include <xsecctl.hxx>
49 using namespace ::com::sun::star
;
50 using namespace ::com::sun::star::uno
;
51 using namespace css::xml::sax
;
55 std::u16string_view
getElement(std::u16string_view version
, size_t * index
)
57 while (*index
< version
.size() && version
[*index
] == '0') {
60 return o3tl::getToken(version
, u
'.', *index
);
64 // Return 1 if version1 is greater than version 2, 0 if they are equal
65 //and -1 if version1 is less version 2
67 std::u16string_view version1
, std::u16string_view version2
)
69 for (size_t i1
= 0, i2
= 0; i1
!= std::u16string_view::npos
|| i2
!= std::u16string_view::npos
;) {
70 std::u16string_view
e1(getElement(version1
, &i1
));
71 std::u16string_view
e2(getElement(version2
, &i2
));
72 if (e1
.size() < e2
.size()) {
74 } else if (e1
.size() > e2
.size()) {
86 static void ImplFillElementList(
87 std::vector
< OUString
>& rList
, const Reference
< css::embed::XStorage
>& rxStore
,
88 std::u16string_view rRootStorageName
, const bool bRecursive
,
89 const DocumentSignatureAlgorithm mode
)
91 const Sequence
< OUString
> aElements
= rxStore
->getElementNames();
93 for ( const auto& rName
: aElements
)
95 if (rName
== "[Content_Types].xml")
99 // If the user enabled validating according to OOo 3.0
100 // then mimetype and all content of META-INF must be excluded.
101 if (mode
!= DocumentSignatureAlgorithm::OOo3_2
102 && (rName
== "META-INF" || rName
== "mimetype"))
108 OUString sEncName
= ::rtl::Uri::encode(
109 rName
, rtl_UriCharClassRelSegment
,
110 rtl_UriEncodeStrict
, RTL_TEXTENCODING_UTF8
);
111 if (sEncName
.isEmpty() && !rName
.isEmpty())
112 throw css::uno::RuntimeException(u
"Failed to encode element name of XStorage"_ustr
, nullptr);
114 if ( rxStore
->isStreamElement( rName
) )
116 //Exclude documentsignatures.xml!
118 DocumentSignatureHelper::GetDocumentContentSignatureDefaultStreamName())
120 OUString
aFullName( rRootStorageName
+ sEncName
);
121 rList
.push_back(aFullName
);
123 else if ( bRecursive
&& rxStore
->isStorageElement( rName
) )
125 Reference
< css::embed::XStorage
> xSubStore
= rxStore
->openStorageElement( rName
, css::embed::ElementModes::READ
);
126 OUString
aFullRootName( rRootStorageName
+ sEncName
+ "/" );
127 ImplFillElementList(rList
, xSubStore
, aFullRootName
, bRecursive
, mode
);
134 bool DocumentSignatureHelper::isODFPre_1_2(std::u16string_view sVersion
)
136 //The property version exists only if the document is at least version 1.2
137 //That is, if the document has version 1.1 and sVersion is empty.
138 //The constant is defined in comphelper/documentconstants.hxx
139 return compareVersions(sVersion
, ODFVER_012_TEXT
) == -1;
142 bool DocumentSignatureHelper::isOOo3_2_Signature(const SignatureInformation
& sigInfo
)
144 return std::any_of(sigInfo
.vSignatureReferenceInfors
.cbegin(),
145 sigInfo
.vSignatureReferenceInfors
.cend(),
146 [](const SignatureReferenceInformation
& info
) { return info
.ouURI
== "META-INF/manifest.xml"; });
149 DocumentSignatureAlgorithm
150 DocumentSignatureHelper::getDocumentAlgorithm(
151 std::u16string_view sODFVersion
, const SignatureInformation
& sigInfo
)
153 OSL_ASSERT(!sODFVersion
.empty());
154 DocumentSignatureAlgorithm mode
= DocumentSignatureAlgorithm::OOo3_2
;
155 if (!isOOo3_2_Signature(sigInfo
))
157 if (isODFPre_1_2(sODFVersion
))
158 mode
= DocumentSignatureAlgorithm::OOo2
;
160 mode
= DocumentSignatureAlgorithm::OOo3_0
;
165 //The function creates a list of files which are to be signed or for which
166 //the signature is to be validated. The strings are UTF8 encoded URIs which
167 //contain '/' as path separators.
169 //The algorithm how document signatures are created and validated has
170 //changed over time. The change affects only which files within the document
171 //are changed. Document signatures created by OOo 2.x only used particular files. Since
172 //OOo 3.0 everything except "mimetype" and "META-INF" are signed. As of OOo 3.2 everything
173 //except META-INF/documentsignatures.xml is signed.
174 //Signatures are validated according to the algorithm which was then used for validation.
175 //That is, when validating a signature which was created by OOo 3.0, then mimetype and
176 //META-INF are not used.
178 //When a signature is created then we always use the latest algorithm. That is, we use
180 std::vector
< OUString
>
181 DocumentSignatureHelper::CreateElementList(
182 const Reference
< css::embed::XStorage
>& rxStore
,
183 DocumentSignatureMode eMode
,
184 const DocumentSignatureAlgorithm mode
)
186 std::vector
< OUString
> aElements
;
187 OUString
aSep( u
"/"_ustr
);
191 case DocumentSignatureMode::Content
:
193 if (mode
== DocumentSignatureAlgorithm::OOo2
) //that is, ODF 1.0, 1.1
196 ImplFillElementList(aElements
, rxStore
, std::u16string_view(), false, mode
);
199 OUString
aSubStorageName( u
"Pictures"_ustr
);
202 Reference
< css::embed::XStorage
> xSubStore
= rxStore
->openStorageElement( aSubStorageName
, css::embed::ElementModes::READ
);
204 aElements
, xSubStore
, Concat2View(aSubStorageName
+aSep
), true, mode
);
206 catch(css::io::IOException
& )
208 ; // Doesn't have to exist...
211 aSubStorageName
= "ObjectReplacements";
214 Reference
< css::embed::XStorage
> xSubStore
= rxStore
->openStorageElement( aSubStorageName
, css::embed::ElementModes::READ
);
216 aElements
, xSubStore
, Concat2View(aSubStorageName
+aSep
), true, mode
);
220 const Sequence
< OUString
> aElementNames
= rxStore
->getElementNames();
221 for ( const auto& rName
: aElementNames
)
223 if ( ( rName
.match( "Object " ) ) && rxStore
->isStorageElement( rName
) )
225 Reference
< css::embed::XStorage
> xTmpSubStore
= rxStore
->openStorageElement( rName
, css::embed::ElementModes::READ
);
227 aElements
, xTmpSubStore
, Concat2View(rName
+aSep
), true, mode
);
231 catch( css::io::IOException
& )
233 ; // Doesn't have to exist...
238 // Everything except META-INF
239 ImplFillElementList(aElements
, rxStore
, std::u16string_view(), true, mode
);
243 case DocumentSignatureMode::Macros
:
246 OUString
aSubStorageName( u
"Basic"_ustr
);
249 Reference
< css::embed::XStorage
> xSubStore
= rxStore
->openStorageElement( aSubStorageName
, css::embed::ElementModes::READ
);
251 aElements
, xSubStore
, Concat2View(aSubStorageName
+aSep
), true, mode
);
253 catch( css::io::IOException
& )
255 ; // Doesn't have to exist...
259 aSubStorageName
= "Dialogs";
262 Reference
< css::embed::XStorage
> xSubStore
= rxStore
->openStorageElement( aSubStorageName
, css::embed::ElementModes::READ
);
264 aElements
, xSubStore
, Concat2View(aSubStorageName
+aSep
), true, mode
);
266 catch( css::io::IOException
& )
268 ; // Doesn't have to exist...
271 aSubStorageName
= "Scripts";
274 Reference
< css::embed::XStorage
> xSubStore
= rxStore
->openStorageElement( aSubStorageName
, css::embed::ElementModes::READ
);
276 aElements
, xSubStore
, Concat2View(aSubStorageName
+aSep
), true, mode
);
278 catch( css::io::IOException
& )
280 ; // Doesn't have to exist...
289 void DocumentSignatureHelper::AppendContentTypes(const uno::Reference
<embed::XStorage
>& xStorage
, std::vector
<OUString
>& rElements
)
291 if (!xStorage
.is() || !xStorage
->hasByName(u
"[Content_Types].xml"_ustr
))
295 uno::Reference
<io::XInputStream
> xRelStream(xStorage
->openStreamElement(u
"[Content_Types].xml"_ustr
, embed::ElementModes::READ
), uno::UNO_QUERY
);
296 uno::Sequence
< uno::Sequence
<beans::StringPair
> > aContentTypeInfo
= comphelper::OFOPXMLHelper::ReadContentTypeSequence(xRelStream
, comphelper::getProcessComponentContext());
297 if (aContentTypeInfo
.getLength() < 2)
299 SAL_WARN("xmlsecurity.helper", "no defaults or overrides in aContentTypeInfo");
302 const uno::Sequence
<beans::StringPair
>& rDefaults
= aContentTypeInfo
[0];
303 const uno::Sequence
<beans::StringPair
>& rOverrides
= aContentTypeInfo
[1];
305 for (OUString
& rElement
: rElements
)
307 auto it
= std::find_if(rOverrides
.begin(), rOverrides
.end(), [&](const beans::StringPair
& rPair
)
309 return rPair
.First
== Concat2View("/" + rElement
);
312 if (it
!= rOverrides
.end())
314 rElement
= "/" + rElement
+ "?ContentType=" + it
->Second
;
318 it
= std::find_if(rDefaults
.begin(), rDefaults
.end(), [&](const beans::StringPair
& rPair
)
320 return rElement
.endsWith(Concat2View("." + rPair
.First
));
323 if (it
!= rDefaults
.end())
325 rElement
= "/" + rElement
+ "?ContentType=" + it
->Second
;
328 SAL_WARN("xmlsecurity.helper", "found no content type for " << rElement
);
331 std::sort(rElements
.begin(), rElements
.end());
334 SignatureStreamHelper
DocumentSignatureHelper::OpenSignatureStream(
335 const Reference
< css::embed::XStorage
>& rxStore
, sal_Int32 nOpenMode
, DocumentSignatureMode eDocSigMode
)
337 sal_Int32 nSubStorageOpenMode
= css::embed::ElementModes::READ
;
338 if ( nOpenMode
& css::embed::ElementModes::WRITE
)
339 nSubStorageOpenMode
= css::embed::ElementModes::WRITE
;
341 SignatureStreamHelper aHelper
;
346 if (rxStore
->hasByName(u
"META-INF"_ustr
))
350 aHelper
.xSignatureStorage
= rxStore
->openStorageElement( u
"META-INF"_ustr
, nSubStorageOpenMode
);
351 if ( aHelper
.xSignatureStorage
.is() )
353 OUString aSIGStreamName
;
354 if ( eDocSigMode
== DocumentSignatureMode::Content
)
355 aSIGStreamName
= DocumentSignatureHelper::GetDocumentContentSignatureDefaultStreamName();
356 else if ( eDocSigMode
== DocumentSignatureMode::Macros
)
357 aSIGStreamName
= DocumentSignatureHelper::GetScriptingContentSignatureDefaultStreamName();
359 aSIGStreamName
= DocumentSignatureHelper::GetPackageSignatureDefaultStreamName();
362 aHelper
.xSignatureStream
363 = aHelper
.xSignatureStorage
->openStreamElement(aSIGStreamName
, nOpenMode
);
364 SAL_INFO("xmlsecurity.helper",
365 "DocumentSignatureHelper::OpenSignatureStream: stream name is '"
366 << aSIGStreamName
<< "'");
367 if (aHelper
.xSignatureStream
.is())
369 uno::Reference
<io::XInputStream
> xInputStream(aHelper
.xSignatureStream
,
372 uno::Reference
<beans::XPropertySet
> xPropertySet(xInputStream
, uno::UNO_QUERY
);
373 xPropertySet
->getPropertyValue(u
"Size"_ustr
) >>= nSize
;
374 if (nSize
>= 0 && nSize
< SAL_MAX_INT32
)
376 uno::Sequence
<sal_Int8
> aData
;
377 xInputStream
->readBytes(aData
, nSize
);
378 SAL_INFO("xmlsecurity.helper",
379 "DocumentSignatureHelper::OpenSignatureStream: stream content is '"
380 << OString(reinterpret_cast<const char*>(aData
.getArray()),
385 aHelper
.xSignatureStream
.clear();
388 aHelper
.xSignatureStream
= aHelper
.xSignatureStorage
->openStreamElement( aSIGStreamName
, nOpenMode
);
391 catch(css::io::IOException
& )
393 // Doesn't have to exist...
394 SAL_WARN_IF( nOpenMode
!= css::embed::ElementModes::READ
, "xmlsecurity.helper", "Error creating signature stream..." );
397 else if(rxStore
->hasByName(u
"[Content_Types].xml"_ustr
))
401 if (rxStore
->hasByName(u
"_xmlsignatures"_ustr
) && (nOpenMode
& embed::ElementModes::TRUNCATE
))
402 // Truncate, then all signatures will be written -> remove previous ones.
403 rxStore
->removeElement(u
"_xmlsignatures"_ustr
);
405 aHelper
.xSignatureStorage
= rxStore
->openStorageElement(u
"_xmlsignatures"_ustr
, nSubStorageOpenMode
);
406 aHelper
.nStorageFormat
= embed::StorageFormats::OFOPXML
;
408 catch (const io::IOException
&)
410 TOOLS_WARN_EXCEPTION_IF(nOpenMode
!= css::embed::ElementModes::READ
, "xmlsecurity.helper", "DocumentSignatureHelper::OpenSignatureStream:");
417 /** Check whether the current file can be signed with GPG (only ODF >= 1.2 can currently) */
418 bool DocumentSignatureHelper::CanSignWithGPG(
419 const Reference
< css::embed::XStorage
>& rxStore
,
420 std::u16string_view sOdfVersion
)
425 if (rxStore
->hasByName(u
"META-INF"_ustr
)) // ODF
427 return !isODFPre_1_2(sOdfVersion
);
435 //sElementList contains all files which are expected to be signed. Only those files must me signed,
437 //The DocumentSignatureAlgorithm indicates if the document was created with OOo 2.x. Then
438 //the uri s in the Reference elements in the signature, were not properly encoded.
439 // For example: <Reference URI="ObjectReplacements/Object 1">
440 bool DocumentSignatureHelper::checkIfAllFilesAreSigned(
441 const ::std::vector
< OUString
> & sElementList
,
442 const SignatureInformation
& sigInfo
,
443 const DocumentSignatureAlgorithm alg
)
445 // Can only be valid if ALL streams are signed, which means real stream count == signed stream count
446 unsigned int nRealCount
= 0;
447 std::function
<OUString(const OUString
&)> fEncode
= [](const OUString
& rStr
) { return rStr
; };
448 if (alg
== DocumentSignatureAlgorithm::OOo2
)
449 //Comparing URIs is a difficult. Therefore we kind of normalize
450 //it before comparing. We assume that our URI do not have a leading "./"
451 //and fragments at the end (...#...)
452 fEncode
= [](const OUString
& rStr
) {
453 return rtl::Uri::encode(rStr
, rtl_UriCharClassPchar
, rtl_UriEncodeCheckEscapes
, RTL_TEXTENCODING_UTF8
);
456 for ( int i
= sigInfo
.vSignatureReferenceInfors
.size(); i
; )
458 const SignatureReferenceInformation
& rInf
= sigInfo
.vSignatureReferenceInfors
[--i
];
459 // There is also an extra entry of type SignatureReferenceType::SAMEDOCUMENT because of signature date.
460 if ( ( rInf
.nType
== SignatureReferenceType::BINARYSTREAM
) || ( rInf
.nType
== SignatureReferenceType::XMLSTREAM
) )
462 //find the file in the element list
463 if (std::any_of(sElementList
.cbegin(), sElementList
.cend(),
464 [&fEncode
, &rInf
](const OUString
& rElement
) { return fEncode(rElement
) == fEncode(rInf
.ouURI
); }))
468 return sElementList
.size() == nRealCount
;
471 /*Compares the Uri which are obtained from CreateElementList with
472 the path obtained from the manifest.xml.
473 Returns true if both strings are equal.
475 bool DocumentSignatureHelper::equalsReferenceUriManifestPath(
476 std::u16string_view rUri
, std::u16string_view rPath
)
478 //split up the uri and path into segments. Both are separated by '/'
479 std::vector
<OUString
> vUriSegments
;
480 for (sal_Int32 nIndex
= 0; nIndex
>= 0; )
481 vUriSegments
.push_back(OUString(o3tl::getToken(rUri
, 0, '/', nIndex
)));
483 std::vector
<OUString
> vPathSegments
;
484 for (sal_Int32 nIndex
= 0; nIndex
>= 0; )
485 vPathSegments
.push_back(OUString(o3tl::getToken(rPath
, 0, '/', nIndex
)));
487 if (vUriSegments
.size() != vPathSegments
.size())
490 //Now compare each segment of the uri with its counterpart from the path
492 vUriSegments
.cbegin(), vUriSegments
.cend(), vPathSegments
.cbegin(),
493 [](const OUString
& rUriSegment
, const OUString
& rPathSegment
) {
494 //Decode the uri segment, so that %20 becomes ' ', etc.
495 OUString sDecUri
= rtl::Uri::decode(rUriSegment
, rtl_UriDecodeWithCharset
, RTL_TEXTENCODING_UTF8
);
496 return sDecUri
== rPathSegment
;
500 OUString
DocumentSignatureHelper::GetDocumentContentSignatureDefaultStreamName()
502 return u
"documentsignatures.xml"_ustr
;
505 OUString
DocumentSignatureHelper::GetScriptingContentSignatureDefaultStreamName()
507 return u
"macrosignatures.xml"_ustr
;
510 OUString
DocumentSignatureHelper::GetPackageSignatureDefaultStreamName()
512 return u
"packagesignatures.xml"_ustr
;
515 void DocumentSignatureHelper::writeDigestMethod(
516 const uno::Reference
<xml::sax::XDocumentHandler
>& xDocumentHandler
)
518 rtl::Reference
<comphelper::AttributeList
> pAttributeList(new comphelper::AttributeList());
519 pAttributeList
->AddAttribute(u
"Algorithm"_ustr
, ALGO_XMLDSIGSHA256
);
520 xDocumentHandler
->startElement(u
"DigestMethod"_ustr
, uno::Reference
<xml::sax::XAttributeList
>(pAttributeList
));
521 xDocumentHandler
->endElement(u
"DigestMethod"_ustr
);
524 static void WriteXadesCert(
525 uno::Reference
<xml::sax::XDocumentHandler
> const& xDocumentHandler
,
526 SignatureInformation::X509CertInfo
const& rCertInfo
)
528 xDocumentHandler
->startElement(u
"xd:Cert"_ustr
, uno::Reference
<xml::sax::XAttributeList
>(new comphelper::AttributeList()));
529 xDocumentHandler
->startElement(u
"xd:CertDigest"_ustr
, uno::Reference
<xml::sax::XAttributeList
>(new comphelper::AttributeList()));
530 DocumentSignatureHelper::writeDigestMethod(xDocumentHandler
);
531 xDocumentHandler
->startElement(u
"DigestValue"_ustr
, uno::Reference
<xml::sax::XAttributeList
>(new comphelper::AttributeList()));
532 assert(!rCertInfo
.CertDigest
.isEmpty());
533 xDocumentHandler
->characters(rCertInfo
.CertDigest
);
534 xDocumentHandler
->endElement(u
"DigestValue"_ustr
);
535 xDocumentHandler
->endElement(u
"xd:CertDigest"_ustr
);
536 xDocumentHandler
->startElement(u
"xd:IssuerSerial"_ustr
, uno::Reference
<xml::sax::XAttributeList
>(new comphelper::AttributeList()));
537 xDocumentHandler
->startElement(u
"X509IssuerName"_ustr
, uno::Reference
<xml::sax::XAttributeList
>(new comphelper::AttributeList()));
538 xDocumentHandler
->characters(rCertInfo
.X509IssuerName
);
539 xDocumentHandler
->endElement(u
"X509IssuerName"_ustr
);
540 xDocumentHandler
->startElement(u
"X509SerialNumber"_ustr
, uno::Reference
<xml::sax::XAttributeList
>(new comphelper::AttributeList()));
541 xDocumentHandler
->characters(rCertInfo
.X509SerialNumber
);
542 xDocumentHandler
->endElement(u
"X509SerialNumber"_ustr
);
543 xDocumentHandler
->endElement(u
"xd:IssuerSerial"_ustr
);
544 xDocumentHandler
->endElement(u
"xd:Cert"_ustr
);
547 void DocumentSignatureHelper::writeSignedProperties(
548 const uno::Reference
<xml::sax::XDocumentHandler
>& xDocumentHandler
,
549 const SignatureInformation
& signatureInfo
,
550 const OUString
& sDate
, const bool bWriteSignatureLineData
)
553 rtl::Reference
<comphelper::AttributeList
> pAttributeList(new comphelper::AttributeList());
554 pAttributeList
->AddAttribute(u
"Id"_ustr
, "idSignedProperties_" + signatureInfo
.ouSignatureId
);
555 xDocumentHandler
->startElement(u
"xd:SignedProperties"_ustr
, uno::Reference
<xml::sax::XAttributeList
>(pAttributeList
));
558 xDocumentHandler
->startElement(u
"xd:SignedSignatureProperties"_ustr
, uno::Reference
<xml::sax::XAttributeList
>(new comphelper::AttributeList()));
559 xDocumentHandler
->startElement(u
"xd:SigningTime"_ustr
, uno::Reference
<xml::sax::XAttributeList
>(new comphelper::AttributeList()));
560 xDocumentHandler
->characters(sDate
);
561 xDocumentHandler
->endElement(u
"xd:SigningTime"_ustr
);
562 xDocumentHandler
->startElement(u
"xd:SigningCertificate"_ustr
, uno::Reference
<xml::sax::XAttributeList
>(new comphelper::AttributeList()));
563 assert(signatureInfo
.GetSigningCertificate() || !signatureInfo
.ouGpgKeyID
.isEmpty());
564 if (signatureInfo
.GetSigningCertificate())
566 // how should this deal with multiple X509Data elements?
567 // for now, let's write all of the certificates ...
568 for (auto const& rData
: signatureInfo
.X509Datas
)
570 for (auto const& it
: rData
)
572 WriteXadesCert(xDocumentHandler
, it
);
578 // for PGP, write empty mandatory X509IssuerName, X509SerialNumber
579 SignatureInformation::X509CertInfo temp
;
580 temp
.CertDigest
= signatureInfo
.ouGpgKeyID
;
581 WriteXadesCert(xDocumentHandler
, temp
);
583 xDocumentHandler
->endElement(u
"xd:SigningCertificate"_ustr
);
584 xDocumentHandler
->startElement(u
"xd:SignaturePolicyIdentifier"_ustr
, uno::Reference
<xml::sax::XAttributeList
>(new comphelper::AttributeList()));
585 xDocumentHandler
->startElement(u
"xd:SignaturePolicyImplied"_ustr
, uno::Reference
<xml::sax::XAttributeList
>(new comphelper::AttributeList()));
586 xDocumentHandler
->endElement(u
"xd:SignaturePolicyImplied"_ustr
);
587 xDocumentHandler
->endElement(u
"xd:SignaturePolicyIdentifier"_ustr
);
589 if (bWriteSignatureLineData
&& !signatureInfo
.ouSignatureLineId
.isEmpty()
590 && signatureInfo
.aValidSignatureImage
.is() && signatureInfo
.aInvalidSignatureImage
.is())
592 rtl::Reference
<comphelper::AttributeList
> pAttributeList(new comphelper::AttributeList());
593 pAttributeList
->AddAttribute(
594 u
"xmlns:loext"_ustr
, u
"urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0"_ustr
);
595 xDocumentHandler
->startElement(
596 u
"loext:SignatureLine"_ustr
,
597 Reference
<XAttributeList
>(pAttributeList
));
600 // Write SignatureLineId element
601 xDocumentHandler
->startElement(
602 u
"loext:SignatureLineId"_ustr
,
603 Reference
<XAttributeList
>(new comphelper::AttributeList()));
604 xDocumentHandler
->characters(signatureInfo
.ouSignatureLineId
);
605 xDocumentHandler
->endElement(u
"loext:SignatureLineId"_ustr
);
609 // Write SignatureLineValidImage element
610 xDocumentHandler
->startElement(
611 u
"loext:SignatureLineValidImage"_ustr
,
612 Reference
<XAttributeList
>(new comphelper::AttributeList()));
614 OUString aGraphicInBase64
;
615 Graphic
aGraphic(signatureInfo
.aValidSignatureImage
);
616 if (!XOutBitmap::GraphicToBase64(aGraphic
, aGraphicInBase64
, false))
617 SAL_WARN("xmlsecurity.helper", "could not convert graphic to base64");
619 xDocumentHandler
->characters(aGraphicInBase64
);
620 xDocumentHandler
->endElement(u
"loext:SignatureLineValidImage"_ustr
);
624 // Write SignatureLineInvalidImage element
625 xDocumentHandler
->startElement(
626 u
"loext:SignatureLineInvalidImage"_ustr
,
627 Reference
<XAttributeList
>(new comphelper::AttributeList()));
628 OUString aGraphicInBase64
;
629 Graphic
aGraphic(signatureInfo
.aInvalidSignatureImage
);
630 if (!XOutBitmap::GraphicToBase64(aGraphic
, aGraphicInBase64
, false))
631 SAL_WARN("xmlsecurity.helper", "could not convert graphic to base64");
632 xDocumentHandler
->characters(aGraphicInBase64
);
633 xDocumentHandler
->endElement(u
"loext:SignatureLineInvalidImage"_ustr
);
636 xDocumentHandler
->endElement(u
"loext:SignatureLine"_ustr
);
639 xDocumentHandler
->endElement(u
"xd:SignedSignatureProperties"_ustr
);
641 xDocumentHandler
->endElement(u
"xd:SignedProperties"_ustr
);
644 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */