libzypp 17.34.1
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 {
52 {
56 KEY_DONT_TRUST = 0,
70 KEY_TRUST_AND_IMPORT
71 };
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
115 bool askUserToAcceptPackageKey( const PublicKey &key_r, const KeyContext &keycontext_r = KeyContext() );
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,
146 const PublicKeyData & keySigning_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:
203 {
204 ACCEPT_NOTHING = 0x0000,
205 ACCEPT_UNSIGNED_FILE = 0x0001,
206 ACCEPT_UNKNOWNKEY = 0x0002,
207 TRUST_KEY_TEMPORARILY = 0x0004,
208 TRUST_AND_IMPORT_KEY = 0x0008,
209 ACCEPT_VERIFICATION_FAILED = 0x0010,
210 };
212
214 static DefaultAccept defaultAccept();
215
217 static void setDefaultAccept( DefaultAccept value_r );
219
220 public:
222 struct Impl;
223
224 public:
226 KeyRing(const Pathname &baseTmpDir);
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
249 PublicKey exportTrustedPublicKey( const PublicKeyData & keyData );
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 ) ZYPP_API;
310
311 bool verifyFileTrustedSignature( const Pathname &file, const Pathname &signature ) ZYPP_API;
312
314 ~KeyRing() override;
315
317 KeyRing::Impl &pimpl();
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
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
ZYPP_DECLARE_FLAGS(DefaultAccept, DefaultAcceptBits)
void dumpTrustedPublicKey(const std::string &id, std::ostream &stream)
Definition KeyRing.h:237
friend std::ostream & operator<<(std::ostream &str, const KeyRing &obj)
void dumpUntrustedPublicKey(const std::string &id, std::ostream &stream)
Definition KeyRing.h:240
RW_pointer< Impl > _pimpl
Pointer to implementation.
Definition KeyRing.h:325
DefaultAcceptBits
DefaultAccept flags (
Definition KeyRing.h:203
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.
const Arch Arch_armv7hnl Arch_armv7nhl ZYPP_API
Definition Arch.h:247
Callbacks from signature verification workflow.
Definition KeyRing.h:45
KeyTrust
User reply options for the askUserToTrustKey callback.
Definition KeyRing.h:52
@ KEY_TRUST_TEMPORARILY
This basically means, we knew the key, but it was not trusted.
Definition KeyRing.h:61
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
Wrapper for const correct access via Smart pointer types.
Definition PtrTypes.h:293
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:639