Kaydet (Commit) c54850b2 authored tarafından Thorsten Behrens's avatar Thorsten Behrens Kaydeden (comit) Katarina Behrens

gpg4libre/comphelper: add storage helper for GPG encryption data

Change-Id: Idba9ad7a821cb33070cf5e5a0f79ae55db99b276
Reviewed-on: https://gerrit.libreoffice.org/41504Reviewed-by: 's avatarKatarina Behrens <Katarina.Behrens@cib.de>
Tested-by: 's avatarKatarina Behrens <Katarina.Behrens@cib.de>
üst f20810a1
...@@ -34,10 +34,14 @@ ...@@ -34,10 +34,14 @@
#include <com/sun/star/xml/crypto/XDigestContext.hpp> #include <com/sun/star/xml/crypto/XDigestContext.hpp>
#include <com/sun/star/xml/crypto/XDigestContextSupplier.hpp> #include <com/sun/star/xml/crypto/XDigestContextSupplier.hpp>
#include <com/sun/star/xml/crypto/DigestID.hpp> #include <com/sun/star/xml/crypto/DigestID.hpp>
#include <com/sun/star/security/DocumentDigitalSignatures.hpp>
#include <com/sun/star/security/XCertificate.hpp>
#include <vector> #include <vector>
#include <rtl/digest.h> #include <rtl/digest.h>
#include <rtl/random.h>
#include <osl/time.h>
#include <osl/diagnose.h> #include <osl/diagnose.h>
#include <ucbhelper/content.hxx> #include <ucbhelper/content.hxx>
...@@ -403,6 +407,53 @@ uno::Sequence< beans::NamedValue > OStorageHelper::CreatePackageEncryptionData( ...@@ -403,6 +407,53 @@ uno::Sequence< beans::NamedValue > OStorageHelper::CreatePackageEncryptionData(
return aEncryptionData; return aEncryptionData;
} }
uno::Sequence< beans::NamedValue > OStorageHelper::CreateGpgPackageEncryptionData()
{
// generate session key
// --------------------
// Get a random number generator and seed it with current timestamp
TimeValue aTime;
osl_getSystemTime( &aTime );
rtlRandomPool aRandomPool = rtl_random_createPool();
rtl_random_addBytes(aRandomPool, &aTime, 8);
// get 16 random chars out of it
uno::Sequence < sal_Int8 > aVector(16);
rtl_random_getBytes( aRandomPool, aVector.getArray(), aVector.getLength() );
rtl_random_destroyPool(aRandomPool);
uno::Sequence< beans::NamedValue > aContainer(2);
uno::Sequence< beans::NamedValue > aGpgEncryptionData(3);
uno::Sequence< beans::NamedValue > aEncryptionData(1);
// TODO fire certificate chooser dialog
uno::Reference< security::XDocumentDigitalSignatures > xSigner(
security::DocumentDigitalSignatures::createWithVersion(
comphelper::getProcessComponentContext(), "1.2" ) );
// The use may provide a description while choosing a certificate.
OUString aDescription;
uno::Reference< security::XCertificate > xSignCertificate=
xSigner->chooseCertificate(aDescription);
uno::Sequence < sal_Int8 > aKeyID;
if (xSignCertificate.is())
{
aKeyID = xSignCertificate->getSHA1Thumbprint();
}
aGpgEncryptionData[0].Name = "KeyId";
aGpgEncryptionData[0].Value <<= aKeyID;
aContainer[0].Name = "GpgInfos";
aContainer[0].Value <<= aGpgEncryptionData;
aContainer[1].Name = "EncryptionKey";
aContainer[1].Value <<= aEncryptionData;
return aContainer;
}
bool OStorageHelper::IsValidZipEntryFileName( const OUString& aName, bool bSlashAllowed ) bool OStorageHelper::IsValidZipEntryFileName( const OUString& aName, bool bSlashAllowed )
{ {
......
...@@ -172,6 +172,9 @@ public: ...@@ -172,6 +172,9 @@ public:
CreatePackageEncryptionData( CreatePackageEncryptionData(
const OUString& aPassword ); const OUString& aPassword );
static css::uno::Sequence< css::beans::NamedValue >
CreateGpgPackageEncryptionData();
static bool IsValidZipEntryFileName( const OUString& aName, bool bSlashAllowed ); static bool IsValidZipEntryFileName( const OUString& aName, bool bSlashAllowed );
static bool IsValidZipEntryFileName( const sal_Unicode *pChar, sal_Int32 nLength, bool bSlashAllowed ); static bool IsValidZipEntryFileName( const sal_Unicode *pChar, sal_Int32 nLength, bool bSlashAllowed );
......
...@@ -1522,12 +1522,7 @@ ErrCode FileDialogHelper_Impl::execute( std::vector<OUString>& rpURLList, ...@@ -1522,12 +1522,7 @@ ErrCode FileDialogHelper_Impl::execute( std::vector<OUString>& rpURLList,
if ( ( aValue >>= bGpg ) && bGpg ) if ( ( aValue >>= bGpg ) && bGpg )
{ {
// ask for a key // ask for a key
OUString aDocName(rpURLList[0]); rpSet->Put( SfxUnoAnyItem( SID_ENCRYPTIONDATA, uno::makeAny( ::comphelper::OStorageHelper::CreateGpgPackageEncryptionData() ) ) );
// ErrCode errCode = RequestKey(pCurrentFilter, aDocName, rpSet);
//if (errCode != ERRCODE_NONE)
rpSet->Put( SfxUnoAnyItem( SID_ENCRYPTIONDATA, uno::makeAny( ::comphelper::OStorageHelper::CreatePackageEncryptionData( aDocName ) ) ) );
return ERRCODE_IO_NOTSUPPORTED; //errCode;
} }
} }
catch( const IllegalArgumentException& ){} catch( const IllegalArgumentException& ){}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment