diff options
author | Sarper Akdemir <sarper.akdemir@allotropia.de> | 2024-07-17 12:47:22 +0200 |
---|---|---|
committer | Sarper Akdemir <sarper.akdemir@allotropia.de> | 2024-07-24 07:08:46 +0200 |
commit | 426c641976688e3e4d1ce66f76b27ccbd2dca55a (patch) | |
tree | 8a56790e284f7f586c1298959a58d61490a6d241 /cui | |
parent | 6ca02ef177df62edb124881248a1ebcd9876ff4c (diff) |
tdf#159040: add sign with default certificate to save dialog
Include X.509 certificates under Tools->Options->UserData
among the keys for signing.
Add a new checkbox to Save file dialog, to sign with that
selected key easily.
The checkbox is disabled if there's no matching key found.
Change-Id: I9fc16790c479819cd1f35bcad040d0ebc7c4bdef
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170619
Tested-by: Jenkins
Reviewed-by: Sarper Akdemir <sarper.akdemir@allotropia.de>
Diffstat (limited to 'cui')
-rw-r--r-- | cui/source/options/optgenrl.cxx | 44 | ||||
-rw-r--r-- | cui/uiconfig/ui/optuserpage.ui | 4 |
2 files changed, 38 insertions, 10 deletions
diff --git a/cui/source/options/optgenrl.cxx b/cui/source/options/optgenrl.cxx index 54963bb86c97..ff2216b6e41c 100644 --- a/cui/source/options/optgenrl.cxx +++ b/cui/source/options/optgenrl.cxx @@ -25,6 +25,8 @@ # include <com/sun/star/xml/crypto/GPGSEInitializer.hpp> # include <com/sun/star/xml/crypto/XXMLSecurityContext.hpp> #endif +#include <com/sun/star/xml/crypto/SEInitializer.hpp> +#include <comphelper/xmlsechelper.hxx> #include <i18nlangtag/languagetag.hxx> #include <i18nlangtag/mslangid.hxx> @@ -300,26 +302,52 @@ void SvxGeneralTabPage::InitCryptography() #if HAVE_FEATURE_GPGME m_xCryptoFrame->show(); - uno::Reference< xml::crypto::XSEInitializer > xSEInitializer; try { - xSEInitializer = xml::crypto::GPGSEInitializer::create( comphelper::getProcessComponentContext() ); - uno::Reference<xml::crypto::XXMLSecurityContext> xSC = xSEInitializer->createSecurityContext( OUString() ); - if (xSC.is()) + uno::Reference<xml::crypto::XXMLSecurityContext> xSecurityContext + = xml::crypto::SEInitializer::create(comphelper::getProcessComponentContext()) + ->createSecurityContext(""); + uno::Reference<xml::crypto::XXMLSecurityContext> xSecurityContextGPG + = xml::crypto::GPGSEInitializer::create(comphelper::getProcessComponentContext()) + ->createSecurityContext(""); + if (xSecurityContextGPG.is()) { - uno::Reference<xml::crypto::XSecurityEnvironment> xSE = xSC->getSecurityEnvironment(); + uno::Reference<xml::crypto::XSecurityEnvironment> xSE = xSecurityContextGPG->getSecurityEnvironment(); uno::Sequence<uno::Reference<security::XCertificate>> xCertificates = xSE->getPersonalCertificates(); if (xCertificates.hasElements()) { for (auto& xCert : asNonConstRange(xCertificates)) { - m_xSigningKeyLB->append_text( xCert->getIssuerName()); - m_xEncryptionKeyLB->append_text( xCert->getIssuerName()); + const auto aIssuer = comphelper::xmlsec::GetContentPart( + xCert->getSubjectName(), xCert->getCertificateKind()); + m_xSigningKeyLB->append_text(aIssuer); + m_xEncryptionKeyLB->append_text(aIssuer); } } + } + + if (xSecurityContext.is()) + { + uno::Reference<xml::crypto::XSecurityEnvironment> xSE = xSecurityContext->getSecurityEnvironment(); + uno::Sequence<uno::Reference<security::XCertificate>> xCertificates + = xSE->getPersonalCertificates(); + + if (xCertificates.hasElements()) + { + for (auto& xCert : asNonConstRange(xCertificates)) + { + const auto aIssuer + = comphelper::xmlsec::GetContentPart(xCert->getSubjectName(), + xCert->getCertificateKind()); + m_xSigningKeyLB->append_text(aIssuer); + } + } + } - //tdf#115015: wrap checkbox text and listboxes if necessary + if (xSecurityContext.is() || xSecurityContextGPG.is()) + { + //tdf#115015: wrap checkbox text and listboxes if necessary int nPrefWidth(m_xEncryptToSelfCB->get_preferred_size().Width()); int nMaxWidth = m_xEncryptToSelfCB->get_approximate_digit_width() * 40; if (nPrefWidth > nMaxWidth) diff --git a/cui/uiconfig/ui/optuserpage.ui b/cui/uiconfig/ui/optuserpage.ui index a3399ae49739..0c69fb176123 100644 --- a/cui/uiconfig/ui/optuserpage.ui +++ b/cui/uiconfig/ui/optuserpage.ui @@ -1098,7 +1098,7 @@ <object class="GtkLabel" id="signingkeylabel"> <property name="visible">True</property> <property name="can-focus">False</property> - <property name="label" translatable="yes" context="optuserpage|signingkeylabel">_OpenPGP signing key:</property> + <property name="label" translatable="yes" context="optuserpage|signingkeylabel">_Signing key:</property> <property name="use-underline">True</property> <property name="mnemonic-widget">signingkey</property> <property name="xalign">0</property> @@ -1151,7 +1151,7 @@ </items> <child internal-child="accessible"> <object class="AtkObject" id="signingkey-atkobject"> - <property name="AtkObject::accessible-description" translatable="yes" context="extended tip | signingkey">Select your OpenPGP key from the drop-down list for signing ODF documents.</property> + <property name="AtkObject::accessible-description" translatable="yes" context="extended tip | signingkey">Select your key from the drop-down list for signing ODF documents.</property> </object> </child> </object> |