summaryrefslogtreecommitdiff
path: root/comphelper
diff options
context:
space:
mode:
authorThorsten Behrens <Thorsten.Behrens@CIB.de>2017-08-24 17:40:09 +0200
committerKatarina Behrens <Katarina.Behrens@cib.de>2017-08-31 12:02:32 +0200
commitc54850b23a8240a41755af171a6d3f990ee69f84 (patch)
tree875ea90bc1490c8a14cc48a42722d38072f7203b /comphelper
parentf20810a1318a8dd55cb01e42a0fde7f0e1b36623 (diff)
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@cib.de> Tested-by: Katarina Behrens <Katarina.Behrens@cib.de>
Diffstat (limited to 'comphelper')
-rw-r--r--comphelper/source/misc/storagehelper.cxx51
1 files changed, 51 insertions, 0 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 )
{