[Libreoffice-commits] .: Branch 'libreoffice-3-5' - 3 commits - package/inc package/source
Miklos Vajna
vmiklos at kemper.freedesktop.org
Fri Jun 8 06:35:33 PDT 2012
package/inc/PackageConstants.hxx | 24 -
package/source/manifest/ManifestImport.cxx | 377 ++++++++++++++++-------------
package/source/manifest/ManifestImport.hxx | 12
package/source/zipapi/ZipFile.cxx | 10
4 files changed, 249 insertions(+), 174 deletions(-)
New commits:
commit 353346a972aa981de0ecf1489a3d327f773f6a1e
Author: Caolán McNamara <caolanm at redhat.com>
Date: Mon May 28 11:43:09 2012 +0100
count and order of receipt of properties doesn't matter
so stick imported properties into assigned slots and throw out empty ones when
finished. Reuse existing ids for this between import and export. Shuffle
FULLPATH to 0 as per import comment
Change-Id: I516116c5327498ad043f6e2fb9bd257599ade2a2
Signed-off-by: Miklos Vajna <vmiklos at suse.cz>
diff --git a/package/inc/PackageConstants.hxx b/package/inc/PackageConstants.hxx
index be82010..7590acd 100644
--- a/package/inc/PackageConstants.hxx
+++ b/package/inc/PackageConstants.hxx
@@ -40,19 +40,19 @@ const sal_Int32 n_ConstDigestLength = 1024;
const sal_Int32 n_ConstDigestDecrypt = 1056; // 1024 + 32
// the constants related to the manifest.xml entries
-#define PKG_MNFST_MEDIATYPE 0
-#define PKG_MNFST_VERSION 1
-#define PKG_MNFST_FULLPATH 2
+#define PKG_MNFST_FULLPATH 0 //FullPath (Put full-path property first for MBA)
+#define PKG_MNFST_VERSION 1 //Version
+#define PKG_MNFST_MEDIATYPE 2 //MediaType
-#define PKG_MNFST_INIVECTOR 3
-#define PKG_MNFST_SALT 4
-#define PKG_MNFST_ITERATION 5
-#define PKG_MNFST_UCOMPSIZE 6
-#define PKG_MNFST_DIGEST 7
-#define PKG_MNFST_ENCALG 8
-#define PKG_MNFST_STARTALG 9
-#define PKG_MNFST_DIGESTALG 10
-#define PKG_MNFST_DERKEYSIZE 11
+#define PKG_MNFST_INIVECTOR 3 //InitialisationVector
+#define PKG_MNFST_SALT 4 //Salt
+#define PKG_MNFST_ITERATION 5 //IterationCount
+#define PKG_MNFST_UCOMPSIZE 6 //Size
+#define PKG_MNFST_DIGEST 7 //Digest
+#define PKG_MNFST_ENCALG 8 //EncryptionAlgorithm
+#define PKG_MNFST_STARTALG 9 //StartKeyAlgorithm
+#define PKG_MNFST_DIGESTALG 10 //DigestAlgorithm
+#define PKG_MNFST_DERKEYSIZE 11 //DerivedKeySize
#define PKG_SIZE_NOENCR_MNFST 3
#define PKG_SIZE_ENCR_MNFST 12
diff --git a/package/source/manifest/ManifestImport.cxx b/package/source/manifest/ManifestImport.cxx
index 1d7cd6c..0944d8e 100644
--- a/package/source/manifest/ManifestImport.cxx
+++ b/package/source/manifest/ManifestImport.cxx
@@ -44,8 +44,7 @@ using ::rtl::OUString;
// ---------------------------------------------------
ManifestImport::ManifestImport( vector < Sequence < PropertyValue > > & rNewManVector )
-: nNumProperty ( 0 )
-, bIgnoreEncryptData ( sal_False )
+: bIgnoreEncryptData ( sal_False )
, nDerivedKeySize( 0 )
, rManVector ( rNewManVector )
@@ -126,28 +125,26 @@ void SAL_CALL ManifestImport::endDocument( )
void ManifestImport::doFileEntry(StringHashMap &rConvertedAttribs)
throw( uno::RuntimeException )
{
- aSequence.realloc ( PKG_SIZE_ENCR_MNFST );
+ aSequence.resize(PKG_SIZE_ENCR_MNFST);
- // Put full-path property first for MBA
- aSequence[nNumProperty].Name = sFullPathProperty;
- aSequence[nNumProperty++].Value <<= rConvertedAttribs[sFullPathAttribute];
- aSequence[nNumProperty].Name = sMediaTypeProperty;
- aSequence[nNumProperty++].Value <<= rConvertedAttribs[sMediaTypeAttribute];
+ aSequence[PKG_MNFST_FULLPATH].Name = sFullPathProperty;
+ aSequence[PKG_MNFST_FULLPATH].Value <<= rConvertedAttribs[sFullPathAttribute];
+ aSequence[PKG_MNFST_MEDIATYPE].Name = sMediaTypeProperty;
+ aSequence[PKG_MNFST_MEDIATYPE].Value <<= rConvertedAttribs[sMediaTypeAttribute];
OUString sVersion = rConvertedAttribs[sVersionAttribute];
if ( sVersion.getLength() )
{
- aSequence[nNumProperty].Name = sVersionProperty;
- aSequence[nNumProperty++].Value <<= sVersion;
+ aSequence[PKG_MNFST_VERSION].Name = sVersionProperty;
+ aSequence[PKG_MNFST_VERSION].Value <<= sVersion;
}
OUString sSize = rConvertedAttribs[sSizeAttribute];
if ( sSize.getLength() )
{
- sal_Int32 nSize;
- nSize = sSize.toInt32();
- aSequence[nNumProperty].Name = sSizeProperty;
- aSequence[nNumProperty++].Value <<= nSize;
+ sal_Int32 nSize = sSize.toInt32();
+ aSequence[PKG_MNFST_UCOMPSIZE].Name = sSizeProperty;
+ aSequence[PKG_MNFST_UCOMPSIZE].Value <<= nSize;
}
}
@@ -162,13 +159,13 @@ void ManifestImport::doEncryptionData(StringHashMap &rConvertedAttribs)
{
if ( aString.equals( sSHA1_1k_Name ) || aString.equals( sSHA1_1k_URL ) )
{
- aSequence[nNumProperty].Name = sDigestAlgProperty;
- aSequence[nNumProperty++].Value <<= xml::crypto::DigestID::SHA1_1K;
+ aSequence[PKG_MNFST_DIGESTALG].Name = sDigestAlgProperty;
+ aSequence[PKG_MNFST_DIGESTALG].Value <<= xml::crypto::DigestID::SHA1_1K;
}
else if ( aString.equals( sSHA256_1k_URL ) )
{
- aSequence[nNumProperty].Name = sDigestAlgProperty;
- aSequence[nNumProperty++].Value <<= xml::crypto::DigestID::SHA256_1K;
+ aSequence[PKG_MNFST_DIGESTALG].Name = sDigestAlgProperty;
+ aSequence[PKG_MNFST_DIGESTALG].Value <<= xml::crypto::DigestID::SHA256_1K;
}
else
bIgnoreEncryptData = sal_True;
@@ -178,8 +175,8 @@ void ManifestImport::doEncryptionData(StringHashMap &rConvertedAttribs)
aString = rConvertedAttribs[sChecksumAttribute];
uno::Sequence < sal_Int8 > aDecodeBuffer;
::sax::Converter::decodeBase64(aDecodeBuffer, aString);
- aSequence[nNumProperty].Name = sDigestProperty;
- aSequence[nNumProperty++].Value <<= aDecodeBuffer;
+ aSequence[PKG_MNFST_DIGEST].Name = sDigestProperty;
+ aSequence[PKG_MNFST_DIGEST].Value <<= aDecodeBuffer;
}
}
}
@@ -192,27 +189,27 @@ void ManifestImport::doAlgorithm(StringHashMap &rConvertedAttribs)
OUString aString = rConvertedAttribs[sAlgorithmNameAttribute];
if ( aString.equals( sBlowfish_Name ) || aString.equals( sBlowfish_URL ) )
{
- aSequence[nNumProperty].Name = sEncryptionAlgProperty;
- aSequence[nNumProperty++].Value <<= xml::crypto::CipherID::BLOWFISH_CFB_8;
+ aSequence[PKG_MNFST_ENCALG].Name = sEncryptionAlgProperty;
+ aSequence[PKG_MNFST_ENCALG].Value <<= xml::crypto::CipherID::BLOWFISH_CFB_8;
}
else if ( aString.equals( sAES256_URL ) )
{
- aSequence[nNumProperty].Name = sEncryptionAlgProperty;
- aSequence[nNumProperty++].Value <<= xml::crypto::CipherID::AES_CBC_W3C_PADDING;
+ aSequence[PKG_MNFST_ENCALG].Name = sEncryptionAlgProperty;
+ aSequence[PKG_MNFST_ENCALG].Value <<= xml::crypto::CipherID::AES_CBC_W3C_PADDING;
OSL_ENSURE( !nDerivedKeySize || nDerivedKeySize == 32, "Unexpected derived key length!" );
nDerivedKeySize = 32;
}
else if ( aString.equals( sAES192_URL ) )
{
- aSequence[nNumProperty].Name = sEncryptionAlgProperty;
- aSequence[nNumProperty++].Value <<= xml::crypto::CipherID::AES_CBC_W3C_PADDING;
+ aSequence[PKG_MNFST_ENCALG].Name = sEncryptionAlgProperty;
+ aSequence[PKG_MNFST_ENCALG].Value <<= xml::crypto::CipherID::AES_CBC_W3C_PADDING;
OSL_ENSURE( !nDerivedKeySize || nDerivedKeySize == 24, "Unexpected derived key length!" );
nDerivedKeySize = 24;
}
else if ( aString.equals( sAES128_URL ) )
{
- aSequence[nNumProperty].Name = sEncryptionAlgProperty;
- aSequence[nNumProperty++].Value <<= xml::crypto::CipherID::AES_CBC_W3C_PADDING;
+ aSequence[PKG_MNFST_ENCALG].Name = sEncryptionAlgProperty;
+ aSequence[PKG_MNFST_ENCALG].Value <<= xml::crypto::CipherID::AES_CBC_W3C_PADDING;
OSL_ENSURE( !nDerivedKeySize || nDerivedKeySize == 16, "Unexpected derived key length!" );
nDerivedKeySize = 16;
}
@@ -224,8 +221,8 @@ void ManifestImport::doAlgorithm(StringHashMap &rConvertedAttribs)
aString = rConvertedAttribs[sInitialisationVectorAttribute];
uno::Sequence < sal_Int8 > aDecodeBuffer;
::sax::Converter::decodeBase64(aDecodeBuffer, aString);
- aSequence[nNumProperty].Name = sInitialisationVectorProperty;
- aSequence[nNumProperty++].Value <<= aDecodeBuffer;
+ aSequence[PKG_MNFST_INIVECTOR].Name = sInitialisationVectorProperty;
+ aSequence[PKG_MNFST_INIVECTOR].Value <<= aDecodeBuffer;
}
}
}
@@ -241,12 +238,12 @@ void ManifestImport::doKeyDerivation(StringHashMap &rConvertedAttribs)
aString = rConvertedAttribs[sSaltAttribute];
uno::Sequence < sal_Int8 > aDecodeBuffer;
::sax::Converter::decodeBase64(aDecodeBuffer, aString);
- aSequence[nNumProperty].Name = sSaltProperty;
- aSequence[nNumProperty++].Value <<= aDecodeBuffer;
+ aSequence[PKG_MNFST_SALT].Name = sSaltProperty;
+ aSequence[PKG_MNFST_SALT].Value <<= aDecodeBuffer;
aString = rConvertedAttribs[sIterationCountAttribute];
- aSequence[nNumProperty].Name = sIterationCountProperty;
- aSequence[nNumProperty++].Value <<= aString.toInt32();
+ aSequence[PKG_MNFST_ITERATION].Name = sIterationCountProperty;
+ aSequence[PKG_MNFST_ITERATION].Value <<= aString.toInt32();
aString = rConvertedAttribs[sKeySizeAttribute];
if ( aString.getLength() )
@@ -260,8 +257,8 @@ void ManifestImport::doKeyDerivation(StringHashMap &rConvertedAttribs)
else if ( nDerivedKeySize != 16 )
OSL_ENSURE( sal_False, "Default derived key length differs from the expected one!" );
- aSequence[nNumProperty].Name = sDerivedKeySizeProperty;
- aSequence[nNumProperty++].Value <<= nDerivedKeySize;
+ aSequence[PKG_MNFST_DERKEYSIZE].Name = sDerivedKeySizeProperty;
+ aSequence[PKG_MNFST_DERKEYSIZE].Value <<= nDerivedKeySize;
}
else
bIgnoreEncryptData = sal_True;
@@ -274,13 +271,13 @@ void ManifestImport::doStartKeyAlg(StringHashMap &rConvertedAttribs)
OUString aString = rConvertedAttribs[sStartKeyAlgNameAttribute];
if ( aString.equals( sSHA256_URL ) )
{
- aSequence[nNumProperty].Name = sStartKeyAlgProperty;
- aSequence[nNumProperty++].Value <<= xml::crypto::DigestID::SHA256;
+ aSequence[PKG_MNFST_STARTALG].Name = sStartKeyAlgProperty;
+ aSequence[PKG_MNFST_STARTALG].Value <<= xml::crypto::DigestID::SHA256;
}
else if ( aString.equals( sSHA1_Name ) || aString.equals( sSHA1_URL ) )
{
- aSequence[nNumProperty].Name = sStartKeyAlgProperty;
- aSequence[nNumProperty++].Value <<= xml::crypto::DigestID::SHA1;
+ aSequence[PKG_MNFST_STARTALG].Name = sStartKeyAlgProperty;
+ aSequence[PKG_MNFST_STARTALG].Value <<= xml::crypto::DigestID::SHA1;
}
else
bIgnoreEncryptData = sal_True;
@@ -349,6 +346,14 @@ void SAL_CALL ManifestImport::startElement( const OUString& aName, const uno::Re
}
}
+namespace
+{
+ bool isEmpty(const com::sun::star::beans::PropertyValue &rProp)
+ {
+ return rProp.Name.isEmpty();
+ }
+}
+
// ---------------------------------------------------
void SAL_CALL ManifestImport::endElement( const OUString& aName )
throw( xml::sax::SAXException, uno::RuntimeException )
@@ -356,12 +361,16 @@ void SAL_CALL ManifestImport::endElement( const OUString& aName )
::rtl::OUString aConvertedName = ConvertName( aName );
if ( !aStack.empty() && aStack.rbegin()->m_aConvertedName.equals( aConvertedName ) )
{
- if ( aConvertedName.equals( sFileEntryElement ) )
+ if ( aConvertedName.equals( sFileEntryElement ) && aStack.back().m_bValid )
{
- aSequence.realloc ( nNumProperty );
+ com::sun::star::beans::PropertyValue aEmpty;
+ aSequence.erase(std::remove_if(aSequence.begin(), aSequence.end(),
+ isEmpty), aSequence.end());
+
bIgnoreEncryptData = sal_False;
- rManVector.push_back ( aSequence );
- nNumProperty = 0;
+ rManVector.push_back ( aSequence.getAsConstList() );
+
+ aSequence.clear();
}
aStack.pop_back();
diff --git a/package/source/manifest/ManifestImport.hxx b/package/source/manifest/ManifestImport.hxx
index 5681f45..68afefd 100644
--- a/package/source/manifest/ManifestImport.hxx
+++ b/package/source/manifest/ManifestImport.hxx
@@ -31,6 +31,7 @@
#include <cppuhelper/implbase1.hxx> // helper for implementations
#include <com/sun/star/xml/sax/XDocumentHandler.hpp>
+#include <comphelper/sequenceasvector.hxx>
#include <vector>
#include <HashMaps.hxx>
@@ -63,8 +64,7 @@ typedef ::std::vector< ManifestScopeEntry > ManifestStack;
class ManifestImport : public cppu::WeakImplHelper1 < com::sun::star::xml::sax::XDocumentHandler >
{
protected:
- com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue > aSequence;
- sal_Int16 nNumProperty;
+ comphelper::SequenceAsVector< com::sun::star::beans::PropertyValue > aSequence;
ManifestStack aStack;
sal_Bool bIgnoreEncryptData;
sal_Int32 nDerivedKeySize;
commit aaff60869472199b762e85167bba604cafe58666
Author: Caolán McNamara <caolanm at redhat.com>
Date: Mon May 28 10:35:31 2012 +0100
unwind manifest xml parser and follow tag hierarchy model
so we validate that each tag is inside the right parent
Change-Id: Ibc82aeaf6b409ef2fed7de0cd8f15c164da65e53
Signed-off-by: Miklos Vajna <vmiklos at suse.cz>
diff --git a/package/source/manifest/ManifestImport.cxx b/package/source/manifest/ManifestImport.cxx
index 8756081..1d7cd6c 100644
--- a/package/source/manifest/ManifestImport.cxx
+++ b/package/source/manifest/ManifestImport.cxx
@@ -123,177 +123,229 @@ 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 )
+void ManifestImport::doFileEntry(StringHashMap &rConvertedAttribs)
+ throw( uno::RuntimeException )
{
- StringHashMap aConvertedAttribs;
- ::rtl::OUString aConvertedName = PushNameAndNamespaces( aName, xAttribs, aConvertedAttribs );
+ aSequence.realloc ( PKG_SIZE_ENCR_MNFST );
- if ( aConvertedName == sFileEntryElement )
+ // Put full-path property first for MBA
+ aSequence[nNumProperty].Name = sFullPathProperty;
+ aSequence[nNumProperty++].Value <<= rConvertedAttribs[sFullPathAttribute];
+ aSequence[nNumProperty].Name = sMediaTypeProperty;
+ aSequence[nNumProperty++].Value <<= rConvertedAttribs[sMediaTypeAttribute];
+
+ OUString sVersion = rConvertedAttribs[sVersionAttribute];
+ if ( sVersion.getLength() )
{
- aSequence.realloc ( PKG_SIZE_ENCR_MNFST );
+ aSequence[nNumProperty].Name = sVersionProperty;
+ aSequence[nNumProperty++].Value <<= sVersion;
+ }
- // Put full-path property first for MBA
- aSequence[nNumProperty].Name = sFullPathProperty;
- aSequence[nNumProperty++].Value <<= aConvertedAttribs[sFullPathAttribute];
- aSequence[nNumProperty].Name = sMediaTypeProperty;
- aSequence[nNumProperty++].Value <<= aConvertedAttribs[sMediaTypeAttribute];
+ OUString sSize = rConvertedAttribs[sSizeAttribute];
+ if ( sSize.getLength() )
+ {
+ sal_Int32 nSize;
+ nSize = sSize.toInt32();
+ aSequence[nNumProperty].Name = sSizeProperty;
+ aSequence[nNumProperty++].Value <<= nSize;
+ }
+}
- OUString sVersion = aConvertedAttribs[sVersionAttribute];
- if ( sVersion.getLength() )
+void ManifestImport::doEncryptionData(StringHashMap &rConvertedAttribs)
+ throw( uno::RuntimeException )
+{
+ // If this element exists, then this stream is encrypted and we need
+ // to import the initialisation vector, salt and iteration count used
+ nDerivedKeySize = 0;
+ OUString aString = rConvertedAttribs[sChecksumTypeAttribute];
+ if ( !bIgnoreEncryptData )
+ {
+ if ( aString.equals( sSHA1_1k_Name ) || aString.equals( sSHA1_1k_URL ) )
+ {
+ aSequence[nNumProperty].Name = sDigestAlgProperty;
+ aSequence[nNumProperty++].Value <<= xml::crypto::DigestID::SHA1_1K;
+ }
+ else if ( aString.equals( sSHA256_1k_URL ) )
{
- aSequence[nNumProperty].Name = sVersionProperty;
- aSequence[nNumProperty++].Value <<= sVersion;
+ aSequence[nNumProperty].Name = sDigestAlgProperty;
+ aSequence[nNumProperty++].Value <<= xml::crypto::DigestID::SHA256_1K;
}
+ else
+ bIgnoreEncryptData = sal_True;
- OUString sSize = aConvertedAttribs[sSizeAttribute];
- if ( sSize.getLength() )
+ if ( !bIgnoreEncryptData )
{
- sal_Int32 nSize;
- nSize = sSize.toInt32();
- aSequence[nNumProperty].Name = sSizeProperty;
- aSequence[nNumProperty++].Value <<= nSize;
+ aString = rConvertedAttribs[sChecksumAttribute];
+ uno::Sequence < sal_Int8 > aDecodeBuffer;
+ ::sax::Converter::decodeBase64(aDecodeBuffer, aString);
+ aSequence[nNumProperty].Name = sDigestProperty;
+ aSequence[nNumProperty++].Value <<= aDecodeBuffer;
}
}
- else if ( aStack.size() > 1 )
+}
+
+void ManifestImport::doAlgorithm(StringHashMap &rConvertedAttribs)
+ throw( uno::RuntimeException )
+{
+ if ( !bIgnoreEncryptData )
{
- ManifestStack::reverse_iterator aIter = aStack.rbegin();
- ++aIter;
+ OUString aString = rConvertedAttribs[sAlgorithmNameAttribute];
+ if ( aString.equals( sBlowfish_Name ) || aString.equals( sBlowfish_URL ) )
+ {
+ aSequence[nNumProperty].Name = sEncryptionAlgProperty;
+ aSequence[nNumProperty++].Value <<= xml::crypto::CipherID::BLOWFISH_CFB_8;
+ }
+ else if ( aString.equals( sAES256_URL ) )
+ {
+ aSequence[nNumProperty].Name = sEncryptionAlgProperty;
+ aSequence[nNumProperty++].Value <<= xml::crypto::CipherID::AES_CBC_W3C_PADDING;
+ OSL_ENSURE( !nDerivedKeySize || nDerivedKeySize == 32, "Unexpected derived key length!" );
+ nDerivedKeySize = 32;
+ }
+ else if ( aString.equals( sAES192_URL ) )
+ {
+ aSequence[nNumProperty].Name = sEncryptionAlgProperty;
+ aSequence[nNumProperty++].Value <<= xml::crypto::CipherID::AES_CBC_W3C_PADDING;
+ OSL_ENSURE( !nDerivedKeySize || nDerivedKeySize == 24, "Unexpected derived key length!" );
+ nDerivedKeySize = 24;
+ }
+ else if ( aString.equals( sAES128_URL ) )
+ {
+ aSequence[nNumProperty].Name = sEncryptionAlgProperty;
+ aSequence[nNumProperty++].Value <<= xml::crypto::CipherID::AES_CBC_W3C_PADDING;
+ OSL_ENSURE( !nDerivedKeySize || nDerivedKeySize == 16, "Unexpected derived key length!" );
+ nDerivedKeySize = 16;
+ }
+ else
+ bIgnoreEncryptData = sal_True;
- if ( aIter->m_aConvertedName.equals( sFileEntryElement ) )
+ if ( !bIgnoreEncryptData )
{
- if ( aConvertedName.equals( sEncryptionDataElement ) )
- {
- // If this element exists, then this stream is encrypted and we need
- // to import the initialisation vector, salt and iteration count used
- nDerivedKeySize = 0;
- OUString aString = aConvertedAttribs[sChecksumTypeAttribute];
- if ( !bIgnoreEncryptData )
- {
- if ( aString.equals( sSHA1_1k_Name ) || aString.equals( sSHA1_1k_URL ) )
- {
- aSequence[nNumProperty].Name = sDigestAlgProperty;
- aSequence[nNumProperty++].Value <<= xml::crypto::DigestID::SHA1_1K;
- }
- else if ( aString.equals( sSHA256_1k_URL ) )
- {
- aSequence[nNumProperty].Name = sDigestAlgProperty;
- aSequence[nNumProperty++].Value <<= xml::crypto::DigestID::SHA256_1K;
- }
- else
- bIgnoreEncryptData = sal_True;
-
- if ( !bIgnoreEncryptData )
- {
- aString = aConvertedAttribs[sChecksumAttribute];
- uno::Sequence < sal_Int8 > aDecodeBuffer;
- ::sax::Converter::decodeBase64(aDecodeBuffer, aString);
- aSequence[nNumProperty].Name = sDigestProperty;
- aSequence[nNumProperty++].Value <<= aDecodeBuffer;
- }
- }
- }
+ aString = rConvertedAttribs[sInitialisationVectorAttribute];
+ uno::Sequence < sal_Int8 > aDecodeBuffer;
+ ::sax::Converter::decodeBase64(aDecodeBuffer, aString);
+ aSequence[nNumProperty].Name = sInitialisationVectorProperty;
+ aSequence[nNumProperty++].Value <<= aDecodeBuffer;
}
- else if ( aIter->m_aConvertedName.equals( sEncryptionDataElement ) )
+ }
+}
+
+void ManifestImport::doKeyDerivation(StringHashMap &rConvertedAttribs)
+ throw( uno::RuntimeException )
+{
+ if ( !bIgnoreEncryptData )
+ {
+ OUString aString = rConvertedAttribs[sKeyDerivationNameAttribute];
+ if ( aString.equals( sPBKDF2_Name ) || aString.equals( sPBKDF2_URL ) )
{
- if ( aConvertedName == sAlgorithmElement )
- {
- if ( !bIgnoreEncryptData )
- {
- OUString aString = aConvertedAttribs[sAlgorithmNameAttribute];
- if ( aString.equals( sBlowfish_Name ) || aString.equals( sBlowfish_URL ) )
- {
- aSequence[nNumProperty].Name = sEncryptionAlgProperty;
- aSequence[nNumProperty++].Value <<= xml::crypto::CipherID::BLOWFISH_CFB_8;
- }
- else if ( aString.equals( sAES256_URL ) )
- {
- aSequence[nNumProperty].Name = sEncryptionAlgProperty;
- aSequence[nNumProperty++].Value <<= xml::crypto::CipherID::AES_CBC_W3C_PADDING;
- OSL_ENSURE( !nDerivedKeySize || nDerivedKeySize == 32, "Unexpected derived key length!" );
- nDerivedKeySize = 32;
- }
- else if ( aString.equals( sAES192_URL ) )
- {
- aSequence[nNumProperty].Name = sEncryptionAlgProperty;
- aSequence[nNumProperty++].Value <<= xml::crypto::CipherID::AES_CBC_W3C_PADDING;
- OSL_ENSURE( !nDerivedKeySize || nDerivedKeySize == 24, "Unexpected derived key length!" );
- nDerivedKeySize = 24;
- }
- else if ( aString.equals( sAES128_URL ) )
- {
- aSequence[nNumProperty].Name = sEncryptionAlgProperty;
- aSequence[nNumProperty++].Value <<= xml::crypto::CipherID::AES_CBC_W3C_PADDING;
- OSL_ENSURE( !nDerivedKeySize || nDerivedKeySize == 16, "Unexpected derived key length!" );
- nDerivedKeySize = 16;
- }
- else
- bIgnoreEncryptData = sal_True;
-
- if ( !bIgnoreEncryptData )
- {
- aString = aConvertedAttribs[sInitialisationVectorAttribute];
- uno::Sequence < sal_Int8 > aDecodeBuffer;
- ::sax::Converter::decodeBase64(aDecodeBuffer, aString);
- aSequence[nNumProperty].Name = sInitialisationVectorProperty;
- aSequence[nNumProperty++].Value <<= aDecodeBuffer;
- }
- }
- }
- else if ( aConvertedName == sKeyDerivationElement )
+ aString = rConvertedAttribs[sSaltAttribute];
+ uno::Sequence < sal_Int8 > aDecodeBuffer;
+ ::sax::Converter::decodeBase64(aDecodeBuffer, aString);
+ aSequence[nNumProperty].Name = sSaltProperty;
+ aSequence[nNumProperty++].Value <<= aDecodeBuffer;
+
+ aString = rConvertedAttribs[sIterationCountAttribute];
+ aSequence[nNumProperty].Name = sIterationCountProperty;
+ aSequence[nNumProperty++].Value <<= aString.toInt32();
+
+ aString = rConvertedAttribs[sKeySizeAttribute];
+ if ( aString.getLength() )
{
- if ( !bIgnoreEncryptData )
- {
- OUString aString = aConvertedAttribs[sKeyDerivationNameAttribute];
- if ( aString.equals( sPBKDF2_Name ) || aString.equals( sPBKDF2_URL ) )
- {
- aString = aConvertedAttribs[sSaltAttribute];
- uno::Sequence < sal_Int8 > aDecodeBuffer;
- ::sax::Converter::decodeBase64(aDecodeBuffer, aString);
- aSequence[nNumProperty].Name = sSaltProperty;
- aSequence[nNumProperty++].Value <<= aDecodeBuffer;
-
- aString = aConvertedAttribs[sIterationCountAttribute];
- aSequence[nNumProperty].Name = sIterationCountProperty;
- aSequence[nNumProperty++].Value <<= aString.toInt32();
-
- aString = aConvertedAttribs[sKeySizeAttribute];
- if ( aString.getLength() )
- {
- sal_Int32 nKey = aString.toInt32();
- OSL_ENSURE( !nDerivedKeySize || nKey == nDerivedKeySize , "Provided derived key length differs from the expected one!" );
- nDerivedKeySize = nKey;
- }
- else if ( !nDerivedKeySize )
- nDerivedKeySize = 16;
- else if ( nDerivedKeySize != 16 )
- OSL_ENSURE( sal_False, "Default derived key length differs from the expected one!" );
-
- aSequence[nNumProperty].Name = sDerivedKeySizeProperty;
- aSequence[nNumProperty++].Value <<= nDerivedKeySize;
- }
- else
- bIgnoreEncryptData = sal_True;
- }
- }
- else if ( aConvertedName == sStartKeyAlgElement )
- {
- OUString aString = aConvertedAttribs[sStartKeyAlgNameAttribute];
- if ( aString.equals( sSHA256_URL ) )
- {
- aSequence[nNumProperty].Name = sStartKeyAlgProperty;
- aSequence[nNumProperty++].Value <<= xml::crypto::DigestID::SHA256;
- }
- else if ( aString.equals( sSHA1_Name ) || aString.equals( sSHA1_URL ) )
- {
- aSequence[nNumProperty].Name = sStartKeyAlgProperty;
- aSequence[nNumProperty++].Value <<= xml::crypto::DigestID::SHA1;
- }
- else
- bIgnoreEncryptData = sal_True;
+ sal_Int32 nKey = aString.toInt32();
+ OSL_ENSURE( !nDerivedKeySize || nKey == nDerivedKeySize , "Provided derived key length differs from the expected one!" );
+ nDerivedKeySize = nKey;
}
+ else if ( !nDerivedKeySize )
+ nDerivedKeySize = 16;
+ else if ( nDerivedKeySize != 16 )
+ OSL_ENSURE( sal_False, "Default derived key length differs from the expected one!" );
+
+ aSequence[nNumProperty].Name = sDerivedKeySizeProperty;
+ aSequence[nNumProperty++].Value <<= nDerivedKeySize;
+ }
+ else
+ bIgnoreEncryptData = sal_True;
+ }
+}
+
+void ManifestImport::doStartKeyAlg(StringHashMap &rConvertedAttribs)
+ throw( uno::RuntimeException )
+{
+ OUString aString = rConvertedAttribs[sStartKeyAlgNameAttribute];
+ if ( aString.equals( sSHA256_URL ) )
+ {
+ aSequence[nNumProperty].Name = sStartKeyAlgProperty;
+ aSequence[nNumProperty++].Value <<= xml::crypto::DigestID::SHA256;
+ }
+ else if ( aString.equals( sSHA1_Name ) || aString.equals( sSHA1_URL ) )
+ {
+ aSequence[nNumProperty].Name = sStartKeyAlgProperty;
+ aSequence[nNumProperty++].Value <<= xml::crypto::DigestID::SHA1;
+ }
+ else
+ bIgnoreEncryptData = sal_True;
+}
+
+// ---------------------------------------------------
+void SAL_CALL ManifestImport::startElement( const OUString& aName, const uno::Reference< xml::sax::XAttributeList >& xAttribs )
+ throw( xml::sax::SAXException, uno::RuntimeException )
+{
+ StringHashMap aConvertedAttribs;
+ ::rtl::OUString aConvertedName = PushNameAndNamespaces( aName, xAttribs, aConvertedAttribs );
+
+ size_t nLevel = aStack.size();
+
+ assert(nLevel >= 1);
+
+ switch (nLevel)
+ {
+ case 1:
+ {
+ if (!aConvertedName.equalsAscii(ELEMENT_MANIFEST)) //manifest:manifest
+ aStack.back().m_bValid = false;
+ break;
+ }
+ case 2:
+ {
+ if (aConvertedName == sFileEntryElement) //manifest:file-entry
+ doFileEntry(aConvertedAttribs);
+ else
+ aStack.back().m_bValid = false;
+ break;
+ }
+ case 3:
+ {
+ ManifestStack::reverse_iterator aIter = aStack.rbegin();
+ ++aIter;
+
+ if (!aIter->m_bValid)
+ aStack.back().m_bValid = false;
+ else if (aConvertedName.equals(sEncryptionDataElement)) //manifest:encryption-data
+ doEncryptionData(aConvertedAttribs);
+ else
+ aStack.back().m_bValid = false;
+ break;
+ }
+ case 4:
+ {
+ ManifestStack::reverse_iterator aIter = aStack.rbegin();
+ ++aIter;
+
+ if (!aIter->m_bValid)
+ aStack.back().m_bValid = false;
+ else if (aConvertedName.equals(sAlgorithmElement)) //manifest:algorithm,
+ doAlgorithm(aConvertedAttribs);
+ else if (aConvertedName.equals(sKeyDerivationElement)) //manifest:key-derivation,
+ doKeyDerivation(aConvertedAttribs);
+ else if (aConvertedName.equals(sStartKeyAlgElement)) //manifest:start-key-generation
+ doStartKeyAlg(aConvertedAttribs);
+ else
+ aStack.back().m_bValid = false;
+ break;
}
+ default:
+ aStack.back().m_bValid = false;
+ break;
}
}
diff --git a/package/source/manifest/ManifestImport.hxx b/package/source/manifest/ManifestImport.hxx
index 1c646a7..5681f45 100644
--- a/package/source/manifest/ManifestImport.hxx
+++ b/package/source/manifest/ManifestImport.hxx
@@ -46,10 +46,12 @@ struct ManifestScopeEntry
{
::rtl::OUString m_aConvertedName;
StringHashMap m_aNamespaces;
+ bool m_bValid;
ManifestScopeEntry( const ::rtl::OUString& aConvertedName, const StringHashMap& aNamespaces )
: m_aConvertedName( aConvertedName )
, m_aNamespaces( aNamespaces )
+ , m_bValid( true )
{}
~ManifestScopeEntry()
@@ -148,6 +150,12 @@ public:
throw(::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
virtual void SAL_CALL setDocumentLocator( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XLocator >& xLocator )
throw(::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
+private:
+ void doFileEntry(StringHashMap &rConvertedAttribs) throw(::com::sun::star::uno::RuntimeException);
+ void doEncryptionData(StringHashMap &rConvertedAttribs) throw(::com::sun::star::uno::RuntimeException);
+ void doAlgorithm(StringHashMap &rConvertedAttribs) throw(::com::sun::star::uno::RuntimeException);
+ void doKeyDerivation(StringHashMap &rConvertedAttribs) throw(::com::sun::star::uno::RuntimeException);
+ void doStartKeyAlg(StringHashMap &rConvertedAttribs) throw(::com::sun::star::uno::RuntimeException);
};
#endif
commit 87a66665bd3cd77d8cbbd0ae27f933d5bb78ce6e
Author: Caolán McNamara <caolanm at redhat.com>
Date: Mon May 28 10:33:40 2012 +0100
check key size
Change-Id: Ia909b0abb3ef84a9f0a14d42379f693ae9e70812
Signed-off-by: Miklos Vajna <vmiklos at suse.cz>
diff --git a/package/source/zipapi/ZipFile.cxx b/package/source/zipapi/ZipFile.cxx
index 16d5a00..f154dfe 100644
--- a/package/source/zipapi/ZipFile.cxx
+++ b/package/source/zipapi/ZipFile.cxx
@@ -157,6 +157,12 @@ uno::Reference< xml::crypto::XCipherContext > ZipFile::StaticGetCipher( const un
try
{
+ if (xEncryptionData->m_nDerivedKeySize < 0)
+ {
+ throw ZipIOException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Invalid derived key length!") ),
+ uno::Reference< XInterface >() );
+ }
+
uno::Sequence< sal_Int8 > aDerivedKey( xEncryptionData->m_nDerivedKeySize );
if ( rtl_Digest_E_None != rtl_digest_PBKDF2( reinterpret_cast< sal_uInt8* >( aDerivedKey.getArray() ),
aDerivedKey.getLength(),
@@ -192,7 +198,7 @@ uno::Reference< xml::crypto::XCipherContext > ZipFile::StaticGetCipher( const un
uno::Reference< XInterface >() );
}
}
- catch( uno::Exception& )
+ catch( ... )
{
OSL_ENSURE( sal_False, "Can not create cipher context!" );
}
@@ -699,7 +705,7 @@ sal_Bool ZipFile::readLOC( ZipEntry &rEntry )
|| rEntry.nPathLen != nPathLen
|| !rEntry.sPath.equals( sLOCPath );
}
- catch(::std::bad_alloc &)
+ catch(...)
{
bBroken = sal_True;
}
More information about the Libreoffice-commits
mailing list