summaryrefslogtreecommitdiffstats
path: root/package/source/manifest
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--package/source/manifest/ManifestDefines.hxx98
-rw-r--r--package/source/manifest/ManifestExport.cxx540
-rw-r--r--package/source/manifest/ManifestExport.hxx39
-rw-r--r--package/source/manifest/ManifestImport.cxx610
-rw-r--r--package/source/manifest/ManifestImport.hxx103
-rw-r--r--package/source/manifest/ManifestReader.cxx121
-rw-r--r--package/source/manifest/ManifestReader.hxx60
-rw-r--r--package/source/manifest/ManifestWriter.cxx113
-rw-r--r--package/source/manifest/ManifestWriter.hxx60
-rw-r--r--package/source/manifest/UnoRegister.cxx70
10 files changed, 1814 insertions, 0 deletions
diff --git a/package/source/manifest/ManifestDefines.hxx b/package/source/manifest/ManifestDefines.hxx
new file mode 100644
index 000000000..44c0cb4c5
--- /dev/null
+++ b/package/source/manifest/ManifestDefines.hxx
@@ -0,0 +1,98 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+#ifndef INCLUDED_PACKAGE_SOURCE_MANIFEST_MANIFESTDEFINES_HXX
+#define INCLUDED_PACKAGE_SOURCE_MANIFEST_MANIFESTDEFINES_HXX
+
+#include <PackageConstants.hxx>
+
+#define MANIFEST_NSPREFIX "manifest:"
+#define ELEMENT_MANIFEST "manifest:manifest"
+#define ATTRIBUTE_XMLNS "xmlns:manifest"
+#define ATTRIBUTE_XMLNS_LOEXT "xmlns:loext"
+#define MANIFEST_NAMESPACE "http://openoffice.org/2001/manifest"
+#define MANIFEST_OASIS_NAMESPACE "urn:oasis:names:tc:opendocument:xmlns:manifest:1.0"
+#define MANIFEST_LOEXT_NAMESPACE "urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0"
+#define MANIFEST_DOCTYPE "<!DOCTYPE manifest:manifest PUBLIC \"-//OpenOffice.org//DTD Manifest 1.0//EN\" \"Manifest.dtd\">"
+#define ATTRIBUTE_CDATA "CDATA"
+
+#define ELEMENT_FILE_ENTRY "manifest:file-entry"
+#define ATTRIBUTE_FULL_PATH "manifest:full-path"
+#define ATTRIBUTE_VERSION "manifest:version"
+#define ATTRIBUTE_MEDIA_TYPE "manifest:media-type"
+#define ATTRIBUTE_SIZE "manifest:size"
+#define ELEMENT_MANIFEST_KEYINFO "loext:keyinfo"
+#define ELEMENT_ENCRYPTED_KEYINFO "loext:KeyInfo"
+#define ELEMENT_ENCRYPTEDKEY "loext:encrypted-key"
+#define ELEMENT_ENCRYPTIONMETHOD "loext:encryption-method"
+#define ELEMENT_PGPDATA "loext:PGPData"
+#define ELEMENT_PGPKEYID "loext:PGPKeyID"
+#define ELEMENT_PGPKEYPACKET "loext:PGPKeyPacket"
+#define ATTRIBUTE_ALGORITHM "loext:PGPAlgorithm"
+#define ELEMENT_CIPHERDATA "loext:CipherData"
+#define ELEMENT_CIPHERVALUE "loext:CipherValue"
+#define ELEMENT_MANIFEST13_KEYINFO "manifest:keyinfo"
+#define ELEMENT_ENCRYPTEDKEY13 "manifest:encrypted-key"
+#define ELEMENT_ENCRYPTIONMETHOD13 "manifest:encryption-method"
+#define ELEMENT_PGPDATA13 "manifest:PGPData"
+#define ELEMENT_PGPKEYID13 "manifest:PGPKeyID"
+#define ELEMENT_PGPKEYPACKET13 "manifest:PGPKeyPacket"
+#define ATTRIBUTE_ALGORITHM13 "manifest:PGPAlgorithm"
+#define ELEMENT_CIPHERDATA13 "manifest:CipherData"
+#define ELEMENT_CIPHERVALUE13 "manifest:CipherValue"
+
+#define ELEMENT_ENCRYPTION_DATA "manifest:encryption-data"
+#define ATTRIBUTE_CHECKSUM_TYPE "manifest:checksum-type"
+#define ATTRIBUTE_CHECKSUM "manifest:checksum"
+
+#define ELEMENT_ALGORITHM "manifest:algorithm"
+#define ATTRIBUTE_ALGORITHM_NAME "manifest:algorithm-name"
+#define ATTRIBUTE_INITIALISATION_VECTOR "manifest:initialisation-vector"
+
+#define ELEMENT_START_KEY_GENERATION "manifest:start-key-generation"
+#define ATTRIBUTE_START_KEY_GENERATION_NAME "manifest:start-key-generation-name"
+#define ATTRIBUTE_KEY_SIZE "manifest:key-size"
+
+#define ELEMENT_KEY_DERIVATION "manifest:key-derivation"
+#define ATTRIBUTE_KEY_DERIVATION_NAME "manifest:key-derivation-name"
+#define ATTRIBUTE_SALT "manifest:salt"
+#define ATTRIBUTE_ITERATION_COUNT "manifest:iteration-count"
+
+/// OFFICE-3708: wrong URL cited in ODF 1.2 and used since OOo 3.4 beta
+#define SHA256_URL_ODF12 "http://www.w3.org/2000/09/xmldsig#sha256"
+#define SHA256_URL "http://www.w3.org/2001/04/xmlenc#sha256"
+#define SHA1_NAME "SHA1"
+#define SHA1_URL "http://www.w3.org/2000/09/xmldsig#sha1"
+
+#define SHA1_1K_NAME "SHA1/1K"
+#define SHA1_1K_URL "urn:oasis:names:tc:opendocument:xmlns:manifest:1.0#sha1-1k"
+#define SHA256_1K_URL "urn:oasis:names:tc:opendocument:xmlns:manifest:1.0#sha256-1k"
+
+#define BLOWFISH_NAME "Blowfish CFB"
+#define BLOWFISH_URL "urn:oasis:names:tc:opendocument:xmlns:manifest:1.0#blowfish"
+#define AES128_URL "http://www.w3.org/2001/04/xmlenc#aes128-cbc"
+#define AES192_URL "http://www.w3.org/2001/04/xmlenc#aes192-cbc"
+#define AES256_URL "http://www.w3.org/2001/04/xmlenc#aes256-cbc"
+
+#define PBKDF2_NAME "PBKDF2"
+#define PGP_NAME "PGP"
+#define PBKDF2_URL "urn:oasis:names:tc:opendocument:xmlns:manifest:1.0#pbkdf2"
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/package/source/manifest/ManifestExport.cxx b/package/source/manifest/ManifestExport.cxx
new file mode 100644
index 000000000..1546b7dbb
--- /dev/null
+++ b/package/source/manifest/ManifestExport.cxx
@@ -0,0 +1,540 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
+#include <com/sun/star/xml/sax/XDocumentHandler.hpp>
+#include <com/sun/star/xml/sax/XAttributeList.hpp>
+#include <com/sun/star/xml/crypto/DigestID.hpp>
+#include <com/sun/star/xml/crypto/CipherID.hpp>
+#include <com/sun/star/beans/PropertyValue.hpp>
+#include <com/sun/star/beans/NamedValue.hpp>
+#include <com/sun/star/uno/RuntimeException.hpp>
+
+#include "ManifestDefines.hxx"
+#include "ManifestExport.hxx"
+#include <sax/tools/converter.hxx>
+
+#include <osl/diagnose.h>
+#include <rtl/ustrbuf.hxx>
+#include <sal/log.hxx>
+#include <comphelper/base64.hxx>
+#include <comphelper/documentconstants.hxx>
+#include <comphelper/attributelist.hxx>
+
+using namespace ::com::sun::star;
+
+#if OSL_DEBUG_LEVEL > 0
+#define THROW_WHERE SAL_WHERE
+#else
+#define THROW_WHERE ""
+#endif
+
+ManifestExport::ManifestExport( uno::Reference< xml::sax::XDocumentHandler > const & xHandler, const uno::Sequence< uno::Sequence < beans::PropertyValue > >& rManList )
+{
+ const OUString sFileEntryElement ( ELEMENT_FILE_ENTRY );
+ const OUString sManifestElement ( ELEMENT_MANIFEST );
+ const OUString sEncryptionDataElement( ELEMENT_ENCRYPTION_DATA );
+ const OUString sAlgorithmElement ( ELEMENT_ALGORITHM );
+ const OUString sStartKeyGenerationElement ( ELEMENT_START_KEY_GENERATION );
+ const OUString sKeyDerivationElement ( ELEMENT_KEY_DERIVATION );
+
+ const OUString sCdataAttribute ( ATTRIBUTE_CDATA );
+ const OUString sMediaTypeAttribute ( ATTRIBUTE_MEDIA_TYPE );
+ const OUString sVersionAttribute ( ATTRIBUTE_VERSION );
+ const OUString sFullPathAttribute ( ATTRIBUTE_FULL_PATH );
+ const OUString sSizeAttribute ( ATTRIBUTE_SIZE );
+ const OUString sKeySizeAttribute ( ATTRIBUTE_KEY_SIZE );
+ const OUString sSaltAttribute ( ATTRIBUTE_SALT );
+ const OUString sInitialisationVectorAttribute ( ATTRIBUTE_INITIALISATION_VECTOR );
+ const OUString sIterationCountAttribute ( ATTRIBUTE_ITERATION_COUNT );
+ const OUString sAlgorithmNameAttribute ( ATTRIBUTE_ALGORITHM_NAME );
+ const OUString sStartKeyGenerationNameAttribute ( ATTRIBUTE_START_KEY_GENERATION_NAME );
+ const OUString sKeyDerivationNameAttribute ( ATTRIBUTE_KEY_DERIVATION_NAME );
+ const OUString sChecksumTypeAttribute ( ATTRIBUTE_CHECKSUM_TYPE );
+ const OUString sChecksumAttribute ( ATTRIBUTE_CHECKSUM);
+
+ const OUString sKeyInfoElement ( ELEMENT_ENCRYPTED_KEYINFO );
+ const OUString sManifestKeyInfoElement ( ELEMENT_MANIFEST_KEYINFO );
+ const OUString sEncryptedKeyElement ( ELEMENT_ENCRYPTEDKEY );
+ const OUString sEncryptionMethodElement ( ELEMENT_ENCRYPTIONMETHOD );
+ const OUString sPgpDataElement ( ELEMENT_PGPDATA );
+ const OUString sPgpKeyIDElement ( ELEMENT_PGPKEYID );
+ const OUString sPGPKeyPacketElement ( ELEMENT_PGPKEYPACKET );
+ const OUString sAlgorithmAttribute ( ATTRIBUTE_ALGORITHM );
+ const OUString sCipherDataElement ( ELEMENT_CIPHERDATA );
+ const OUString sCipherValueElement ( ELEMENT_CIPHERVALUE );
+ const OUString sManifestKeyInfoElement13 ( ELEMENT_MANIFEST13_KEYINFO );
+ const OUString sEncryptedKeyElement13 ( ELEMENT_ENCRYPTEDKEY13 );
+ const OUString sEncryptionMethodElement13 ( ELEMENT_ENCRYPTIONMETHOD13 );
+ const OUString sPgpDataElement13 ( ELEMENT_PGPDATA13 );
+ const OUString sPgpKeyIDElement13 ( ELEMENT_PGPKEYID13 );
+ const OUString sPGPKeyPacketElement13 ( ELEMENT_PGPKEYPACKET13 );
+ const OUString sAlgorithmAttribute13 ( ATTRIBUTE_ALGORITHM13 );
+ const OUString sCipherDataElement13 ( ELEMENT_CIPHERDATA13 );
+ const OUString sCipherValueElement13 ( ELEMENT_CIPHERVALUE13 );
+ const OUString sKeyInfo ( "KeyInfo" );
+ const OUString sPgpKeyIDProperty ( "KeyId" );
+ const OUString sPgpKeyPacketProperty ( "KeyPacket" );
+ const OUString sCipherValueProperty ( "CipherValue" );
+ const OUString sFullPathProperty ( "FullPath" );
+ const OUString sVersionProperty ( "Version" );
+ const OUString sMediaTypeProperty ( "MediaType" );
+ const OUString sIterationCountProperty ( "IterationCount" );
+ const OUString sDerivedKeySizeProperty ( "DerivedKeySize" );
+ const OUString sSaltProperty ( "Salt" );
+ const OUString sInitialisationVectorProperty( "InitialisationVector" );
+ const OUString sSizeProperty ( "Size" );
+ const OUString sDigestProperty ( "Digest" );
+ const OUString sEncryptionAlgProperty ( "EncryptionAlgorithm" );
+ const OUString sStartKeyAlgProperty ( "StartKeyAlgorithm" );
+ const OUString sDigestAlgProperty ( "DigestAlgorithm" );
+
+ const OUString sWhiteSpace ( " " );
+
+ const OUString sSHA256_URL_ODF12 ( SHA256_URL_ODF12 );
+ const OUString sSHA1_Name ( SHA1_NAME );
+
+ const OUString sSHA1_1k_Name ( SHA1_1K_NAME );
+ const OUString sSHA256_1k_URL ( SHA256_1K_URL );
+
+ const OUString sBlowfish_Name ( BLOWFISH_NAME );
+ const OUString sAES256_URL ( AES256_URL );
+
+ const OUString sPBKDF2_Name ( PBKDF2_NAME );
+ const OUString sPGP_Name ( PGP_NAME );
+
+ ::comphelper::AttributeList * pRootAttrList = new ::comphelper::AttributeList;
+
+ // find the mediatype of the document if any
+ OUString aDocMediaType;
+ OUString aDocVersion;
+ const uno::Sequence<beans::PropertyValue>* pRootFolderPropSeq = nullptr;
+ for (const uno::Sequence < beans::PropertyValue >& rSequence : rManList)
+ {
+ OUString aMediaType;
+ OUString aPath;
+ OUString aVersion;
+
+ for (const beans::PropertyValue& rValue : rSequence)
+ {
+ if (rValue.Name == sMediaTypeProperty )
+ {
+ rValue.Value >>= aMediaType;
+ }
+ else if (rValue.Name == sFullPathProperty )
+ {
+ rValue.Value >>= aPath;
+ }
+ else if (rValue.Name == sVersionProperty )
+ {
+ rValue.Value >>= aVersion;
+ }
+
+ if ( !aPath.isEmpty() && !aMediaType.isEmpty() && !aVersion.isEmpty() )
+ break;
+ }
+
+ if ( aPath == "/" )
+ {
+ aDocMediaType = aMediaType;
+ aDocVersion = aVersion;
+ pRootFolderPropSeq = &rSequence;
+ break;
+ }
+ }
+
+ bool bProvideDTD = false;
+ bool bAcceptNonemptyVersion = false;
+ bool bStoreStartKeyGeneration = false;
+ if ( !aDocMediaType.isEmpty() )
+ {
+ if ( aDocMediaType == MIMETYPE_OASIS_OPENDOCUMENT_TEXT_ASCII
+ || aDocMediaType == MIMETYPE_OASIS_OPENDOCUMENT_TEXT_WEB_ASCII
+ || aDocMediaType == MIMETYPE_OASIS_OPENDOCUMENT_TEXT_GLOBAL_ASCII
+ || aDocMediaType == MIMETYPE_OASIS_OPENDOCUMENT_DRAWING_ASCII
+ || aDocMediaType == MIMETYPE_OASIS_OPENDOCUMENT_PRESENTATION_ASCII
+ || aDocMediaType == MIMETYPE_OASIS_OPENDOCUMENT_SPREADSHEET_ASCII
+ || aDocMediaType == MIMETYPE_OASIS_OPENDOCUMENT_CHART_ASCII
+ || aDocMediaType == MIMETYPE_OASIS_OPENDOCUMENT_DATABASE_ASCII
+ || aDocMediaType == MIMETYPE_OASIS_OPENDOCUMENT_FORMULA_ASCII
+ || aDocMediaType == MIMETYPE_OASIS_OPENDOCUMENT_TEXT_TEMPLATE_ASCII
+ || aDocMediaType == MIMETYPE_OASIS_OPENDOCUMENT_TEXT_GLOBAL_TEMPLATE_ASCII
+ || aDocMediaType == MIMETYPE_OASIS_OPENDOCUMENT_DRAWING_TEMPLATE_ASCII
+ || aDocMediaType == MIMETYPE_OASIS_OPENDOCUMENT_PRESENTATION_TEMPLATE_ASCII
+ || aDocMediaType == MIMETYPE_OASIS_OPENDOCUMENT_SPREADSHEET_TEMPLATE_ASCII
+ || aDocMediaType == MIMETYPE_OASIS_OPENDOCUMENT_CHART_TEMPLATE_ASCII
+ || aDocMediaType == MIMETYPE_OASIS_OPENDOCUMENT_FORMULA_TEMPLATE_ASCII )
+
+ {
+ // oasis format
+ pRootAttrList->AddAttribute ( ATTRIBUTE_XMLNS,
+ sCdataAttribute,
+ MANIFEST_OASIS_NAMESPACE );
+ bAcceptNonemptyVersion = true;
+ if ( aDocVersion.compareTo( ODFVER_012_TEXT ) >= 0 )
+ {
+ // this is ODF12 or later generation, let encrypted
+ // streams contain start-key-generation entry
+ bStoreStartKeyGeneration = true;
+ pRootAttrList->AddAttribute ( sVersionAttribute, sCdataAttribute, aDocVersion );
+ // plus gpg4libre extensions - loext NS for that
+ pRootAttrList->AddAttribute ( ATTRIBUTE_XMLNS_LOEXT,
+ sCdataAttribute,
+ MANIFEST_LOEXT_NAMESPACE );
+ }
+ }
+ else
+ {
+ // even if it is no SO6 format the namespace must be specified
+ // thus SO6 format is used as default one
+ pRootAttrList->AddAttribute ( ATTRIBUTE_XMLNS,
+ sCdataAttribute,
+ MANIFEST_NAMESPACE );
+
+ bProvideDTD = true;
+ }
+ }
+
+ uno::Reference < xml::sax::XAttributeList > xRootAttrList (pRootAttrList);
+
+ xHandler->startDocument();
+ uno::Reference < xml::sax::XExtendedDocumentHandler > xExtHandler ( xHandler, uno::UNO_QUERY );
+ if ( xExtHandler.is() && bProvideDTD )
+ {
+ xExtHandler->unknown ( MANIFEST_DOCTYPE );
+ xHandler->ignorableWhitespace ( sWhiteSpace );
+ }
+ xHandler->startElement( sManifestElement, xRootAttrList );
+
+ const uno::Any *pKeyInfoProperty = nullptr;
+ if ( pRootFolderPropSeq )
+ {
+ // do we have package-wide encryption info?
+ for (const beans::PropertyValue& rValue : *pRootFolderPropSeq)
+ {
+ if (rValue.Name == sKeyInfo )
+ pKeyInfoProperty = &rValue.Value;
+ }
+
+ if ( pKeyInfoProperty )
+ {
+ // yeah, so that goes directly below the manifest:manifest
+ // element
+ OUStringBuffer aBuffer;
+
+ xHandler->ignorableWhitespace ( sWhiteSpace );
+
+ // ==== manifest:keyinfo & children
+ bool const isODF13(aDocVersion.compareTo(ODFVER_013_TEXT) >= 0);
+ if (!isODF13)
+ {
+ xHandler->startElement(sManifestKeyInfoElement, nullptr);
+ }
+ xHandler->ignorableWhitespace ( sWhiteSpace );
+
+ uno::Sequence< uno::Sequence < beans::NamedValue > > aKeyInfoSequence;
+ *pKeyInfoProperty >>= aKeyInfoSequence;
+ for (const uno::Sequence<beans::NamedValue>& rKeyInfoSequence : std::as_const(aKeyInfoSequence))
+ {
+ uno::Sequence < sal_Int8 > aPgpKeyID;
+ uno::Sequence < sal_Int8 > aPgpKeyPacket;
+ uno::Sequence < sal_Int8 > aCipherValue;
+ for (const beans::NamedValue& rNValue : rKeyInfoSequence)
+ {
+ if (rNValue.Name == sPgpKeyIDProperty )
+ rNValue.Value >>= aPgpKeyID;
+ else if (rNValue.Name == sPgpKeyPacketProperty )
+ rNValue.Value >>= aPgpKeyPacket;
+ else if (rNValue.Name == sCipherValueProperty )
+ rNValue.Value >>= aCipherValue;
+ }
+
+ if (aPgpKeyID.hasElements() && aCipherValue.hasElements() )
+ {
+ // ==== manifest:encrypted-key & children - one for each recipient
+ xHandler->startElement(isODF13 ? sEncryptedKeyElement13 : sEncryptedKeyElement, nullptr);
+ xHandler->ignorableWhitespace ( sWhiteSpace );
+
+ ::comphelper::AttributeList * pNewAttrList = new ::comphelper::AttributeList;
+ uno::Reference < xml::sax::XAttributeList > xNewAttrList (pNewAttrList);
+ // TODO: the algorithm should rather be configurable
+ pNewAttrList->AddAttribute(
+ isODF13 ? sAlgorithmAttribute13 : sAlgorithmAttribute,
+ sCdataAttribute,
+ "http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p" );
+ xHandler->startElement(isODF13 ? sEncryptionMethodElement13 : sEncryptionMethodElement, xNewAttrList);
+ xHandler->endElement(isODF13 ? sEncryptionMethodElement13 : sEncryptionMethodElement);
+ xHandler->ignorableWhitespace ( sWhiteSpace );
+
+ // note: the mismatch here corresponds to ODF 1.3 cs01 schema
+ xHandler->startElement(isODF13 ? sManifestKeyInfoElement13 : sKeyInfoElement, nullptr);
+ xHandler->ignorableWhitespace ( sWhiteSpace );
+
+ xHandler->startElement(isODF13 ? sPgpDataElement13 : sPgpDataElement, nullptr);
+ xHandler->ignorableWhitespace ( sWhiteSpace );
+
+ xHandler->startElement(isODF13 ? sPgpKeyIDElement13 : sPgpKeyIDElement, nullptr);
+ ::comphelper::Base64::encode(aBuffer, aPgpKeyID);
+ xHandler->characters( aBuffer.makeStringAndClear() );
+ xHandler->endElement(isODF13 ? sPgpKeyIDElement13 : sPgpKeyIDElement);
+ xHandler->ignorableWhitespace ( sWhiteSpace );
+
+ // key packet is optional
+ if (aPgpKeyPacket.hasElements())
+ {
+ xHandler->startElement(isODF13 ? sPGPKeyPacketElement13 : sPGPKeyPacketElement, nullptr);
+ ::comphelper::Base64::encode(aBuffer, aPgpKeyPacket);
+ xHandler->characters( aBuffer.makeStringAndClear() );
+ xHandler->endElement(isODF13 ? sPGPKeyPacketElement13 : sPGPKeyPacketElement);
+ xHandler->ignorableWhitespace ( sWhiteSpace );
+ }
+
+ xHandler->endElement(isODF13 ? sPgpDataElement13 : sPgpDataElement);
+ xHandler->ignorableWhitespace ( sWhiteSpace );
+
+ xHandler->endElement(isODF13 ? sManifestKeyInfoElement13 : sKeyInfoElement);
+ xHandler->ignorableWhitespace ( sWhiteSpace );
+
+ xHandler->startElement(isODF13 ? sCipherDataElement13 : sCipherDataElement, nullptr);
+ xHandler->ignorableWhitespace ( sWhiteSpace );
+
+ xHandler->startElement(isODF13 ? sCipherValueElement13 : sCipherValueElement, nullptr);
+ ::comphelper::Base64::encode(aBuffer, aCipherValue);
+ xHandler->characters( aBuffer.makeStringAndClear() );
+ xHandler->endElement(isODF13 ? sCipherValueElement13 : sCipherValueElement);
+ xHandler->ignorableWhitespace ( sWhiteSpace );
+
+ xHandler->endElement(isODF13 ? sCipherDataElement13 : sCipherDataElement);
+ xHandler->ignorableWhitespace ( sWhiteSpace );
+
+ xHandler->endElement(isODF13 ? sEncryptedKeyElement13 : sEncryptedKeyElement);
+ xHandler->ignorableWhitespace ( sWhiteSpace );
+ }
+ }
+
+ if (!isODF13)
+ {
+ xHandler->endElement(sManifestKeyInfoElement);
+ }
+ xHandler->ignorableWhitespace ( sWhiteSpace );
+ }
+ }
+
+ // now write individual file entries
+ for (const uno::Sequence<beans::PropertyValue>& rSequence : rManList)
+ {
+ ::comphelper::AttributeList *pAttrList = new ::comphelper::AttributeList;
+ OUString aString;
+ const uno::Any *pVector = nullptr, *pSalt = nullptr, *pIterationCount = nullptr, *pDigest = nullptr, *pDigestAlg = nullptr, *pEncryptAlg = nullptr, *pStartKeyAlg = nullptr, *pDerivedKeySize = nullptr;
+ for (const beans::PropertyValue& rValue : rSequence)
+ {
+ if (rValue.Name == sMediaTypeProperty )
+ {
+ rValue.Value >>= aString;
+ pAttrList->AddAttribute ( sMediaTypeAttribute, sCdataAttribute, aString );
+ }
+ else if (rValue.Name == sVersionProperty )
+ {
+ rValue.Value >>= aString;
+ // the version is stored only if it is not empty
+ if ( bAcceptNonemptyVersion && !aString.isEmpty() )
+ pAttrList->AddAttribute ( sVersionAttribute, sCdataAttribute, aString );
+ }
+ else if (rValue.Name == sFullPathProperty )
+ {
+ rValue.Value >>= aString;
+ pAttrList->AddAttribute ( sFullPathAttribute, sCdataAttribute, aString );
+ }
+ else if (rValue.Name == sSizeProperty )
+ {
+ sal_Int64 nSize = 0;
+ rValue.Value >>= nSize;
+ pAttrList->AddAttribute ( sSizeAttribute, sCdataAttribute, OUString::number( nSize ) );
+ }
+ else if (rValue.Name == sInitialisationVectorProperty )
+ pVector = &rValue.Value;
+ else if (rValue.Name == sSaltProperty )
+ pSalt = &rValue.Value;
+ else if (rValue.Name == sIterationCountProperty )
+ pIterationCount = &rValue.Value;
+ else if (rValue.Name == sDigestProperty )
+ pDigest = &rValue.Value;
+ else if (rValue.Name == sDigestAlgProperty )
+ pDigestAlg = &rValue.Value;
+ else if (rValue.Name == sEncryptionAlgProperty )
+ pEncryptAlg = &rValue.Value;
+ else if (rValue.Name == sStartKeyAlgProperty )
+ pStartKeyAlg = &rValue.Value;
+ else if (rValue.Name == sDerivedKeySizeProperty )
+ pDerivedKeySize = &rValue.Value;
+ }
+
+ xHandler->ignorableWhitespace ( sWhiteSpace );
+ uno::Reference < xml::sax::XAttributeList > xAttrList ( pAttrList );
+ xHandler->startElement( sFileEntryElement , xAttrList);
+ if ( pVector && pSalt && pIterationCount && pDigest && pDigestAlg && pEncryptAlg && pStartKeyAlg && pDerivedKeySize )
+ {
+ // ==== Encryption Data
+ ::comphelper::AttributeList * pNewAttrList = new ::comphelper::AttributeList;
+ uno::Reference < xml::sax::XAttributeList > xNewAttrList (pNewAttrList);
+ OUStringBuffer aBuffer;
+ uno::Sequence < sal_Int8 > aSequence;
+
+ xHandler->ignorableWhitespace ( sWhiteSpace );
+
+ // ==== Digest
+ OUString sChecksumType;
+ sal_Int32 nDigestAlgID = 0;
+ *pDigestAlg >>= nDigestAlgID;
+ if ( nDigestAlgID == xml::crypto::DigestID::SHA256_1K )
+ sChecksumType = sSHA256_1k_URL;
+ else if ( nDigestAlgID == xml::crypto::DigestID::SHA1_1K )
+ sChecksumType = sSHA1_1k_Name;
+ else
+ throw uno::RuntimeException( THROW_WHERE "Unexpected digest algorithm is provided!" );
+
+ pNewAttrList->AddAttribute ( sChecksumTypeAttribute, sCdataAttribute, sChecksumType );
+ *pDigest >>= aSequence;
+ ::comphelper::Base64::encode(aBuffer, aSequence);
+ pNewAttrList->AddAttribute ( sChecksumAttribute, sCdataAttribute, aBuffer.makeStringAndClear() );
+
+ xHandler->startElement( sEncryptionDataElement , xNewAttrList);
+
+ // ==== Algorithm
+ pNewAttrList = new ::comphelper::AttributeList;
+ xNewAttrList = pNewAttrList;
+
+ sal_Int32 nEncAlgID = 0;
+ sal_Int32 nDerivedKeySize = 0;
+ *pEncryptAlg >>= nEncAlgID;
+ *pDerivedKeySize >>= nDerivedKeySize;
+
+ OUString sEncAlgName;
+ if ( nEncAlgID == xml::crypto::CipherID::AES_CBC_W3C_PADDING )
+ {
+ OSL_ENSURE( nDerivedKeySize, "Unexpected key size is provided!" );
+ if ( nDerivedKeySize != 32 )
+ throw uno::RuntimeException( THROW_WHERE "Unexpected key size is provided!" );
+
+ sEncAlgName = sAES256_URL;
+ }
+ else if ( nEncAlgID == xml::crypto::CipherID::BLOWFISH_CFB_8 )
+ {
+ sEncAlgName = sBlowfish_Name;
+ }
+ else
+ throw uno::RuntimeException( THROW_WHERE "Unexpected encryption algorithm is provided!" );
+
+ pNewAttrList->AddAttribute ( sAlgorithmNameAttribute, sCdataAttribute, sEncAlgName );
+
+ *pVector >>= aSequence;
+ ::comphelper::Base64::encode(aBuffer, aSequence);
+ pNewAttrList->AddAttribute ( sInitialisationVectorAttribute, sCdataAttribute, aBuffer.makeStringAndClear() );
+
+ xHandler->ignorableWhitespace ( sWhiteSpace );
+ xHandler->startElement( sAlgorithmElement , xNewAttrList);
+ xHandler->ignorableWhitespace ( sWhiteSpace );
+ xHandler->endElement( sAlgorithmElement );
+
+ if ( bStoreStartKeyGeneration )
+ {
+ // ==== Start Key Generation
+ pNewAttrList = new ::comphelper::AttributeList;
+ xNewAttrList = pNewAttrList;
+
+ OUString sStartKeyAlg;
+ OUString sStartKeySize;
+ sal_Int32 nStartKeyAlgID = 0;
+ *pStartKeyAlg >>= nStartKeyAlgID;
+ if ( nStartKeyAlgID == xml::crypto::DigestID::SHA256 )
+ {
+ sStartKeyAlg = sSHA256_URL_ODF12; // TODO use SHA256_URL
+ aBuffer.append( sal_Int32(32) );
+ sStartKeySize = aBuffer.makeStringAndClear();
+ }
+ else if ( nStartKeyAlgID == xml::crypto::DigestID::SHA1 )
+ {
+ sStartKeyAlg = sSHA1_Name;
+ aBuffer.append( sal_Int32(20) );
+ sStartKeySize = aBuffer.makeStringAndClear();
+ }
+ else
+ throw uno::RuntimeException( THROW_WHERE "Unexpected start key algorithm is provided!" );
+
+ pNewAttrList->AddAttribute ( sStartKeyGenerationNameAttribute, sCdataAttribute, sStartKeyAlg );
+ pNewAttrList->AddAttribute ( sKeySizeAttribute, sCdataAttribute, sStartKeySize );
+
+ xHandler->ignorableWhitespace ( sWhiteSpace );
+ xHandler->startElement( sStartKeyGenerationElement , xNewAttrList);
+ xHandler->ignorableWhitespace ( sWhiteSpace );
+ xHandler->endElement( sStartKeyGenerationElement );
+ }
+
+ // ==== Key Derivation
+ pNewAttrList = new ::comphelper::AttributeList;
+ xNewAttrList = pNewAttrList;
+
+ if (pKeyInfoProperty)
+ {
+ pNewAttrList->AddAttribute(sKeyDerivationNameAttribute,
+ sCdataAttribute,
+ sPGP_Name);
+ // no start-key-generation needed, our session key has
+ // max size already
+ bStoreStartKeyGeneration = false;
+ }
+ else
+ {
+ pNewAttrList->AddAttribute(sKeyDerivationNameAttribute,
+ sCdataAttribute,
+ sPBKDF2_Name);
+
+ if (bStoreStartKeyGeneration)
+ {
+ aBuffer.append(nDerivedKeySize);
+ pNewAttrList->AddAttribute(sKeySizeAttribute, sCdataAttribute, aBuffer.makeStringAndClear());
+ }
+
+ sal_Int32 nCount = 0;
+ *pIterationCount >>= nCount;
+ aBuffer.append(nCount);
+ pNewAttrList->AddAttribute(sIterationCountAttribute, sCdataAttribute, aBuffer.makeStringAndClear());
+
+ *pSalt >>= aSequence;
+ ::comphelper::Base64::encode(aBuffer, aSequence);
+ pNewAttrList->AddAttribute(sSaltAttribute, sCdataAttribute, aBuffer.makeStringAndClear());
+ }
+
+ xHandler->ignorableWhitespace(sWhiteSpace);
+ xHandler->startElement(sKeyDerivationElement, xNewAttrList);
+ xHandler->ignorableWhitespace(sWhiteSpace);
+ xHandler->endElement(sKeyDerivationElement);
+
+ xHandler->ignorableWhitespace ( sWhiteSpace );
+ xHandler->endElement( sEncryptionDataElement );
+ }
+ xHandler->ignorableWhitespace ( sWhiteSpace );
+ xHandler->endElement( sFileEntryElement );
+ }
+ xHandler->ignorableWhitespace ( sWhiteSpace );
+ xHandler->endElement( sManifestElement );
+ xHandler->endDocument();
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/package/source/manifest/ManifestExport.hxx b/package/source/manifest/ManifestExport.hxx
new file mode 100644
index 000000000..f7fbff66b
--- /dev/null
+++ b/package/source/manifest/ManifestExport.hxx
@@ -0,0 +1,39 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_PACKAGE_SOURCE_MANIFEST_MANIFESTEXPORT_HXX
+#define INCLUDED_PACKAGE_SOURCE_MANIFEST_MANIFESTEXPORT_HXX
+
+#include <com/sun/star/uno/Sequence.h>
+#include <com/sun/star/uno/Reference.h>
+#include <rtl/ustring.hxx>
+
+namespace com::sun::star {
+ namespace beans { struct PropertyValue;}
+ namespace xml::sax { class XDocumentHandler; }
+}
+class ManifestExport
+{
+public:
+ ManifestExport(css::uno::Reference < css::xml::sax::XDocumentHandler > const & xHandler, const css::uno::Sequence < css::uno::Sequence < css::beans::PropertyValue > > &rManList );
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/package/source/manifest/ManifestImport.cxx b/package/source/manifest/ManifestImport.cxx
new file mode 100644
index 000000000..cc7558f3b
--- /dev/null
+++ b/package/source/manifest/ManifestImport.cxx
@@ -0,0 +1,610 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include "ManifestImport.hxx"
+#include "ManifestDefines.hxx"
+#include <sax/tools/converter.hxx>
+#include <osl/diagnose.h>
+#include <com/sun/star/xml/sax/XAttributeList.hpp>
+#include <com/sun/star/xml/crypto/DigestID.hpp>
+#include <com/sun/star/xml/crypto/CipherID.hpp>
+#include <com/sun/star/beans/PropertyValue.hpp>
+#include <comphelper/base64.hxx>
+#include <comphelper/sequence.hxx>
+
+using namespace com::sun::star::uno;
+using namespace com::sun::star::beans;
+using namespace com::sun::star;
+using namespace std;
+
+
+static const OUStringLiteral gsFileEntryElement ( ELEMENT_FILE_ENTRY );
+static const OUStringLiteral gsEncryptionDataElement( ELEMENT_ENCRYPTION_DATA );
+static const OUStringLiteral gsAlgorithmElement ( ELEMENT_ALGORITHM );
+static const OUStringLiteral gsStartKeyAlgElement ( ELEMENT_START_KEY_GENERATION );
+static const OUStringLiteral gsKeyDerivationElement( ELEMENT_KEY_DERIVATION );
+
+static const OUStringLiteral gsMediaTypeAttribute ( ATTRIBUTE_MEDIA_TYPE );
+static const OUStringLiteral gsVersionAttribute ( ATTRIBUTE_VERSION );
+static const OUStringLiteral gsFullPathAttribute ( ATTRIBUTE_FULL_PATH );
+static const OUStringLiteral gsSizeAttribute ( ATTRIBUTE_SIZE );
+static const OUStringLiteral gsSaltAttribute ( ATTRIBUTE_SALT );
+static const OUStringLiteral gsInitialisationVectorAttribute ( ATTRIBUTE_INITIALISATION_VECTOR );
+static const OUStringLiteral gsIterationCountAttribute ( ATTRIBUTE_ITERATION_COUNT );
+static const OUStringLiteral gsKeySizeAttribute ( ATTRIBUTE_KEY_SIZE );
+static const OUStringLiteral gsAlgorithmNameAttribute ( ATTRIBUTE_ALGORITHM_NAME );
+static const OUStringLiteral gsStartKeyAlgNameAttribute ( ATTRIBUTE_START_KEY_GENERATION_NAME );
+static const OUStringLiteral gsKeyDerivationNameAttribute ( ATTRIBUTE_KEY_DERIVATION_NAME );
+static const OUStringLiteral gsChecksumAttribute ( ATTRIBUTE_CHECKSUM );
+static const OUStringLiteral gsChecksumTypeAttribute ( ATTRIBUTE_CHECKSUM_TYPE );
+
+static const OUStringLiteral gsKeyInfoElement ( ELEMENT_ENCRYPTED_KEYINFO );
+static const OUStringLiteral gsManifestKeyInfoElement ( ELEMENT_MANIFEST_KEYINFO );
+static const OUStringLiteral gsEncryptedKeyElement ( ELEMENT_ENCRYPTEDKEY );
+static const OUStringLiteral gsEncryptionMethodElement ( ELEMENT_ENCRYPTIONMETHOD );
+static const OUStringLiteral gsPgpDataElement ( ELEMENT_PGPDATA );
+static const OUStringLiteral gsPgpKeyIDElement ( ELEMENT_PGPKEYID );
+static const OUStringLiteral gsPGPKeyPacketElement ( ELEMENT_PGPKEYPACKET );
+static const OUStringLiteral gsAlgorithmAttribute ( ATTRIBUTE_ALGORITHM );
+static const OUStringLiteral gsCipherDataElement ( ELEMENT_CIPHERDATA );
+static const OUStringLiteral gsCipherValueElement ( ELEMENT_CIPHERVALUE );
+
+static const OUStringLiteral gsManifestKeyInfoElement13 ( ELEMENT_MANIFEST13_KEYINFO );
+static const OUStringLiteral gsEncryptedKeyElement13 ( ELEMENT_ENCRYPTEDKEY13 );
+static const OUStringLiteral gsEncryptionMethodElement13 ( ELEMENT_ENCRYPTIONMETHOD13 );
+static const OUStringLiteral gsPgpDataElement13 ( ELEMENT_PGPDATA13 );
+static const OUStringLiteral gsPgpKeyIDElement13 ( ELEMENT_PGPKEYID13 );
+static const OUStringLiteral gsPGPKeyPacketElement13 ( ELEMENT_PGPKEYPACKET13 );
+static const OUStringLiteral gsAlgorithmAttribute13 ( ATTRIBUTE_ALGORITHM13 );
+static const OUStringLiteral gsCipherDataElement13 ( ELEMENT_CIPHERDATA13 );
+static const OUStringLiteral gsCipherValueElement13 ( ELEMENT_CIPHERVALUE13 );
+
+static const OUStringLiteral gsFullPathProperty ( "FullPath" );
+static const OUStringLiteral gsMediaTypeProperty ( "MediaType" );
+static const OUStringLiteral gsVersionProperty ( "Version" );
+static const OUStringLiteral gsIterationCountProperty ( "IterationCount" );
+static const OUStringLiteral gsDerivedKeySizeProperty ( "DerivedKeySize" );
+static const OUStringLiteral gsSaltProperty ( "Salt" );
+static const OUStringLiteral gsInitialisationVectorProperty ( "InitialisationVector" );
+static const OUStringLiteral gsSizeProperty ( "Size" );
+static const OUStringLiteral gsDigestProperty ( "Digest" );
+static const OUStringLiteral gsEncryptionAlgProperty ( "EncryptionAlgorithm" );
+static const OUStringLiteral gsStartKeyAlgProperty ( "StartKeyAlgorithm" );
+static const OUStringLiteral gsDigestAlgProperty ( "DigestAlgorithm" );
+
+static const OUStringLiteral gsSHA256_URL_ODF12 ( SHA256_URL_ODF12 );
+static const OUStringLiteral gsSHA256_URL ( SHA256_URL );
+static const OUStringLiteral gsSHA1_Name ( SHA1_NAME );
+static const OUStringLiteral gsSHA1_URL ( SHA1_URL );
+
+static const OUStringLiteral gsSHA256_1k_URL ( SHA256_1K_URL );
+static const OUStringLiteral gsSHA1_1k_Name ( SHA1_1K_NAME );
+static const OUStringLiteral gsSHA1_1k_URL ( SHA1_1K_URL );
+
+static const OUStringLiteral gsBlowfish_Name ( BLOWFISH_NAME );
+static const OUStringLiteral gsBlowfish_URL ( BLOWFISH_URL );
+static const OUStringLiteral gsAES128_URL ( AES128_URL );
+static const OUStringLiteral gsAES192_URL ( AES192_URL );
+static const OUStringLiteral gsAES256_URL ( AES256_URL );
+
+static const OUStringLiteral gsPBKDF2_Name ( PBKDF2_NAME );
+static const OUStringLiteral gsPBKDF2_URL ( PBKDF2_URL );
+
+ManifestImport::ManifestImport( vector < Sequence < PropertyValue > > & rNewManVector )
+ : bIgnoreEncryptData ( false )
+ , bPgpEncryption ( false )
+ , nDerivedKeySize( 0 )
+ , rManVector ( rNewManVector )
+{
+ aStack.reserve( 10 );
+}
+
+ManifestImport::~ManifestImport()
+{
+}
+
+void SAL_CALL ManifestImport::startDocument( )
+{
+}
+
+void SAL_CALL ManifestImport::endDocument( )
+{
+}
+
+void ManifestImport::doFileEntry(StringHashMap &rConvertedAttribs)
+{
+ aSequence.resize(PKG_SIZE_ENCR_MNFST);
+
+ aSequence[PKG_MNFST_FULLPATH].Name = gsFullPathProperty;
+ aSequence[PKG_MNFST_FULLPATH].Value <<= rConvertedAttribs[gsFullPathAttribute];
+ aSequence[PKG_MNFST_MEDIATYPE].Name = gsMediaTypeProperty;
+ aSequence[PKG_MNFST_MEDIATYPE].Value <<= rConvertedAttribs[gsMediaTypeAttribute];
+
+ OUString sVersion = rConvertedAttribs[gsVersionAttribute];
+ if ( sVersion.getLength() ) {
+ aSequence[PKG_MNFST_VERSION].Name = gsVersionProperty;
+ aSequence[PKG_MNFST_VERSION].Value <<= sVersion;
+ }
+
+ OUString sSize = rConvertedAttribs[gsSizeAttribute];
+ if ( sSize.getLength() ) {
+ sal_Int64 nSize = sSize.toInt64();
+ aSequence[PKG_MNFST_UCOMPSIZE].Name = gsSizeProperty;
+ aSequence[PKG_MNFST_UCOMPSIZE].Value <<= nSize;
+ }
+}
+
+void ManifestImport::doEncryptedKey(StringHashMap &)
+{
+ aKeyInfoSequence.clear();
+ aKeyInfoSequence.resize(3);
+}
+
+void ManifestImport::doEncryptionMethod(StringHashMap &rConvertedAttribs,
+ const OUString& rAlgoAttrName)
+{
+ OUString aString = rConvertedAttribs[rAlgoAttrName];
+ if ( aKeyInfoSequence.size() != 3
+ || aString != "http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p" )
+ {
+ bIgnoreEncryptData = true;
+ }
+}
+
+void ManifestImport::doEncryptedCipherValue()
+{
+ if ( aKeyInfoSequence.size() == 3 )
+ {
+ aKeyInfoSequence[2].Name = "CipherValue";
+ uno::Sequence < sal_Int8 > aDecodeBuffer;
+ ::comphelper::Base64::decode(aDecodeBuffer, aCurrentCharacters.toString());
+ aKeyInfoSequence[2].Value <<= aDecodeBuffer;
+ aCurrentCharacters = ""; // consumed
+ }
+ else
+ bIgnoreEncryptData = true;
+}
+
+void ManifestImport::doEncryptedKeyId()
+{
+ if ( aKeyInfoSequence.size() == 3 )
+ {
+ aKeyInfoSequence[0].Name = "KeyId";
+ uno::Sequence < sal_Int8 > aDecodeBuffer;
+ ::comphelper::Base64::decode(aDecodeBuffer, aCurrentCharacters.toString());
+ aKeyInfoSequence[0].Value <<= aDecodeBuffer;
+ aCurrentCharacters = ""; // consumed
+ }
+ else
+ bIgnoreEncryptData = true;
+}
+
+void ManifestImport::doEncryptedKeyPacket()
+{
+ if ( aKeyInfoSequence.size() == 3 )
+ {
+ aKeyInfoSequence[1].Name = "KeyPacket";
+ uno::Sequence < sal_Int8 > aDecodeBuffer;
+ ::comphelper::Base64::decode(aDecodeBuffer, aCurrentCharacters.toString());
+ aKeyInfoSequence[1].Value <<= aDecodeBuffer;
+ aCurrentCharacters = ""; // consumed
+ }
+ else
+ bIgnoreEncryptData = true;
+}
+
+void ManifestImport::doEncryptionData(StringHashMap &rConvertedAttribs)
+{
+ // If this element exists, then this stream is encrypted and we need
+ // to import the initialisation vector, salt and iteration count used
+ nDerivedKeySize = 0;
+ OUString aString = rConvertedAttribs[gsChecksumTypeAttribute];
+ if ( bIgnoreEncryptData )
+ return;
+
+ if ( aString == gsSHA1_1k_Name || aString == gsSHA1_1k_URL ) {
+ aSequence[PKG_MNFST_DIGESTALG].Name = gsDigestAlgProperty;
+ aSequence[PKG_MNFST_DIGESTALG].Value <<= xml::crypto::DigestID::SHA1_1K;
+ } else if ( aString == gsSHA256_1k_URL ) {
+ aSequence[PKG_MNFST_DIGESTALG].Name = gsDigestAlgProperty;
+ aSequence[PKG_MNFST_DIGESTALG].Value <<= xml::crypto::DigestID::SHA256_1K;
+ } else
+ bIgnoreEncryptData = true;
+
+ if ( !bIgnoreEncryptData ) {
+ aString = rConvertedAttribs[gsChecksumAttribute];
+ uno::Sequence < sal_Int8 > aDecodeBuffer;
+ ::comphelper::Base64::decode(aDecodeBuffer, aString);
+ aSequence[PKG_MNFST_DIGEST].Name = gsDigestProperty;
+ aSequence[PKG_MNFST_DIGEST].Value <<= aDecodeBuffer;
+ }
+}
+
+void ManifestImport::doAlgorithm(StringHashMap &rConvertedAttribs)
+{
+ if ( bIgnoreEncryptData )
+ return;
+
+ OUString aString = rConvertedAttribs[gsAlgorithmNameAttribute];
+ if ( aString == gsBlowfish_Name || aString == gsBlowfish_URL ) {
+ aSequence[PKG_MNFST_ENCALG].Name = gsEncryptionAlgProperty;
+ aSequence[PKG_MNFST_ENCALG].Value <<= xml::crypto::CipherID::BLOWFISH_CFB_8;
+ } else if ( aString == gsAES256_URL ) {
+ aSequence[PKG_MNFST_ENCALG].Name = gsEncryptionAlgProperty;
+ aSequence[PKG_MNFST_ENCALG].Value <<= xml::crypto::CipherID::AES_CBC_W3C_PADDING;
+ OSL_ENSURE( !nDerivedKeySize || nDerivedKeySize == 32, "Unexpected derived key length!" );
+ nDerivedKeySize = 32;
+ } else if ( aString == gsAES192_URL ) {
+ aSequence[PKG_MNFST_ENCALG].Name = gsEncryptionAlgProperty;
+ aSequence[PKG_MNFST_ENCALG].Value <<= xml::crypto::CipherID::AES_CBC_W3C_PADDING;
+ OSL_ENSURE( !nDerivedKeySize || nDerivedKeySize == 24, "Unexpected derived key length!" );
+ nDerivedKeySize = 24;
+ } else if ( aString == gsAES128_URL ) {
+ aSequence[PKG_MNFST_ENCALG].Name = gsEncryptionAlgProperty;
+ aSequence[PKG_MNFST_ENCALG].Value <<= xml::crypto::CipherID::AES_CBC_W3C_PADDING;
+ OSL_ENSURE( !nDerivedKeySize || nDerivedKeySize == 16, "Unexpected derived key length!" );
+ nDerivedKeySize = 16;
+ } else
+ bIgnoreEncryptData = true;
+
+ if ( !bIgnoreEncryptData ) {
+ aString = rConvertedAttribs[gsInitialisationVectorAttribute];
+ uno::Sequence < sal_Int8 > aDecodeBuffer;
+ ::comphelper::Base64::decode(aDecodeBuffer, aString);
+ aSequence[PKG_MNFST_INIVECTOR].Name = gsInitialisationVectorProperty;
+ aSequence[PKG_MNFST_INIVECTOR].Value <<= aDecodeBuffer;
+ }
+}
+
+void ManifestImport::doKeyDerivation(StringHashMap &rConvertedAttribs)
+{
+ if ( bIgnoreEncryptData )
+ return;
+
+ OUString aString = rConvertedAttribs[gsKeyDerivationNameAttribute];
+ if ( aString == gsPBKDF2_Name || aString == gsPBKDF2_URL ) {
+ aString = rConvertedAttribs[gsSaltAttribute];
+ uno::Sequence < sal_Int8 > aDecodeBuffer;
+ ::comphelper::Base64::decode(aDecodeBuffer, aString);
+ aSequence[PKG_MNFST_SALT].Name = gsSaltProperty;
+ aSequence[PKG_MNFST_SALT].Value <<= aDecodeBuffer;
+
+ aString = rConvertedAttribs[gsIterationCountAttribute];
+ aSequence[PKG_MNFST_ITERATION].Name = gsIterationCountProperty;
+ aSequence[PKG_MNFST_ITERATION].Value <<= aString.toInt32();
+
+ aString = rConvertedAttribs[gsKeySizeAttribute];
+ if ( aString.getLength() ) {
+ sal_Int32 nKey = aString.toInt32();
+ OSL_ENSURE( !nDerivedKeySize || nKey == nDerivedKeySize , "Provided derived key length differs from the expected one!" );
+ nDerivedKeySize = nKey;
+ } else if ( !nDerivedKeySize )
+ nDerivedKeySize = 16;
+ else if ( nDerivedKeySize != 16 )
+ OSL_ENSURE( false, "Default derived key length differs from the expected one!" );
+
+ aSequence[PKG_MNFST_DERKEYSIZE].Name = gsDerivedKeySizeProperty;
+ aSequence[PKG_MNFST_DERKEYSIZE].Value <<= nDerivedKeySize;
+ } else if ( bPgpEncryption ) {
+ if ( aString != "PGP" )
+ bIgnoreEncryptData = true;
+ } else
+ bIgnoreEncryptData = true;
+}
+
+void ManifestImport::doStartKeyAlg(StringHashMap &rConvertedAttribs)
+{
+ OUString aString = rConvertedAttribs[gsStartKeyAlgNameAttribute];
+ if (aString == gsSHA256_URL || aString == gsSHA256_URL_ODF12) {
+ aSequence[PKG_MNFST_STARTALG].Name = gsStartKeyAlgProperty;
+ aSequence[PKG_MNFST_STARTALG].Value <<= xml::crypto::DigestID::SHA256;
+ } else if ( aString == gsSHA1_Name || aString == gsSHA1_URL ) {
+ aSequence[PKG_MNFST_STARTALG].Name = gsStartKeyAlgProperty;
+ aSequence[PKG_MNFST_STARTALG].Value <<= xml::crypto::DigestID::SHA1;
+ } else
+ bIgnoreEncryptData = true;
+}
+
+void SAL_CALL ManifestImport::startElement( const OUString& aName, const uno::Reference< xml::sax::XAttributeList >& xAttribs )
+{
+ StringHashMap aConvertedAttribs;
+ OUString aConvertedName = PushNameAndNamespaces( aName, xAttribs, aConvertedAttribs );
+
+ size_t nLevel = aStack.size();
+
+ assert(nLevel >= 1);
+
+ switch (nLevel) {
+ case 1: {
+ if (aConvertedName != ELEMENT_MANIFEST) //manifest:manifest
+ aStack.back().m_bValid = false;
+ break;
+ }
+ case 2: {
+ if (aConvertedName == gsFileEntryElement) //manifest:file-entry
+ doFileEntry(aConvertedAttribs);
+ else if (aConvertedName == gsManifestKeyInfoElement) //loext:keyinfo
+ ;
+ else if (aConvertedName == gsEncryptedKeyElement13) //manifest:encrypted-key
+ doEncryptedKey(aConvertedAttribs);
+ else
+ aStack.back().m_bValid = false;
+ break;
+ }
+ case 3: {
+ ManifestStack::reverse_iterator aIter = aStack.rbegin();
+ ++aIter;
+
+ if (!aIter->m_bValid)
+ aStack.back().m_bValid = false;
+ else if (aConvertedName == gsEncryptionDataElement) //manifest:encryption-data
+ doEncryptionData(aConvertedAttribs);
+ else if (aConvertedName == gsEncryptedKeyElement) //loext:encrypted-key
+ doEncryptedKey(aConvertedAttribs);
+ else if (aConvertedName == gsEncryptionMethodElement13) //manifest:encryption-method
+ doEncryptionMethod(aConvertedAttribs, gsAlgorithmAttribute13);
+ else if (aConvertedName == gsManifestKeyInfoElement13) //manifest:keyinfo
+ ;
+ else if (aConvertedName == gsCipherDataElement13) //manifest:CipherData
+ ;
+ else
+ aStack.back().m_bValid = false;
+ break;
+ }
+ case 4: {
+ ManifestStack::reverse_iterator aIter = aStack.rbegin();
+ ++aIter;
+
+ if (!aIter->m_bValid)
+ aStack.back().m_bValid = false;
+ else if (aConvertedName == gsAlgorithmElement) //manifest:algorithm,
+ doAlgorithm(aConvertedAttribs);
+ else if (aConvertedName == gsKeyDerivationElement) //manifest:key-derivation,
+ doKeyDerivation(aConvertedAttribs);
+ else if (aConvertedName == gsStartKeyAlgElement) //manifest:start-key-generation
+ doStartKeyAlg(aConvertedAttribs);
+ else if (aConvertedName == gsEncryptionMethodElement) //loext:encryption-method
+ doEncryptionMethod(aConvertedAttribs, gsAlgorithmAttribute);
+ else if (aConvertedName == gsKeyInfoElement) //loext:KeyInfo
+ ;
+ else if (aConvertedName == gsCipherDataElement) //loext:CipherData
+ ;
+ else if (aConvertedName == gsPgpDataElement13) //manifest:PGPData
+ ;
+ else if (aConvertedName == gsCipherValueElement13) //manifest:CipherValue
+ // ciphervalue action happens on endElement
+ aCurrentCharacters = "";
+ else
+ aStack.back().m_bValid = false;
+ break;
+ }
+ case 5: {
+ ManifestStack::reverse_iterator aIter = aStack.rbegin();
+ ++aIter;
+
+ if (!aIter->m_bValid)
+ aStack.back().m_bValid = false;
+ else if (aConvertedName == gsPgpDataElement) //loext:PGPData
+ ;
+ else if (aConvertedName == gsCipherValueElement) //loext:CipherValue
+ // ciphervalue action happens on endElement
+ aCurrentCharacters = "";
+ else if (aConvertedName == gsPgpKeyIDElement13) //manifest:PGPKeyID
+ // ciphervalue action happens on endElement
+ aCurrentCharacters = "";
+ else if (aConvertedName == gsPGPKeyPacketElement13) //manifest:PGPKeyPacket
+ // ciphervalue action happens on endElement
+ aCurrentCharacters = "";
+ else
+ aStack.back().m_bValid = false;
+ break;
+ }
+ case 6: {
+ ManifestStack::reverse_iterator aIter = aStack.rbegin();
+ ++aIter;
+
+ if (!aIter->m_bValid)
+ aStack.back().m_bValid = false;
+ else if (aConvertedName == gsPgpKeyIDElement) //loext:PGPKeyID
+ // ciphervalue action happens on endElement
+ aCurrentCharacters = "";
+ else if (aConvertedName == gsPGPKeyPacketElement) //loext:PGPKeyPacket
+ // ciphervalue action happens on endElement
+ aCurrentCharacters = "";
+ else
+ aStack.back().m_bValid = false;
+ break;
+ }
+ default:
+ aStack.back().m_bValid = false;
+ break;
+ }
+}
+
+namespace
+{
+bool isEmpty(const css::beans::PropertyValue &rProp)
+{
+ return rProp.Name.isEmpty();
+}
+}
+
+void SAL_CALL ManifestImport::endElement( const OUString& aName )
+{
+ size_t nLevel = aStack.size();
+
+ assert(nLevel >= 1);
+
+ OUString aConvertedName = ConvertName( aName );
+ if ( !(!aStack.empty() && aStack.rbegin()->m_aConvertedName == aConvertedName) ) return;
+
+ if ( aConvertedName == gsFileEntryElement && aStack.back().m_bValid ) {
+ // root folder gets KeyInfo entry if any, for PGP encryption
+ if (!bIgnoreEncryptData && !aKeys.empty() && aSequence[PKG_MNFST_FULLPATH].Value.get<OUString>() == "/" )
+ {
+ aSequence[PKG_SIZE_NOENCR_MNFST].Name = "KeyInfo";
+ aSequence[PKG_SIZE_NOENCR_MNFST].Value <<= comphelper::containerToSequence(aKeys);
+ }
+ aSequence.erase(std::remove_if(aSequence.begin(), aSequence.end(),
+ isEmpty), aSequence.end());
+
+ bIgnoreEncryptData = false;
+ rManVector.push_back ( comphelper::containerToSequence(aSequence) );
+
+ aSequence.clear();
+ }
+ else if ( (aConvertedName == gsEncryptedKeyElement
+ || aConvertedName == gsEncryptedKeyElement13)
+ && aStack.back().m_bValid ) {
+ if ( !bIgnoreEncryptData )
+ {
+ aKeys.push_back( comphelper::containerToSequence(aKeyInfoSequence) );
+ bPgpEncryption = true;
+ }
+ aKeyInfoSequence.clear();
+ }
+
+ // end element handling for elements with cdata
+ switch (nLevel) {
+ case 4: {
+ if (aConvertedName == gsCipherValueElement13) //manifest:CipherValue
+ doEncryptedCipherValue();
+ else
+ aStack.back().m_bValid = false;
+ break;
+ }
+ case 5: {
+ if (aConvertedName == gsCipherValueElement) //loext:CipherValue
+ doEncryptedCipherValue();
+ else if (aConvertedName == gsPgpKeyIDElement13) //manifest:PGPKeyID
+ doEncryptedKeyId();
+ else if (aConvertedName == gsPGPKeyPacketElement13) //manifest:PGPKeyPacket
+ doEncryptedKeyPacket();
+ else
+ aStack.back().m_bValid = false;
+ break;
+ }
+ case 6: {
+ if (aConvertedName == gsPgpKeyIDElement) //loext:PGPKeyID
+ doEncryptedKeyId();
+ else if (aConvertedName == gsPGPKeyPacketElement) //loext:PGPKeyPacket
+ doEncryptedKeyPacket();
+ else
+ aStack.back().m_bValid = false;
+ break;
+ }
+ }
+
+ aStack.pop_back();
+}
+
+void SAL_CALL ManifestImport::characters( const OUString& aChars )
+{
+ aCurrentCharacters.append(aChars);
+}
+
+void SAL_CALL ManifestImport::ignorableWhitespace( const OUString& /*aWhitespaces*/ )
+{
+}
+
+void SAL_CALL ManifestImport::processingInstruction( const OUString& /*aTarget*/, const OUString& /*aData*/ )
+{
+}
+
+void SAL_CALL ManifestImport::setDocumentLocator( const uno::Reference< xml::sax::XLocator >& /*xLocator*/ )
+{
+}
+
+OUString ManifestImport::PushNameAndNamespaces( const OUString& aName, const uno::Reference< xml::sax::XAttributeList >& xAttribs, StringHashMap& o_aConvertedAttribs )
+{
+ StringHashMap aNamespaces;
+ ::std::vector< ::std::pair< OUString, OUString > > aAttribsStrs;
+
+ if ( xAttribs.is() ) {
+ sal_Int16 nAttrCount = xAttribs.is() ? xAttribs->getLength() : 0;
+ aAttribsStrs.reserve( nAttrCount );
+
+ for( sal_Int16 nInd = 0; nInd < nAttrCount; nInd++ ) {
+ OUString aAttrName = xAttribs->getNameByIndex( nInd );
+ OUString aAttrValue = xAttribs->getValueByIndex( nInd );
+ if ( aAttrName.getLength() >= 5
+ && aAttrName.startsWith("xmlns")
+ && ( aAttrName.getLength() == 5 || aAttrName[5] == ':' ) ) {
+ // this is a namespace declaration
+ OUString aNsName( ( aAttrName.getLength() == 5 ) ? OUString() : aAttrName.copy( 6 ) );
+ aNamespaces[aNsName] = aAttrValue;
+ } else {
+ // this is no namespace declaration
+ aAttribsStrs.emplace_back( aAttrName, aAttrValue );
+ }
+ }
+ }
+
+ OUString aConvertedName = ConvertNameWithNamespace( aName, aNamespaces );
+ if ( !aConvertedName.getLength() )
+ aConvertedName = ConvertName( aName );
+
+ aStack.emplace_back( aConvertedName, aNamespaces );
+
+ for (const std::pair<OUString,OUString> & rAttribsStr : aAttribsStrs) {
+ // convert the attribute names on filling
+ o_aConvertedAttribs[ConvertName( rAttribsStr.first )] = rAttribsStr.second;
+ }
+
+ return aConvertedName;
+}
+
+OUString ManifestImport::ConvertNameWithNamespace( const OUString& aName, const StringHashMap& aNamespaces )
+{
+ OUString aNsAlias;
+ OUString aPureName = aName;
+
+ sal_Int32 nInd = aName.indexOf( ':' );
+ if ( nInd != -1 && nInd < aName.getLength() ) {
+ aNsAlias = aName.copy( 0, nInd );
+ aPureName = aName.copy( nInd + 1 );
+ }
+
+ OUString aResult;
+
+ StringHashMap::const_iterator aIter = aNamespaces.find( aNsAlias );
+ if ( aIter != aNamespaces.end()
+ && ( aIter->second == MANIFEST_NAMESPACE || aIter->second == MANIFEST_OASIS_NAMESPACE ) ) {
+ // no check for manifest.xml consistency currently since the old versions have supported inconsistent documents as well
+ aResult = MANIFEST_NSPREFIX + aPureName;
+ }
+
+ return aResult;
+}
+
+OUString ManifestImport::ConvertName( const OUString& aName )
+{
+ OUString aConvertedName;
+ for ( ManifestStack::reverse_iterator aIter = aStack.rbegin(); !aConvertedName.getLength() && aIter != aStack.rend(); ++aIter ) {
+ if ( !aIter->m_aNamespaces.empty() )
+ aConvertedName = ConvertNameWithNamespace( aName, aIter->m_aNamespaces );
+ }
+
+ if ( !aConvertedName.getLength() )
+ aConvertedName = aName;
+
+ return aConvertedName;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/package/source/manifest/ManifestImport.hxx b/package/source/manifest/ManifestImport.hxx
new file mode 100644
index 000000000..08ee251f6
--- /dev/null
+++ b/package/source/manifest/ManifestImport.hxx
@@ -0,0 +1,103 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_PACKAGE_SOURCE_MANIFEST_MANIFESTIMPORT_HXX
+#define INCLUDED_PACKAGE_SOURCE_MANIFEST_MANIFESTIMPORT_HXX
+
+#include <cppuhelper/implbase.hxx>
+#include <com/sun/star/xml/sax/XDocumentHandler.hpp>
+#include <com/sun/star/beans/NamedValue.hpp>
+#include <vector>
+#include <rtl/ustrbuf.hxx>
+
+#include <HashMaps.hxx>
+
+namespace com::sun::star {
+ namespace xml::sax { class XAttributeList; }
+ namespace beans { struct PropertyValue; }
+}
+
+typedef std::unordered_map< OUString, OUString > StringHashMap;
+
+struct ManifestScopeEntry
+{
+ OUString m_aConvertedName;
+ StringHashMap m_aNamespaces;
+ bool m_bValid;
+
+ ManifestScopeEntry( const OUString& aConvertedName, const StringHashMap& aNamespaces )
+ : m_aConvertedName( aConvertedName )
+ , m_aNamespaces( aNamespaces )
+ , m_bValid( true )
+ {}
+};
+
+typedef ::std::vector< ManifestScopeEntry > ManifestStack;
+
+class ManifestImport final : public cppu::WeakImplHelper < css::xml::sax::XDocumentHandler >
+{
+ std::vector< css::beans::NamedValue > aKeyInfoSequence;
+ std::vector< css::uno::Sequence< css::beans::NamedValue > > aKeys;
+ std::vector< css::beans::PropertyValue > aSequence;
+ OUStringBuffer aCurrentCharacters{64};
+ ManifestStack aStack;
+ bool bIgnoreEncryptData;
+ bool bPgpEncryption;
+ sal_Int32 nDerivedKeySize;
+ ::std::vector < css::uno::Sequence < css::beans::PropertyValue > > & rManVector;
+
+
+ OUString PushNameAndNamespaces( const OUString& aName,
+ const css::uno::Reference< css::xml::sax::XAttributeList >& xAttribs,
+ StringHashMap& o_aConvertedAttribs );
+ static OUString ConvertNameWithNamespace( const OUString& aName, const StringHashMap& aNamespaces );
+ OUString ConvertName( const OUString& aName );
+
+public:
+ ManifestImport( std::vector < css::uno::Sequence < css::beans::PropertyValue > > & rNewVector );
+ virtual ~ManifestImport() override;
+ virtual void SAL_CALL startDocument( ) override;
+ virtual void SAL_CALL endDocument( ) override;
+ virtual void SAL_CALL startElement( const OUString& aName, const css::uno::Reference< css::xml::sax::XAttributeList >& xAttribs ) override;
+ virtual void SAL_CALL endElement( const OUString& aName ) override;
+ virtual void SAL_CALL characters( const OUString& aChars ) override;
+ virtual void SAL_CALL ignorableWhitespace( const OUString& aWhitespaces ) override;
+ virtual void SAL_CALL processingInstruction( const OUString& aTarget, const OUString& aData ) override;
+ virtual void SAL_CALL setDocumentLocator( const css::uno::Reference< css::xml::sax::XLocator >& xLocator ) override;
+
+private:
+ /// @throws css::uno::RuntimeException
+ void doFileEntry(StringHashMap &rConvertedAttribs);
+ /// @throws css::uno::RuntimeException
+ void doEncryptionData(StringHashMap &rConvertedAttribs);
+ /// @throws css::uno::RuntimeException
+ void doAlgorithm(StringHashMap &rConvertedAttribs);
+ /// @throws css::uno::RuntimeException
+ void doKeyDerivation(StringHashMap &rConvertedAttribs);
+ /// @throws css::uno::RuntimeException
+ void doStartKeyAlg(StringHashMap &rConvertedAttribs);
+ void doEncryptedKey(StringHashMap &);
+ void doEncryptionMethod(StringHashMap &, const OUString &);
+ void doEncryptedCipherValue();
+ void doEncryptedKeyId();
+ void doEncryptedKeyPacket();
+};
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/package/source/manifest/ManifestReader.cxx b/package/source/manifest/ManifestReader.cxx
new file mode 100644
index 000000000..50fd851b3
--- /dev/null
+++ b/package/source/manifest/ManifestReader.cxx
@@ -0,0 +1,121 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include "ManifestReader.hxx"
+#include "ManifestImport.hxx"
+#include <sal/log.hxx>
+#include <tools/diagnose_ex.h>
+#include <comphelper/processfactory.hxx>
+#include <comphelper/sequence.hxx>
+#include <cppuhelper/factory.hxx>
+#include <cppuhelper/supportsservice.hxx>
+#include <com/sun/star/io/IOException.hpp>
+#include <com/sun/star/xml/sax/XDocumentHandler.hpp>
+#include <com/sun/star/xml/sax/SAXParseException.hpp>
+#include <com/sun/star/xml/sax/Parser.hpp>
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/lang/XSingleServiceFactory.hpp>
+#include <vector>
+
+using namespace ::std;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::beans;
+using namespace ::com::sun::star::io;
+using namespace ::com::sun::star::lang;
+using namespace ::com::sun::star::registry;
+using namespace ::com::sun::star::packages;
+using namespace ::com::sun::star::xml::sax;
+
+ManifestReader::ManifestReader( const Reference < XComponentContext > & xContext )
+: m_xContext ( xContext )
+{
+}
+ManifestReader::~ManifestReader()
+{
+}
+Sequence< Sequence< PropertyValue > > SAL_CALL ManifestReader::readManifestSequence( const Reference< XInputStream >& rStream )
+{
+ Sequence < Sequence < PropertyValue > > aManifestSequence;
+ Reference < XParser > xParser = Parser::create(m_xContext);
+ try
+ {
+ vector < Sequence < PropertyValue > > aManVector;
+ Reference < XDocumentHandler > xFilter = new ManifestImport( aManVector );
+ InputSource aParserInput;
+ aParserInput.aInputStream = rStream;
+ aParserInput.sSystemId = "META-INF/manifest.xml";
+ xParser->setDocumentHandler ( xFilter );
+ xParser->parseStream( aParserInput );
+ aManifestSequence = comphelper::containerToSequence(aManVector);
+ }
+ catch (const SAXParseException&)
+ {
+ TOOLS_WARN_EXCEPTION("package", "ignoring");
+ }
+ catch (const SAXException&)
+ {
+ TOOLS_WARN_EXCEPTION("package", "ignoring");
+ }
+ catch (const IOException&)
+ {
+ TOOLS_WARN_EXCEPTION("package", "ignoring");
+ }
+ xParser->setDocumentHandler ( Reference < XDocumentHandler > () );
+ return aManifestSequence;
+}
+// Component functions
+
+static Reference < XInterface > ManifestReader_createInstance( Reference< XMultiServiceFactory > const & rServiceFactory )
+{
+ return *new ManifestReader( comphelper::getComponentContext(rServiceFactory) );
+}
+OUString ManifestReader::static_getImplementationName()
+{
+ return "com.sun.star.packages.manifest.comp.ManifestReader";
+}
+
+Sequence < OUString > ManifestReader::static_getSupportedServiceNames()
+{
+ Sequence < OUString > aNames { "com.sun.star.packages.manifest.ManifestReader" };
+ return aNames;
+}
+
+OUString ManifestReader::getImplementationName()
+{
+ return static_getImplementationName();
+}
+
+sal_Bool SAL_CALL ManifestReader::supportsService(OUString const & rServiceName)
+{
+ return cppu::supportsService(this, rServiceName );
+}
+
+Sequence < OUString > ManifestReader::getSupportedServiceNames()
+{
+ return static_getSupportedServiceNames();
+}
+Reference < XSingleServiceFactory > ManifestReader::createServiceFactory( Reference < XMultiServiceFactory > const & rServiceFactory )
+{
+ return cppu::createSingleFactory (rServiceFactory,
+ static_getImplementationName(),
+ ManifestReader_createInstance,
+ static_getSupportedServiceNames());
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/package/source/manifest/ManifestReader.hxx b/package/source/manifest/ManifestReader.hxx
new file mode 100644
index 000000000..e30884424
--- /dev/null
+++ b/package/source/manifest/ManifestReader.hxx
@@ -0,0 +1,60 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_PACKAGE_SOURCE_MANIFEST_MANIFESTREADER_HXX
+#define INCLUDED_PACKAGE_SOURCE_MANIFEST_MANIFESTREADER_HXX
+
+#include <cppuhelper/implbase.hxx>
+#include <com/sun/star/packages/manifest/XManifestReader.hpp>
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/lang/XServiceInfo.hpp>
+
+namespace com::sun::star {
+ namespace lang { class XSingleServiceFactory; }
+ namespace uno { class XComponentContext; }
+}
+
+class ManifestReader: public ::cppu::WeakImplHelper
+<
+ css::packages::manifest::XManifestReader,
+ css::lang::XServiceInfo
+>
+{
+private:
+ css::uno::Reference< css::uno::XComponentContext > m_xContext;
+public:
+ ManifestReader( const css::uno::Reference< css::uno::XComponentContext > & xContext );
+ virtual ~ManifestReader() override;
+
+ // XManifestReader
+ virtual css::uno::Sequence< css::uno::Sequence< css::beans::PropertyValue > > SAL_CALL readManifestSequence( const css::uno::Reference< css::io::XInputStream >& rStream ) override;
+
+ // XServiceInfo
+ virtual OUString SAL_CALL getImplementationName( ) override;
+ virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
+ virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
+
+ // Component constructor
+ static OUString static_getImplementationName();
+ static css::uno::Sequence < OUString > static_getSupportedServiceNames();
+ static css::uno::Reference < css::lang::XSingleServiceFactory > createServiceFactory( css::uno::Reference < css::lang::XMultiServiceFactory > const & rServiceFactory );
+};
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/package/source/manifest/ManifestWriter.cxx b/package/source/manifest/ManifestWriter.cxx
new file mode 100644
index 000000000..8fbb9bd6a
--- /dev/null
+++ b/package/source/manifest/ManifestWriter.cxx
@@ -0,0 +1,113 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include "ManifestWriter.hxx"
+#include "ManifestExport.hxx"
+#include <cppuhelper/exc_hlp.hxx>
+#include <comphelper/processfactory.hxx>
+#include <cppuhelper/factory.hxx>
+#include <cppuhelper/supportsservice.hxx>
+#include <com/sun/star/io/XActiveDataSource.hpp>
+#include <com/sun/star/xml/sax/Writer.hpp>
+#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/lang/XSingleServiceFactory.hpp>
+#include <com/sun/star/xml/sax/SAXException.hpp>
+
+#include <osl/diagnose.hxx>
+#include <sal/log.hxx>
+
+using namespace ::com::sun::star;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::beans;
+using namespace ::com::sun::star::io;
+using namespace ::com::sun::star::lang;
+using namespace ::com::sun::star::registry;
+using namespace ::com::sun::star::packages;
+using namespace ::com::sun::star::xml::sax;
+
+#if OSL_DEBUG_LEVEL > 0
+#define THROW_WHERE SAL_WHERE
+#else
+#define THROW_WHERE ""
+#endif
+
+ManifestWriter::ManifestWriter( const Reference < XComponentContext > & xContext )
+: m_xContext ( xContext )
+{
+}
+ManifestWriter::~ManifestWriter()
+{
+}
+
+// XManifestWriter methods
+void SAL_CALL ManifestWriter::writeManifestSequence( const Reference< XOutputStream >& rStream, const Sequence< Sequence< PropertyValue > >& rSequence )
+{
+ Reference < XWriter > xSource = Writer::create( m_xContext );
+ xSource->setOutputStream ( rStream );
+ try {
+ ManifestExport( xSource, rSequence);
+ }
+ catch( SAXException& )
+ {
+ css::uno::Any anyEx = cppu::getCaughtException();
+ throw css::lang::WrappedTargetRuntimeException( THROW_WHERE,
+ nullptr, anyEx );
+ }
+}
+
+// Component methods
+static Reference < XInterface > ManifestWriter_createInstance( Reference< XMultiServiceFactory > const & rServiceFactory )
+{
+ return *new ManifestWriter( comphelper::getComponentContext(rServiceFactory) );
+}
+
+OUString ManifestWriter::static_getImplementationName()
+{
+ return "com.sun.star.packages.manifest.comp.ManifestWriter";
+}
+
+Sequence < OUString > ManifestWriter::static_getSupportedServiceNames()
+{
+ Sequence<OUString> aNames { "com.sun.star.packages.manifest.ManifestWriter" };
+ return aNames;
+}
+
+OUString ManifestWriter::getImplementationName()
+{
+ return static_getImplementationName();
+}
+
+sal_Bool SAL_CALL ManifestWriter::supportsService(OUString const & rServiceName)
+{
+ return cppu::supportsService(this, rServiceName);
+}
+Sequence < OUString > ManifestWriter::getSupportedServiceNames()
+{
+ return static_getSupportedServiceNames();
+}
+Reference < XSingleServiceFactory > ManifestWriter::createServiceFactory( Reference < XMultiServiceFactory > const & rServiceFactory )
+{
+ return cppu::createSingleFactory (rServiceFactory,
+ static_getImplementationName(),
+ ManifestWriter_createInstance,
+ static_getSupportedServiceNames());
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/package/source/manifest/ManifestWriter.hxx b/package/source/manifest/ManifestWriter.hxx
new file mode 100644
index 000000000..7d83a7383
--- /dev/null
+++ b/package/source/manifest/ManifestWriter.hxx
@@ -0,0 +1,60 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_PACKAGE_SOURCE_MANIFEST_MANIFESTWRITER_HXX
+#define INCLUDED_PACKAGE_SOURCE_MANIFEST_MANIFESTWRITER_HXX
+
+#include <cppuhelper/implbase.hxx>
+#include <com/sun/star/packages/manifest/XManifestWriter.hpp>
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/lang/XServiceInfo.hpp>
+
+namespace com::sun::star {
+ namespace lang { class XSingleServiceFactory; }
+ namespace uno { class XComponentContext; }
+}
+
+class ManifestWriter: public ::cppu::WeakImplHelper
+<
+ css::packages::manifest::XManifestWriter,
+ css::lang::XServiceInfo
+>
+{
+private:
+ css::uno::Reference< css::uno::XComponentContext > m_xContext;
+public:
+ ManifestWriter( const css::uno::Reference< css::uno::XComponentContext > & xContext );
+ virtual ~ManifestWriter() override;
+
+ // XManifestWriter
+ virtual void SAL_CALL writeManifestSequence( const css::uno::Reference< css::io::XOutputStream >& rStream, const css::uno::Sequence< css::uno::Sequence< css::beans::PropertyValue > >& rSequence ) override;
+
+ // XServiceInfo
+ virtual OUString SAL_CALL getImplementationName( ) override;
+ virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
+ virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
+
+ // Component constructor
+ static OUString static_getImplementationName();
+ static css::uno::Sequence < OUString > static_getSupportedServiceNames();
+ static css::uno::Reference < css::lang::XSingleServiceFactory > createServiceFactory( css::uno::Reference < css::lang::XMultiServiceFactory > const & rServiceFactory );
+};
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/package/source/manifest/UnoRegister.cxx b/package/source/manifest/UnoRegister.cxx
new file mode 100644
index 000000000..aa14db7d7
--- /dev/null
+++ b/package/source/manifest/UnoRegister.cxx
@@ -0,0 +1,70 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include "ManifestReader.hxx"
+#include "ManifestWriter.hxx"
+#include <cppuhelper/factory.hxx>
+#include <com/sun/star/registry/XRegistryKey.hpp>
+#include <ZipPackage.hxx>
+
+#include <zipfileaccess.hxx>
+
+using namespace ::com::sun::star;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::beans;
+using namespace ::com::sun::star::lang;
+using namespace ::com::sun::star::registry;
+using namespace ::com::sun::star::packages;
+
+/**
+ * This function is called to get service factories for an implementation.
+ * @param pImplName name of implementation
+ * @param pServiceManager generic uno interface providing a service manager to instantiate components
+ * @param pRegistryKey registry data key to read and write component persistent data
+ * @return a component factory (generic uno interface)
+ */
+extern "C" SAL_DLLPUBLIC_EXPORT void * package2_component_getFactory(
+ const char * pImplName, void * pServiceManager, void * /*pRegistryKey*/ )
+{
+ void * pRet = nullptr;
+ uno::Reference< XMultiServiceFactory > xSMgr(
+ static_cast< XMultiServiceFactory * >( pServiceManager ) );
+ uno::Reference< XSingleServiceFactory > xFactory;
+
+ if (ManifestReader::static_getImplementationName().equalsAscii( pImplName ) )
+ xFactory = ManifestReader::createServiceFactory ( xSMgr );
+ else if (ManifestWriter::static_getImplementationName().equalsAscii( pImplName ) )
+ xFactory = ManifestWriter::createServiceFactory ( xSMgr );
+ else if (ZipPackage::static_getImplementationName().equalsAscii( pImplName ) )
+ xFactory = ZipPackage::createServiceFactory ( xSMgr );
+ else if ( OZipFileAccess::impl_staticGetImplementationName().equalsAscii( pImplName ) )
+ xFactory = ::cppu::createSingleFactory( xSMgr,
+ OZipFileAccess::impl_staticGetImplementationName(),
+ OZipFileAccess::impl_staticCreateSelfInstance,
+ OZipFileAccess::impl_staticGetSupportedServiceNames() );
+
+ if ( xFactory.is() )
+ {
+ xFactory->acquire();
+ pRet = xFactory.get();
+ }
+ return pRet;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */