1*a3872823SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*a3872823SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*a3872823SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*a3872823SAndrew Rist * distributed with this work for additional information 6*a3872823SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*a3872823SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*a3872823SAndrew Rist * "License"); you may not use this file except in compliance 9*a3872823SAndrew Rist * with the License. You may obtain a copy of the License at 10*a3872823SAndrew Rist * 11*a3872823SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*a3872823SAndrew Rist * 13*a3872823SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*a3872823SAndrew Rist * software distributed under the License is distributed on an 15*a3872823SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*a3872823SAndrew Rist * KIND, either express or implied. See the License for the 17*a3872823SAndrew Rist * specific language governing permissions and limitations 18*a3872823SAndrew Rist * under the License. 19*a3872823SAndrew Rist * 20*a3872823SAndrew Rist *************************************************************/ 21*a3872823SAndrew Rist 22*a3872823SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_package.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp> 28cdf0e10cSrcweir #include <com/sun/star/xml/sax/XDocumentHandler.hpp> 29cdf0e10cSrcweir #include <com/sun/star/xml/sax/XAttributeList.hpp> 30cdf0e10cSrcweir #include <com/sun/star/xml/crypto/DigestID.hpp> 31cdf0e10cSrcweir #include <com/sun/star/xml/crypto/CipherID.hpp> 32cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp> 33cdf0e10cSrcweir #include <com/sun/star/uno/RuntimeException.hpp> 34cdf0e10cSrcweir 35cdf0e10cSrcweir #include <ManifestDefines.hxx> 36cdf0e10cSrcweir #include <ManifestExport.hxx> 37cdf0e10cSrcweir #include <Base64Codec.hxx> 38cdf0e10cSrcweir 39cdf0e10cSrcweir #include <rtl/ustrbuf.hxx> 40cdf0e10cSrcweir #include <comphelper/documentconstants.hxx> 41cdf0e10cSrcweir #include <comphelper/attributelist.hxx> 42cdf0e10cSrcweir 43cdf0e10cSrcweir using namespace ::com::sun::star; 44cdf0e10cSrcweir 45cdf0e10cSrcweir ManifestExport::ManifestExport( uno::Reference< xml::sax::XDocumentHandler > xHandler, const uno::Sequence< uno::Sequence < beans::PropertyValue > >& rManList ) 46cdf0e10cSrcweir { 47cdf0e10cSrcweir const ::rtl::OUString sFileEntryElement ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_FILE_ENTRY ) ); 48cdf0e10cSrcweir const ::rtl::OUString sManifestElement ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_MANIFEST ) ); 49cdf0e10cSrcweir const ::rtl::OUString sEncryptionDataElement( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_ENCRYPTION_DATA ) ); 50cdf0e10cSrcweir const ::rtl::OUString sAlgorithmElement ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_ALGORITHM ) ); 51cdf0e10cSrcweir const ::rtl::OUString sStartKeyGenerationElement ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_START_KEY_GENERATION ) ); 52cdf0e10cSrcweir const ::rtl::OUString sKeyDerivationElement ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_KEY_DERIVATION ) ); 53cdf0e10cSrcweir 54cdf0e10cSrcweir const ::rtl::OUString sCdataAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_CDATA ) ); 55cdf0e10cSrcweir const ::rtl::OUString sMediaTypeAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_MEDIA_TYPE ) ); 56cdf0e10cSrcweir const ::rtl::OUString sVersionAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_VERSION ) ); 57cdf0e10cSrcweir const ::rtl::OUString sFullPathAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_FULL_PATH ) ); 58cdf0e10cSrcweir const ::rtl::OUString sSizeAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_SIZE ) ); 59cdf0e10cSrcweir const ::rtl::OUString sKeySizeAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_KEY_SIZE ) ); 60cdf0e10cSrcweir const ::rtl::OUString sSaltAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_SALT ) ); 61cdf0e10cSrcweir const ::rtl::OUString sInitialisationVectorAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_INITIALISATION_VECTOR ) ); 62cdf0e10cSrcweir const ::rtl::OUString sIterationCountAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_ITERATION_COUNT ) ); 63cdf0e10cSrcweir const ::rtl::OUString sAlgorithmNameAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_ALGORITHM_NAME ) ); 64cdf0e10cSrcweir const ::rtl::OUString sStartKeyGenerationNameAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_START_KEY_GENERATION_NAME ) ); 65cdf0e10cSrcweir const ::rtl::OUString sKeyDerivationNameAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_KEY_DERIVATION_NAME ) ); 66cdf0e10cSrcweir const ::rtl::OUString sChecksumTypeAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_CHECKSUM_TYPE ) ); 67cdf0e10cSrcweir const ::rtl::OUString sChecksumAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_CHECKSUM) ); 68cdf0e10cSrcweir 69cdf0e10cSrcweir const ::rtl::OUString sFullPathProperty ( RTL_CONSTASCII_USTRINGPARAM ( "FullPath" ) ); 70cdf0e10cSrcweir const ::rtl::OUString sVersionProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Version" ) ); 71cdf0e10cSrcweir const ::rtl::OUString sMediaTypeProperty ( RTL_CONSTASCII_USTRINGPARAM ( "MediaType" ) ); 72cdf0e10cSrcweir const ::rtl::OUString sIterationCountProperty ( RTL_CONSTASCII_USTRINGPARAM ( "IterationCount" ) ); 73cdf0e10cSrcweir const ::rtl::OUString sDerivedKeySizeProperty ( RTL_CONSTASCII_USTRINGPARAM ( "DerivedKeySize" ) ); 74cdf0e10cSrcweir const ::rtl::OUString sSaltProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Salt" ) ); 75cdf0e10cSrcweir const ::rtl::OUString sInitialisationVectorProperty( RTL_CONSTASCII_USTRINGPARAM ( "InitialisationVector" ) ); 76cdf0e10cSrcweir const ::rtl::OUString sSizeProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Size" ) ); 77cdf0e10cSrcweir const ::rtl::OUString sDigestProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Digest" ) ); 78cdf0e10cSrcweir const ::rtl::OUString sEncryptionAlgProperty ( RTL_CONSTASCII_USTRINGPARAM ( "EncryptionAlgorithm" ) ); 79cdf0e10cSrcweir const ::rtl::OUString sStartKeyAlgProperty ( RTL_CONSTASCII_USTRINGPARAM ( "StartKeyAlgorithm" ) ); 80cdf0e10cSrcweir const ::rtl::OUString sDigestAlgProperty ( RTL_CONSTASCII_USTRINGPARAM ( "DigestAlgorithm" ) ); 81cdf0e10cSrcweir 82cdf0e10cSrcweir const ::rtl::OUString sWhiteSpace ( RTL_CONSTASCII_USTRINGPARAM ( " " ) ); 83cdf0e10cSrcweir 84cdf0e10cSrcweir const ::rtl::OUString sSHA256_URL ( RTL_CONSTASCII_USTRINGPARAM ( SHA256_URL ) ); 85cdf0e10cSrcweir const ::rtl::OUString sSHA1_Name ( RTL_CONSTASCII_USTRINGPARAM ( SHA1_NAME ) ); 86cdf0e10cSrcweir 87cdf0e10cSrcweir const ::rtl::OUString sSHA1_1k_Name ( RTL_CONSTASCII_USTRINGPARAM ( SHA1_1K_NAME ) ); 88cdf0e10cSrcweir const ::rtl::OUString sSHA256_1k_URL ( RTL_CONSTASCII_USTRINGPARAM ( SHA256_1K_URL ) ); 89cdf0e10cSrcweir 90cdf0e10cSrcweir const ::rtl::OUString sBlowfish_Name ( RTL_CONSTASCII_USTRINGPARAM ( BLOWFISH_NAME ) ); 91cdf0e10cSrcweir const ::rtl::OUString sAES256_URL ( RTL_CONSTASCII_USTRINGPARAM ( AES256_URL ) ); 92cdf0e10cSrcweir 93cdf0e10cSrcweir const ::rtl::OUString sPBKDF2_Name ( RTL_CONSTASCII_USTRINGPARAM ( PBKDF2_NAME ) ); 94cdf0e10cSrcweir 95cdf0e10cSrcweir ::comphelper::AttributeList * pRootAttrList = new ::comphelper::AttributeList; 96cdf0e10cSrcweir const uno::Sequence < beans::PropertyValue > *pSequence = rManList.getConstArray(); 97cdf0e10cSrcweir const sal_uInt32 nManLength = rManList.getLength(); 98cdf0e10cSrcweir 99cdf0e10cSrcweir // find the mediatype of the document if any 100cdf0e10cSrcweir ::rtl::OUString aDocMediaType; 101cdf0e10cSrcweir ::rtl::OUString aDocVersion; 102cdf0e10cSrcweir for (sal_uInt32 nInd = 0; nInd < nManLength ; nInd++ ) 103cdf0e10cSrcweir { 104cdf0e10cSrcweir ::rtl::OUString aMediaType; 105cdf0e10cSrcweir ::rtl::OUString aPath; 106cdf0e10cSrcweir ::rtl::OUString aVersion; 107cdf0e10cSrcweir 108cdf0e10cSrcweir const beans::PropertyValue *pValue = pSequence[nInd].getConstArray(); 109cdf0e10cSrcweir for (sal_uInt32 j = 0, nNum = pSequence[nInd].getLength(); j < nNum; j++, pValue++) 110cdf0e10cSrcweir { 111cdf0e10cSrcweir if (pValue->Name.equals (sMediaTypeProperty) ) 112cdf0e10cSrcweir { 113cdf0e10cSrcweir pValue->Value >>= aMediaType; 114cdf0e10cSrcweir } 115cdf0e10cSrcweir else if (pValue->Name.equals (sFullPathProperty) ) 116cdf0e10cSrcweir { 117cdf0e10cSrcweir pValue->Value >>= aPath; 118cdf0e10cSrcweir } 119cdf0e10cSrcweir else if (pValue->Name.equals (sVersionProperty) ) 120cdf0e10cSrcweir { 121cdf0e10cSrcweir pValue->Value >>= aVersion; 122cdf0e10cSrcweir } 123cdf0e10cSrcweir 124cdf0e10cSrcweir if ( aPath.getLength() && aMediaType.getLength() && aVersion.getLength() ) 125cdf0e10cSrcweir break; 126cdf0e10cSrcweir } 127cdf0e10cSrcweir 128cdf0e10cSrcweir if ( aPath.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) ) ) ) 129cdf0e10cSrcweir { 130cdf0e10cSrcweir aDocMediaType = aMediaType; 131cdf0e10cSrcweir aDocVersion = aVersion; 132cdf0e10cSrcweir break; 133cdf0e10cSrcweir } 134cdf0e10cSrcweir } 135cdf0e10cSrcweir 136cdf0e10cSrcweir sal_Bool bProvideDTD = sal_False; 137cdf0e10cSrcweir sal_Bool bAcceptNonemptyVersion = sal_False; 138cdf0e10cSrcweir sal_Bool bStoreStartKeyGeneration = sal_False; 139cdf0e10cSrcweir if ( aDocMediaType.getLength() ) 140cdf0e10cSrcweir { 141cdf0e10cSrcweir if ( aDocMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_TEXT_ASCII ) ) ) 142cdf0e10cSrcweir || aDocMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_TEXT_WEB_ASCII ) ) ) 143cdf0e10cSrcweir || aDocMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_TEXT_GLOBAL_ASCII ) ) ) 144cdf0e10cSrcweir || aDocMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_DRAWING_ASCII ) ) ) 145cdf0e10cSrcweir || aDocMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_PRESENTATION_ASCII ) ) ) 146cdf0e10cSrcweir || aDocMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_SPREADSHEET_ASCII ) ) ) 147cdf0e10cSrcweir || aDocMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_CHART_ASCII ) ) ) 148cdf0e10cSrcweir || aDocMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_DATABASE_ASCII ) ) ) 149cdf0e10cSrcweir || aDocMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_FORMULA_ASCII ) ) ) 150cdf0e10cSrcweir 151cdf0e10cSrcweir || aDocMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_TEXT_TEMPLATE_ASCII ) ) ) 152cdf0e10cSrcweir || aDocMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_DRAWING_TEMPLATE_ASCII ) ) ) 153cdf0e10cSrcweir || aDocMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_PRESENTATION_TEMPLATE_ASCII ) ) ) 154cdf0e10cSrcweir || aDocMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_SPREADSHEET_TEMPLATE_ASCII ) ) ) 155cdf0e10cSrcweir || aDocMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_CHART_TEMPLATE_ASCII ) ) ) 156cdf0e10cSrcweir || aDocMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MIMETYPE_OASIS_OPENDOCUMENT_FORMULA_TEMPLATE_ASCII ) ) ) ) 157cdf0e10cSrcweir 158cdf0e10cSrcweir { 159cdf0e10cSrcweir // oasis format 160cdf0e10cSrcweir pRootAttrList->AddAttribute ( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_XMLNS ) ), 161cdf0e10cSrcweir sCdataAttribute, 162cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( MANIFEST_OASIS_NAMESPACE ) ) ); 163cdf0e10cSrcweir bAcceptNonemptyVersion = sal_True; 164cdf0e10cSrcweir if ( aDocVersion.compareTo( ODFVER_012_TEXT ) >= 0 ) 165cdf0e10cSrcweir { 166cdf0e10cSrcweir // this is ODF12 generation, let encrypted streams contain start-key-generation entry 167cdf0e10cSrcweir bStoreStartKeyGeneration = sal_True; 168cdf0e10cSrcweir 169cdf0e10cSrcweir // starting from ODF12 the version should be also in manifest:manifest element 170cdf0e10cSrcweir pRootAttrList->AddAttribute ( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_VERSION ) ), 171cdf0e10cSrcweir sCdataAttribute, 172cdf0e10cSrcweir aDocVersion ); 173cdf0e10cSrcweir } 174cdf0e10cSrcweir } 175cdf0e10cSrcweir else 176cdf0e10cSrcweir { 177cdf0e10cSrcweir // even if it is no SO6 format the namespace must be specified 178cdf0e10cSrcweir // thus SO6 format is used as default one 179cdf0e10cSrcweir pRootAttrList->AddAttribute ( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_XMLNS ) ), 180cdf0e10cSrcweir sCdataAttribute, 181cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( MANIFEST_NAMESPACE ) ) ); 182cdf0e10cSrcweir 183cdf0e10cSrcweir bProvideDTD = sal_True; 184cdf0e10cSrcweir } 185cdf0e10cSrcweir } 186cdf0e10cSrcweir 187cdf0e10cSrcweir uno::Reference < xml::sax::XAttributeList > xRootAttrList (pRootAttrList); 188cdf0e10cSrcweir 189cdf0e10cSrcweir xHandler->startDocument(); 190cdf0e10cSrcweir uno::Reference < xml::sax::XExtendedDocumentHandler > xExtHandler ( xHandler, uno::UNO_QUERY ); 191cdf0e10cSrcweir if ( xExtHandler.is() && bProvideDTD ) 192cdf0e10cSrcweir { 193cdf0e10cSrcweir ::rtl::OUString aDocType ( RTL_CONSTASCII_USTRINGPARAM ( MANIFEST_DOCTYPE ) ); 194cdf0e10cSrcweir xExtHandler->unknown ( aDocType ); 195cdf0e10cSrcweir xHandler->ignorableWhitespace ( sWhiteSpace ); 196cdf0e10cSrcweir } 197cdf0e10cSrcweir xHandler->startElement( sManifestElement, xRootAttrList ); 198cdf0e10cSrcweir 199cdf0e10cSrcweir for (sal_uInt32 i = 0 ; i < nManLength ; i++) 200cdf0e10cSrcweir { 201cdf0e10cSrcweir ::comphelper::AttributeList *pAttrList = new ::comphelper::AttributeList; 202cdf0e10cSrcweir const beans::PropertyValue *pValue = pSequence[i].getConstArray(); 203cdf0e10cSrcweir ::rtl::OUString aString; 204cdf0e10cSrcweir const uno::Any *pVector = NULL, *pSalt = NULL, *pIterationCount = NULL, *pDigest = NULL, *pDigestAlg = NULL, *pEncryptAlg = NULL, *pStartKeyAlg = NULL, *pDerivedKeySize = NULL; 205cdf0e10cSrcweir for (sal_uInt32 j = 0, nNum = pSequence[i].getLength(); j < nNum; j++, pValue++) 206cdf0e10cSrcweir { 207cdf0e10cSrcweir if (pValue->Name.equals (sMediaTypeProperty) ) 208cdf0e10cSrcweir { 209cdf0e10cSrcweir pValue->Value >>= aString; 210cdf0e10cSrcweir pAttrList->AddAttribute ( sMediaTypeAttribute, sCdataAttribute, aString ); 211cdf0e10cSrcweir } 212cdf0e10cSrcweir else if (pValue->Name.equals (sVersionProperty) ) 213cdf0e10cSrcweir { 214cdf0e10cSrcweir pValue->Value >>= aString; 215cdf0e10cSrcweir // the version is stored only if it is not empty 216cdf0e10cSrcweir if ( bAcceptNonemptyVersion && aString.getLength() ) 217cdf0e10cSrcweir pAttrList->AddAttribute ( sVersionAttribute, sCdataAttribute, aString ); 218cdf0e10cSrcweir } 219cdf0e10cSrcweir else if (pValue->Name.equals (sFullPathProperty) ) 220cdf0e10cSrcweir { 221cdf0e10cSrcweir pValue->Value >>= aString; 222cdf0e10cSrcweir pAttrList->AddAttribute ( sFullPathAttribute, sCdataAttribute, aString ); 223cdf0e10cSrcweir } 224cdf0e10cSrcweir else if (pValue->Name.equals (sSizeProperty) ) 225cdf0e10cSrcweir { 226cdf0e10cSrcweir sal_Int32 nSize = 0; 227cdf0e10cSrcweir pValue->Value >>= nSize; 228cdf0e10cSrcweir ::rtl::OUStringBuffer aBuffer; 229cdf0e10cSrcweir aBuffer.append ( nSize ); 230cdf0e10cSrcweir pAttrList->AddAttribute ( sSizeAttribute, sCdataAttribute, aBuffer.makeStringAndClear() ); 231cdf0e10cSrcweir } 232cdf0e10cSrcweir else if (pValue->Name.equals (sInitialisationVectorProperty) ) 233cdf0e10cSrcweir pVector = &pValue->Value; 234cdf0e10cSrcweir else if (pValue->Name.equals (sSaltProperty) ) 235cdf0e10cSrcweir pSalt = &pValue->Value; 236cdf0e10cSrcweir else if (pValue->Name.equals (sIterationCountProperty) ) 237cdf0e10cSrcweir pIterationCount = &pValue->Value; 238cdf0e10cSrcweir else if (pValue->Name.equals ( sDigestProperty ) ) 239cdf0e10cSrcweir pDigest = &pValue->Value; 240cdf0e10cSrcweir else if (pValue->Name.equals ( sDigestAlgProperty ) ) 241cdf0e10cSrcweir pDigestAlg = &pValue->Value; 242cdf0e10cSrcweir else if (pValue->Name.equals ( sEncryptionAlgProperty ) ) 243cdf0e10cSrcweir pEncryptAlg = &pValue->Value; 244cdf0e10cSrcweir else if (pValue->Name.equals ( sStartKeyAlgProperty ) ) 245cdf0e10cSrcweir pStartKeyAlg = &pValue->Value; 246cdf0e10cSrcweir else if (pValue->Name.equals ( sDerivedKeySizeProperty ) ) 247cdf0e10cSrcweir pDerivedKeySize = &pValue->Value; 248cdf0e10cSrcweir } 249cdf0e10cSrcweir 250cdf0e10cSrcweir xHandler->ignorableWhitespace ( sWhiteSpace ); 251cdf0e10cSrcweir uno::Reference < xml::sax::XAttributeList > xAttrList ( pAttrList ); 252cdf0e10cSrcweir xHandler->startElement( sFileEntryElement , xAttrList); 253cdf0e10cSrcweir if ( pVector && pSalt && pIterationCount && pDigest && pDigestAlg && pEncryptAlg && pStartKeyAlg && pDerivedKeySize ) 254cdf0e10cSrcweir { 255cdf0e10cSrcweir // ==== Encryption Data 256cdf0e10cSrcweir ::comphelper::AttributeList * pNewAttrList = new ::comphelper::AttributeList; 257cdf0e10cSrcweir uno::Reference < xml::sax::XAttributeList > xNewAttrList (pNewAttrList); 258cdf0e10cSrcweir ::rtl::OUStringBuffer aBuffer; 259cdf0e10cSrcweir uno::Sequence < sal_Int8 > aSequence; 260cdf0e10cSrcweir 261cdf0e10cSrcweir xHandler->ignorableWhitespace ( sWhiteSpace ); 262cdf0e10cSrcweir 263cdf0e10cSrcweir // ==== Digest 264cdf0e10cSrcweir ::rtl::OUString sChecksumType; 265cdf0e10cSrcweir sal_Int32 nDigestAlgID = 0; 266cdf0e10cSrcweir *pDigestAlg >>= nDigestAlgID; 267cdf0e10cSrcweir if ( nDigestAlgID == xml::crypto::DigestID::SHA256_1K ) 268cdf0e10cSrcweir sChecksumType = sSHA256_1k_URL; 269cdf0e10cSrcweir else if ( nDigestAlgID == xml::crypto::DigestID::SHA1_1K ) 270cdf0e10cSrcweir sChecksumType = sSHA1_1k_Name; 271cdf0e10cSrcweir else 272cdf0e10cSrcweir throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected digest algorithm is provided!" ) ), uno::Reference< uno::XInterface >() ); 273cdf0e10cSrcweir 274cdf0e10cSrcweir pNewAttrList->AddAttribute ( sChecksumTypeAttribute, sCdataAttribute, sChecksumType ); 275cdf0e10cSrcweir *pDigest >>= aSequence; 276cdf0e10cSrcweir Base64Codec::encodeBase64( aBuffer, aSequence ); 277cdf0e10cSrcweir pNewAttrList->AddAttribute ( sChecksumAttribute, sCdataAttribute, aBuffer.makeStringAndClear() ); 278cdf0e10cSrcweir 279cdf0e10cSrcweir xHandler->startElement( sEncryptionDataElement , xNewAttrList); 280cdf0e10cSrcweir 281cdf0e10cSrcweir // ==== Algorithm 282cdf0e10cSrcweir pNewAttrList = new ::comphelper::AttributeList; 283cdf0e10cSrcweir xNewAttrList = pNewAttrList; 284cdf0e10cSrcweir 285cdf0e10cSrcweir sal_Int32 nEncAlgID = 0; 286cdf0e10cSrcweir sal_Int32 nDerivedKeySize = 0; 287cdf0e10cSrcweir *pEncryptAlg >>= nEncAlgID; 288cdf0e10cSrcweir *pDerivedKeySize >>= nDerivedKeySize; 289cdf0e10cSrcweir 290cdf0e10cSrcweir ::rtl::OUString sEncAlgName; 291cdf0e10cSrcweir if ( nEncAlgID == xml::crypto::CipherID::AES_CBC_W3C_PADDING ) 292cdf0e10cSrcweir { 293cdf0e10cSrcweir OSL_ENSURE( nDerivedKeySize, "Unexpected key size is provided!" ); 294cdf0e10cSrcweir if ( nDerivedKeySize != 32 ) 295cdf0e10cSrcweir throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected key size is provided!" ) ), uno::Reference< uno::XInterface >() ); 296cdf0e10cSrcweir 297cdf0e10cSrcweir sEncAlgName = sAES256_URL; 298cdf0e10cSrcweir } 299cdf0e10cSrcweir else if ( nEncAlgID == xml::crypto::CipherID::BLOWFISH_CFB_8 ) 300cdf0e10cSrcweir { 301cdf0e10cSrcweir sEncAlgName = sBlowfish_Name; 302cdf0e10cSrcweir } 303cdf0e10cSrcweir else 304cdf0e10cSrcweir throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpecte encryption algorithm is provided!" ) ), uno::Reference< uno::XInterface >() ); 305cdf0e10cSrcweir 306cdf0e10cSrcweir pNewAttrList->AddAttribute ( sAlgorithmNameAttribute, sCdataAttribute, sEncAlgName ); 307cdf0e10cSrcweir 308cdf0e10cSrcweir *pVector >>= aSequence; 309cdf0e10cSrcweir Base64Codec::encodeBase64 ( aBuffer, aSequence ); 310cdf0e10cSrcweir pNewAttrList->AddAttribute ( sInitialisationVectorAttribute, sCdataAttribute, aBuffer.makeStringAndClear() ); 311cdf0e10cSrcweir 312cdf0e10cSrcweir xHandler->ignorableWhitespace ( sWhiteSpace ); 313cdf0e10cSrcweir xHandler->startElement( sAlgorithmElement , xNewAttrList); 314cdf0e10cSrcweir xHandler->ignorableWhitespace ( sWhiteSpace ); 315cdf0e10cSrcweir xHandler->endElement( sAlgorithmElement ); 316cdf0e10cSrcweir 317cdf0e10cSrcweir // ==== Key Derivation 318cdf0e10cSrcweir pNewAttrList = new ::comphelper::AttributeList; 319cdf0e10cSrcweir xNewAttrList = pNewAttrList; 320cdf0e10cSrcweir 321cdf0e10cSrcweir pNewAttrList->AddAttribute ( sKeyDerivationNameAttribute, sCdataAttribute, sPBKDF2_Name ); 322cdf0e10cSrcweir 323cdf0e10cSrcweir if ( bStoreStartKeyGeneration ) 324cdf0e10cSrcweir { 325cdf0e10cSrcweir aBuffer.append( nDerivedKeySize ); 326cdf0e10cSrcweir pNewAttrList->AddAttribute ( sKeySizeAttribute, sCdataAttribute, aBuffer.makeStringAndClear() ); 327cdf0e10cSrcweir } 328cdf0e10cSrcweir 329cdf0e10cSrcweir sal_Int32 nCount = 0; 330cdf0e10cSrcweir *pIterationCount >>= nCount; 331cdf0e10cSrcweir aBuffer.append (nCount); 332cdf0e10cSrcweir pNewAttrList->AddAttribute ( sIterationCountAttribute, sCdataAttribute, aBuffer.makeStringAndClear() ); 333cdf0e10cSrcweir 334cdf0e10cSrcweir *pSalt >>= aSequence; 335cdf0e10cSrcweir Base64Codec::encodeBase64 ( aBuffer, aSequence ); 336cdf0e10cSrcweir pNewAttrList->AddAttribute ( sSaltAttribute, sCdataAttribute, aBuffer.makeStringAndClear() ); 337cdf0e10cSrcweir 338cdf0e10cSrcweir xHandler->ignorableWhitespace ( sWhiteSpace ); 339cdf0e10cSrcweir xHandler->startElement( sKeyDerivationElement , xNewAttrList); 340cdf0e10cSrcweir xHandler->ignorableWhitespace ( sWhiteSpace ); 341cdf0e10cSrcweir xHandler->endElement( sKeyDerivationElement ); 342cdf0e10cSrcweir 343cdf0e10cSrcweir // we have to store start-key-generation element as the last one to workaround the parsing problem 344cdf0e10cSrcweir // in OOo3.1 and older versions 345cdf0e10cSrcweir if ( bStoreStartKeyGeneration ) 346cdf0e10cSrcweir { 347cdf0e10cSrcweir // ==== Start Key Generation 348cdf0e10cSrcweir pNewAttrList = new ::comphelper::AttributeList; 349cdf0e10cSrcweir xNewAttrList = pNewAttrList; 350cdf0e10cSrcweir 351cdf0e10cSrcweir ::rtl::OUString sStartKeyAlg; 352cdf0e10cSrcweir ::rtl::OUString sStartKeySize; 353cdf0e10cSrcweir sal_Int32 nStartKeyAlgID = 0; 354cdf0e10cSrcweir *pStartKeyAlg >>= nStartKeyAlgID; 355cdf0e10cSrcweir if ( nStartKeyAlgID == xml::crypto::DigestID::SHA256 ) 356cdf0e10cSrcweir { 357cdf0e10cSrcweir sStartKeyAlg = sSHA256_URL; 358cdf0e10cSrcweir aBuffer.append( (sal_Int32)32 ); 359cdf0e10cSrcweir sStartKeySize = aBuffer.makeStringAndClear(); 360cdf0e10cSrcweir } 361cdf0e10cSrcweir else if ( nStartKeyAlgID == xml::crypto::DigestID::SHA1 ) 362cdf0e10cSrcweir { 363cdf0e10cSrcweir sStartKeyAlg = sSHA1_Name; 364cdf0e10cSrcweir aBuffer.append( (sal_Int32)20 ); 365cdf0e10cSrcweir sStartKeySize = aBuffer.makeStringAndClear(); 366cdf0e10cSrcweir } 367cdf0e10cSrcweir else 368cdf0e10cSrcweir throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected start key algorithm is provided!" ) ), uno::Reference< uno::XInterface >() ); 369cdf0e10cSrcweir 370cdf0e10cSrcweir pNewAttrList->AddAttribute ( sStartKeyGenerationNameAttribute, sCdataAttribute, sStartKeyAlg ); 371cdf0e10cSrcweir pNewAttrList->AddAttribute ( sKeySizeAttribute, sCdataAttribute, sStartKeySize ); 372cdf0e10cSrcweir 373cdf0e10cSrcweir xHandler->ignorableWhitespace ( sWhiteSpace ); 374cdf0e10cSrcweir xHandler->startElement( sStartKeyGenerationElement , xNewAttrList); 375cdf0e10cSrcweir xHandler->ignorableWhitespace ( sWhiteSpace ); 376cdf0e10cSrcweir xHandler->endElement( sStartKeyGenerationElement ); 377cdf0e10cSrcweir } 378cdf0e10cSrcweir 379cdf0e10cSrcweir xHandler->ignorableWhitespace ( sWhiteSpace ); 380cdf0e10cSrcweir xHandler->endElement( sEncryptionDataElement ); 381cdf0e10cSrcweir } 382cdf0e10cSrcweir xHandler->ignorableWhitespace ( sWhiteSpace ); 383cdf0e10cSrcweir xHandler->endElement( sFileEntryElement ); 384cdf0e10cSrcweir } 385cdf0e10cSrcweir xHandler->ignorableWhitespace ( sWhiteSpace ); 386cdf0e10cSrcweir xHandler->endElement( sManifestElement ); 387cdf0e10cSrcweir xHandler->endDocument(); 388cdf0e10cSrcweir } 389