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