[Libreoffice-commits] core.git: comphelper/source include/comphelper sfx2/source

Thorsten Behrens Thorsten.Behrens at CIB.de
Thu Aug 31 10:06:46 UTC 2017


 comphelper/source/misc/storagehelper.cxx |   51 +++++++++++++++++++++++++++++++
 include/comphelper/storagehelper.hxx     |    3 +
 sfx2/source/dialog/filedlghelper.cxx     |    7 ----
 3 files changed, 55 insertions(+), 6 deletions(-)

New commits:
commit c54850b23a8240a41755af171a6d3f990ee69f84
Author: Thorsten Behrens <Thorsten.Behrens at CIB.de>
Date:   Thu Aug 24 17:40:09 2017 +0200

    gpg4libre/comphelper: add storage helper for GPG encryption data
    
    Change-Id: Idba9ad7a821cb33070cf5e5a0f79ae55db99b276
    Reviewed-on: https://gerrit.libreoffice.org/41504
    Reviewed-by: Katarina Behrens <Katarina.Behrens at cib.de>
    Tested-by: Katarina Behrens <Katarina.Behrens at cib.de>

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& ){}


More information about the Libreoffice-commits mailing list