libzypp  17.6.2
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"
27 #include "zypp/KeyContext.h"
28 
30 namespace zypp
31 {
32 
33  DEFINE_PTR_TYPE(KeyRing);
34 
45  {
51  enum KeyTrust
52  {
71  };
72 
73  constexpr static const char * ACCEPT_PACKAGE_KEY_REQUEST = "KeyRingReport/AcceptPackageKey";
74 
79  virtual KeyTrust askUserToAcceptKey( const PublicKey &key, const KeyContext &keycontext = KeyContext() );
80 
82  virtual void infoVerify( const std::string & file_r, const PublicKeyData & keyData_r, const KeyContext &keycontext = KeyContext() );
83 
84  virtual bool askUserToAcceptUnsignedFile( const std::string &file, const KeyContext &keycontext = KeyContext() );
85 
92  virtual bool askUserToAcceptUnknownKey( const std::string &file, const std::string &id, const KeyContext &keycontext = KeyContext() );
93 
99  virtual bool askUserToAcceptVerificationFailed( const std::string &file, const PublicKey &key, const KeyContext &keycontext = KeyContext() );
100 
116  bool askUserToAcceptPackageKey( const PublicKey &key_r, const KeyContext &keycontext_r = KeyContext() );
117 
118  };
119 
121  {
122  virtual void trustedKeyAdded( const PublicKey &/*key*/ )
123  {}
124  virtual void trustedKeyRemoved( const PublicKey &/*key*/ )
125  {}
126  };
127 
129  {
130  public:
135  : Exception( "Bad Key Exception" )
136  {}
140  KeyRingException( const std::string & msg_r )
141  : Exception( msg_r )
142  {}
144  virtual ~KeyRingException() throw() {};
145  };
146 
148  //
149  // CLASS NAME : KeyRing
150  //
155  {
156  friend std::ostream & operator<<( std::ostream & str, const KeyRing & obj );
157 
158  public:
171  {
172  ACCEPT_NOTHING = 0x0000,
178  };
179  ZYPP_DECLARE_FLAGS( DefaultAccept, DefaultAcceptBits );
180 
182  static DefaultAccept defaultAccept();
183 
185  static void setDefaultAccept( DefaultAccept value_r );
187 
188  public:
190  class Impl;
191 
192  public:
194  KeyRing(const Pathname &baseTmpDir);
195 
200  void importKey( const PublicKey &key, bool trusted = false);
201 
203  void multiKeyImport( const Pathname & keyfile_r, bool trusted_r = false );
204 
205  void dumpTrustedPublicKey( const std::string &id, std::ostream &stream )
206  { dumpPublicKey(id, true, stream); }
207 
208  void dumpUntrustedPublicKey( const std::string &id, std::ostream &stream )
209  { dumpPublicKey(id, false, stream); }
210 
211  void dumpPublicKey( const std::string &id, bool trusted, std::ostream &stream );
212 
214  PublicKey exportPublicKey( const PublicKeyData & keyData );
215 
218 
222  std::string readSignatureKeyId( const Pathname &signature );
223 
227  bool isKeyTrusted( const std::string &id );
228 
233  bool isKeyKnown( const std::string &id );
234 
239  void deleteKey( const std::string &id, bool trusted = false );
240 
244  std::list<PublicKey> publicKeys();
245 
249  std::list<PublicKey> trustedPublicKeys();
250 
254  std::list<PublicKeyData> publicKeyData();
255 
259  std::list<PublicKeyData> trustedPublicKeyData();
260 
264  PublicKeyData trustedPublicKeyData( const std::string &id );
265 
296  bool verifyFileSignatureWorkflow( const Pathname &file, const std::string &filedesc, const Pathname &signature, bool & sigValid_r, const KeyContext &keycontext = KeyContext());
298  bool verifyFileSignatureWorkflow( const Pathname &file, const std::string filedesc, const Pathname &signature, const KeyContext &keycontext = KeyContext());
299 
306  bool verifyFileSignature( const Pathname &file, const Pathname &signature );
307 
308  bool verifyFileTrustedSignature( const Pathname &file, const Pathname &signature );
309 
311  ~KeyRing();
312 
313  private:
316  };
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
void importKey(const PublicKey &key, bool trusted=false)
imports a key from a file.
Definition: KeyRing.cc:613
PublicKey exportTrustedPublicKey(const PublicKeyData &keyData)
Export a trusted public key identified by its key data.
Definition: KeyRing.cc:658
void dumpTrustedPublicKey(const std::string &id, std::ostream &stream)
Definition: KeyRing.h:205
Gpg key handling.
Definition: KeyRing.h:154
Helper filtering the files offered by a RepomdFileReader.
This basically means, we knew the key, but it was not trusted.
Definition: KeyRing.h:61
PublicKey exportPublicKey(const PublicKeyData &keyData)
Export a public key identified by its key data.
Definition: KeyRing.cc:655
KeyRingException(const std::string &msg_r)
Ctor taking message.
Definition: KeyRing.h:140
Class representing one GPG Public Keys data.
Definition: PublicKey.h:139
void dumpPublicKey(const std::string &id, bool trusted, std::ostream &stream)
Definition: KeyRing.cc:652
std::list< PublicKey > trustedPublicKeys()
Get a list of trusted public keys in the keyring (incl.
Definition: KeyRing.cc:628
ZYPP_DECLARE_OPERATORS_FOR_FLAGS(DiskUsageCounter::MountPoint::HintFlags)
virtual bool askUserToAcceptUnsignedFile(const std::string &file, const KeyContext &keycontext=KeyContext())
Definition: KeyRing.cc:63
String related utilities and Regular expression matching.
KeyRing(const Pathname &baseTmpDir)
Default ctor.
Definition: KeyRing.cc:605
std::list< PublicKeyData > trustedPublicKeyData()
Get a list of trusted public key data in the keyring (key data only)
Definition: KeyRing.cc:634
bool verifyFileSignatureWorkflow(const Pathname &file, const std::string &filedesc, const Pathname &signature, bool &sigValid_r, const KeyContext &keycontext=KeyContext())
Follows a signature verification interacting with the user.
Definition: KeyRing.cc:640
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:82
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:76
KeyRingException()
Ctor taking message.
Definition: KeyRing.h:134
Internal connection to rpm database.
Definition: KeyRing.h:336
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:60
ZYPP_DECLARE_FLAGS(DefaultAccept, DefaultAcceptBits)
KeyTrust
User reply options for the askUserToTrustKey callback.
Definition: KeyRing.h:51
~KeyRing()
Dtor.
Definition: KeyRing.cc:609
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
Definition: NonCopyable.h:26
static void setDefaultAccept(DefaultAccept value_r)
Set the active accept bits.
Definition: KeyRing.cc:54
void dumpUntrustedPublicKey(const std::string &id, std::ostream &stream)
Definition: KeyRing.h:208
DEFINE_PTR_TYPE(Application)
std::ostream & operator<<(std::ostream &str, const KeyRing &)
Definition: KeyRing.h:320
virtual void trustedKeyAdded(const PublicKey &)
Definition: KeyRing.h:122
Base class for reference counted objects.
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:664
static constexpr const char * ACCEPT_PACKAGE_KEY_REQUEST
Definition: KeyRing.h:73
void multiKeyImport(const Pathname &keyfile_r, bool trusted_r=false)
Initial import from RpmDb.
Definition: KeyRing.cc:616
User has chosen not to trust the key.
Definition: KeyRing.h:56
DefaultAcceptBits
DefaultAccept flags (
Definition: KeyRing.h:170
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:67
static DefaultAccept defaultAccept()
Get the active accept bits.
Definition: KeyRing.cc:51
RW_pointer< Impl > _pimpl
Pointer to implementation.
Definition: KeyRing.h:315
Class representing one GPG Public Key (PublicKeyData + ASCII armored in a tempfile).
Definition: PublicKey.h:272
std::list< PublicKeyData > publicKeyData()
Get a list of public key data in the keyring (key data only)
Definition: KeyRing.cc:631
Base class for Exception.
Definition: Exception.h:145
Callbacks from signature verification workflow.
Definition: KeyRing.h:44
void deleteKey(const std::string &id, bool trusted=false)
removes a key from the keyring.
Definition: KeyRing.cc:622
friend std::ostream & operator<<(std::ostream &str, const KeyRing &obj)
bool verifyFileTrustedSignature(const Pathname &file, const Pathname &signature)
Definition: KeyRing.cc:649
bool isKeyTrusted(const std::string &id)
true if the key id is trusted
Definition: KeyRing.cc:661
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
virtual void trustedKeyRemoved(const PublicKey &)
Definition: KeyRing.h:124
std::string readSignatureKeyId(const Pathname &signature)
reads the public key id from a signature
Definition: KeyRing.cc:619
bool verifyFileSignature(const Pathname &file, const Pathname &signature)
Verifies a file against a signature, with no user interaction.
Definition: KeyRing.cc:646
virtual ~KeyRingException()
Dtor.
Definition: KeyRing.h:144
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:79
std::list< PublicKey > publicKeys()
Get a list of public keys in the keyring (incl.
Definition: KeyRing.cc:625