xref: /AOO41X/main/package/source/manifest/ManifestImport.cxx (revision a38728232e8c39f9058a1a2aa8ee4e6db7b8ca34)
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
10cdf0e10cSrcweir  *
11*a3872823SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
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.
19cdf0e10cSrcweir  *
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 #include <ManifestImport.hxx>
27cdf0e10cSrcweir #include <ManifestDefines.hxx>
28cdf0e10cSrcweir #include <Base64Codec.hxx>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include <com/sun/star/xml/sax/XAttributeList.hpp>
31cdf0e10cSrcweir #include <com/sun/star/xml/crypto/DigestID.hpp>
32cdf0e10cSrcweir #include <com/sun/star/xml/crypto/CipherID.hpp>
33cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir using namespace com::sun::star::uno;
36cdf0e10cSrcweir using namespace com::sun::star::beans;
37cdf0e10cSrcweir using namespace com::sun::star;
38cdf0e10cSrcweir using namespace rtl;
39cdf0e10cSrcweir using namespace std;
40cdf0e10cSrcweir 
41cdf0e10cSrcweir // ---------------------------------------------------
42cdf0e10cSrcweir ManifestImport::ManifestImport( vector < Sequence < PropertyValue > > & rNewManVector )
43cdf0e10cSrcweir : nNumProperty ( 0 )
44cdf0e10cSrcweir , bIgnoreEncryptData    ( sal_False )
45cdf0e10cSrcweir , nDerivedKeySize( 0 )
46cdf0e10cSrcweir , rManVector ( rNewManVector )
47cdf0e10cSrcweir 
48cdf0e10cSrcweir , sFileEntryElement     ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_FILE_ENTRY ) )
49cdf0e10cSrcweir , sManifestElement      ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_MANIFEST ) )
50cdf0e10cSrcweir , sEncryptionDataElement( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_ENCRYPTION_DATA ) )
51cdf0e10cSrcweir , sAlgorithmElement ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_ALGORITHM ) )
52cdf0e10cSrcweir , sStartKeyAlgElement   ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_START_KEY_GENERATION ) )
53cdf0e10cSrcweir , sKeyDerivationElement( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_KEY_DERIVATION ) )
54cdf0e10cSrcweir 
55cdf0e10cSrcweir , sCdataAttribute               ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_CDATA ) )
56cdf0e10cSrcweir , sMediaTypeAttribute           ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_MEDIA_TYPE ) )
57cdf0e10cSrcweir , sVersionAttribute             ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_VERSION ) )
58cdf0e10cSrcweir , sFullPathAttribute            ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_FULL_PATH ) )
59cdf0e10cSrcweir , sSizeAttribute                ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_SIZE ) )
60cdf0e10cSrcweir , sSaltAttribute                ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_SALT ) )
61cdf0e10cSrcweir , sInitialisationVectorAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_INITIALISATION_VECTOR ) )
62cdf0e10cSrcweir , sIterationCountAttribute      ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_ITERATION_COUNT ) )
63cdf0e10cSrcweir , sKeySizeAttribute             ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_KEY_SIZE ) )
64cdf0e10cSrcweir , sAlgorithmNameAttribute       ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_ALGORITHM_NAME ) )
65cdf0e10cSrcweir , sStartKeyAlgNameAttribute     ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_START_KEY_GENERATION_NAME ) )
66cdf0e10cSrcweir , sKeyDerivationNameAttribute   ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_KEY_DERIVATION_NAME ) )
67cdf0e10cSrcweir , sChecksumAttribute            ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_CHECKSUM ) )
68cdf0e10cSrcweir , sChecksumTypeAttribute        ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_CHECKSUM_TYPE ) )
69cdf0e10cSrcweir 
70cdf0e10cSrcweir , sFullPathProperty             ( RTL_CONSTASCII_USTRINGPARAM ( "FullPath" ) )
71cdf0e10cSrcweir , sMediaTypeProperty            ( RTL_CONSTASCII_USTRINGPARAM ( "MediaType" ) )
72cdf0e10cSrcweir , sVersionProperty              ( RTL_CONSTASCII_USTRINGPARAM ( "Version" ) )
73cdf0e10cSrcweir , sIterationCountProperty       ( RTL_CONSTASCII_USTRINGPARAM ( "IterationCount" ) )
74cdf0e10cSrcweir , sDerivedKeySizeProperty       ( RTL_CONSTASCII_USTRINGPARAM ( "DerivedKeySize" ) )
75cdf0e10cSrcweir , sSaltProperty                 ( RTL_CONSTASCII_USTRINGPARAM ( "Salt" ) )
76cdf0e10cSrcweir , sInitialisationVectorProperty ( RTL_CONSTASCII_USTRINGPARAM ( "InitialisationVector" ) )
77cdf0e10cSrcweir , sSizeProperty                 ( RTL_CONSTASCII_USTRINGPARAM ( "Size" ) )
78cdf0e10cSrcweir , sDigestProperty               ( RTL_CONSTASCII_USTRINGPARAM ( "Digest" ) )
79cdf0e10cSrcweir , sEncryptionAlgProperty        ( RTL_CONSTASCII_USTRINGPARAM ( "EncryptionAlgorithm" ) )
80cdf0e10cSrcweir , sStartKeyAlgProperty          ( RTL_CONSTASCII_USTRINGPARAM ( "StartKeyAlgorithm" ) )
81cdf0e10cSrcweir , sDigestAlgProperty            ( RTL_CONSTASCII_USTRINGPARAM ( "DigestAlgorithm" ) )
82cdf0e10cSrcweir 
83cdf0e10cSrcweir , sWhiteSpace                   ( RTL_CONSTASCII_USTRINGPARAM ( " " ) )
84cdf0e10cSrcweir 
85cdf0e10cSrcweir , sSHA256_URL                   ( RTL_CONSTASCII_USTRINGPARAM ( SHA256_URL ) )
86cdf0e10cSrcweir , sSHA1_Name                    ( RTL_CONSTASCII_USTRINGPARAM ( SHA1_NAME ) )
87cdf0e10cSrcweir , sSHA1_URL                     ( RTL_CONSTASCII_USTRINGPARAM ( SHA1_URL ) )
88cdf0e10cSrcweir 
89cdf0e10cSrcweir , sSHA256_1k_URL                ( RTL_CONSTASCII_USTRINGPARAM ( SHA256_1K_URL ) )
90cdf0e10cSrcweir , sSHA1_1k_Name                 ( RTL_CONSTASCII_USTRINGPARAM ( SHA1_1K_NAME ) )
91cdf0e10cSrcweir , sSHA1_1k_URL                  ( RTL_CONSTASCII_USTRINGPARAM ( SHA1_1K_URL ) )
92cdf0e10cSrcweir 
93cdf0e10cSrcweir , sBlowfish_Name                ( RTL_CONSTASCII_USTRINGPARAM ( BLOWFISH_NAME ) )
94cdf0e10cSrcweir , sBlowfish_URL                 ( RTL_CONSTASCII_USTRINGPARAM ( BLOWFISH_URL ) )
95cdf0e10cSrcweir , sAES128_URL                   ( RTL_CONSTASCII_USTRINGPARAM ( AES128_URL ) )
96cdf0e10cSrcweir , sAES192_URL                   ( RTL_CONSTASCII_USTRINGPARAM ( AES192_URL ) )
97cdf0e10cSrcweir , sAES256_URL                   ( RTL_CONSTASCII_USTRINGPARAM ( AES256_URL ) )
98cdf0e10cSrcweir 
99cdf0e10cSrcweir , sPBKDF2_Name                  ( RTL_CONSTASCII_USTRINGPARAM ( PBKDF2_NAME ) )
100cdf0e10cSrcweir , sPBKDF2_URL                   ( RTL_CONSTASCII_USTRINGPARAM ( PBKDF2_URL ) )
101cdf0e10cSrcweir {
102cdf0e10cSrcweir     aStack.reserve( 10 );
103cdf0e10cSrcweir }
104cdf0e10cSrcweir 
105cdf0e10cSrcweir // ---------------------------------------------------
106cdf0e10cSrcweir ManifestImport::~ManifestImport ( void )
107cdf0e10cSrcweir {
108cdf0e10cSrcweir }
109cdf0e10cSrcweir 
110cdf0e10cSrcweir // ---------------------------------------------------
111cdf0e10cSrcweir void SAL_CALL ManifestImport::startDocument(  )
112cdf0e10cSrcweir         throw( xml::sax::SAXException, uno::RuntimeException )
113cdf0e10cSrcweir {
114cdf0e10cSrcweir }
115cdf0e10cSrcweir 
116cdf0e10cSrcweir // ---------------------------------------------------
117cdf0e10cSrcweir void SAL_CALL ManifestImport::endDocument(  )
118cdf0e10cSrcweir         throw( xml::sax::SAXException, uno::RuntimeException )
119cdf0e10cSrcweir {
120cdf0e10cSrcweir }
121cdf0e10cSrcweir 
122cdf0e10cSrcweir // ---------------------------------------------------
123cdf0e10cSrcweir void SAL_CALL ManifestImport::startElement( const OUString& aName, const uno::Reference< xml::sax::XAttributeList >& xAttribs )
124cdf0e10cSrcweir         throw( xml::sax::SAXException, uno::RuntimeException )
125cdf0e10cSrcweir {
126cdf0e10cSrcweir     StringHashMap aConvertedAttribs;
127cdf0e10cSrcweir     ::rtl::OUString aConvertedName = PushNameAndNamespaces( aName, xAttribs, aConvertedAttribs );
128cdf0e10cSrcweir 
129cdf0e10cSrcweir     if ( aConvertedName == sFileEntryElement )
130cdf0e10cSrcweir     {
131cdf0e10cSrcweir         aSequence.realloc ( PKG_SIZE_ENCR_MNFST );
132cdf0e10cSrcweir 
133cdf0e10cSrcweir         // Put full-path property first for MBA
134cdf0e10cSrcweir         aSequence[nNumProperty].Name = sFullPathProperty;
135cdf0e10cSrcweir         aSequence[nNumProperty++].Value <<= aConvertedAttribs[sFullPathAttribute];
136cdf0e10cSrcweir         aSequence[nNumProperty].Name = sMediaTypeProperty;
137cdf0e10cSrcweir         aSequence[nNumProperty++].Value <<= aConvertedAttribs[sMediaTypeAttribute];
138cdf0e10cSrcweir 
139cdf0e10cSrcweir         OUString sVersion = aConvertedAttribs[sVersionAttribute];
140cdf0e10cSrcweir         if ( sVersion.getLength() )
141cdf0e10cSrcweir         {
142cdf0e10cSrcweir             aSequence[nNumProperty].Name = sVersionProperty;
143cdf0e10cSrcweir             aSequence[nNumProperty++].Value <<= sVersion;
144cdf0e10cSrcweir         }
145cdf0e10cSrcweir 
146cdf0e10cSrcweir         OUString sSize = aConvertedAttribs[sSizeAttribute];
147cdf0e10cSrcweir         if ( sSize.getLength() )
148cdf0e10cSrcweir         {
149cdf0e10cSrcweir             sal_Int32 nSize;
150cdf0e10cSrcweir             nSize = sSize.toInt32();
151cdf0e10cSrcweir             aSequence[nNumProperty].Name = sSizeProperty;
152cdf0e10cSrcweir             aSequence[nNumProperty++].Value <<= nSize;
153cdf0e10cSrcweir         }
154cdf0e10cSrcweir     }
155cdf0e10cSrcweir     else if ( aStack.size() > 1 )
156cdf0e10cSrcweir     {
157cdf0e10cSrcweir         ManifestStack::reverse_iterator aIter = aStack.rbegin();
158cdf0e10cSrcweir         aIter++;
159cdf0e10cSrcweir 
160cdf0e10cSrcweir         if ( aIter->m_aConvertedName.equals( sFileEntryElement ) )
161cdf0e10cSrcweir         {
162cdf0e10cSrcweir             if ( aConvertedName.equals( sEncryptionDataElement ) )
163cdf0e10cSrcweir             {
164cdf0e10cSrcweir                 // If this element exists, then this stream is encrypted and we need
165cdf0e10cSrcweir                 // to import the initialisation vector, salt and iteration count used
166cdf0e10cSrcweir                 nDerivedKeySize = 0;
167cdf0e10cSrcweir                 OUString aString = aConvertedAttribs[sChecksumTypeAttribute];
168cdf0e10cSrcweir                 if ( !bIgnoreEncryptData )
169cdf0e10cSrcweir                 {
170cdf0e10cSrcweir                     if ( aString.equals( sSHA1_1k_Name ) || aString.equals( sSHA1_1k_URL ) )
171cdf0e10cSrcweir                     {
172cdf0e10cSrcweir                         aSequence[nNumProperty].Name = sDigestAlgProperty;
173cdf0e10cSrcweir                         aSequence[nNumProperty++].Value <<= xml::crypto::DigestID::SHA1_1K;
174cdf0e10cSrcweir                     }
175cdf0e10cSrcweir                     else if ( aString.equals( sSHA256_1k_URL ) )
176cdf0e10cSrcweir                     {
177cdf0e10cSrcweir                         aSequence[nNumProperty].Name = sDigestAlgProperty;
178cdf0e10cSrcweir                         aSequence[nNumProperty++].Value <<= xml::crypto::DigestID::SHA256_1K;
179cdf0e10cSrcweir                     }
180cdf0e10cSrcweir                     else
181cdf0e10cSrcweir                         bIgnoreEncryptData = sal_True;
182cdf0e10cSrcweir 
183cdf0e10cSrcweir                     if ( !bIgnoreEncryptData )
184cdf0e10cSrcweir                     {
185cdf0e10cSrcweir                         aString = aConvertedAttribs[sChecksumAttribute];
186cdf0e10cSrcweir                         uno::Sequence < sal_Int8 > aDecodeBuffer;
187cdf0e10cSrcweir                         Base64Codec::decodeBase64( aDecodeBuffer, aString );
188cdf0e10cSrcweir                         aSequence[nNumProperty].Name = sDigestProperty;
189cdf0e10cSrcweir                         aSequence[nNumProperty++].Value <<= aDecodeBuffer;
190cdf0e10cSrcweir                     }
191cdf0e10cSrcweir                 }
192cdf0e10cSrcweir             }
193cdf0e10cSrcweir         }
194cdf0e10cSrcweir         else if ( aIter->m_aConvertedName.equals( sEncryptionDataElement ) )
195cdf0e10cSrcweir         {
196cdf0e10cSrcweir             if ( aConvertedName == sAlgorithmElement )
197cdf0e10cSrcweir             {
198cdf0e10cSrcweir                 if ( !bIgnoreEncryptData )
199cdf0e10cSrcweir                 {
200cdf0e10cSrcweir                     OUString aString = aConvertedAttribs[sAlgorithmNameAttribute];
201cdf0e10cSrcweir                     if ( aString.equals( sBlowfish_Name ) || aString.equals( sBlowfish_URL ) )
202cdf0e10cSrcweir                     {
203cdf0e10cSrcweir                         aSequence[nNumProperty].Name = sEncryptionAlgProperty;
204cdf0e10cSrcweir                         aSequence[nNumProperty++].Value <<= xml::crypto::CipherID::BLOWFISH_CFB_8;
205cdf0e10cSrcweir                     }
206cdf0e10cSrcweir                     else if ( aString.equals( sAES256_URL ) )
207cdf0e10cSrcweir                     {
208cdf0e10cSrcweir                         aSequence[nNumProperty].Name = sEncryptionAlgProperty;
209cdf0e10cSrcweir                         aSequence[nNumProperty++].Value <<= xml::crypto::CipherID::AES_CBC_W3C_PADDING;
210cdf0e10cSrcweir                         OSL_ENSURE( !nDerivedKeySize || nDerivedKeySize == 32, "Unexpected derived key length!" );
211cdf0e10cSrcweir                         nDerivedKeySize = 32;
212cdf0e10cSrcweir                     }
213cdf0e10cSrcweir                     else if ( aString.equals( sAES192_URL ) )
214cdf0e10cSrcweir                     {
215cdf0e10cSrcweir                         aSequence[nNumProperty].Name = sEncryptionAlgProperty;
216cdf0e10cSrcweir                         aSequence[nNumProperty++].Value <<= xml::crypto::CipherID::AES_CBC_W3C_PADDING;
217cdf0e10cSrcweir                         OSL_ENSURE( !nDerivedKeySize || nDerivedKeySize == 24, "Unexpected derived key length!" );
218cdf0e10cSrcweir                         nDerivedKeySize = 24;
219cdf0e10cSrcweir                     }
220cdf0e10cSrcweir                     else if ( aString.equals( sAES128_URL ) )
221cdf0e10cSrcweir                     {
222cdf0e10cSrcweir                         aSequence[nNumProperty].Name = sEncryptionAlgProperty;
223cdf0e10cSrcweir                         aSequence[nNumProperty++].Value <<= xml::crypto::CipherID::AES_CBC_W3C_PADDING;
224cdf0e10cSrcweir                         OSL_ENSURE( !nDerivedKeySize || nDerivedKeySize == 16, "Unexpected derived key length!" );
225cdf0e10cSrcweir                         nDerivedKeySize = 16;
226cdf0e10cSrcweir                     }
227cdf0e10cSrcweir                     else
228cdf0e10cSrcweir                         bIgnoreEncryptData = sal_True;
229cdf0e10cSrcweir 
230cdf0e10cSrcweir                     if ( !bIgnoreEncryptData )
231cdf0e10cSrcweir                     {
232cdf0e10cSrcweir                         aString = aConvertedAttribs[sInitialisationVectorAttribute];
233cdf0e10cSrcweir                         uno::Sequence < sal_Int8 > aDecodeBuffer;
234cdf0e10cSrcweir                         Base64Codec::decodeBase64 ( aDecodeBuffer, aString );
235cdf0e10cSrcweir                         aSequence[nNumProperty].Name = sInitialisationVectorProperty;
236cdf0e10cSrcweir                         aSequence[nNumProperty++].Value <<= aDecodeBuffer;
237cdf0e10cSrcweir                     }
238cdf0e10cSrcweir                 }
239cdf0e10cSrcweir             }
240cdf0e10cSrcweir             else if ( aConvertedName == sKeyDerivationElement )
241cdf0e10cSrcweir             {
242cdf0e10cSrcweir                 if ( !bIgnoreEncryptData )
243cdf0e10cSrcweir                 {
244cdf0e10cSrcweir                     OUString aString = aConvertedAttribs[sKeyDerivationNameAttribute];
245cdf0e10cSrcweir                     if ( aString.equals( sPBKDF2_Name ) || aString.equals( sPBKDF2_URL ) )
246cdf0e10cSrcweir                     {
247cdf0e10cSrcweir                         aString = aConvertedAttribs[sSaltAttribute];
248cdf0e10cSrcweir                         uno::Sequence < sal_Int8 > aDecodeBuffer;
249cdf0e10cSrcweir                         Base64Codec::decodeBase64 ( aDecodeBuffer, aString );
250cdf0e10cSrcweir                         aSequence[nNumProperty].Name = sSaltProperty;
251cdf0e10cSrcweir                         aSequence[nNumProperty++].Value <<= aDecodeBuffer;
252cdf0e10cSrcweir 
253cdf0e10cSrcweir                         aString = aConvertedAttribs[sIterationCountAttribute];
254cdf0e10cSrcweir                         aSequence[nNumProperty].Name = sIterationCountProperty;
255cdf0e10cSrcweir                         aSequence[nNumProperty++].Value <<= aString.toInt32();
256cdf0e10cSrcweir 
257cdf0e10cSrcweir                         aString = aConvertedAttribs[sKeySizeAttribute];
258cdf0e10cSrcweir                         if ( aString.getLength() )
259cdf0e10cSrcweir                         {
260cdf0e10cSrcweir                             sal_Int32 nKey = aString.toInt32();
261cdf0e10cSrcweir                             OSL_ENSURE( !nDerivedKeySize || nKey == nDerivedKeySize , "Provided derived key length differs from the expected one!" );
262cdf0e10cSrcweir                             nDerivedKeySize = nKey;
263cdf0e10cSrcweir                         }
264cdf0e10cSrcweir                         else if ( !nDerivedKeySize )
265cdf0e10cSrcweir                             nDerivedKeySize = 16;
266cdf0e10cSrcweir                         else if ( nDerivedKeySize != 16 )
267cdf0e10cSrcweir                             OSL_ENSURE( sal_False, "Default derived key length differs from the expected one!" );
268cdf0e10cSrcweir 
269cdf0e10cSrcweir                         aSequence[nNumProperty].Name = sDerivedKeySizeProperty;
270cdf0e10cSrcweir                         aSequence[nNumProperty++].Value <<= nDerivedKeySize;
271cdf0e10cSrcweir                     }
272cdf0e10cSrcweir                     else
273cdf0e10cSrcweir                         bIgnoreEncryptData = sal_True;
274cdf0e10cSrcweir                 }
275cdf0e10cSrcweir             }
276cdf0e10cSrcweir             else if ( aConvertedName == sStartKeyAlgElement )
277cdf0e10cSrcweir             {
278cdf0e10cSrcweir                 OUString aString = aConvertedAttribs[sStartKeyAlgNameAttribute];
279cdf0e10cSrcweir                 if ( aString.equals( sSHA256_URL ) )
280cdf0e10cSrcweir                 {
281cdf0e10cSrcweir                     aSequence[nNumProperty].Name = sStartKeyAlgProperty;
282cdf0e10cSrcweir                     aSequence[nNumProperty++].Value <<= xml::crypto::DigestID::SHA256;
283cdf0e10cSrcweir                 }
284cdf0e10cSrcweir                 else if ( aString.equals( sSHA1_Name ) || aString.equals( sSHA1_URL ) )
285cdf0e10cSrcweir                 {
286cdf0e10cSrcweir                     aSequence[nNumProperty].Name = sStartKeyAlgProperty;
287cdf0e10cSrcweir                     aSequence[nNumProperty++].Value <<= xml::crypto::DigestID::SHA1;
288cdf0e10cSrcweir                 }
289cdf0e10cSrcweir                 else
290cdf0e10cSrcweir                     bIgnoreEncryptData = sal_True;
291cdf0e10cSrcweir             }
292cdf0e10cSrcweir         }
293cdf0e10cSrcweir     }
294cdf0e10cSrcweir }
295cdf0e10cSrcweir 
296cdf0e10cSrcweir // ---------------------------------------------------
297cdf0e10cSrcweir void SAL_CALL ManifestImport::endElement( const OUString& aName )
298cdf0e10cSrcweir     throw( xml::sax::SAXException, uno::RuntimeException )
299cdf0e10cSrcweir {
300cdf0e10cSrcweir     ::rtl::OUString aConvertedName = ConvertName( aName );
301cdf0e10cSrcweir     if ( !aStack.empty() && aStack.rbegin()->m_aConvertedName.equals( aConvertedName ) )
302cdf0e10cSrcweir     {
303cdf0e10cSrcweir         if ( aConvertedName.equals( sFileEntryElement ) )
304cdf0e10cSrcweir         {
305cdf0e10cSrcweir             aSequence.realloc ( nNumProperty );
306cdf0e10cSrcweir             bIgnoreEncryptData = sal_False;
307cdf0e10cSrcweir             rManVector.push_back ( aSequence );
308cdf0e10cSrcweir             nNumProperty = 0;
309cdf0e10cSrcweir         }
310cdf0e10cSrcweir 
311cdf0e10cSrcweir         aStack.pop_back();
312cdf0e10cSrcweir     }
313cdf0e10cSrcweir }
314cdf0e10cSrcweir 
315cdf0e10cSrcweir // ---------------------------------------------------
316cdf0e10cSrcweir void SAL_CALL ManifestImport::characters( const OUString& /*aChars*/ )
317cdf0e10cSrcweir         throw( xml::sax::SAXException, uno::RuntimeException )
318cdf0e10cSrcweir {
319cdf0e10cSrcweir }
320cdf0e10cSrcweir 
321cdf0e10cSrcweir // ---------------------------------------------------
322cdf0e10cSrcweir void SAL_CALL ManifestImport::ignorableWhitespace( const OUString& /*aWhitespaces*/ )
323cdf0e10cSrcweir         throw( xml::sax::SAXException, uno::RuntimeException )
324cdf0e10cSrcweir {
325cdf0e10cSrcweir }
326cdf0e10cSrcweir 
327cdf0e10cSrcweir // ---------------------------------------------------
328cdf0e10cSrcweir void SAL_CALL ManifestImport::processingInstruction( const OUString& /*aTarget*/, const OUString& /*aData*/ )
329cdf0e10cSrcweir         throw( xml::sax::SAXException, uno::RuntimeException )
330cdf0e10cSrcweir {
331cdf0e10cSrcweir }
332cdf0e10cSrcweir 
333cdf0e10cSrcweir // ---------------------------------------------------
334cdf0e10cSrcweir void SAL_CALL ManifestImport::setDocumentLocator( const uno::Reference< xml::sax::XLocator >& /*xLocator*/ )
335cdf0e10cSrcweir         throw( xml::sax::SAXException, uno::RuntimeException )
336cdf0e10cSrcweir {
337cdf0e10cSrcweir }
338cdf0e10cSrcweir 
339cdf0e10cSrcweir // ---------------------------------------------------
340cdf0e10cSrcweir ::rtl::OUString ManifestImport::PushNameAndNamespaces( const ::rtl::OUString& aName, const uno::Reference< xml::sax::XAttributeList >& xAttribs, StringHashMap& o_aConvertedAttribs )
341cdf0e10cSrcweir {
342cdf0e10cSrcweir     StringHashMap aNamespaces;
343cdf0e10cSrcweir     ::std::vector< ::std::pair< ::rtl::OUString, ::rtl::OUString > > aAttribsStrs;
344cdf0e10cSrcweir 
345cdf0e10cSrcweir     if ( xAttribs.is() )
346cdf0e10cSrcweir     {
347cdf0e10cSrcweir         sal_Int16 nAttrCount = xAttribs.is() ? xAttribs->getLength() : 0;
348cdf0e10cSrcweir         aAttribsStrs.reserve( nAttrCount );
349cdf0e10cSrcweir 
350cdf0e10cSrcweir         for( sal_Int16 nInd = 0; nInd < nAttrCount; nInd++ )
351cdf0e10cSrcweir         {
352cdf0e10cSrcweir             ::rtl::OUString aAttrName = xAttribs->getNameByIndex( nInd );
353cdf0e10cSrcweir             ::rtl::OUString aAttrValue = xAttribs->getValueByIndex( nInd );
354cdf0e10cSrcweir             if ( aAttrName.getLength() >= 5
355cdf0e10cSrcweir               && aAttrName.compareToAscii( "xmlns", 5 ) == 0
356cdf0e10cSrcweir               && ( aAttrName.getLength() == 5 || aAttrName.getStr()[5] == ( sal_Unicode )':' ) )
357cdf0e10cSrcweir             {
358cdf0e10cSrcweir                 // this is a namespace declaration
359cdf0e10cSrcweir                 ::rtl::OUString aNsName( ( aAttrName.getLength() == 5 ) ? ::rtl::OUString() : aAttrName.copy( 6 ) );
360cdf0e10cSrcweir                 aNamespaces[aNsName] = aAttrValue;
361cdf0e10cSrcweir             }
362cdf0e10cSrcweir             else
363cdf0e10cSrcweir             {
364cdf0e10cSrcweir                 // this is no namespace declaration
365cdf0e10cSrcweir                 aAttribsStrs.push_back( pair< ::rtl::OUString, ::rtl::OUString >( aAttrName, aAttrValue ) );
366cdf0e10cSrcweir             }
367cdf0e10cSrcweir         }
368cdf0e10cSrcweir     }
369cdf0e10cSrcweir 
370cdf0e10cSrcweir     ::rtl::OUString aConvertedName = ConvertNameWithNamespace( aName, aNamespaces );
371cdf0e10cSrcweir     if ( !aConvertedName.getLength() )
372cdf0e10cSrcweir         aConvertedName = ConvertName( aName );
373cdf0e10cSrcweir 
374cdf0e10cSrcweir     aStack.push_back( ManifestScopeEntry( aConvertedName, aNamespaces ) );
375cdf0e10cSrcweir 
376cdf0e10cSrcweir     for ( sal_uInt16 nInd = 0; nInd < aAttribsStrs.size(); nInd++ )
377cdf0e10cSrcweir     {
378cdf0e10cSrcweir         // convert the attribute names on filling
379cdf0e10cSrcweir         o_aConvertedAttribs[ConvertName( aAttribsStrs[nInd].first )] = aAttribsStrs[nInd].second;
380cdf0e10cSrcweir     }
381cdf0e10cSrcweir 
382cdf0e10cSrcweir     return aConvertedName;
383cdf0e10cSrcweir }
384cdf0e10cSrcweir 
385cdf0e10cSrcweir // ---------------------------------------------------
386cdf0e10cSrcweir ::rtl::OUString ManifestImport::ConvertNameWithNamespace( const ::rtl::OUString& aName, const StringHashMap& aNamespaces )
387cdf0e10cSrcweir {
388cdf0e10cSrcweir     ::rtl::OUString aNsAlias;
389cdf0e10cSrcweir     ::rtl::OUString aPureName = aName;
390cdf0e10cSrcweir 
391cdf0e10cSrcweir     sal_Int32 nInd = aName.indexOf( ( sal_Unicode )':' );
392cdf0e10cSrcweir     if ( nInd != -1 && nInd < aName.getLength() )
393cdf0e10cSrcweir     {
394cdf0e10cSrcweir         aNsAlias = aName.copy( 0, nInd );
395cdf0e10cSrcweir         aPureName = aName.copy( nInd + 1 );
396cdf0e10cSrcweir     }
397cdf0e10cSrcweir 
398cdf0e10cSrcweir     ::rtl::OUString aResult;
399cdf0e10cSrcweir 
400cdf0e10cSrcweir     StringHashMap::const_iterator aIter = aNamespaces.find( aNsAlias );
401cdf0e10cSrcweir     if ( aIter != aNamespaces.end()
402cdf0e10cSrcweir       && ( aIter->second.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MANIFEST_NAMESPACE ) ) )
403cdf0e10cSrcweir         || aIter->second.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MANIFEST_OASIS_NAMESPACE ) ) ) ) )
404cdf0e10cSrcweir     {
405cdf0e10cSrcweir         // no check for manifest.xml consistency currently since the old versions have supported inconsistent documents as well
406cdf0e10cSrcweir         aResult = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MANIFEST_NSPREFIX ) );
407cdf0e10cSrcweir         aResult += aPureName;
408cdf0e10cSrcweir     }
409cdf0e10cSrcweir 
410cdf0e10cSrcweir     return aResult;
411cdf0e10cSrcweir }
412cdf0e10cSrcweir 
413cdf0e10cSrcweir // ---------------------------------------------------
414cdf0e10cSrcweir ::rtl::OUString ManifestImport::ConvertName( const ::rtl::OUString& aName )
415cdf0e10cSrcweir {
416cdf0e10cSrcweir     ::rtl::OUString aConvertedName;
417cdf0e10cSrcweir     for ( ManifestStack::reverse_iterator aIter = aStack.rbegin(); !aConvertedName.getLength() && aIter != aStack.rend(); aIter++ )
418cdf0e10cSrcweir     {
419cdf0e10cSrcweir         if ( !aIter->m_aNamespaces.empty() )
420cdf0e10cSrcweir             aConvertedName = ConvertNameWithNamespace( aName, aIter->m_aNamespaces );
421cdf0e10cSrcweir     }
422cdf0e10cSrcweir 
423cdf0e10cSrcweir     if ( !aConvertedName.getLength() )
424cdf0e10cSrcweir         aConvertedName = aName;
425cdf0e10cSrcweir 
426cdf0e10cSrcweir     return aConvertedName;
427cdf0e10cSrcweir }
428cdf0e10cSrcweir 
429