diff options
author | Frank Schoenheit [fs] <frank.schoenheit@oracle.com> | 2011-01-05 10:07:18 +0100 |
---|---|---|
committer | Frank Schoenheit [fs] <frank.schoenheit@oracle.com> | 2011-01-05 10:07:18 +0100 |
commit | a620f8a0d8995e9f211b8b70f67f3edd61e1bf2b (patch) | |
tree | 76356b36845ae48ce0c0804a46465571e933c0b1 /comphelper | |
parent | 255da0d3dc8891c9595c1bd65b93dda4c2d7b32e (diff) | |
parent | 7997ab5bac6fbdfe3b3427c322507a993d33acbc (diff) |
dba34b: merged DEV300m96
Diffstat (limited to 'comphelper')
-rw-r--r-- | comphelper/inc/comphelper/docpasswordhelper.hxx | 63 | ||||
-rw-r--r-- | comphelper/inc/comphelper/documentconstants.hxx | 38 | ||||
-rw-r--r-- | comphelper/inc/comphelper/mediadescriptor.hxx | 27 | ||||
-rw-r--r-- | comphelper/inc/comphelper/mimeconfighelper.hxx | 15 | ||||
-rw-r--r-- | comphelper/inc/comphelper/storagehelper.hxx | 11 | ||||
-rw-r--r-- | comphelper/prj/build.lst | 2 | ||||
-rw-r--r-- | comphelper/source/misc/docpasswordhelper.cxx | 152 | ||||
-rw-r--r-- | comphelper/source/misc/mediadescriptor.cxx | 42 | ||||
-rw-r--r-- | comphelper/source/misc/mimeconfighelper.cxx | 200 | ||||
-rw-r--r-- | comphelper/source/misc/storagehelper.cxx | 52 |
10 files changed, 499 insertions, 103 deletions
diff --git a/comphelper/inc/comphelper/docpasswordhelper.hxx b/comphelper/inc/comphelper/docpasswordhelper.hxx index dbbb68372a07..7e9f06318a26 100644 --- a/comphelper/inc/comphelper/docpasswordhelper.hxx +++ b/comphelper/inc/comphelper/docpasswordhelper.hxx @@ -28,6 +28,7 @@ #ifndef COMPHELPER_DOCPASSWORDHELPR_HXX #define COMPHELPER_DOCPASSWORDHELPR_HXX +#include <com/sun/star/beans/NamedValue.hpp> #include "comphelper/comphelperdllapi.h" #include <vector> #include "comphelper/docpasswordrequest.hxx" @@ -53,7 +54,7 @@ enum DocPasswordVerifierResult /** Base class for a password verifier used by the DocPasswordHelper class below. - Users have to implement the virtual function and pass an instance of the + Users have to implement the virtual functions and pass an instance of the verifier to one of the password request functions. */ class COMPHELPER_DLLPUBLIC IDocPasswordVerifier @@ -63,6 +64,14 @@ public: /** Will be called everytime a password needs to be verified. + @param rPassword + The password to be verified + + @param o_rEncryptionData + Output parameter, that is filled with the EncryptionData generated + from the password. The data is filled only if the validation was + successful. + @return The result of the verification. - DocPasswordVerifierResult_OK, if and only if the passed password is valid and can be used to process the related document. @@ -72,7 +81,23 @@ public: occured while password verification. The password request loop will be aborted. */ - virtual DocPasswordVerifierResult verifyPassword( const ::rtl::OUString& rPassword ) = 0; + virtual DocPasswordVerifierResult verifyPassword( const ::rtl::OUString& rPassword, ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& o_rEncryptionData ) = 0; + + /** Will be called everytime an encryption data needs to be verified. + + @param rEncryptionData + The data will be validated + + @return The result of the verification. + - DocPasswordVerifierResult_OK, if and only if the passed encryption data + is valid and can be used to process the related document. + - DocPasswordVerifierResult_WRONG_PASSWORD, if the encryption data is + wrong. + - DocPasswordVerifierResult_ABORT, if an unrecoverable error + occured while data verification. The password request loop + will be aborted. + */ + virtual DocPasswordVerifierResult verifyEncryptionData( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& o_rEncryptionData ) = 0; }; @@ -195,6 +220,35 @@ public: // ------------------------------------------------------------------------ + /** This helper function generates a random sequence of bytes of + requested length. + */ + + static ::com::sun::star::uno::Sequence< sal_Int8 > GenerateRandomByteSequence( + sal_Int32 nLength ); + + // ------------------------------------------------------------------------ + + /** This helper function generates a byte sequence representing the + key digest value used by MSCodec_Std97 codec. + */ + + static ::com::sun::star::uno::Sequence< sal_Int8 > GenerateStd97Key( + const ::rtl::OUString& aPassword, + const ::com::sun::star::uno::Sequence< sal_Int8 >& aDocId ); + + // ------------------------------------------------------------------------ + + /** This helper function generates a byte sequence representing the + key digest value used by MSCodec_Std97 codec. + */ + + static ::com::sun::star::uno::Sequence< sal_Int8 > GenerateStd97Key( + const sal_uInt16 pPassData[16], + const ::com::sun::star::uno::Sequence< sal_Int8 >& aDocId ); + + // ------------------------------------------------------------------------ + /** This helper function tries to request and verify a password to load a protected document. @@ -248,8 +302,9 @@ public: passed password verifier. If empty, no valid password has been found, or the user has chossen to cancel password input. */ - static ::rtl::OUString requestAndVerifyDocPassword( + static ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > requestAndVerifyDocPassword( IDocPasswordVerifier& rVerifier, + const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& rMediaEncData, const ::rtl::OUString& rMediaPassword, const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& rxInteractHandler, @@ -300,7 +355,7 @@ public: passed password verifier. If empty, no valid password has been found, or the user has chossen to cancel password input. */ - static ::rtl::OUString requestAndVerifyDocPassword( + static ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > requestAndVerifyDocPassword( IDocPasswordVerifier& rVerifier, MediaDescriptor& rMediaDesc, DocPasswordRequestType eRequestType, diff --git a/comphelper/inc/comphelper/documentconstants.hxx b/comphelper/inc/comphelper/documentconstants.hxx index b78150586e28..73b90d72cc8a 100644 --- a/comphelper/inc/comphelper/documentconstants.hxx +++ b/comphelper/inc/comphelper/documentconstants.hxx @@ -111,3 +111,41 @@ #define ODFVER_012_TEXT ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ODFVER_012_TEXT_ASCII ) ) #endif +// filter flags +// TODO/LATER: The flags should be part of the UNO specification +#define SFX_FILTER_IMPORT 0x00000001L +#define SFX_FILTER_EXPORT 0x00000002L +#define SFX_FILTER_TEMPLATE 0x00000004L +#define SFX_FILTER_INTERNAL 0x00000008L +#define SFX_FILTER_TEMPLATEPATH 0x00000010L +#define SFX_FILTER_OWN 0x00000020L +#define SFX_FILTER_ALIEN 0x00000040L +#define SFX_FILTER_USESOPTIONS 0x00000080L + +#define SFX_FILTER_DEFAULT 0x00000100L +#define SFX_FILTER_EXECUTABLE 0x00000200L +#define SFX_FILTER_SUPPORTSSELECTION 0x00000400L +#define SFX_FILTER_MAPTOAPPPLUG 0x00000800L +#define SFX_FILTER_NOTINFILEDLG 0x00001000L +#define SFX_FILTER_NOTINCHOOSER 0x00002000L +#define SFX_FILTER_ASYNC 0x00004000L +#define SFX_FILTER_CREATOR 0x00008000L +#define SFX_FILTER_OPENREADONLY 0x00010000L +#define SFX_FILTER_MUSTINSTALL 0x00020000L +#define SFX_FILTER_CONSULTSERVICE 0x00040000L + +#define SFX_FILTER_STARONEFILTER 0x00080000L +#define SFX_FILTER_PACKED 0x00100000L +#define SFX_FILTER_SILENTEXPORT 0x00200000L + +#define SFX_FILTER_BROWSERPREFERED 0x00400000L + +#define SFX_FILTER_ENCRYPTION 0x01000000L +#define SFX_FILTER_PASSWORDTOMODIFY 0x02000000L + +#define SFX_FILTER_PREFERED 0x10000000L + +#define SFX_FILTER_VERSION_NONE 0 +#define SFX_FILTER_NOTINSTALLED SFX_FILTER_MUSTINSTALL | SFX_FILTER_CONSULTSERVICE + + diff --git a/comphelper/inc/comphelper/mediadescriptor.hxx b/comphelper/inc/comphelper/mediadescriptor.hxx index 7d2333045390..e92a6c4650f6 100644 --- a/comphelper/inc/comphelper/mediadescriptor.hxx +++ b/comphelper/inc/comphelper/mediadescriptor.hxx @@ -78,6 +78,7 @@ class COMPHELPER_DLLPUBLIC MediaDescriptor : public SequenceAsHashMap static const ::rtl::OUString& PROP_DEEPDETECTION(); static const ::rtl::OUString& PROP_DETECTSERVICE(); static const ::rtl::OUString& PROP_DOCUMENTSERVICE(); + static const ::rtl::OUString& PROP_ENCRYPTIONDATA(); static const ::rtl::OUString& PROP_EXTENSION(); static const ::rtl::OUString& PROP_FILENAME(); static const ::rtl::OUString& PROP_FILTERNAME(); @@ -127,10 +128,6 @@ class COMPHELPER_DLLPUBLIC MediaDescriptor : public SequenceAsHashMap //------------------------------------------- // interface public: - /** Value type of the 'ComponentData' property. - */ - typedef ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > ComponentDataSequence; - //--------------------------------------- /** @short these ctors do nothing - excepting that they forward the given parameters to the base class ctors. @@ -204,8 +201,9 @@ class COMPHELPER_DLLPUBLIC MediaDescriptor : public SequenceAsHashMap /** Returns a value from the sequence contained in the property 'ComponentData' of this media descriptor. - @descr The property 'ComponentData' should be empty or should - contain a value of type ComponentDataSequence (see above). + @descr The property 'ComponentData' should be empty, or should + contain a value of type sequence<com.sun.star.beans.NamedValue> + or sequence<com.sun.star.beans.PropertyValue>. @return The value with the specified name, if existing in the sequence of the 'ComponentData' property, otherwise an empty @@ -218,10 +216,11 @@ class COMPHELPER_DLLPUBLIC MediaDescriptor : public SequenceAsHashMap /** Inserts a value into the sequence contained in the property 'ComponentData' of the media descriptor. - @descr The property 'ComponentData' should be empty or should - contain a value of type ComponentDataSequence (see above). The - passed value will be inserted into the sequence, or, if already - existing, will be overwritten. + @descr The property 'ComponentData' should be empty, or should + contain a value of type sequence<com.sun.star.beans.NamedValue> + or sequence<com.sun.star.beans.PropertyValue>. The passed value + will be inserted into the sequence, or, if already existing, + will be overwritten. @param rName The name of the value to be inserted into the sequence of the 'ComponentData' property. @@ -237,10 +236,10 @@ class COMPHELPER_DLLPUBLIC MediaDescriptor : public SequenceAsHashMap /** Removes a value from the sequence contained in the property 'ComponentData' of the media descriptor. - @descr The property 'ComponentData' should be empty or should - contain a value of type ComponentDataSequence (see above). The - value with the passed name will be removed from the sequence, - if existing. + @descr The property 'ComponentData' should be empty, or should + contain a value of type sequence<com.sun.star.beans.NamedValue> + or sequence<com.sun.star.beans.PropertyValue>. The value with + the passed name will be removed from the sequence, if existing. @param rName The name of the value to be removed from the sequence of the 'ComponentData' property. diff --git a/comphelper/inc/comphelper/mimeconfighelper.hxx b/comphelper/inc/comphelper/mimeconfighelper.hxx index 5e02d4761cb1..16a0a159d5a4 100644 --- a/comphelper/inc/comphelper/mimeconfighelper.hxx +++ b/comphelper/inc/comphelper/mimeconfighelper.hxx @@ -32,6 +32,7 @@ #include <com/sun/star/uno/Sequence.hxx> #include <com/sun/star/lang/XMultiServiceFactory.hpp> #include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/container/XContainerQuery.hpp> #include <com/sun/star/beans/NamedValue.hpp> #include <com/sun/star/beans/PropertyValue.hpp> #include <com/sun/star/embed/VerbDescriptor.hpp> @@ -50,6 +51,8 @@ class COMPHELPER_DLLPUBLIC MimeConfigurationHelper ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > m_xVerbsConfig; ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > m_xMediaTypeConfig; + ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > m_xFilterFactory; + public: MimeConfigurationHelper( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory ); @@ -106,6 +109,10 @@ public: ::rtl::OUString GetFactoryNameByMediaType( const ::rtl::OUString& aMediaType ); // typedetection related + ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > GetFilterFactory(); + + sal_Int32 GetFilterFlags( const ::rtl::OUString& aFilterName ); + ::rtl::OUString UpdateMediaDescriptorWithFilterName( ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aMediaDescr, sal_Bool bIgnoreType ); @@ -117,6 +124,14 @@ public: ::rtl::OUString GetDefaultFilterFromServiceName( const ::rtl::OUString& aServName, sal_Int32 nVersion ); + ::rtl::OUString GetExportFilterFromImportFilter( const ::rtl::OUString& aImportFilterName ); + + static ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SearchForFilter( + const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerQuery >& xFilterQuery, + const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& aSearchRequest, + sal_Int32 nMustFlags, + sal_Int32 nDontFlags ); + static sal_Bool ClassIDsEqual( const ::com::sun::star::uno::Sequence< sal_Int8 >& aClassID1, const ::com::sun::star::uno::Sequence< sal_Int8 >& aClassID2 ); static ::com::sun::star::uno::Sequence< sal_Int8 > GetSequenceClassID( sal_uInt32 n1, sal_uInt16 n2, sal_uInt16 n3, diff --git a/comphelper/inc/comphelper/storagehelper.hxx b/comphelper/inc/comphelper/storagehelper.hxx index b7e5704c4d68..9d44b42e9514 100644 --- a/comphelper/inc/comphelper/storagehelper.hxx +++ b/comphelper/inc/comphelper/storagehelper.hxx @@ -33,6 +33,7 @@ #include <com/sun/star/lang/XSingleServiceFactory.hpp> #include <com/sun/star/embed/XStorage.hpp> #include <com/sun/star/embed/ElementModes.hpp> +#include <com/sun/star/beans/NamedValue.hpp> #include <com/sun/star/io/XInputStream.hpp> #include <com/sun/star/io/XOutputStream.hpp> #include <com/sun/star/io/XStream.hpp> @@ -43,6 +44,9 @@ #define ZIP_STORAGE_FORMAT_STRING ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ZipFormat" ) ) #define OFOPXML_STORAGE_FORMAT_STRING ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OFOPXMLFormat" ) ) +#define PACKAGE_ENCRYPTIONDATA_SHA1UTF8 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PackageSHA1UTF8EncryptionKey" ) ) +#define PACKAGE_ENCRYPTIONDATA_SHA1MS1252 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PackageSHA1MS1252EncryptionKey" ) ) + namespace comphelper { class COMPHELPER_DLLPUBLIC OStorageHelper @@ -112,9 +116,9 @@ public: = ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >() ) throw ( ::com::sun::star::uno::Exception ); - static void SetCommonStoragePassword( + static void SetCommonStorageEncryptionData( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage, - const ::rtl::OUString& aPass ) + const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& aEncryptionData ) throw ( ::com::sun::star::uno::Exception ); // the following method supports only storages of OOo formats @@ -159,6 +163,9 @@ public: sal_Bool bRepairStorage = sal_False ) throw ( ::com::sun::star::uno::Exception ); + static ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > + CreatePackageEncryptionData( const ::rtl::OUString& aPassword ); + static sal_Bool IsValidZipEntryFileName( const ::rtl::OUString& aName, sal_Bool bSlashAllowed ); static sal_Bool IsValidZipEntryFileName( const sal_Unicode *pChar, sal_Int32 nLength, sal_Bool bSlashAllowed ); diff --git a/comphelper/prj/build.lst b/comphelper/prj/build.lst index 793d8bf30e09..91e836cabd68 100644 --- a/comphelper/prj/build.lst +++ b/comphelper/prj/build.lst @@ -1,4 +1,4 @@ -ph comphelper : cppuhelper ucbhelper offuh vos salhelper NULL +ph comphelper : cppuhelper ucbhelper offuh vos salhelper LIBXSLT:libxslt NULL ph comphelper usr1 - all ph_mkout NULL ph comphelper\inc nmake - all ph_inc NULL ph comphelper\source\container nmake - all ph_container ph_inc NULL diff --git a/comphelper/source/misc/docpasswordhelper.cxx b/comphelper/source/misc/docpasswordhelper.cxx index 37941352ae28..3c8d66bd57e4 100644 --- a/comphelper/source/misc/docpasswordhelper.cxx +++ b/comphelper/source/misc/docpasswordhelper.cxx @@ -84,16 +84,9 @@ uno::Sequence< beans::PropertyValue > DocPasswordHelper::GenerateNewModifyPasswo { uno::Sequence< beans::PropertyValue > aResult; - uno::Sequence< sal_Int8 > aSalt( 16 ); + uno::Sequence< sal_Int8 > aSalt = GenerateRandomByteSequence( 16 ); sal_Int32 nCount = 1024; - TimeValue aTime; - osl_getSystemTime( &aTime ); - rtlRandomPool aRandomPool = rtl_random_createPool (); - rtl_random_addBytes ( aRandomPool, &aTime, 8 ); - - rtl_random_getBytes ( aRandomPool, aSalt.getArray(), 16 ); - uno::Sequence< sal_Int8 > aNewHash = GeneratePBKDF2Hash( aPassword, aSalt, nCount, 16 ); if ( aNewHash.getLength() ) { @@ -108,9 +101,6 @@ uno::Sequence< beans::PropertyValue > DocPasswordHelper::GenerateNewModifyPasswo aResult[3].Value <<= aNewHash; } - // Clean up random pool memory - rtl_random_destroyPool ( aRandomPool ); - return aResult; } @@ -282,9 +272,98 @@ Sequence< sal_Int8 > DocPasswordHelper::GetXLHashAsSequence( } // ============================================================================ +/*static*/ uno::Sequence< sal_Int8 > DocPasswordHelper::GenerateRandomByteSequence( sal_Int32 nLength ) +{ + uno::Sequence< sal_Int8 > aResult( nLength ); + + TimeValue aTime; + osl_getSystemTime( &aTime ); + rtlRandomPool aRandomPool = rtl_random_createPool (); + rtl_random_addBytes ( aRandomPool, &aTime, 8 ); + rtl_random_getBytes ( aRandomPool, aResult.getArray(), nLength ); + rtl_random_destroyPool ( aRandomPool ); -/*static*/ OUString DocPasswordHelper::requestAndVerifyDocPassword( + return aResult; +} + + +// ============================================================================ +/*static*/ uno::Sequence< sal_Int8 > DocPasswordHelper::GenerateStd97Key( const ::rtl::OUString& aPassword, const uno::Sequence< sal_Int8 >& aDocId ) +{ + uno::Sequence< sal_Int8 > aResultKey; + if ( aPassword.getLength() && aDocId.getLength() == 16 ) + { + sal_uInt16 pPassData[16]; + rtl_zeroMemory( pPassData, sizeof(pPassData) ); + + sal_Int32 nPassLen = ::std::min< sal_Int32 >( aPassword.getLength(), 15 ); + rtl_copyMemory( pPassData, aPassword.getStr(), nPassLen * sizeof(pPassData[0]) ); + + aResultKey = GenerateStd97Key( pPassData, aDocId ); + } + + return aResultKey; +} + +// ============================================================================ +/*static*/ uno::Sequence< sal_Int8 > DocPasswordHelper::GenerateStd97Key( const sal_uInt16 pPassData[16], const uno::Sequence< sal_Int8 >& aDocId ) +{ + uno::Sequence< sal_Int8 > aResultKey; + if ( pPassData[0] && aDocId.getLength() == 16 ) + { + sal_uInt8 pKeyData[64]; + rtl_zeroMemory( pKeyData, sizeof(pKeyData) ); + + sal_Int32 nInd = 0; + + // Fill PassData into KeyData. + for ( nInd = 0; nInd < 16 && pPassData[nInd]; nInd++) + { + pKeyData[2*nInd] = sal::static_int_cast< sal_uInt8 >( (pPassData[nInd] >> 0) & 0xff ); + pKeyData[2*nInd + 1] = sal::static_int_cast< sal_uInt8 >( (pPassData[nInd] >> 8) & 0xff ); + } + + pKeyData[2*nInd] = 0x80; + pKeyData[56] = sal::static_int_cast< sal_uInt8 >( nInd << 4 ); + + // Fill raw digest of KeyData into KeyData. + rtlDigest hDigest = rtl_digest_create ( rtl_Digest_AlgorithmMD5 ); + (void)rtl_digest_updateMD5 ( + hDigest, pKeyData, sizeof(pKeyData)); + (void)rtl_digest_rawMD5 ( + hDigest, pKeyData, RTL_DIGEST_LENGTH_MD5); + + // Update digest with KeyData and Unique. + for ( nInd = 0; nInd < 16; nInd++ ) + { + rtl_digest_updateMD5( hDigest, pKeyData, 5 ); + rtl_digest_updateMD5( hDigest, (const sal_uInt8*)aDocId.getConstArray(), aDocId.getLength() ); + } + + // Update digest with padding. + pKeyData[16] = 0x80; + rtl_zeroMemory( pKeyData + 17, sizeof(pKeyData) - 17 ); + pKeyData[56] = 0x80; + pKeyData[57] = 0x0a; + + rtl_digest_updateMD5( hDigest, &(pKeyData[16]), sizeof(pKeyData) - 16 ); + + // Fill raw digest of above updates + aResultKey.realloc( RTL_DIGEST_LENGTH_MD5 ); + rtl_digest_rawMD5 ( hDigest, (sal_uInt8*)aResultKey.getArray(), aResultKey.getLength() ); + + // Erase KeyData array and leave. + rtl_zeroMemory( pKeyData, sizeof(pKeyData) ); + } + + return aResultKey; +} + +// ============================================================================ + +/*static*/ ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > DocPasswordHelper::requestAndVerifyDocPassword( IDocPasswordVerifier& rVerifier, + const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& rMediaEncData, const OUString& rMediaPassword, const Reference< XInteractionHandler >& rxInteractHandler, const OUString& rDocumentName, @@ -292,7 +371,7 @@ Sequence< sal_Int8 > DocPasswordHelper::GetXLHashAsSequence( const ::std::vector< OUString >* pDefaultPasswords, bool* pbIsDefaultPassword ) { - OUString aPassword; + ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > aEncData; DocPasswordVerifierResult eResult = DocPasswordVerifierResult_WRONG_PASSWORD; // first, try provided default passwords @@ -302,23 +381,32 @@ Sequence< sal_Int8 > DocPasswordHelper::GetXLHashAsSequence( { for( ::std::vector< OUString >::const_iterator aIt = pDefaultPasswords->begin(), aEnd = pDefaultPasswords->end(); (eResult == DocPasswordVerifierResult_WRONG_PASSWORD) && (aIt != aEnd); ++aIt ) { - aPassword = *aIt; - OSL_ENSURE( aPassword.getLength() > 0, "DocPasswordHelper::requestAndVerifyDocPassword - unexpected empty default password" ); - if( aPassword.getLength() > 0 ) + OSL_ENSURE( aIt->getLength() > 0, "DocPasswordHelper::requestAndVerifyDocPassword - unexpected empty default password" ); + if( aIt->getLength() > 0 ) { - eResult = rVerifier.verifyPassword( aPassword ); + eResult = rVerifier.verifyPassword( *aIt, aEncData ); if( pbIsDefaultPassword ) *pbIsDefaultPassword = eResult == DocPasswordVerifierResult_OK; } } } + // try media encryption data (skip, if result is OK or ABORT) + if( eResult == DocPasswordVerifierResult_WRONG_PASSWORD ) + { + if( rMediaEncData.getLength() > 0 ) + { + eResult = rVerifier.verifyEncryptionData( rMediaEncData ); + if( eResult == DocPasswordVerifierResult_OK ) + aEncData = rMediaEncData; + } + } + // try media password (skip, if result is OK or ABORT) if( eResult == DocPasswordVerifierResult_WRONG_PASSWORD ) { - aPassword = rMediaPassword; - if( aPassword.getLength() > 0 ) - eResult = rVerifier.verifyPassword( aPassword ); + if( rMediaPassword.getLength() > 0 ) + eResult = rVerifier.verifyPassword( rMediaPassword, aEncData ); } // request a password (skip, if result is OK or ABORT) @@ -332,9 +420,8 @@ Sequence< sal_Int8 > DocPasswordHelper::GetXLHashAsSequence( rxInteractHandler->handle( xRequest ); if( pRequest->isPassword() ) { - aPassword = pRequest->getPassword(); - if( aPassword.getLength() > 0 ) - eResult = rVerifier.verifyPassword( aPassword ); + if( pRequest->getPassword().getLength() > 0 ) + eResult = rVerifier.verifyPassword( pRequest->getPassword(), aEncData ); } else { @@ -347,15 +434,17 @@ Sequence< sal_Int8 > DocPasswordHelper::GetXLHashAsSequence( { } - return (eResult == DocPasswordVerifierResult_OK) ? aPassword : OUString(); + return (eResult == DocPasswordVerifierResult_OK) ? aEncData : uno::Sequence< beans::NamedValue >(); } -/*static*/ OUString DocPasswordHelper::requestAndVerifyDocPassword( +/*static*/ ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > DocPasswordHelper::requestAndVerifyDocPassword( IDocPasswordVerifier& rVerifier, MediaDescriptor& rMediaDesc, DocPasswordRequestType eRequestType, const ::std::vector< OUString >* pDefaultPasswords ) { + uno::Sequence< beans::NamedValue > aMediaEncData = rMediaDesc.getUnpackedValueOrDefault( + MediaDescriptor::PROP_ENCRYPTIONDATA(), uno::Sequence< beans::NamedValue >() ); OUString aMediaPassword = rMediaDesc.getUnpackedValueOrDefault( MediaDescriptor::PROP_PASSWORD(), OUString() ); Reference< XInteractionHandler > xInteractHandler = rMediaDesc.getUnpackedValueOrDefault( @@ -364,14 +453,17 @@ Sequence< sal_Int8 > DocPasswordHelper::GetXLHashAsSequence( MediaDescriptor::PROP_URL(), OUString() ); bool bIsDefaultPassword = false; - OUString aPassword = requestAndVerifyDocPassword( - rVerifier, aMediaPassword, xInteractHandler, aDocumentName, eRequestType, pDefaultPasswords, &bIsDefaultPassword ); + uno::Sequence< beans::NamedValue > aEncryptionData = requestAndVerifyDocPassword( + rVerifier, aMediaEncData, aMediaPassword, xInteractHandler, aDocumentName, eRequestType, pDefaultPasswords, &bIsDefaultPassword ); + + rMediaDesc.erase( MediaDescriptor::PROP_PASSWORD() ); + rMediaDesc.erase( MediaDescriptor::PROP_ENCRYPTIONDATA() ); // insert valid password into media descriptor (but not a default password) - if( (aPassword.getLength() > 0) && !bIsDefaultPassword ) - rMediaDesc[ MediaDescriptor::PROP_PASSWORD() ] <<= aPassword; + if( (aEncryptionData.getLength() > 0) && !bIsDefaultPassword ) + rMediaDesc[ MediaDescriptor::PROP_ENCRYPTIONDATA() ] <<= aEncryptionData; - return aPassword; + return aEncryptionData; } // ============================================================================ diff --git a/comphelper/source/misc/mediadescriptor.cxx b/comphelper/source/misc/mediadescriptor.cxx index 9e02afe8c56c..e0b3e797264a 100644 --- a/comphelper/source/misc/mediadescriptor.cxx +++ b/comphelper/source/misc/mediadescriptor.cxx @@ -28,6 +28,7 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_comphelper.hxx" #include <comphelper/mediadescriptor.hxx> +#include <comphelper/namedvaluecollection.hxx> #include <comphelper/stillreadwriteinteraction.hxx> #include <com/sun/star/ucb/XContent.hpp> @@ -112,6 +113,12 @@ const ::rtl::OUString& MediaDescriptor::PROP_DOCUMENTSERVICE() return sProp; } +const ::rtl::OUString& MediaDescriptor::PROP_ENCRYPTIONDATA() +{ + static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("EncryptionData")); + return sProp; +} + const ::rtl::OUString& MediaDescriptor::PROP_EXTENSION() { static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Extension")); @@ -477,27 +484,30 @@ sal_Bool MediaDescriptor::isStreamReadOnly() const css::uno::Any MediaDescriptor::getComponentDataEntry( const ::rtl::OUString& rName ) const { - SequenceAsHashMap aCompDataMap( getUnpackedValueOrDefault( PROP_COMPONENTDATA(), ComponentDataSequence() ) ); - SequenceAsHashMap::iterator aIt = aCompDataMap.find( rName ); - return (aIt == aCompDataMap.end()) ? css::uno::Any() : aIt->second; + css::uno::Any aEntry; + SequenceAsHashMap::const_iterator aPropertyIter = find( PROP_COMPONENTDATA() ); + if( aPropertyIter != end() ) + return NamedValueCollection( aPropertyIter->second ).get( rName ); + return css::uno::Any(); } void MediaDescriptor::setComponentDataEntry( const ::rtl::OUString& rName, const css::uno::Any& rValue ) { if( rValue.hasValue() ) { - // get or craete the 'ComponentData' property entry + // get or create the 'ComponentData' property entry css::uno::Any& rCompDataAny = operator[]( PROP_COMPONENTDATA() ); - // check type, insert the value - OSL_ENSURE( !rCompDataAny.hasValue() || rCompDataAny.has< ComponentDataSequence >(), - "MediaDescriptor::setComponentDataEntry - incompatible 'ComponentData' property in media descriptor" ); - if( !rCompDataAny.hasValue() || rCompDataAny.has< ComponentDataSequence >() ) + // insert the value (retain sequence type, create NamedValue elements by default) + bool bHasNamedValues = !rCompDataAny.hasValue() || rCompDataAny.has< css::uno::Sequence< css::beans::NamedValue > >(); + bool bHasPropValues = rCompDataAny.has< css::uno::Sequence< css::beans::PropertyValue > >(); + OSL_ENSURE( bHasNamedValues || bHasPropValues, "MediaDescriptor::setComponentDataEntry - incompatible 'ComponentData' property in media descriptor" ); + if( bHasNamedValues || bHasPropValues ) { // insert or overwrite the passed value SequenceAsHashMap aCompDataMap( rCompDataAny ); aCompDataMap[ rName ] = rValue; - // write back the sequence (sal_False = use NamedValue instead of PropertyValue) - rCompDataAny = aCompDataMap.getAsConstAny( sal_False ); + // write back the sequence (restore sequence with correct element type) + rCompDataAny = aCompDataMap.getAsConstAny( bHasPropValues ); } } else @@ -512,18 +522,20 @@ void MediaDescriptor::clearComponentDataEntry( const ::rtl::OUString& rName ) SequenceAsHashMap::iterator aPropertyIter = find( PROP_COMPONENTDATA() ); if( aPropertyIter != end() ) { - OSL_ENSURE( aPropertyIter->second.has< ComponentDataSequence >(), - "MediaDescriptor::clearComponentDataEntry - incompatible 'ComponentData' property in media descriptor" ); - if( aPropertyIter->second.has< ComponentDataSequence >() ) + css::uno::Any& rCompDataAny = aPropertyIter->second; + bool bHasNamedValues = rCompDataAny.has< css::uno::Sequence< css::beans::NamedValue > >(); + bool bHasPropValues = rCompDataAny.has< css::uno::Sequence< css::beans::PropertyValue > >(); + OSL_ENSURE( bHasNamedValues || bHasPropValues, "MediaDescriptor::clearComponentDataEntry - incompatible 'ComponentData' property in media descriptor" ); + if( bHasNamedValues || bHasPropValues ) { // remove the value with the passed name - SequenceAsHashMap aCompDataMap( aPropertyIter->second ); + SequenceAsHashMap aCompDataMap( rCompDataAny ); aCompDataMap.erase( rName ); // write back the sequence, or remove it completely if it is empty if( aCompDataMap.empty() ) erase( aPropertyIter ); else - aPropertyIter->second = aCompDataMap.getAsConstAny( sal_False ); + rCompDataAny = aCompDataMap.getAsConstAny( bHasPropValues ); } } } diff --git a/comphelper/source/misc/mimeconfighelper.cxx b/comphelper/source/misc/mimeconfighelper.cxx index b677c977739e..5be9df3d61b6 100644 --- a/comphelper/source/misc/mimeconfighelper.cxx +++ b/comphelper/source/misc/mimeconfighelper.cxx @@ -35,6 +35,7 @@ #include <comphelper/mimeconfighelper.hxx> #include <comphelper/classids.hxx> #include <comphelper/sequenceashashmap.hxx> +#include <comphelper/documentconstants.hxx> using namespace ::com::sun::star; @@ -187,6 +188,46 @@ uno::Reference< container::XNameAccess > MimeConfigurationHelper::GetMediaTypeCo return m_xMediaTypeConfig; } + +//----------------------------------------------------------------------- +uno::Reference< container::XNameAccess > MimeConfigurationHelper::GetFilterFactory() +{ + osl::MutexGuard aGuard( m_aMutex ); + + if ( !m_xFilterFactory.is() ) + m_xFilterFactory.set( + m_xFactory->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.document.FilterFactory" ) ), + uno::UNO_QUERY ); + + return m_xFilterFactory; +} + +//----------------------------------------------------------------------- +sal_Int32 MimeConfigurationHelper::GetFilterFlags( const ::rtl::OUString& aFilterName ) +{ + sal_Int32 nFlags = 0; + try + { + if ( aFilterName.getLength() ) + { + uno::Reference< container::XNameAccess > xFilterFactory( + GetFilterFactory(), + uno::UNO_SET_THROW ); + + uno::Any aFilterAny = xFilterFactory->getByName( aFilterName ); + uno::Sequence< beans::PropertyValue > aData; + if ( aFilterAny >>= aData ) + { + SequenceAsHashMap aFilterHM( aData ); + nFlags = aFilterHM.getUnpackedValueOrDefault( ::rtl::OUString::createFromAscii( "Flags" ), (sal_Int32)0 ); + } + } + } catch( uno::Exception& ) + {} + + return nFlags; +} + //------------------------------------------------------------------------- ::rtl::OUString MimeConfigurationHelper::GetDocServiceNameFromFilter( const ::rtl::OUString& aFilterName ) { @@ -195,8 +236,8 @@ uno::Reference< container::XNameAccess > MimeConfigurationHelper::GetMediaTypeCo try { uno::Reference< container::XNameAccess > xFilterFactory( - m_xFactory->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.document.FilterFactory" ) ), - uno::UNO_QUERY_THROW ); + GetFilterFactory(), + uno::UNO_SET_THROW ); uno::Any aFilterAnyData = xFilterFactory->getByName( aFilterName ); uno::Sequence< beans::PropertyValue > aFilterData; @@ -668,36 +709,17 @@ uno::Sequence< beans::NamedValue > MimeConfigurationHelper::GetObjectPropsByDocu sal_Bool MimeConfigurationHelper::AddFilterNameCheckOwnFile( uno::Sequence< beans::PropertyValue >& aMediaDescr ) { + sal_Bool bResult = sal_False; + ::rtl::OUString aFilterName = UpdateMediaDescriptorWithFilterName( aMediaDescr, sal_False ); if ( aFilterName.getLength() ) { - try - { - uno::Reference< container::XNameAccess > xFilterFactory( - m_xFactory->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.document.FilterFactory" ) ), - uno::UNO_QUERY_THROW ); - - uno::Any aFilterAnyData = xFilterFactory->getByName( aFilterName ); - uno::Sequence< beans::PropertyValue > aFilterData; - if ( aFilterAnyData >>= aFilterData ) - { - for ( sal_Int32 nInd = 0; nInd < aFilterData.getLength(); nInd++ ) - if ( aFilterData[nInd].Name.equalsAscii( "Flags" ) ) - { - uno::Any aVal = aFilterData[nInd].Value; - sal_Int32 nFlags = 0; - // check the OWN flag - if ( ( aFilterData[nInd].Value >>= nFlags ) && ( nFlags & 0x20 ) ) - return sal_True; - break; - } - } - } - catch( uno::Exception& ) - {} + sal_Int32 nFlags = GetFilterFlags( aFilterName ); + // check the OWN flag + bResult = ( nFlags & SFX_FILTER_OWN ); } - return sal_False; + return bResult; } //----------------------------------------------------------- @@ -709,7 +731,7 @@ sal_Bool MimeConfigurationHelper::AddFilterNameCheckOwnFile( try { uno::Reference< container::XContainerQuery > xFilterQuery( - m_xFactory->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.document.FilterFactory" ) ), + GetFilterFactory(), uno::UNO_QUERY_THROW ); uno::Sequence< beans::NamedValue > aSearchRequest( 2 ); @@ -734,14 +756,15 @@ sal_Bool MimeConfigurationHelper::AddFilterNameCheckOwnFile( (sal_Int32)0 ); // that should be import, export, own filter and not a template filter ( TemplatePath flag ) - if ( ( ( nFlags & 0x23L ) == 0x23L ) && !( nFlags & 0x10 ) ) + sal_Int32 nRequired = ( SFX_FILTER_OWN | SFX_FILTER_EXPORT | SFX_FILTER_IMPORT ); + if ( ( ( nFlags & nRequired ) == nRequired ) && !( nFlags & SFX_FILTER_TEMPLATEPATH ) ) { // if there are more than one filter the preffered one should be used // if there is no preffered filter the first one will be used - if ( !aResult.getLength() || ( nFlags & 0x10000000L ) ) + if ( !aResult.getLength() || ( nFlags & SFX_FILTER_PREFERED ) ) aResult = aPropsHM.getUnpackedValueOrDefault( ::rtl::OUString::createFromAscii( "Name" ), ::rtl::OUString() ); - if ( nFlags & 0x10000000L ) + if ( nFlags & SFX_FILTER_PREFERED ) break; // the preffered filter was found } } @@ -752,6 +775,116 @@ sal_Bool MimeConfigurationHelper::AddFilterNameCheckOwnFile( return aResult; } + +//------------------------------------------------------------------------- +::rtl::OUString MimeConfigurationHelper::GetExportFilterFromImportFilter( const ::rtl::OUString& aImportFilterName ) +{ + ::rtl::OUString aExportFilterName; + + try + { + if ( aImportFilterName.getLength() ) + { + uno::Reference< container::XNameAccess > xFilterFactory( + GetFilterFactory(), + uno::UNO_SET_THROW ); + + uno::Any aImpFilterAny = xFilterFactory->getByName( aImportFilterName ); + uno::Sequence< beans::PropertyValue > aImpData; + if ( aImpFilterAny >>= aImpData ) + { + SequenceAsHashMap aImpFilterHM( aImpData ); + sal_Int32 nFlags = aImpFilterHM.getUnpackedValueOrDefault( ::rtl::OUString::createFromAscii( "Flags" ), + (sal_Int32)0 ); + + if ( !( nFlags & SFX_FILTER_IMPORT ) ) + { + OSL_ENSURE( sal_False, "This is no import filter!" ); + throw uno::Exception(); + } + + if ( nFlags & SFX_FILTER_EXPORT ) + { + aExportFilterName = aImportFilterName; + } + else + { + ::rtl::OUString aDocumentServiceName = aImpFilterHM.getUnpackedValueOrDefault( ::rtl::OUString::createFromAscii( "DocumentService" ), ::rtl::OUString() ); + ::rtl::OUString aTypeName = aImpFilterHM.getUnpackedValueOrDefault( ::rtl::OUString::createFromAscii( "Type" ), ::rtl::OUString() ); + + OSL_ENSURE( aDocumentServiceName.getLength() && aTypeName.getLength(), "Incomplete filter data!" ); + if ( aDocumentServiceName.getLength() && aTypeName.getLength() ) + { + uno::Sequence< beans::NamedValue > aSearchRequest( 2 ); + aSearchRequest[0].Name = ::rtl::OUString::createFromAscii( "Type" ); + aSearchRequest[0].Value <<= aTypeName; + aSearchRequest[1].Name = ::rtl::OUString::createFromAscii( "DocumentService" ); + aSearchRequest[1].Value <<= aDocumentServiceName; + + uno::Sequence< beans::PropertyValue > aExportFilterProps = SearchForFilter( + uno::Reference< container::XContainerQuery >( xFilterFactory, uno::UNO_QUERY_THROW ), + aSearchRequest, + SFX_FILTER_EXPORT, + SFX_FILTER_INTERNAL ); + + if ( aExportFilterProps.getLength() ) + { + SequenceAsHashMap aExpPropsHM( aExportFilterProps ); + aExportFilterName = aExpPropsHM.getUnpackedValueOrDefault( ::rtl::OUString::createFromAscii( "Name" ), ::rtl::OUString() ); + } + } + } + } + } + } + catch( uno::Exception& ) + {} + + return aExportFilterName; +} + +//------------------------------------------------------------------------- +// static +uno::Sequence< beans::PropertyValue > MimeConfigurationHelper::SearchForFilter( + const uno::Reference< container::XContainerQuery >& xFilterQuery, + const uno::Sequence< beans::NamedValue >& aSearchRequest, + sal_Int32 nMustFlags, + sal_Int32 nDontFlags ) +{ + uno::Sequence< beans::PropertyValue > aFilterProps; + uno::Reference< container::XEnumeration > xFilterEnum = + xFilterQuery->createSubSetEnumerationByProperties( aSearchRequest ); + + // the first default filter will be taken, + // if there is no filter with flag default the first acceptable filter will be taken + if ( xFilterEnum.is() ) + { + while ( xFilterEnum->hasMoreElements() ) + { + uno::Sequence< beans::PropertyValue > aProps; + if ( xFilterEnum->nextElement() >>= aProps ) + { + SequenceAsHashMap aPropsHM( aProps ); + sal_Int32 nFlags = aPropsHM.getUnpackedValueOrDefault( ::rtl::OUString::createFromAscii( "Flags" ), + (sal_Int32)0 ); + if ( ( ( nFlags & nMustFlags ) == nMustFlags ) && !( nFlags & nDontFlags ) ) + { + if ( ( nFlags & SFX_FILTER_DEFAULT ) == SFX_FILTER_DEFAULT ) + { + aFilterProps = aProps; + break; + } + else if ( !aFilterProps.getLength() ) + aFilterProps = aProps; + } + } + } + } + + return aFilterProps; +} + + //------------------------------------------------------------------------- sal_Bool MimeConfigurationHelper::ClassIDsEqual( const uno::Sequence< sal_Int8 >& aClassID1, const uno::Sequence< sal_Int8 >& aClassID2 ) { @@ -764,7 +897,8 @@ sal_Bool MimeConfigurationHelper::ClassIDsEqual( const uno::Sequence< sal_Int8 > return sal_True; } -//---------------------------------------------- + +//------------------------------------------------------------------------- uno::Sequence< sal_Int8 > MimeConfigurationHelper::GetSequenceClassID( sal_uInt32 n1, sal_uInt16 n2, sal_uInt16 n3, sal_uInt8 b8, sal_uInt8 b9, sal_uInt8 b10, sal_uInt8 b11, sal_uInt8 b12, sal_uInt8 b13, sal_uInt8 b14, sal_uInt8 b15 ) @@ -789,6 +923,8 @@ uno::Sequence< sal_Int8 > MimeConfigurationHelper::GetSequenceClassID( sal_uInt3 return aResult; } + +//------------------------------------------------------------------------- uno::Sequence<sal_Int8> MimeConfigurationHelper::GetSequenceClassIDFromObjectName(const ::rtl::OUString& _sObjectName) { uno::Sequence<sal_Int8> aClassId; diff --git a/comphelper/source/misc/storagehelper.cxx b/comphelper/source/misc/storagehelper.cxx index db5ba71cd876..60ffa965fcf1 100644 --- a/comphelper/source/misc/storagehelper.cxx +++ b/comphelper/source/misc/storagehelper.cxx @@ -28,12 +28,15 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_comphelper.hxx" #include <com/sun/star/embed/ElementModes.hpp> -#include <com/sun/star/embed/XEncryptionProtectedSource.hpp> +#include <com/sun/star/embed/XEncryptionProtectedSource2.hpp> #include <com/sun/star/ucb/XSimpleFileAccess.hpp> #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/beans/NamedValue.hpp> #include <com/sun/star/beans/IllegalTypeException.hpp> +#include <rtl/digest.h> + #include <ucbhelper/content.hxx> #include <comphelper/fileformat.h> @@ -236,16 +239,16 @@ uno::Reference< io::XInputStream > OStorageHelper::GetInputStreamFromURL( } // ---------------------------------------------------------------------- -void OStorageHelper::SetCommonStoragePassword( +void OStorageHelper::SetCommonStorageEncryptionData( const uno::Reference< embed::XStorage >& xStorage, - const ::rtl::OUString& aPass ) + const uno::Sequence< beans::NamedValue >& aEncryptionData ) throw ( uno::Exception ) { - uno::Reference< embed::XEncryptionProtectedSource > xEncrSet( xStorage, uno::UNO_QUERY ); + uno::Reference< embed::XEncryptionProtectedSource2 > xEncrSet( xStorage, uno::UNO_QUERY ); if ( !xEncrSet.is() ) throw io::IOException(); // TODO - xEncrSet->setEncryptionPassword( aPass ); + xEncrSet->setEncryptionData( aEncryptionData ); } // ---------------------------------------------------------------------- @@ -419,6 +422,45 @@ uno::Reference< embed::XStorage > OStorageHelper::GetStorageOfFormatFromStream( } // ---------------------------------------------------------------------- +uno::Sequence< beans::NamedValue > OStorageHelper::CreatePackageEncryptionData( const ::rtl::OUString& aPassword ) +{ + // TODO/LATER: Should not the method be part of DocPasswordHelper? + uno::Sequence< beans::NamedValue > aEncryptionData; + if ( aPassword.getLength() ) + { + // MS_1252 encoding was used for SO60 document format password encoding, + // this encoding supports only a minor subset of nonascii characters, + // but for compatibility reasons it has to be used for old document formats + aEncryptionData.realloc( 2 ); + aEncryptionData[0].Name = PACKAGE_ENCRYPTIONDATA_SHA1UTF8; + aEncryptionData[1].Name = PACKAGE_ENCRYPTIONDATA_SHA1MS1252; + + rtl_TextEncoding pEncoding[2] = { RTL_TEXTENCODING_UTF8, RTL_TEXTENCODING_MS_1252 }; + + for ( sal_Int32 nInd = 0; nInd < 2; nInd++ ) + { + ::rtl::OString aByteStrPass = ::rtl::OUStringToOString( aPassword, pEncoding[nInd] ); + + sal_uInt8 pBuffer[RTL_DIGEST_LENGTH_SHA1]; + rtlDigestError nError = rtl_digest_SHA1( aByteStrPass.getStr(), + aByteStrPass.getLength(), + pBuffer, + RTL_DIGEST_LENGTH_SHA1 ); + + if ( nError != rtl_Digest_E_None ) + { + aEncryptionData.realloc( 0 ); + break; + } + + aEncryptionData[nInd].Value <<= uno::Sequence< sal_Int8 >( (sal_Int8*)pBuffer, RTL_DIGEST_LENGTH_SHA1 ); + } + } + + return aEncryptionData; +} + +// ---------------------------------------------------------------------- sal_Bool OStorageHelper::IsValidZipEntryFileName( const ::rtl::OUString& aName, sal_Bool bSlashAllowed ) { return IsValidZipEntryFileName( aName.getStr(), aName.getLength(), bSlashAllowed ); |