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