libzypp 17.38.15
KeyRing.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12#ifndef ZYPP_KEYRING_H
13#define ZYPP_KEYRING_H
14
15#include <iosfwd>
16#include <functional>
17#include <map>
18#include <list>
19#include <set>
20#include <string>
21
24#include <zypp/Callback.h>
26#include <zypp/Locale.h>
28
31
33namespace zypp
34{
35
37
48 {
75
80 virtual KeyTrust askUserToAcceptKey( const PublicKey &key, const KeyContext &keycontext = KeyContext() );
81
83 virtual void infoVerify( const std::string & file_r, const PublicKeyData & keyData_r, const KeyContext &keycontext = KeyContext() );
84
85 virtual bool askUserToAcceptUnsignedFile( const std::string &file, const KeyContext &keycontext = KeyContext() );
86
93 virtual bool askUserToAcceptUnknownKey( const std::string &file, const std::string &id, const KeyContext &keycontext = KeyContext() );
94
100 virtual bool askUserToAcceptVerificationFailed( const std::string &file, const PublicKey &key, const KeyContext &keycontext = KeyContext() );
101
118 bool askUserToAcceptPackageKey( const PublicKey &key_r, const KeyContext &keycontext_r = KeyContext() );
120 constexpr static const char * ACCEPT_PACKAGE_KEY_REQUEST = "KeyRingReport/AcceptPackageKey";
121
131 void reportNonImportedKeys( const std::set<Edition> &keys_r );
133 constexpr static const char *KEYS_NOT_IMPORTED_REPORT = "KeyRingReport/KeysNotImported";
134
135
148 void reportAutoImportKey( const std::list<PublicKeyData> & keyDataList_r,
149 const PublicKeyData & keySigning_r,
150 const KeyContext &keyContext_r );
152 constexpr static const char *REPORT_AUTO_IMPORT_KEY = "KeyRingReport/reportAutoImportKey";
153 };
154
156 {
157 virtual void trustedKeyAdded( const PublicKey &/*key*/ )
158 {}
159 virtual void trustedKeyRemoved( const PublicKey &/*key*/ )
160 {}
161 };
162
164 //
165 // CLASS NAME : KeyRing
166 //
171 {
172 friend std::ostream & operator<<( std::ostream & str, const KeyRing & obj );
173
174 public:
179
196
198 static DefaultAccept defaultAccept();
199
201 static void setDefaultAccept( DefaultAccept value_r );
203
204 public:
206 struct Impl;
207
208 public:
210 KeyRing(const Pathname &baseTmpDir);
211
216 void importKey( const PublicKey &key, bool trusted = false);
217
219 void multiKeyImport( const Pathname & keyfile_r, bool trusted_r = false );
220
221 void dumpTrustedPublicKey( const std::string &id, std::ostream &stream )
222 { dumpPublicKey(id, true, stream); }
223
224 void dumpUntrustedPublicKey( const std::string &id, std::ostream &stream )
225 { dumpPublicKey(id, false, stream); }
226
227 void dumpPublicKey( const std::string &id, bool trusted, std::ostream &stream );
228
230 PublicKey exportPublicKey( const PublicKeyData & keyData );
231
233 PublicKey exportTrustedPublicKey( const PublicKeyData & keyData );
234
238 std::string readSignatureKeyId( const Pathname &signature );
239
243 bool isKeyTrusted( const std::string &id );
244
249 bool isKeyKnown( const std::string &id );
250
255 void deleteKey( const std::string &id, bool trusted = false );
256
260 std::list<PublicKey> publicKeys();
261
265 std::list<PublicKey> trustedPublicKeys();
266
270 std::list<PublicKeyData> publicKeyData();
271
275 std::list<PublicKeyData> trustedPublicKeyData();
276
280 PublicKeyData publicKeyData( const std::string &id );
281
285 PublicKeyData trustedPublicKeyData( const std::string &id );
286
293 bool verifyFileSignature( const Pathname &file, const Pathname &signature ) ZYPP_API;
294
295 bool verifyFileTrustedSignature( const Pathname &file, const Pathname &signature ) ZYPP_API;
296
298 ~KeyRing() override;
299
301 KeyRing::Impl &pimpl();
302
303 public:
305 void allowPreload( bool yesno_r );
306
311 void setTrustedKeyRingInit( std::function<void()> init_r );
312
313 private:
316 };
317
318
320 inline std::ostream & operator<<( std::ostream & str, const KeyRing & /*obj*/ )
321 {
322 //return str << obj.asString();
323 return str;
324 }
325
327 ZYPP_DECLARE_OPERATORS_FOR_FLAGS( KeyRing::DefaultAccept );
328
330
331 namespace target
332 {
333 namespace rpm
334 {
337 {};
338 }
339 }
340
342} // namespace zypp
344#endif // ZYPP_KEYRING_H
#define ZYPP_DECLARE_OPERATORS_FOR_FLAGS(Name)
relates: Flags
Definition Flags.h:177
#define DEFINE_PTR_TYPE(NAME)
Forward declaration of Ptr types.
Definition PtrTypes.h:639
Gpg key handling.
Definition KeyRing.h:171
ZYPP_DECLARE_FLAGS(DefaultAccept, DefaultAcceptBits)
static DefaultAccept defaultAccept()
Get the active accept bits.
Definition KeyRing.cc:53
void dumpTrustedPublicKey(const std::string &id, std::ostream &stream)
Definition KeyRing.h:221
void dumpPublicKey(const std::string &id, bool trusted, std::ostream &stream)
Definition KeyRing.cc:228
void multiKeyImport(const Pathname &keyfile_r, bool trusted_r=false)
Initial import from RpmDb.
Definition KeyRing.cc:196
KeyRing(const Pathname &baseTmpDir)
Default ctor.
Definition KeyRing.cc:174
void dumpUntrustedPublicKey(const std::string &id, std::ostream &stream)
Definition KeyRing.h:224
void importKey(const PublicKey &key, bool trusted=false)
imports a key from a file.
Definition KeyRing.cc:193
RW_pointer< Impl > _pimpl
Pointer to implementation.
Definition KeyRing.h:315
static void setDefaultAccept(DefaultAccept value_r)
Set the active accept bits.
Definition KeyRing.cc:56
DefaultAcceptBits
DefaultAccept flags (
Definition KeyRing.h:187
@ TRUST_KEY_TEMPORARILY
Definition KeyRing.h:191
@ ACCEPT_VERIFICATION_FAILED
Definition KeyRing.h:193
@ ACCEPT_UNKNOWNKEY
Definition KeyRing.h:190
@ TRUST_AND_IMPORT_KEY
Definition KeyRing.h:192
@ ACCEPT_UNSIGNED_FILE
Definition KeyRing.h:189
Class representing one GPG Public Keys data.
Definition PublicKey.h:201
Class representing one GPG Public Key (PublicKeyData + ASCII armored in a tempfile).
Definition PublicKey.h:378
Base class for reference counted objects.
String related utilities and Regular expression matching.
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
Definition NonCopyable.h:26
Easy-to use interface to the ZYPP dependency resolver.
const Arch Arch_empty ZYPP_API
relates: Arch This is an empty Arch represented by an empty string.
Definition Arch.h:173
std::ostream & operator<<(std::ostream &str, const Capabilities &obj)
relates: Capabilities Stream output
Callbacks from signature verification workflow.
Definition KeyRing.h:48
static constexpr const char * ACCEPT_PACKAGE_KEY_REQUEST
relates: askUserToAcceptPackageKey generic reports UserData::type
Definition KeyRing.h:120
void reportNonImportedKeys(const std::set< Edition > &keys_r)
Notify the user about keys that were not imported from the rpm key database into zypp keyring.
Definition KeyRing.cc:96
KeyTrust
User reply options for the askUserToTrustKey callback.
Definition KeyRing.h:55
@ KEY_TRUST_AND_IMPORT
Import the key.
Definition KeyRing.h:73
@ KEY_DONT_TRUST
User has chosen not to trust the key.
Definition KeyRing.h:59
@ KEY_TRUST_TEMPORARILY
This basically means, we knew the key, but it was not trusted.
Definition KeyRing.h:64
static constexpr const char * KEYS_NOT_IMPORTED_REPORT
relates: reportNonImportedKeys generic reports UserData::type
Definition KeyRing.h:133
static constexpr const char * REPORT_AUTO_IMPORT_KEY
relates: reportAutoImportKey generic reports UserData::type
Definition KeyRing.h:152
void reportAutoImportKey(const std::list< PublicKeyData > &keyDataList_r, const PublicKeyData &keySigning_r, const KeyContext &keyContext_r)
Notify that a repository auto imported new package signing keys.
Definition KeyRing.cc:103
virtual void trustedKeyAdded(const PublicKey &)
Definition KeyRing.h:157
virtual void trustedKeyRemoved(const PublicKey &)
Definition KeyRing.h:159
Wrapper for const correct access via Smart pointer types.
Definition PtrTypes.h:293
Internal connection to rpm database.
Definition KeyRing.h:337