Libkleo

gnupg.h
1/* -*- mode: c++; c-basic-offset:4 -*-
2 utils/gnupg.h
3
4 This file is part of Kleopatra, the KDE keymanager
5 SPDX-FileCopyrightText: 2008 Klarälvdalens Datakonsult AB
6 SPDX-FileCopyrightText: 2020-2022 g10 Code GmbH
7 SPDX-FileContributor: Ingo Klöcker <dev@ingo-kloecker.de>
8
9 SPDX-License-Identifier: GPL-2.0-or-later
10*/
11
12#pragma once
13
14#include "kleo_export.h"
15
16#include <QStringList>
17
18#include <gpgme++/engineinfo.h>
19#include <gpgme++/key.h>
20
21class QString;
22class QByteArray;
23
24namespace Kleo
25{
26
27KLEO_EXPORT QString gnupgHomeDirectory();
28KLEO_EXPORT QString gnupgPrivateKeysDirectory();
29
30KLEO_EXPORT QString gpgConfPath();
31KLEO_EXPORT QString gpgSmPath();
32KLEO_EXPORT QString gpgPath();
33
34KLEO_EXPORT QString gpgConfListDir(const char *which);
35KLEO_EXPORT QString gpg4winInstallPath();
36KLEO_EXPORT QString gnupgInstallPath();
37KLEO_EXPORT const QString &paperKeyInstallPath();
38
39/**
40 * Verify \p filePath using gpgv. If \p sigPath is provided it uses
41 * this signature, otherwise it adds .sig to the \p filePath. If
42 * \p keyring is provided that is the keyring where the signature is
43 * checked against. Otherwise it uses the default of gpgv.
44 * \p additionalSearchPaths can be used to specify where gpgv is
45 * searched for first.
46 *
47 * Blocks until the verification is done which can be indefinetly to
48 * allow for very large files.
49 *
50 * Returns true if the verification was successful, false if any problem
51 * occured. */
52KLEO_EXPORT bool gpgvVerify(const QString &filePath, const QString &sigPath = {}, const QString &keyring = {}, const QStringList &additionalSearchPaths = {});
53
54/**
55 * Returns a list of filename globs of files in one of the whitelisted folders
56 * to watch for changes.
57 * \sa gnupgFolderWhitelist, Kleo::FileSystemWatcher
58 */
59KLEO_EXPORT QStringList gnupgFileWhitelist();
60/**
61 * Returns a list of absolute paths of folders to watch for changes.
62 * \sa gnupgFileWhitelist, Kleo::FileSystemWatcher
63 */
64KLEO_EXPORT QStringList gnupgFolderWhitelist();
65KLEO_EXPORT int makeGnuPGError(int code);
66
67KLEO_EXPORT bool engineIsVersion(int major, int minor, int patch, GpgME::Engine = GpgME::GpgConfEngine);
68
69/** Returns true, if GnuPG knows which keyserver to use for keyserver
70 * operations.
71 *
72 * Since GnuPG 2.2.42/2.4.4 dirmngr supports the special value "none"
73 * to disable usage of the default keyserver. If this value is configured
74 * and GnuPG is new enough then this function returns false.
75 * Since version 2.1.19 GnuPG has a builtin default keyserver, so that this
76 * function always returns true (unless the above applies).
77 * For older versions of GnuPG it checks if a keyserver has been configured.
78 */
79KLEO_EXPORT bool haveKeyserverConfigured();
80
81/** Returns the configured keyserver or an empty string if no keyserver is
82 * configured. The special value "none" indicates that no keyserver shall
83 * be used.
84 *
85 * Note: Since GnuPG 2.1.19 gpg/dirmngr uses a default keyserver if no
86 * keyserver is configured.
87 * Since GnuPG 2.2.42/2.4.4 dirmngr supports the special value "none"
88 * to disable usage of the default keyserver.
89 */
90KLEO_EXPORT QString keyserver();
91
92/** Returns true, if GnuPG knows which server to use for directory service
93 * operations for X.509 certificates.
94 */
95KLEO_EXPORT bool haveX509DirectoryServerConfigured();
96
97/* Use gnupgUsesDeVsCompliance() or gnupgIsDeVsCompliant() instead. */
98KLEO_DEPRECATED_EXPORT bool gpgComplianceP(const char *mode);
99
100/**
101 * Use Kleo::DeVSCompliance::isActive() instead.
102 */
103KLEO_DEPRECATED_EXPORT bool gnupgUsesDeVsCompliance();
104
105/**
106 * Use Kleo::DeVSCompliance::isCompliant() instead.
107 */
108KLEO_DEPRECATED_EXPORT bool gnupgIsDeVsCompliant();
109
110/* Convert GnuPG output to a QString with proper encoding.
111 * Takes Gpg Quirks into account and might handle future
112 * changes in GnuPG Output. */
113KLEO_EXPORT QString stringFromGpgOutput(const QByteArray &ba);
114
115/* Check if a minimum version is there. Strings should be in the format:
116 * 1.2.3 */
117KLEO_EXPORT bool versionIsAtLeast(const char *minimum, const char *actual);
118
119/** Returns a list of component names (e.g. GnuPG, libgcrypt) followed by
120 * version numbers. This is meant for displaying in the About dialog.
121 */
122KLEO_EXPORT QStringList backendVersionInfo();
123
124enum LaunchGpgAgentOptions {
125 CheckForRunningAgent,
126 SkipCheckForRunningAgent,
127};
128
129/** Launch the GnuPG agent if it is not already running. */
130KLEO_EXPORT void launchGpgAgent(LaunchGpgAgentOptions options = CheckForRunningAgent);
131
132/** Shut down all GnuPG daemons and restart the GnuPG agent. */
133KLEO_EXPORT void restartGpgAgent();
134
135/**
136 * Returns a static list of the available algorithms.
137 */
138KLEO_EXPORT const std::vector<std::string> &availableAlgorithms();
139
140/**
141 * Returns a static list of the preferred algorithms with decreasing preference.
142 */
143KLEO_EXPORT const std::vector<std::string> &preferredAlgorithms();
144
145/**
146 * Returns a static list of algorithms that are explicitly not supported.
147 */
148KLEO_EXPORT const std::vector<std::string> &ignoredAlgorithms();
149
150/**
151 * Returns the lines of the private key file for the given keygrip.
152 */
153KLEO_EXPORT std::vector<QByteArray> readSecretKeyFile(const QString &keyGrip);
154}
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:29:01 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.