[Libreoffice-commits] core.git: Branch 'libreoffice-6-0' - xmlsecurity/inc xmlsecurity/source

Katarina Behrens Katarina.Behrens at cib.de
Tue Dec 19 07:22:39 UTC 2017


 xmlsecurity/inc/certificatechooser.hxx            |    2 +
 xmlsecurity/source/dialogs/certificatechooser.cxx |   29 ++++++++++++++++++++--
 2 files changed, 29 insertions(+), 2 deletions(-)

New commits:
commit 253c11a0c31a1034a5b90e0f3389301a681fc07a
Author: Katarina Behrens <Katarina.Behrens at cib.de>
Date:   Thu Dec 14 18:12:56 2017 +0100

    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 at CIB.de>
    Tested-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>
    (cherry picked from commit ee40674b4c9343db5e69cd5118bdbcf8e6edad6d)
    Reviewed-on: https://gerrit.libreoffice.org/46759
    Tested-by: Jenkins <ci at libreoffice.org>

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);
 }
 


More information about the Libreoffice-commits mailing list