File indexing completed on 2024-06-16 04:58:33

0001 /* -*- mode: c++; c-basic-offset:4 -*-
0002     utils/gnupg.h
0003 
0004     This file is part of Kleopatra, the KDE keymanager
0005     SPDX-FileCopyrightText: 2008 Klarälvdalens Datakonsult AB
0006     SPDX-FileCopyrightText: 2020-2022 g10 Code GmbH
0007     SPDX-FileContributor: Ingo Klöcker <dev@ingo-kloecker.de>
0008 
0009     SPDX-License-Identifier: GPL-2.0-or-later
0010 */
0011 
0012 #pragma once
0013 
0014 #include "kleo_export.h"
0015 
0016 #include <QStringList>
0017 
0018 #include <gpgme++/engineinfo.h>
0019 #include <gpgme++/key.h>
0020 
0021 class QString;
0022 class QByteArray;
0023 
0024 namespace Kleo
0025 {
0026 
0027 KLEO_EXPORT QString gnupgHomeDirectory();
0028 KLEO_EXPORT QString gnupgPrivateKeysDirectory();
0029 
0030 KLEO_EXPORT QString gpgConfPath();
0031 KLEO_EXPORT QString gpgSmPath();
0032 KLEO_EXPORT QString gpgPath();
0033 
0034 KLEO_EXPORT QString gpgConfListDir(const char *which);
0035 KLEO_EXPORT QString gpg4winInstallPath();
0036 KLEO_EXPORT QString gnupgInstallPath();
0037 KLEO_EXPORT const QString &paperKeyInstallPath();
0038 
0039 /**
0040  * Verify \p filePath using gpgv. If \p sigPath is provided it uses
0041  * this signature, otherwise it adds .sig to the \p filePath. If
0042  * \p keyring is provided that is the keyring where the signature is
0043  * checked against. Otherwise it uses the default of gpgv.
0044  * \p additionalSearchPaths can be used to specify where gpgv is
0045  * searched for first.
0046  *
0047  * Blocks until the verification is done which can be indefinetly to
0048  * allow for very large files.
0049  *
0050  * Returns true if the verification was successful, false if any problem
0051  * occured. */
0052 KLEO_EXPORT bool gpgvVerify(const QString &filePath, const QString &sigPath = {}, const QString &keyring = {}, const QStringList &additionalSearchPaths = {});
0053 
0054 /**
0055  * Returns a list of filename globs of files in one of the whitelisted folders
0056  * to watch for changes.
0057  * \sa gnupgFolderWhitelist, Kleo::FileSystemWatcher
0058  */
0059 KLEO_EXPORT QStringList gnupgFileWhitelist();
0060 /**
0061  * Returns a list of absolute paths of folders to watch for changes.
0062  * \sa gnupgFileWhitelist, Kleo::FileSystemWatcher
0063  */
0064 KLEO_EXPORT QStringList gnupgFolderWhitelist();
0065 KLEO_EXPORT int makeGnuPGError(int code);
0066 
0067 KLEO_EXPORT bool engineIsVersion(int major, int minor, int patch, GpgME::Engine = GpgME::GpgConfEngine);
0068 
0069 /** Returns true, if GnuPG knows which keyserver to use for keyserver
0070  *  operations.
0071  *
0072  *  Since GnuPG 2.2.42/2.4.4 dirmngr supports the special value "none"
0073  *  to disable usage of the default keyserver. If this value is configured
0074  *  and GnuPG is new enough then this function returns false.
0075  *  Since version 2.1.19 GnuPG has a builtin default keyserver, so that this
0076  *  function always returns true (unless the above applies).
0077  *  For older versions of GnuPG it checks if a keyserver has been configured.
0078  */
0079 KLEO_EXPORT bool haveKeyserverConfigured();
0080 
0081 /** Returns the configured keyserver or an empty string if no keyserver is
0082  *  configured. The special value "none" indicates that no keyserver shall
0083  *  be used.
0084  *
0085  *  Note: Since GnuPG 2.1.19 gpg/dirmngr uses a default keyserver if no
0086  *        keyserver is configured.
0087  *        Since GnuPG 2.2.42/2.4.4 dirmngr supports the special value "none"
0088  *        to disable usage of the default keyserver.
0089  */
0090 KLEO_EXPORT QString keyserver();
0091 
0092 /** Returns true, if GnuPG knows which server to use for directory service
0093  *  operations for X.509 certificates.
0094  */
0095 KLEO_EXPORT bool haveX509DirectoryServerConfigured();
0096 
0097 /* Use gnupgUsesDeVsCompliance() or gnupgIsDeVsCompliant() instead. */
0098 KLEO_DEPRECATED_EXPORT bool gpgComplianceP(const char *mode);
0099 
0100 /**
0101  * Use Kleo::DeVSCompliance::isActive() instead.
0102  */
0103 KLEO_DEPRECATED_EXPORT bool gnupgUsesDeVsCompliance();
0104 
0105 /**
0106  * Use Kleo::DeVSCompliance::isCompliant() instead.
0107  */
0108 KLEO_DEPRECATED_EXPORT bool gnupgIsDeVsCompliant();
0109 
0110 /* Convert GnuPG output to a QString with proper encoding.
0111  * Takes Gpg Quirks into account and might handle future
0112  * changes in GnuPG Output. */
0113 KLEO_EXPORT QString stringFromGpgOutput(const QByteArray &ba);
0114 
0115 /* Check if a minimum version is there. Strings should be in the format:
0116  * 1.2.3 */
0117 KLEO_EXPORT bool versionIsAtLeast(const char *minimum, const char *actual);
0118 
0119 /** Returns a list of component names (e.g. GnuPG, libgcrypt) followed by
0120  *  version numbers. This is meant for displaying in the About dialog.
0121  */
0122 KLEO_EXPORT QStringList backendVersionInfo();
0123 
0124 /** Launch the GnuPG agent if it is not already running. */
0125 KLEO_EXPORT void launchGpgAgent();
0126 
0127 /** Shut down all GnuPG daemons. They will be restarted automatically when
0128  *  needed.
0129  */
0130 KLEO_EXPORT void killDaemons();
0131 
0132 /**
0133  * Returns a static list of the available algorithms.
0134  */
0135 KLEO_EXPORT const std::vector<std::string> &availableAlgorithms();
0136 
0137 /**
0138  * Returns a static list of the preferred algorithms with decreasing preference.
0139  */
0140 KLEO_EXPORT const std::vector<std::string> &preferredAlgorithms();
0141 
0142 /**
0143  * Returns a static list of algorithms that are explicitly not supported.
0144  */
0145 KLEO_EXPORT const std::vector<std::string> &ignoredAlgorithms();
0146 }