summaryrefslogtreecommitdiff
path: root/xmlsecurity/source
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 01:23:09 +0100
commitee40674b4c9343db5e69cd5118bdbcf8e6edad6d (patch)
treed838ed6a778555caac381b49caeb7186bdb41464 /xmlsecurity/source
parente0c3e356fd9151819db13d844f87ec200e2dbee3 (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>
Diffstat (limited to 'xmlsecurity/source')
-rw-r--r--xmlsecurity/source/dialogs/certificatechooser.cxx29
1 files changed, 27 insertions, 2 deletions
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);
}