diff options
-rw-r--r-- | package/source/manifest/ManifestImport.cxx | 134 |
1 files changed, 87 insertions, 47 deletions
diff --git a/package/source/manifest/ManifestImport.cxx b/package/source/manifest/ManifestImport.cxx index b163ba09eff8..40c82ef5f744 100644 --- a/package/source/manifest/ManifestImport.cxx +++ b/package/source/manifest/ManifestImport.cxx @@ -2,9 +2,9 @@ * * $RCSfile: ManifestImport.cxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: mtg $ $Date: 2001-04-27 14:56:05 $ + * last change: $Author: mtg $ $Date: 2001-05-08 13:55:13 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -77,6 +77,34 @@ using namespace std; ManifestImport::ManifestImport( vector < Sequence < PropertyValue > > & rNewManVector ) : rManVector ( rNewManVector ) , nNumProperty (0) +, bIgnoreEncryptData ( sal_False ) + +, sFileEntryElement ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_FILE_ENTRY ) ) +, sManifestElement ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_MANIFEST ) ) +, sEncryptionDataElement( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_ENCRYPTION_DATA ) ) +, sAlgorithmElement ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_ALGORITHM ) ) +, sKeyDerivationElement( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_KEY_DERIVATION ) ) + +, sCdataAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_CDATA ) ) +, sMediaTypeAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_MEDIA_TYPE ) ) +, sFullPathAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_FULL_PATH ) ) +, sSizeAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_SIZE ) ) +, sSaltAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_SALT ) ) +, sInitialisationVectorAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_INITIALISATION_VECTOR ) ) +, sIterationCountAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_ITERATION_COUNT ) ) +, sAlgorithmNameAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_ALGORITHM_NAME ) ) +, sKeyDerivationNameAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_KEY_DERIVATION_NAME ) ) + +, sFullPathProperty ( RTL_CONSTASCII_USTRINGPARAM ( "FullPath" ) ) +, sMediaTypeProperty ( RTL_CONSTASCII_USTRINGPARAM ( "MediaType" ) ) +, sIterationCountProperty ( RTL_CONSTASCII_USTRINGPARAM ( "IterationCount" ) ) +, sSaltProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Salt" ) ) +, sInitialisationVectorProperty ( RTL_CONSTASCII_USTRINGPARAM ( "InitialisationVector" ) ) +, sSizeProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Size" ) ) + +, sWhiteSpace ( RTL_CONSTASCII_USTRINGPARAM ( " " ) ) +, sBlowfish ( RTL_CONSTASCII_USTRINGPARAM ( "Blowfish CFB" ) ) +, sPBKDF2 ( RTL_CONSTASCII_USTRINGPARAM ( "PBKDF2" ) ) { } ManifestImport::~ManifestImport (void ) @@ -93,54 +121,69 @@ void SAL_CALL ManifestImport::endDocument( ) void SAL_CALL ManifestImport::startElement( const OUString& aName, const uno::Reference< xml::sax::XAttributeList >& xAttribs ) throw(xml::sax::SAXException, uno::RuntimeException) { - static const OUString sEncryptionDataElement ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_ENCRYPTION_DATA ) ); - static const OUString sInitialisationVectorElement ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_INITIALISATION_VECTOR ) ); - static const OUString sAlgorithmAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_INITIALISATION_VECTOR ) ); - static const OUString sSaltAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_SALT ) ); - static const OUString sIterationCountAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_ITERATION_COUNT ) ); - static const OUString sManifestElement ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_MANIFEST ) ); - static const OUString sFileEntryElement ( RTL_CONSTASCII_USTRINGPARAM ( ELEMENT_FILE_ENTRY ) ); - static const OUString sCdataAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_CDATA ) ); - static const OUString sMediaTypeAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_MEDIA_TYPE ) ); - static const OUString sFullPathAttribute ( RTL_CONSTASCII_USTRINGPARAM ( ATTRIBUTE_FULL_PATH ) ); - static const OUString sMediaTypeProperty ( RTL_CONSTASCII_USTRINGPARAM ( "MediaType" ) ); - static const OUString sFullPathProperty ( RTL_CONSTASCII_USTRINGPARAM ( "FullPath" ) ); - static const OUString sSaltProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Salt" ) ); - static const OUString sAlgorithmProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Algorithm" ) ); - static const OUString sIterationCountProperty ( RTL_CONSTASCII_USTRINGPARAM ( "IterationCount" ) ); - if (aName == sFileEntryElement) { aStack.push( e_FileEntry ); - aSequence.realloc ( 2 ); - aSequence[0].Name = sMediaTypeProperty; - aSequence[0].Value <<= xAttribs->getValueByName( sMediaTypeAttribute ); - aSequence[1].Name = sFullPathProperty; - aSequence[1].Value <<= xAttribs->getValueByName( sFullPathAttribute ); - nNumProperty=2; + aSequence.realloc ( 6 ); // Can have at most 6 entries (currently, will realloc to actual number in endElement) + aSequence[nNumProperty].Name = sMediaTypeProperty; + aSequence[nNumProperty++].Value <<= xAttribs->getValueByName( sMediaTypeAttribute ); + aSequence[nNumProperty].Name = sFullPathProperty; + aSequence[nNumProperty++].Value <<= xAttribs->getValueByName( sFullPathAttribute ); + + OUString sSize = xAttribs->getValueByName ( sSizeAttribute ); + if (sSize.getLength()) + { + sal_Int32 nSize; + nSize = sSize.toInt32(); + aSequence[nNumProperty].Name = sSizeProperty; + aSequence[nNumProperty++].Value <<= nSize; + } } else if (!aStack.empty()) { if (aStack.top() == e_FileEntry && aName == sEncryptionDataElement) { - aSequence.realloc (nNumProperty+3); + // If this element exists, then this stream is encrypted and we need + // to store the initialisation vector, salt and iteration count used aStack.push (e_EncryptionData ); - aSequence[nNumProperty].Name = sAlgorithmProperty; - aSequence[nNumProperty].Value <<= xAttribs->getValueByName( sAlgorithmAttribute ); - aSequence[nNumProperty+1].Name = sSaltProperty; - OUString aString; - aString = xAttribs->getValueByName ( sSaltAttribute ); - Sequence < sal_Int8 > aDecodeBuffer; - Base64Codec::decodeBase64 (aDecodeBuffer, aString); - aSequence[nNumProperty+1].Value <<= aDecodeBuffer; - aSequence[nNumProperty+2].Name = sIterationCountProperty; - aSequence[nNumProperty+2].Value <<= xAttribs->getValueByName( sIterationCountAttribute ); - nNumProperty+=3; } - else if (aStack.top() == e_EncryptionData && aName == sInitialisationVectorElement) + else if (aStack.top() == e_EncryptionData && aName == sAlgorithmElement) { - aStack.push (e_InitialisationVector); - aSequence.realloc (++nNumProperty); + aStack.push (e_Algorithm); + OUString aString = xAttribs->getValueByName ( sAlgorithmNameAttribute ); + if (aString == sBlowfish && !bIgnoreEncryptData) + { + aString = xAttribs->getValueByName ( sInitialisationVectorAttribute ); + Sequence < sal_uInt8 > aDecodeBuffer; + Base64Codec::decodeBase64 (aDecodeBuffer, aString); + aSequence[nNumProperty].Name = sIterationCountProperty; + aSequence[nNumProperty++].Value <<= aDecodeBuffer; + } + else + // If we don't recognise the algorithm, then the key derivation info + // is useless to us + bIgnoreEncryptData = sal_True; + } + else if (aStack.top() == e_EncryptionData && aName == sKeyDerivationElement) + { + aStack.push (e_KeyDerivation); + OUString aString = xAttribs->getValueByName ( sKeyDerivationNameAttribute ); + if ( aString == sPBKDF2 && !bIgnoreEncryptData ) + { + aString = xAttribs->getValueByName ( sSaltAttribute ); + Sequence < sal_uInt8 > aDecodeBuffer; + Base64Codec::decodeBase64 (aDecodeBuffer, aString); + aSequence[nNumProperty].Name = sSaltProperty; + aSequence[nNumProperty++].Value <<= aDecodeBuffer; + + aString = xAttribs->getValueByName ( sIterationCountAttribute ); + aSequence[nNumProperty].Name = sIterationCountAttribute; + aSequence[nNumProperty++].Value <<= aString.toInt32(); + } + else + // If we don't recognise the key derivation technique, then the + // algorithm info is useless to us + bIgnoreEncryptData = sal_True; } } } @@ -150,21 +193,18 @@ void SAL_CALL ManifestImport::endElement( const OUString& aName ) if ( !aStack.empty() ) { if (aStack.top() == e_FileEntry) + { + aSequence.realloc ( nNumProperty ); + bIgnoreEncryptData = sal_False; rManVector.push_back ( aSequence ); + nNumProperty = 0; + } aStack.pop(); } } void SAL_CALL ManifestImport::characters( const OUString& aChars ) throw(xml::sax::SAXException, uno::RuntimeException) { - if (!aStack.empty() && aStack.top() == e_InitialisationVector) - { - const OUString sAlgorithmProperty ( RTL_CONSTASCII_USTRINGPARAM ( "Algorithm" ) ); - Sequence < sal_Int8 > aDecodeBuffer; - Base64Codec::decodeBase64 (aDecodeBuffer, aChars); - aSequence[nNumProperty-1].Name = sAlgorithmProperty; - aSequence[nNumProperty-1].Value <<= aDecodeBuffer; - } } void SAL_CALL ManifestImport::ignorableWhitespace( const OUString& aWhitespaces ) throw(xml::sax::SAXException, uno::RuntimeException) |