Certificate Manager button is hidden in case no manager exists.

A new function is implemented to check for that in
digitalsignaturesdialog.cxx

Change-Id: I4cf1c710e6a145e8f0d10716cb81394bdcf7a74f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153367
Tested-by: Jenkins
Reviewed-by: Thorsten Behrens <thorsten.behrens@allotropia.de>
This commit is contained in:
TokieSan
2023-06-24 18:19:18 +02:00
committed by Thorsten Behrens
parent 79bce686b7
commit 17ba20e132
3 changed files with 68 additions and 16 deletions
@@ -89,6 +89,7 @@ private:
void ImplGetSignatureInformations(bool bUseTempStream, bool bCacheLastSignature);
void ImplFillSignaturesBox();
void ImplShowSignaturesDetails();
bool IsThereCertificateMgr();
css::uno::Reference<css::security::XCertificate> getCertificate(const SignatureInformation& rInfo);
css::uno::Reference<css::xml::crypto::XSecurityEnvironment> getSecurityEnvironmentForCertificate(
@@ -115,6 +115,16 @@ namespace
m_nODF = nTmp;
}
const std::vector<std::u16string_view> aGUIServersWindows = { u"Gpg4win\\kleopatra.exe",
u"Gpg4win\\bin\\kleopatra.exe",
u"GNU\\GnuPG\\kleopatra.exe",
u"GNU\\GnuPG\\launch-gpa.exe",
u"GNU\\GnuPG\\gpa.exe",
u"GnuPG\\bin\\gpa.exe",
u"GNU\\GnuPG\\bin\\kleopatra.exe",
u"GNU\\GnuPG\\bin\\launch-gpa.exe",
u"GNU\\GnuPG\\bin\\gpa.exe"};
const std::vector<std::u16string_view> aGUIServersNix = { u"kleopatra", u"seahorse", u"gpa", u"kgpg" };
}
DigitalSignaturesDialog::DigitalSignaturesDialog(
@@ -201,6 +211,11 @@ DigitalSignaturesDialog::DigitalSignaturesDialog(
m_xRemoveBtn->hide();
m_xStartCertMgrBtn->hide();
}
if ( !IsThereCertificateMgr() )
{
m_xStartCertMgrBtn->hide();
}
}
DigitalSignaturesDialog::~DigitalSignaturesDialog()
@@ -473,22 +488,54 @@ IMPL_LINK_NOARG(DigitalSignaturesDialog, RemoveButtonHdl, weld::Button&, void)
}
}
bool DigitalSignaturesDialog::IsThereCertificateMgr()
{
static std::vector<std::u16string_view> aGUIServers;
#ifdef _WIN32
static const OUString aPath = [] {
sal::systools::CoTaskMemAllocated<wchar_t> sPath;
HRESULT hr
= SHGetKnownFolderPath(FOLDERID_ProgramFilesX86, KF_FLAG_DEFAULT, nullptr, &sPath);
if (SUCCEEDED(hr))
return OUString(o3tl::toU(sPath));
return OUString();
}();
if (aPath.isEmpty())
return false;
aGUIServers = aGUIServersWindows;
#else
const char* cPath = getenv("PATH");
if (!cPath)
return false;
OUString aPath(cPath, strlen(cPath), osl_getThreadTextEncoding());
aGUIServers = aGUIServersNix;
#endif
if (aGUIServers.empty())
return false;
OUString sFoundGUIServer, sExecutable;
for ( auto const &rServer : aGUIServers )
{
osl::FileBase::RC searchError = osl::File::searchFileURL(OUString(rServer), aPath, sFoundGUIServer );
if (searchError == osl::FileBase::E_None)
{
osl::File::getSystemPathFromFileURL( sFoundGUIServer, sExecutable );
break;
}
}
return ( !sExecutable.isEmpty() );
}
IMPL_LINK_NOARG(DigitalSignaturesDialog, CertMgrButtonHdl, weld::Button&, void)
{
static std::vector<std::u16string_view> aGUIServers;
#ifdef _WIN32
// FIXME: call GpgME::dirInfo("bindir") somewhere in
// SecurityEnvironmentGpg or whatnot
// FIXME: perhaps poke GpgME for uiserver, and hope it returns something useful?
static const std::u16string_view aGUIServers[] = { u"Gpg4win\\kleopatra.exe",
u"Gpg4win\\bin\\kleopatra.exe",
u"GNU\\GnuPG\\kleopatra.exe",
u"GNU\\GnuPG\\launch-gpa.exe",
u"GNU\\GnuPG\\gpa.exe",
u"GnuPG\\bin\\gpa.exe",
u"GNU\\GnuPG\\bin\\kleopatra.exe",
u"GNU\\GnuPG\\bin\\launch-gpa.exe",
u"GNU\\GnuPG\\bin\\gpa.exe",
};
static const OUString aPath = [] {
sal::systools::CoTaskMemAllocated<wchar_t> sPath;
HRESULT hr
@@ -499,17 +546,21 @@ IMPL_LINK_NOARG(DigitalSignaturesDialog, CertMgrButtonHdl, weld::Button&, void)
}();
if (aPath.isEmpty())
return;
aGUIServers = aGUIServersWindows;
#else
static const std::u16string_view aGUIServers[] = { u"kleopatra", u"seahorse", u"gpa", u"kgpg" };
const char* cPath = getenv("PATH");
if (!cPath)
return;
OUString aPath(cPath, strlen(cPath), osl_getThreadTextEncoding());
aGUIServers = aGUIServersNix;
#endif
if (aGUIServers.empty())
return;
OUString sFoundGUIServer, sExecutable;
for ( auto const &rServer : aGUIServers )
for ( auto const &rServer : aGUIServers)
{
osl::FileBase::RC searchError = osl::File::searchFileURL(OUString(rServer), aPath, sFoundGUIServer );
if (searchError == osl::FileBase::E_None)
@@ -210,7 +210,7 @@
<property name="can_focus">False</property>
<property name="spacing">12</property>
<property name="homogeneous">True</property>
<property name="layout_style">spread</property>
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="view">
<property name="label" translatable="yes" context="digitalsignaturesdialog|view">View Certificate...</property>
@@ -224,7 +224,7 @@
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
@@ -243,7 +243,7 @@
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
@@ -261,7 +261,7 @@
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>