/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
SecurityEnvironmentGpg::SecurityEnvironmentGpg()
{ #ifdef _WIN32 // On Windows, gpgme expects gpgme-w32spawn.exe to be in the same directory as the current // process executable. This assumption might be wrong, e.g., for bundled python, which is // in instdir/program/python-core-x.y.z/bin, while gpgme-w32spawn.exe is in instdir/program. // If we can't find gpgme-w32spawn.exe in the current executable location, then try to find // the spawn executable, and inform gpgme about actual location using gpgme_set_global_flag.
[[maybe_unused]] staticbool bSpawnPathInitialized = [] { auto accessUrl = [](const INetURLObject& url) {
osl::File file(url.GetMainURL(INetURLObject::DecodeMechanism::NONE)); return file.open(osl_File_OpenFlag_Read) == osl::FileBase::E_None;
};
OUString sPath;
osl_getExecutableFile(&sPath.pData);
INetURLObject aPathUrl(sPath);
aPathUrl.setName(u"gpgme-w32spawn.exe"); if (!accessUrl(aPathUrl))
{
sPath = "$BRAND_BASE_DIR/" LIBO_LIBEXEC_FOLDER "/gpgme-w32spawn.exe";
rtl::Bootstrap::expandMacros(sPath);
aPathUrl.SetURL(sPath); if (accessUrl(aPathUrl))
{
aPathUrl.removeSegment();
GpgME::setGlobalFlag("w32-inst-dir",
aPathUrl.getFSysPath(FSysStyle::Dos).toUtf8().getStr());
}
} returntrue;
}(); #endif
GpgME::Error err = GpgME::checkEngine(GpgME::OpenPGP); if (err) throw RuntimeException(u"The GpgME library failed to initialize for the OpenPGP protocol."_ustr);
m_ctx.reset( GpgME::Context::createForProtocol(GpgME::OpenPGP) ); if (m_ctx == nullptr) throw RuntimeException(u"The GpgME library failed to initialize for the OpenPGP protocol."_ustr);
m_ctx->setArmor(false);
}
m_ctx->setKeyListMode(GPGME_KEYLIST_MODE_LOCAL);
GpgME::Error err = m_ctx->startKeyListing("", bPrivateOnly ); while (!err) {
GpgME::Key k = m_ctx->nextKey(err); if (err) break; if (!k.isRevoked() && !k.isExpired() && !k.isDisabled() && !k.isInvalid()) { // We can't create CertificateImpl here as CertificateImpl::setCertificate uses GpgME API // which interrupts our key listing here. So first get the keys from GpgME, then create the CertificateImpls
keyList.push_back(k);
}
}
m_ctx->endKeyListing();
Sequence< Reference< XCertificate > > xCertificateSequence(keyList.size()); auto xCertificateSequenceRange = asNonConstRange(xCertificateSequence); int i = 0; for (autoconst& key : keyList) {
rtl::Reference<CertificateImpl> xCert = new CertificateImpl();
xCert->setCertificate(m_ctx, key);
xCertificateSequenceRange[i++] = xCert; // fills xCertificateSequence
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.