summaryrefslogtreecommitdiff
path: root/xmlsecurity
diff options
context:
space:
mode:
authorKatarina Behrens <Katarina.Behrens@cib.de>2017-12-14 18:12:56 +0100
committerThorsten Behrens <Thorsten.Behrens@CIB.de>2017-12-19 08:20:30 +0100
commit253c11a0c31a1034a5b90e0f3389301a681fc07a (patch)
treed31f1b9a6d93bf37903504afd33dab3ae2d0eec4 /xmlsecurity
parent5aa5843d4dc668899776192d8200ddddb06a6156 (diff)
Do things with preferred GPG keys
For signing, preselect the key in the list of available keys. For encryption, when 'encrypt to self' bit is set, add user's key to the list of keys to encryption. Change-Id: I5bbfd0e2cc97b76c1304a2a345a51cf83bc5949e Reviewed-on: https://gerrit.libreoffice.org/46694 Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de> Tested-by: Thorsten Behrens <Thorsten.Behrens@CIB.de> (cherry picked from commit ee40674b4c9343db5e69cd5118bdbcf8e6edad6d) Reviewed-on: https://gerrit.libreoffice.org/46759 Tested-by: Jenkins <ci@libreoffice.org>
Diffstat (limited to 'xmlsecurity')
-rw-r--r--xmlsecurity/inc/certificatechooser.hxx2
-rw-r--r--xmlsecurity/source/dialogs/certificatechooser.cxx29
2 files changed, 29 insertions, 2 deletions
diff --git a/xmlsecurity/inc/certificatechooser.hxx b/xmlsecurity/inc/certificatechooser.hxx
index be3828b5c5e9..6049eb4a3869 100644
--- a/xmlsecurity/inc/certificatechooser.hxx
+++ b/xmlsecurity/inc/certificatechooser.hxx
@@ -73,6 +73,8 @@ private:
bool mbInitialized;
UserAction meAction;
+ OUString msPreferredKey;
+ css::uno::Reference<css::security::XCertificate> mxEncryptToSelf;
DECL_LINK(ViewButtonHdl, Button*, void);
DECL_LINK(CertificateHighlightHdl, SvTreeListBox*, void );
diff --git a/xmlsecurity/source/dialogs/certificatechooser.cxx b/xmlsecurity/source/dialogs/certificatechooser.cxx
index bf100c6d0401..5a1edcae872d 100644
--- a/xmlsecurity/source/dialogs/certificatechooser.cxx
+++ b/xmlsecurity/source/dialogs/certificatechooser.cxx
@@ -17,7 +17,7 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
-
+#include <config_gpgme.h>
#include <certificatechooser.hxx>
#include <certificateviewer.hxx>
#include <biginteger.hxx>
@@ -31,6 +31,7 @@
#include <resourcemanager.hxx>
#include <vcl/msgbox.hxx>
#include <svtools/treelistentry.hxx>
+#include <unotools/useroptions.hxx>
using namespace css;
@@ -159,11 +160,14 @@ void CertificateChooser::ImplInitialize()
if ( mbInitialized )
return;
+ SvtUserOptions aUserOpts;
+
switch (meAction)
{
case UserAction::Sign:
m_pFTSign->Show();
m_pOKBtn->SetText( get<FixedText>("str_sign")->GetText() );
+ msPreferredKey = aUserOpts.GetSigningKey();
break;
case UserAction::Encrypt:
@@ -172,6 +176,7 @@ void CertificateChooser::ImplInitialize()
m_pDescriptionED->Hide();
m_pCertLB->SetSelectionMode( SelectionMode::Multiple );
m_pOKBtn->SetText( get<FixedText>("str_encrypt")->GetText() );
+ msPreferredKey = aUserOpts.GetEncryptionKey();
break;
}
@@ -210,6 +215,7 @@ void CertificateChooser::ImplInitialize()
}
}
+
// fill list of certificates; the first entry will be selected
for ( sal_Int32 nC = 0; nC < nCertificates; ++nC )
{
@@ -218,12 +224,26 @@ void CertificateChooser::ImplInitialize()
userData->xSecurityContext = secContext;
userData->xSecurityEnvironment = secEnvironment;
mvUserData.push_back(userData);
+
+ OUString sIssuer = XmlSec::GetContentPart( xCerts[ nC ]->getIssuerName() );
SvTreeListEntry* pEntry = m_pCertLB->InsertEntry( XmlSec::GetContentPart( xCerts[ nC ]->getSubjectName() )
- + "\t" + XmlSec::GetContentPart( xCerts[ nC ]->getIssuerName() )
+ + "\t" + sIssuer
+ "\t" + XmlSec::GetCertificateKind( xCerts[ nC ]->getCertificateKind() )
+ "\t" + XmlSec::GetDateString( xCerts[ nC ]->getNotValidAfter() )
+ "\t" + UsageInClearText( xCerts[ nC ]->getCertificateUsage() ) );
pEntry->SetUserData( userData.get() );
+
+#if HAVE_FEATURE_GPGME
+ // only GPG has preferred keys
+ if ( sIssuer == msPreferredKey )
+ {
+ if ( meAction == UserAction::Sign )
+ m_pCertLB->Select( pEntry );
+ else if ( meAction == UserAction::Encrypt &&
+ aUserOpts.GetEncryptToSelf() )
+ mxEncryptToSelf = xCerts[nC];
+ }
+#endif
}
}
@@ -259,6 +279,11 @@ uno::Sequence<uno::Reference< css::security::XCertificate > > CertificateChooser
aRet.push_back( xCert );
}
+#if HAVE_FEATURE_GPGME
+ if ( mxEncryptToSelf.is())
+ aRet.push_back( mxEncryptToSelf );
+#endif
+
return comphelper::containerToSequence(aRet);
}