libzypp  11.13.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"
27 #include "zypp/KeyContext.h"
28 
30 namespace zypp
31 {
32 
33  DEFINE_PTR_TYPE(KeyRing);
34 
45  {
51  enum KeyTrust
52  {
71  };
72 
77  virtual KeyTrust askUserToAcceptKey( const PublicKey &key, const KeyContext &keycontext = KeyContext() );
78 
79  virtual bool askUserToAcceptUnsignedFile( const std::string &file, const KeyContext &keycontext = KeyContext() );
80 
87  virtual bool askUserToAcceptUnknownKey( const std::string &file, const std::string &id, const KeyContext &keycontext = KeyContext() );
88 
94  virtual bool askUserToAcceptVerificationFailed( const std::string &file, const PublicKey &key, const KeyContext &keycontext = KeyContext() );
95 
96  };
97 
99  {
100  virtual void trustedKeyAdded( const PublicKey &/*key*/ )
101  {}
102  virtual void trustedKeyRemoved( const PublicKey &/*key*/ )
103  {}
104  };
105 
107  {
108  public:
113  : Exception( "Bad Key Exception" )
114  {}
118  KeyRingException( const std::string & msg_r )
119  : Exception( msg_r )
120  {}
122  virtual ~KeyRingException() throw() {};
123  };
124 
126  //
127  // CLASS NAME : KeyRing
128  //
133  {
134  friend std::ostream & operator<<( std::ostream & str, const KeyRing & obj );
135 
136  public:
149  {
150  ACCEPT_NOTHING = 0x0000,
156  };
157  ZYPP_DECLARE_FLAGS( DefaultAccept, DefaultAcceptBits );
158 
160  static DefaultAccept defaultAccept();
161 
163  static void setDefaultAccept( DefaultAccept value_r );
165 
166  public:
168  class Impl;
169 
170  public:
172  KeyRing(const Pathname &baseTmpDir);
173 
178  void importKey( const PublicKey &key, bool trusted = false);
179 
181  void multiKeyImport( const Pathname & keyfile_r, bool trusted_r = false );
182 
183  void dumpTrustedPublicKey( const std::string &id, std::ostream &stream )
184  { dumpPublicKey(id, true, stream); }
185 
186  void dumpUntrustedPublicKey( const std::string &id, std::ostream &stream )
187  { dumpPublicKey(id, false, stream); }
188 
189  void dumpPublicKey( const std::string &id, bool trusted, std::ostream &stream );
190 
192  PublicKey exportPublicKey( const PublicKeyData & keyData );
193 
196 
200  std::string readSignatureKeyId( const Pathname &signature );
201 
205  bool isKeyTrusted( const std::string &id );
206 
211  bool isKeyKnown( const std::string &id );
212 
217  void deleteKey( const std::string &id, bool trusted = false );
218 
222  std::list<PublicKey> publicKeys();
223 
227  std::list<PublicKey> trustedPublicKeys();
228 
232  std::list<PublicKeyData> publicKeyData();
233 
237  std::list<PublicKeyData> trustedPublicKeyData();
238 
243  std::list<std::string> publicKeyIds() ZYPP_DEPRECATED;
244 
249  std::list<std::string> trustedPublicKeyIds() ZYPP_DEPRECATED;
250 
276  const Pathname &file,
277  const std::string filedesc,
278  const Pathname &signature,
279  const KeyContext &keycontext = KeyContext());
280 
281 
288  bool verifyFileSignature( const Pathname &file, const Pathname &signature );
289 
290  bool verifyFileTrustedSignature( const Pathname &file, const Pathname &signature );
291 
293  ~KeyRing();
294 
295  private:
298  };
300 
302  inline std::ostream & operator<<( std::ostream & str, const KeyRing & /*obj*/ )
303  {
304  //return str << obj.asString();
305  return str;
306  }
307 
309  ZYPP_DECLARE_OPERATORS_FOR_FLAGS( KeyRing::DefaultAccept );
310 
312 
313  namespace target
314  {
315  namespace rpm
316  {
319  {};
320  }
321  }
322 
324 } // namespace zypp
326 #endif // ZYPP_KEYRING_H