libzypp 17.32.5
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 <map>
17#include <list>
18#include <set>
19#include <string>
20
22#include <zypp/base/Flags.h>
23#include <zypp/Callback.h>
24#include <zypp/base/PtrTypes.h>
25#include <zypp/Locale.h>
26#include <zypp/PublicKey.h>
28
30namespace zypp
31{
32
34
45 {
72
77 virtual KeyTrust askUserToAcceptKey( const PublicKey &key, const KeyContext &keycontext = KeyContext() );
78
80 virtual void infoVerify( const std::string & file_r, const PublicKeyData & keyData_r, const KeyContext &keycontext = KeyContext() );
81
82 virtual bool askUserToAcceptUnsignedFile( const std::string &file, const KeyContext &keycontext = KeyContext() );
83
90 virtual bool askUserToAcceptUnknownKey( const std::string &file, const std::string &id, const KeyContext &keycontext = KeyContext() );
91
97 virtual bool askUserToAcceptVerificationFailed( const std::string &file, const PublicKey &key, const KeyContext &keycontext = KeyContext() );
98
117 constexpr static const char * ACCEPT_PACKAGE_KEY_REQUEST = "KeyRingReport/AcceptPackageKey";
118
128 void reportNonImportedKeys( const std::set<Edition> &keys_r );
130 constexpr static const char *KEYS_NOT_IMPORTED_REPORT = "KeyRingReport/KeysNotImported";
131
132
145 void reportAutoImportKey( const std::list<PublicKeyData> & keyDataList_r,
147 const KeyContext &keyContext_r );
149 constexpr static const char *REPORT_AUTO_IMPORT_KEY = "KeyRingReport/reportAutoImportKey";
150 };
151
153 {
154 virtual void trustedKeyAdded( const PublicKey &/*key*/ )
155 {}
156 virtual void trustedKeyRemoved( const PublicKey &/*key*/ )
157 {}
158 };
159
161 {
162 public:
167 : Exception( "Bad Key Exception" )
168 {}
172 KeyRingException( const std::string & msg_r )
173 : Exception( msg_r )
174 {}
176 ~KeyRingException() throw() override {};
177 };
178
180 //
181 // CLASS NAME : KeyRing
182 //
187 {
188 friend std::ostream & operator<<( std::ostream & str, const KeyRing & obj );
189
190 public:
212
215
219
220 public:
222 struct Impl;
223
224 public:
227
232 void importKey( const PublicKey &key, bool trusted = false);
233
235 void multiKeyImport( const Pathname & keyfile_r, bool trusted_r = false );
236
237 void dumpTrustedPublicKey( const std::string &id, std::ostream &stream )
238 { dumpPublicKey(id, true, stream); }
239
240 void dumpUntrustedPublicKey( const std::string &id, std::ostream &stream )
241 { dumpPublicKey(id, false, stream); }
242
243 void dumpPublicKey( const std::string &id, bool trusted, std::ostream &stream );
244
246 PublicKey exportPublicKey( const PublicKeyData & keyData );
247
250
254 std::string readSignatureKeyId( const Pathname &signature );
255
259 bool isKeyTrusted( const std::string &id );
260
265 bool isKeyKnown( const std::string &id );
266
271 void deleteKey( const std::string &id, bool trusted = false );
272
276 std::list<PublicKey> publicKeys();
277
281 std::list<PublicKey> trustedPublicKeys();
282
286 std::list<PublicKeyData> publicKeyData();
287
291 std::list<PublicKeyData> trustedPublicKeyData();
292
296 PublicKeyData publicKeyData( const std::string &id );
297
301 PublicKeyData trustedPublicKeyData( const std::string &id );
302
309 bool verifyFileSignature( const Pathname &file, const Pathname &signature );
310
311 bool verifyFileTrustedSignature( const Pathname &file, const Pathname &signature );
312
314 ~KeyRing() override;
315
318
319 public:
321 void allowPreload( bool yesno_r );
322
323 private:
326 };
328
330 inline std::ostream & operator<<( std::ostream & str, const KeyRing & /*obj*/ )
331 {
332 //return str << obj.asString();
333 return str;
334 }
335
337 ZYPP_DECLARE_OPERATORS_FOR_FLAGS( KeyRing::DefaultAccept );
338
340
341 namespace target
342 {
343 namespace rpm
344 {
347 {};
348 }
349 }
350
352} // namespace zypp
354#endif // ZYPP_KEYRING_H
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
Definition AutoDispose.h:95
Base class for Exception.
Definition Exception.h:147
KeyRingException()
Ctor taking message.
Definition KeyRing.h:166
~KeyRingException() override
Dtor.
Definition KeyRing.h:176
KeyRingException(const std::string &msg_r)
Ctor taking message.
Definition KeyRing.h:172
Gpg key handling.
Definition KeyRing.h:187
std::ostream & operator<<(std::ostream &str, const KeyRing &)
Stream output.
Definition KeyRing.h:330
KeyRing::Impl & pimpl()
Access to private functions for the KeyRingWorkflow implementations.
Definition KeyRing.cc:453
bool isKeyKnown(const std::string &id)
true if the key id is knows, that means at least exist on the untrusted keyring
Definition KeyRing.cc:509
std::list< PublicKey > publicKeys()
Get a list of public keys in the keyring (incl.
Definition KeyRing.cc:474
ZYPP_DECLARE_FLAGS(DefaultAccept, DefaultAcceptBits)
std::list< PublicKey > trustedPublicKeys()
Get a list of trusted public keys in the keyring (incl.
Definition KeyRing.cc:477
static DefaultAccept defaultAccept()
Get the active accept bits.
Definition KeyRing.cc:56
void dumpTrustedPublicKey(const std::string &id, std::ostream &stream)
Definition KeyRing.h:237
~KeyRing() override
Dtor.
Definition KeyRing.cc:450
void dumpPublicKey(const std::string &id, bool trusted, std::ostream &stream)
Definition KeyRing.cc:497
bool verifyFileSignature(const Pathname &file, const Pathname &signature)
Verifies a file against a signature, with no user interaction.
Definition KeyRing.cc:492
friend std::ostream & operator<<(std::ostream &str, const KeyRing &obj)
void multiKeyImport(const Pathname &keyfile_r, bool trusted_r=false)
Initial import from RpmDb.
Definition KeyRing.cc:465
KeyRing(const Pathname &baseTmpDir)
Default ctor.
Definition KeyRing.cc:446
PublicKey exportPublicKey(const PublicKeyData &keyData)
Export a public key identified by its key data.
Definition KeyRing.cc:500
std::string readSignatureKeyId(const Pathname &signature)
reads the public key id from a signature
Definition KeyRing.cc:468
void allowPreload(bool yesno_r)
The general keyring may be populated with known keys stored on the system.
Definition KeyRing.cc:458
void dumpUntrustedPublicKey(const std::string &id, std::ostream &stream)
Definition KeyRing.h:240
bool verifyFileTrustedSignature(const Pathname &file, const Pathname &signature)
Definition KeyRing.cc:495
void importKey(const PublicKey &key, bool trusted=false)
imports a key from a file.
Definition KeyRing.cc:462
RW_pointer< Impl > _pimpl
Pointer to implementation.
Definition KeyRing.h:325
void deleteKey(const std::string &id, bool trusted=false)
removes a key from the keyring.
Definition KeyRing.cc:471
std::list< PublicKeyData > trustedPublicKeyData()
Get a list of trusted public key data in the keyring (key data only)
Definition KeyRing.cc:483
static void setDefaultAccept(DefaultAccept value_r)
Set the active accept bits.
Definition KeyRing.cc:59
std::list< PublicKeyData > publicKeyData()
Get a list of public key data in the keyring (key data only)
Definition KeyRing.cc:480
DefaultAcceptBits
DefaultAccept flags (
Definition KeyRing.h:203
@ TRUST_KEY_TEMPORARILY
Definition KeyRing.h:207
@ ACCEPT_VERIFICATION_FAILED
Definition KeyRing.h:209
@ ACCEPT_UNKNOWNKEY
Definition KeyRing.h:206
@ TRUST_AND_IMPORT_KEY
Definition KeyRing.h:208
@ ACCEPT_UNSIGNED_FILE
Definition KeyRing.h:205
PublicKey exportTrustedPublicKey(const PublicKeyData &keyData)
Export a trusted public key identified by its key data.
Definition KeyRing.cc:503
bool isKeyTrusted(const std::string &id)
true if the key id is trusted
Definition KeyRing.cc:506
Class representing one GPG Public Keys data.
Definition PublicKey.h:208
Class representing one GPG Public Key (PublicKeyData + ASCII armored in a tempfile).
Definition PublicKey.h:365
Base class for reference counted objects.
bool trusted
Definition keyringwf.cc:152
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.
Callbacks from signature verification workflow.
Definition KeyRing.h:45
virtual void infoVerify(const std::string &file_r, const PublicKeyData &keyData_r, const KeyContext &keycontext=KeyContext())
Informal callback showing the trusted key that will be used for verification.
Definition KeyRing.cc:65
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:99
KeyTrust
User reply options for the askUserToTrustKey callback.
Definition KeyRing.h:52
@ KEY_TRUST_AND_IMPORT
Import the key.
Definition KeyRing.h:70
@ KEY_DONT_TRUST
User has chosen not to trust the key.
Definition KeyRing.h:56
@ KEY_TRUST_TEMPORARILY
This basically means, we knew the key, but it was not trusted.
Definition KeyRing.h:61
static constexpr const char * REPORT_AUTO_IMPORT_KEY
generic reports UserData::type
Definition KeyRing.h:149
virtual bool askUserToAcceptUnsignedFile(const std::string &file, const KeyContext &keycontext=KeyContext())
Definition KeyRing.cc:68
bool askUserToAcceptPackageKey(const PublicKey &key_r, const KeyContext &keycontext_r=KeyContext())
Ask user to trust and/or import the package key to trusted keyring, using ReportBase::report.
Definition KeyRing.cc:87
static constexpr const char * ACCEPT_PACKAGE_KEY_REQUEST
generic reports UserData::type
Definition KeyRing.h:117
static constexpr const char * KEYS_NOT_IMPORTED_REPORT
generic reports UserData::type
Definition KeyRing.h:130
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:106
virtual KeyTrust askUserToAcceptKey(const PublicKey &key, const KeyContext &keycontext=KeyContext())
Ask user to trust and/or import the key to trusted keyring.
Definition KeyRing.cc:72
virtual bool askUserToAcceptUnknownKey(const std::string &file, const std::string &id, const KeyContext &keycontext=KeyContext())
we DONT know the key, only its id, but we have never seen it, the difference with trust key is that i...
Definition KeyRing.cc:81
virtual bool askUserToAcceptVerificationFailed(const std::string &file, const PublicKey &key, const KeyContext &keycontext=KeyContext())
The file filedesc is signed but the verification failed.
Definition KeyRing.cc:84
virtual void trustedKeyAdded(const PublicKey &)
Definition KeyRing.h:154
virtual void trustedKeyRemoved(const PublicKey &)
Definition KeyRing.h:156
KeyRing implementation.
Definition keyring_p.h:95
Internal connection to rpm database.
Definition KeyRing.h:347
#define ZYPP_DECLARE_OPERATORS_FOR_FLAGS(Name)
Definition Flags.h:177
#define DEFINE_PTR_TYPE(NAME)
Forward declaration of Ptr types.
Definition PtrTypes.h:638