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

KDE's Doxygen guidelines are available online.