summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--comphelper/source/misc/storagehelper.cxx51
-rw-r--r--include/comphelper/storagehelper.hxx3
-rw-r--r--sfx2/source/dialog/filedlghelper.cxx7
3 files changed, 55 insertions, 6 deletions
diff --git a/comphelper/source/misc/storagehelper.cxx b/comphelper/source/misc/storagehelper.cxx
index ed55fe219e52..19e427c1fc87 100644
--- a/comphelper/source/misc/storagehelper.cxx
+++ b/comphelper/source/misc/storagehelper.cxx
@@ -34,10 +34,14 @@
#include <com/sun/star/xml/crypto/XDigestContext.hpp>
#include <com/sun/star/xml/crypto/XDigestContextSupplier.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 <rtl/digest.h>
+#include <rtl/random.h>
+#include <osl/time.h>
#include <osl/diagnose.h>
#include <ucbhelper/content.hxx>
@@ -403,6 +407,53 @@ uno::Sequence< beans::NamedValue > OStorageHelper::CreatePackageEncryptionData(
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 )
{
diff --git a/include/comphelper/storagehelper.hxx b/include/comphelper/storagehelper.hxx
index 84c958fb1f23..1f5e22cb14e3 100644
--- a/include/comphelper/storagehelper.hxx
+++ b/include/comphelper/storagehelper.hxx
@@ -172,6 +172,9 @@ public:
CreatePackageEncryptionData(
const OUString& aPassword );
+ static css::uno::Sequence< css::beans::NamedValue >
+ CreateGpgPackageEncryptionData();
+
static bool IsValidZipEntryFileName( const OUString& aName, bool bSlashAllowed );
static bool IsValidZipEntryFileName( const sal_Unicode *pChar, sal_Int32 nLength, bool bSlashAllowed );
diff --git a/sfx2/source/dialog/filedlghelper.cxx b/sfx2/source/dialog/filedlghelper.cxx
index d6a5489f85ce..a4a6847deeea 100644
--- a/sfx2/source/dialog/filedlghelper.cxx
+++ b/sfx2/source/dialog/filedlghelper.cxx
@@ -1522,12 +1522,7 @@ ErrCode FileDialogHelper_Impl::execute( std::vector<OUString>& rpURLList,
if ( ( aValue >>= bGpg ) && bGpg )
{
// ask for a key
- OUString aDocName(rpURLList[0]);
- // 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;
+ rpSet->Put( SfxUnoAnyItem( SID_ENCRYPTIONDATA, uno::makeAny( ::comphelper::OStorageHelper::CreateGpgPackageEncryptionData() ) ) );
}
}
catch( const IllegalArgumentException& ){}