libzypp  17.3.1
KeyRing.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #include <iostream>
13 #include <fstream>
14 #include <sys/file.h>
15 #include <cstdio>
16 #include <unistd.h>
17 
18 #include "zypp/TmpPath.h"
19 #include "zypp/ZYppFactory.h"
20 #include "zypp/ZYpp.h"
21 
22 #include "zypp/base/LogTools.h"
23 #include "zypp/base/IOStream.h"
24 #include "zypp/base/String.h"
25 #include "zypp/base/Regex.h"
26 #include "zypp/base/Gettext.h"
27 #include "zypp/base/WatchFile.h"
28 #include "zypp/PathInfo.h"
29 #include "zypp/KeyRing.h"
30 #include "zypp/ExternalProgram.h"
31 #include "zypp/TmpPath.h"
32 #include "zypp/ZYppCallbacks.h" // JobReport::instance
33 #include "zypp/KeyManager.h"
34 
35 using std::endl;
36 
37 #undef ZYPP_BASE_LOGGER_LOGGROUP
38 #define ZYPP_BASE_LOGGER_LOGGROUP "zypp::KeyRing"
39 
41 namespace zypp
42 {
43 
44  IMPL_PTR_TYPE(KeyRing);
45 
46  namespace
47  {
48  KeyRing::DefaultAccept _keyRingDefaultAccept( KeyRing::ACCEPT_NOTHING );
49  }
50 
51  KeyRing::DefaultAccept KeyRing::defaultAccept()
52  { return _keyRingDefaultAccept; }
53 
54  void KeyRing::setDefaultAccept( DefaultAccept value_r )
55  {
56  MIL << "Set new KeyRing::DefaultAccept: " << value_r << endl;
57  _keyRingDefaultAccept = value_r;
58  }
59 
60  void KeyRingReport::infoVerify( const std::string & file_r, const PublicKeyData & keyData_r, const KeyContext & keycontext )
61  {}
62 
63  bool KeyRingReport::askUserToAcceptUnsignedFile( const std::string & file, const KeyContext & keycontext )
64  { return _keyRingDefaultAccept.testFlag( KeyRing::ACCEPT_UNSIGNED_FILE ); }
65 
67  KeyRingReport::askUserToAcceptKey( const PublicKey & key, const KeyContext & keycontext )
68  {
69  if ( _keyRingDefaultAccept.testFlag( KeyRing::TRUST_KEY_TEMPORARILY ) )
70  return KEY_TRUST_TEMPORARILY;
71  if ( _keyRingDefaultAccept.testFlag( KeyRing::TRUST_AND_IMPORT_KEY ) )
72  return KEY_TRUST_AND_IMPORT;
73  return KEY_DONT_TRUST;
74  }
75 
76  bool KeyRingReport::askUserToAcceptUnknownKey( const std::string & file, const std::string & id, const KeyContext & keycontext )
77  { return _keyRingDefaultAccept.testFlag( KeyRing::ACCEPT_UNKNOWNKEY ); }
78 
79  bool KeyRingReport::askUserToAcceptVerificationFailed( const std::string & file, const PublicKey & key, const KeyContext & keycontext )
80  { return _keyRingDefaultAccept.testFlag( KeyRing::ACCEPT_VERIFICATION_FAILED ); }
81 
82  namespace
83  {
91  struct CachedPublicKeyData : private base::NonCopyable
92  {
93  const std::list<PublicKeyData> & operator()( const Pathname & keyring_r ) const
94  { return getData( keyring_r ); }
95 
96  void setDirty( const Pathname & keyring_r )
97  { _cacheMap[keyring_r].setDirty(); }
98 
99  private:
100  struct Cache
101  {
102  Cache() {}
103 
104  void setDirty()
105  {
106  _keyringK.reset();
107  _keyringP.reset();
108  }
109 
110  void assertCache( const Pathname & keyring_r )
111  {
112  // .kbx since gpg2-2.1
113  if ( !_keyringK )
114  _keyringK.reset( new WatchFile( keyring_r/"pubring.kbx", WatchFile::NO_INIT ) );
115  if ( !_keyringP )
116  _keyringP.reset( new WatchFile( keyring_r/"pubring.gpg", WatchFile::NO_INIT ) );
117  }
118 
119  bool hasChanged() const
120  {
121  bool k = _keyringK->hasChanged(); // be sure both files are checked
122  bool p = _keyringP->hasChanged();
123  return k || p;
124  }
125 
126  std::list<PublicKeyData> _data;
127 
128  private:
131  };
132 
133  typedef std::map<Pathname,Cache> CacheMap;
134 
135  const std::list<PublicKeyData> & getData( const Pathname & keyring_r ) const
136  {
137  Cache & cache( _cacheMap[keyring_r] );
138  // init new cache entry
139  cache.assertCache( keyring_r );
140  return getData( keyring_r, cache );
141  }
142 
143  const std::list<PublicKeyData> & getData( const Pathname & keyring_r, Cache & cache_r ) const
144  {
145  if ( cache_r.hasChanged() ) {
147  if (ctx) {
148  if (ctx->setHomedir(keyring_r)) {
149  std::list<PublicKeyData> foundKeys = ctx->listKeys();
150  cache_r._data.swap(foundKeys);
151  }
152  }
153  MIL << "Found keys: " << cache_r._data << endl;
154  }
155  return cache_r._data;
156  }
157 
158  mutable CacheMap _cacheMap;
159  };
161  }
162 
164  //
165  // CLASS NAME : KeyRing::Impl
166  //
169  {
170  Impl( const Pathname & baseTmpDir )
171  : _trusted_tmp_dir( baseTmpDir, "zypp-trusted-kr" )
172  , _general_tmp_dir( baseTmpDir, "zypp-general-kr" )
173  , _base_dir( baseTmpDir )
174  {
175  MIL << "Current KeyRing::DefaultAccept: " << _keyRingDefaultAccept << endl;
176  }
177 
178  void importKey( const PublicKey & key, bool trusted = false );
179  void multiKeyImport( const Pathname & keyfile_r, bool trusted_r = false );
180  void deleteKey( const std::string & id, bool trusted );
181 
182  std::string readSignatureKeyId( const Pathname & signature );
183 
184  bool isKeyTrusted( const std::string & id )
185  { return bool(publicKeyExists( id, trustedKeyRing() )); }
186  bool isKeyKnown( const std::string & id )
187  { return publicKeyExists( id, trustedKeyRing() ) || publicKeyExists( id, generalKeyRing() ); }
188 
189  std::list<PublicKey> trustedPublicKeys()
190  { return publicKeys( trustedKeyRing() ); }
191  std::list<PublicKey> publicKeys()
192  { return publicKeys( generalKeyRing() ); }
193 
194  const std::list<PublicKeyData> & trustedPublicKeyData()
195  { return publicKeyData( trustedKeyRing() ); }
196  const std::list<PublicKeyData> & publicKeyData()
197  { return publicKeyData( generalKeyRing() ); }
198 
199  void dumpPublicKey( const std::string & id, bool trusted, std::ostream & stream )
200  { dumpPublicKey( id, ( trusted ? trustedKeyRing() : generalKeyRing() ), stream ); }
201 
203  { return exportKey( keyData, generalKeyRing() ); }
205  { return exportKey( keyData, trustedKeyRing() ); }
206 
207  bool verifyFileSignatureWorkflow( const Pathname & file, const std::string & filedesc, const Pathname & signature, bool & sigValid_r, const KeyContext & keycontext = KeyContext());
208 
209  bool verifyFileSignature( const Pathname & file, const Pathname & signature )
210  { return verifyFile( file, signature, generalKeyRing() ); }
211  bool verifyFileTrustedSignature( const Pathname & file, const Pathname & signature )
212  { return verifyFile( file, signature, trustedKeyRing() ); }
213 
214  PublicKeyData trustedPublicKeyExists( const std::string & id )
215  { return publicKeyExists(id, trustedKeyRing());}
216 
217  private:
218  bool verifyFile( const Pathname & file, const Pathname & signature, const Pathname & keyring );
219  void importKey( const Pathname & keyfile, const Pathname & keyring );
220 
221  PublicKey exportKey( const std::string & id, const Pathname & keyring );
222  PublicKey exportKey( const PublicKeyData & keyData, const Pathname & keyring );
223  PublicKey exportKey( const PublicKey & key, const Pathname & keyring )
224  { return exportKey( key.keyData(), keyring ); }
225 
226  void dumpPublicKey( const std::string & id, const Pathname & keyring, std::ostream & stream );
227  filesystem::TmpFile dumpPublicKeyToTmp( const std::string & id, const Pathname & keyring );
228 
229  void deleteKey( const std::string & id, const Pathname & keyring );
230 
231  std::list<PublicKey> publicKeys( const Pathname & keyring);
232  const std::list<PublicKeyData> & publicKeyData( const Pathname & keyring )
233  { return cachedPublicKeyData( keyring ); }
234 
236  PublicKeyData publicKeyExists( const std::string & id, const Pathname & keyring );
237 
238  const Pathname generalKeyRing() const
239  { return _general_tmp_dir.path(); }
240  const Pathname trustedKeyRing() const
241  { return _trusted_tmp_dir.path(); }
242 
243  // Used for trusted and untrusted keyrings
247 
248  private:
254  CachedPublicKeyData cachedPublicKeyData;
255  };
257 
258  namespace
259  {
261  struct ImportKeyCBHelper
262  {
263  void operator()( const PublicKey & key_r )
264  {
265  try {
266  _rpmdbEmitSignal->trustedKeyAdded( key_r );
267  _emitSignal->trustedKeyAdded( key_r );
268  }
269  catch ( const Exception & excp )
270  {
271  ERR << "Could not import key into rpmdb: " << excp << endl;
272  // TODO: JobReport as hotfix for bsc#1057188; should bubble up and go through some callback
274  }
275  }
276 
277  private:
278  callback::SendReport<target::rpm::KeyRingSignals> _rpmdbEmitSignal;
279  callback::SendReport<KeyRingSignals> _emitSignal;
280  };
281  } // namespace
282 
283 
284  void KeyRing::Impl::importKey( const PublicKey & key, bool trusted )
285  {
286  importKey( key.path(), trusted ? trustedKeyRing() : generalKeyRing() );
287  MIL << "Imported key " << key << " to " << (trusted ? "trustedKeyRing" : "generalKeyRing" ) << endl;
288 
289  if ( trusted )
290  {
291  ImportKeyCBHelper emitSignal;
292  if ( key.hiddenKeys().empty() )
293  {
294  emitSignal( key );
295  }
296  else
297  {
298  // multiple keys: Export individual keys ascii armored to import in rpmdb
299  emitSignal( exportKey( key, trustedKeyRing() ) );
300  for ( const PublicKeyData & hkey : key.hiddenKeys() )
301  emitSignal( exportKey( hkey, trustedKeyRing() ) );
302  }
303  }
304  }
305 
306  void KeyRing::Impl::multiKeyImport( const Pathname & keyfile_r, bool trusted_r )
307  {
308  importKey( keyfile_r, trusted_r ? trustedKeyRing() : generalKeyRing() );
309  }
310 
311  void KeyRing::Impl::deleteKey( const std::string & id, bool trusted )
312  {
313  PublicKeyData keyDataToDel( publicKeyExists( id, trusted ? trustedKeyRing() : generalKeyRing() ) );
314  if ( ! keyDataToDel )
315  {
316  WAR << "Key to delete [" << id << "] is not in " << (trusted ? "trustedKeyRing" : "generalKeyRing" ) << endl;
317  return;
318  }
319  deleteKey( id, trusted ? trustedKeyRing() : generalKeyRing() );
320  MIL << "Deleted key [" << id << "] from " << (trusted ? "trustedKeyRing" : "generalKeyRing" ) << endl;
321 
322  if ( trusted )
323  try {
324  PublicKey key( keyDataToDel );
325 
327  rpmdbEmitSignal->trustedKeyRemoved( key );
328 
330  emitSignal->trustedKeyRemoved( key );
331  }
332  catch ( const Exception & excp )
333  {
334  ERR << "Could not delete key from rpmmdb: " << excp << endl;
335  // TODO: JobReport as hotfix for bsc#1057188; should bubble up and go through some callback
337  }
338  }
339 
340  PublicKeyData KeyRing::Impl::publicKeyExists( const std::string & id, const Pathname & keyring )
341  {
342  PublicKeyData ret;
343  for ( const PublicKeyData & key : publicKeyData( keyring ) )
344  {
345  if ( key.providesKey( id ) )
346  {
347  ret = key;
348  break;
349  }
350  }
351  MIL << (ret ? "Found" : "No") << " key [" << id << "] in keyring " << keyring << endl;
352  return ret;
353  }
354 
355  PublicKey KeyRing::Impl::exportKey( const PublicKeyData & keyData, const Pathname & keyring )
356  {
357  return PublicKey( dumpPublicKeyToTmp( keyData.id(), keyring ), keyData );
358  }
359 
360  PublicKey KeyRing::Impl::exportKey( const std::string & id, const Pathname & keyring )
361  {
362  PublicKeyData keyData( publicKeyExists( id, keyring ) );
363  if ( keyData )
364  return PublicKey( dumpPublicKeyToTmp( keyData.id(), keyring ), keyData );
365 
366  // Here: key not found
367  WAR << "No key [" << id << "] to export from " << keyring << endl;
368  return PublicKey();
369  }
370 
371 
372  void KeyRing::Impl::dumpPublicKey( const std::string & id, const Pathname & keyring, std::ostream & stream )
373  {
375  if (!ctx || !ctx->setHomedir(keyring))
376  return;
377  ctx->exportKey(id, stream);
378  }
379 
380  filesystem::TmpFile KeyRing::Impl::dumpPublicKeyToTmp( const std::string & id, const Pathname & keyring )
381  {
382  filesystem::TmpFile tmpFile( _base_dir, "pubkey-"+id+"-" );
383  MIL << "Going to export key [" << id << "] from " << keyring << " to " << tmpFile.path() << endl;
384 
385  std::ofstream os( tmpFile.path().c_str() );
386  dumpPublicKey( id, keyring, os );
387  os.close();
388  return tmpFile;
389  }
390 
391  bool KeyRing::Impl::verifyFileSignatureWorkflow( const Pathname & file, const std::string & filedesc, const Pathname & signature, bool & sigValid_r, const KeyContext & context )
392  {
393  sigValid_r = false; // set true if signature is actually successfully validated!
394 
396  MIL << "Going to verify signature for " << filedesc << " ( " << file << " ) with " << signature << endl;
397 
398  // if signature does not exists, ask user if he wants to accept unsigned file.
399  if( signature.empty() || (!PathInfo( signature ).isExist()) )
400  {
401  bool res = report->askUserToAcceptUnsignedFile( filedesc, context );
402  MIL << "askUserToAcceptUnsignedFile: " << res << endl;
403  return res;
404  }
405 
406  // get the id of the signature (it might be a subkey id!)
407  std::string id = readSignatureKeyId( signature );
408 
409  // does key exists in trusted keyring
410  PublicKeyData trustedKeyData( publicKeyExists( id, trustedKeyRing() ) );
411  if ( trustedKeyData )
412  {
413  MIL << "Key is trusted: " << trustedKeyData << endl;
414 
415  // lets look if there is an updated key in the
416  // general keyring
417  PublicKeyData generalKeyData( publicKeyExists( id, generalKeyRing() ) );
418  if ( generalKeyData )
419  {
420  // bnc #393160: Comment #30: Compare at least the fingerprint
421  // in case an attacker created a key the the same id.
422  //
423  // FIXME: bsc#1008325: For keys using subkeys, we'd actually need
424  // to compare the subkey sets, to tell whether a key was updated.
425  // because created() remains unchanged if the primary key is not touched.
426  // For now we wait until a new subkey signs the data and treat it as a
427  // new key (else part below).
428  if ( trustedKeyData.fingerprint() == generalKeyData.fingerprint()
429  && trustedKeyData.created() < generalKeyData.created() )
430  {
431  MIL << "Key was updated. Saving new version into trusted keyring: " << generalKeyData << endl;
432  importKey( exportKey( generalKeyData, generalKeyRing() ), true );
433  trustedKeyData = publicKeyExists( id, trustedKeyRing() ); // re-read: invalidated by import?
434  }
435  }
436 
437  // it exists, is trusted, does it validate?
438  report->infoVerify( filedesc, trustedKeyData, context );
439  if ( verifyFile( file, signature, trustedKeyRing() ) )
440  {
441  return (sigValid_r=true); // signature is actually successfully validated!
442  }
443  else
444  {
445  bool res = report->askUserToAcceptVerificationFailed( filedesc, exportKey( trustedKeyData, trustedKeyRing() ), context );
446  MIL << "askUserToAcceptVerificationFailed: " << res << endl;
447  return res;
448  }
449  }
450  else
451  {
452  PublicKeyData generalKeyData( publicKeyExists( id, generalKeyRing() ) );
453  if ( generalKeyData )
454  {
455  PublicKey key( exportKey( generalKeyData, generalKeyRing() ) );
456  MIL << "Key [" << id << "] " << key.name() << " is not trusted" << endl;
457 
458  // ok the key is not trusted, ask the user to trust it or not
459  KeyRingReport::KeyTrust reply = report->askUserToAcceptKey( key, context );
460  if ( reply == KeyRingReport::KEY_TRUST_TEMPORARILY ||
462  {
463  MIL << "User wants to trust key [" << id << "] " << key.name() << endl;
464 
465  Pathname whichKeyring;
467  {
468  MIL << "User wants to import key [" << id << "] " << key.name() << endl;
469  importKey( key, true );
470  whichKeyring = trustedKeyRing();
471  }
472  else
473  whichKeyring = generalKeyRing();
474 
475  // does it validate?
476  report->infoVerify( filedesc, generalKeyData, context );
477  if ( verifyFile( file, signature, whichKeyring ) )
478  {
479  return (sigValid_r=true); // signature is actually successfully validated!
480  }
481  else
482  {
483  bool res = report->askUserToAcceptVerificationFailed( filedesc, key, context );
484  MIL << "askUserToAcceptVerificationFailed: " << res << endl;
485  return res;
486  }
487  }
488  else
489  {
490  MIL << "User does not want to trust key [" << id << "] " << key.name() << endl;
491  return false;
492  }
493  }
494  else
495  {
496  // signed with an unknown key...
497  MIL << "File [" << file << "] ( " << filedesc << " ) signed with unknown key [" << id << "]" << endl;
498  bool res = report->askUserToAcceptUnknownKey( filedesc, id, context );
499  MIL << "askUserToAcceptUnknownKey: " << res << endl;
500  return res;
501  }
502  }
503  return false;
504  }
505 
506  std::list<PublicKey> KeyRing::Impl::publicKeys( const Pathname & keyring )
507  {
508  const std::list<PublicKeyData> & keys( publicKeyData( keyring ) );
509  std::list<PublicKey> ret;
510 
511  for_( it, keys.begin(), keys.end() )
512  {
513  PublicKey key( exportKey( *it, keyring ) );
514  ret.push_back( key );
515  MIL << "Found key " << key << endl;
516  }
517  return ret;
518  }
519 
520  void KeyRing::Impl::importKey( const Pathname & keyfile, const Pathname & keyring )
521  {
522  if ( ! PathInfo( keyfile ).isExist() )
523  // TranslatorExplanation first %s is key name, second is keyring name
524  ZYPP_THROW(KeyRingException( str::Format(_("Tried to import not existent key %s into keyring %s"))
525  % keyfile.asString()
526  % keyring.asString() ));
527 
529  if(!ctx || !ctx->setHomedir(keyring))
530  ZYPP_THROW(KeyRingException(_("Failed to import key.")));
531 
532  cachedPublicKeyData.setDirty( keyring );
533  if(!ctx->importKey(keyfile))
534  ZYPP_THROW(KeyRingException(_("Failed to import key.")));
535  }
536 
537  void KeyRing::Impl::deleteKey( const std::string & id, const Pathname & keyring )
538  {
540  if(!ctx) {
541  ZYPP_THROW(KeyRingException(_("Failed to delete key.")));
542  }
543 
544  if(!ctx->setHomedir(keyring)) {
545  ZYPP_THROW(KeyRingException(_("Failed to delete key.")));
546  }
547 
548  if(!ctx->deleteKey(id)){
549  ZYPP_THROW(KeyRingException(_("Failed to delete key.")));
550  }
551 
552  cachedPublicKeyData.setDirty( keyring );
553  }
554 
555  std::string KeyRing::Impl::readSignatureKeyId( const Pathname & signature )
556  {
557  if ( ! PathInfo( signature ).isFile() )
558  ZYPP_THROW(KeyRingException( str::Format(_("Signature file %s not found")) % signature.asString() ));
559 
560  MIL << "Determining key id of signature " << signature << endl;
561 
563  if(!ctx) {
564  return std::string();
565  }
566 
567  std::list<std::string> fprs = ctx->readSignatureFingerprints(signature);
568  if (fprs.size()) {
569  std::string &id = fprs.back();
570  MIL << "Determined key id [" << id << "] for signature " << signature << endl;
571  return id;
572  }
573  return std::string();
574  }
575 
576  bool KeyRing::Impl::verifyFile( const Pathname & file, const Pathname & signature, const Pathname & keyring )
577  {
579  if (!ctx || !ctx->setHomedir(keyring))
580  return false;
581 
582  return ctx->verify(file, signature);
583  }
584 
586 
588  //
589  // CLASS NAME : KeyRing
590  //
592 
593  KeyRing::KeyRing( const Pathname & baseTmpDir )
594  : _pimpl( new Impl( baseTmpDir ) )
595  {}
596 
598  {}
599 
600 
601  void KeyRing::importKey( const PublicKey & key, bool trusted )
602  { _pimpl->importKey( key, trusted ); }
603 
604  void KeyRing::multiKeyImport( const Pathname & keyfile_r, bool trusted_r )
605  { _pimpl->multiKeyImport( keyfile_r, trusted_r ); }
606 
607  std::string KeyRing::readSignatureKeyId( const Pathname & signature )
608  { return _pimpl->readSignatureKeyId( signature ); }
609 
610  void KeyRing::deleteKey( const std::string & id, bool trusted )
611  { _pimpl->deleteKey( id, trusted ); }
612 
613  std::list<PublicKey> KeyRing::publicKeys()
614  { return _pimpl->publicKeys(); }
615 
616  std:: list<PublicKey> KeyRing::trustedPublicKeys()
617  { return _pimpl->trustedPublicKeys(); }
618 
619  std::list<PublicKeyData> KeyRing::publicKeyData()
620  { return _pimpl->publicKeyData(); }
621 
622  std::list<PublicKeyData> KeyRing::trustedPublicKeyData()
623  { return _pimpl->trustedPublicKeyData(); }
624 
626  { return _pimpl->trustedPublicKeyExists( id_r ); }
627 
628  bool KeyRing::verifyFileSignatureWorkflow( const Pathname & file, const std::string & filedesc, const Pathname & signature, bool & sigValid_r, const KeyContext & keycontext )
629  { return _pimpl->verifyFileSignatureWorkflow( file, filedesc, signature, sigValid_r, keycontext ); }
630 
631  bool KeyRing::verifyFileSignatureWorkflow( const Pathname & file, const std::string filedesc, const Pathname & signature, const KeyContext & keycontext )
632  { bool unused; return _pimpl->verifyFileSignatureWorkflow( file, filedesc, signature, unused, keycontext ); }
633 
634  bool KeyRing::verifyFileSignature( const Pathname & file, const Pathname & signature )
635  { return _pimpl->verifyFileSignature( file, signature ); }
636 
637  bool KeyRing::verifyFileTrustedSignature( const Pathname & file, const Pathname & signature )
638  { return _pimpl->verifyFileTrustedSignature( file, signature ); }
639 
640  void KeyRing::dumpPublicKey( const std::string & id, bool trusted, std::ostream & stream )
641  { _pimpl->dumpPublicKey( id, trusted, stream ); }
642 
644  { return _pimpl->exportPublicKey( keyData ); }
645 
647  { return _pimpl->exportTrustedPublicKey( keyData ); }
648 
649  bool KeyRing::isKeyTrusted( const std::string & id )
650  { return _pimpl->isKeyTrusted( id ); }
651 
652  bool KeyRing::isKeyKnown( const std::string & id )
653  { return _pimpl->isKeyKnown( id ); }
654 
656 } // namespace zypp
void importKey(const PublicKey &key, bool trusted=false)
imports a key from a file.
Definition: KeyRing.cc:601
const std::list< PublicKeyData > & publicKeyData()
Definition: KeyRing.cc:196
Interface to gettext.
static Ptr createForOpenPGP()
Creates a new KeyManagerCtx for PGP.
Definition: KeyManager.cc:153
#define MIL
Definition: Logger.h:64
PublicKey exportTrustedPublicKey(const PublicKeyData &keyData)
Export a trusted public key identified by its key data.
Definition: KeyRing.cc:646
PublicKey exportPublicKey(const PublicKeyData &keyData)
Definition: KeyRing.cc:202
void dumpPublicKey(const std::string &id, bool trusted, std::ostream &stream)
Definition: KeyRing.cc:199
void deleteKey(const std::string &id, bool trusted)
Definition: KeyRing.cc:311
PublicKey exportKey(const std::string &id, const Pathname &keyring)
Definition: KeyRing.cc:360
static bool error(const std::string &msg_r, const UserData &userData_r=UserData())
send error text
bool isKeyTrusted(const std::string &id)
Definition: KeyRing.cc:184
const std::list< PublicKeyData > & hiddenKeys() const
Additional keys data in case the ASCII armored blob containes multiple keys.
Definition: PublicKey.cc:508
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Definition: Exception.h:392
const std::list< PublicKeyData > & trustedPublicKeyData()
Definition: KeyRing.cc:194
const PublicKeyData & keyData() const
The public keys data (.
Definition: PublicKey.cc:502
std::string name() const
Definition: PublicKey.cc:514
PublicKey exportKey(const PublicKey &key, const Pathname &keyring)
Definition: KeyRing.cc:223
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:643
Class representing one GPG Public Keys data.
Definition: PublicKey.h:139
bool isKeyKnown(const std::string &id)
Definition: KeyRing.cc:186
void dumpPublicKey(const std::string &id, bool trusted, std::ostream &stream)
Definition: KeyRing.cc:640
PublicKeyData publicKeyExists(const std::string &id, const Pathname &keyring)
Get PublicKeyData for ID (false if ID is not found).
Definition: KeyRing.cc:340
void multiKeyImport(const Pathname &keyfile_r, bool trusted_r=false)
Definition: KeyRing.cc:306
std::list< PublicKey > trustedPublicKeys()
Get a list of trusted public keys in the keyring (incl.
Definition: KeyRing.cc:616
bool verifyFile(const Pathname &file, const Pathname &signature, const Pathname &keyring)
Definition: KeyRing.cc:576
virtual bool askUserToAcceptUnsignedFile(const std::string &file, const KeyContext &keycontext=KeyContext())
Definition: KeyRing.cc:63
const char * c_str() const
String representation.
Definition: Pathname.h:109
KeyRing(const Pathname &baseTmpDir)
Default ctor.
Definition: KeyRing.cc:593
std::list< PublicKeyData > trustedPublicKeyData()
Get a list of trusted public key data in the keyring (key data only)
Definition: KeyRing.cc:622
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:628
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition: Easy.h:27
Pathname path() const
Definition: TmpPath.cc:146
Convenient building of std::string with boost::format.
Definition: String.h:251
Provide a new empty temporary file and delete it when no longer needed.
Definition: TmpPath.h:127
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
CachedPublicKeyData cachedPublicKeyData
Functor returning the keyrings data (cached).
Definition: KeyRing.cc:254
#define ERR
Definition: Logger.h:66
callback::SendReport< target::rpm::KeyRingSignals > _rpmdbEmitSignal
Definition: KeyRing.cc:278
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
PublicKey exportTrustedPublicKey(const PublicKeyData &keyData)
Definition: KeyRing.cc:204
KeyTrust
User reply options for the askUserToTrustKey callback.
Definition: KeyRing.h:51
bool empty() const
Test for an empty path.
Definition: Pathname.h:113
~KeyRing()
Dtor.
Definition: KeyRing.cc:597
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
Definition: NonCopyable.h:26
Date created() const
Creation / last modification date (latest selfsig).
Definition: PublicKey.cc:301
PublicKeyData trustedPublicKeyExists(const std::string &id)
Definition: KeyRing.cc:214
static void setDefaultAccept(DefaultAccept value_r)
Set the active accept bits.
Definition: KeyRing.cc:54
Provide a new empty temporary directory and recursively delete it when no longer needed.
Definition: TmpPath.h:177
filesystem::TmpDir _trusted_tmp_dir
Definition: KeyRing.cc:244
bool verifyFileSignature(const Pathname &file, const Pathname &signature)
Definition: KeyRing.cc:209
std::list< PublicKeyData > _data
Definition: KeyRing.cc:126
const std::string & asString() const
String representation.
Definition: Pathname.h:90
bool verifyFileSignatureWorkflow(const Pathname &file, const std::string &filedesc, const Pathname &signature, bool &sigValid_r, const KeyContext &keycontext=KeyContext())
Definition: KeyRing.cc:391
bool isExist() const
Return whether valid stat info exists.
Definition: PathInfo.h:281
std::string asUserHistory() const
A single (multiline) string composed of asUserString and historyAsString.
Definition: Exception.cc:91
const Pathname generalKeyRing() const
Definition: KeyRing.cc:238
filesystem::TmpFile dumpPublicKeyToTmp(const std::string &id, const Pathname &keyring)
Definition: KeyRing.cc:380
#define WAR
Definition: Logger.h:65
IMPL_PTR_TYPE(Application)
KeyRing implementation.
Definition: KeyRing.cc:168
std::list< PublicKey > trustedPublicKeys()
Definition: KeyRing.cc:189
scoped_ptr< WatchFile > _keyringP
Definition: KeyRing.cc:130
void importKey(const PublicKey &key, bool trusted=false)
Definition: KeyRing.cc:284
#define _(MSG)
Definition: Gettext.h:29
Impl(const Pathname &baseTmpDir)
Definition: KeyRing.cc:170
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:652
Pathname _base_dir
Definition: KeyRing.cc:246
void multiKeyImport(const Pathname &keyfile_r, bool trusted_r=false)
Initial import from RpmDb.
Definition: KeyRing.cc:604
User has chosen not to trust the key.
Definition: KeyRing.h:56
std::string fingerprint() const
Key fingerprint.
Definition: PublicKey.cc:298
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
scoped_ptr< WatchFile > _keyringK
Definition: KeyRing.cc:129
static DefaultAccept defaultAccept()
Get the active accept bits.
Definition: KeyRing.cc:51
RW_pointer< Impl > _pimpl
Pointer to implementation.
Definition: KeyRing.h:296
Class representing one GPG Public Key (PublicKeyData + ASCII armored in a tempfile).
Definition: PublicKey.h:269
std::list< PublicKeyData > publicKeyData()
Get a list of public key data in the keyring (key data only)
Definition: KeyRing.cc:619
Base class for Exception.
Definition: Exception.h:145
Pathname path() const
File containig the ASCII armored key.
Definition: PublicKey.cc:505
std::string id() const
Key ID.
Definition: PublicKey.cc:292
const Pathname trustedKeyRing() const
Definition: KeyRing.cc:240
callback::SendReport< DownloadProgressReport > * report
Definition: MediaCurl.cc:199
std::list< PublicKey > publicKeys()
Definition: KeyRing.cc:191
void deleteKey(const std::string &id, bool trusted=false)
removes a key from the keyring.
Definition: KeyRing.cc:610
bool verifyFileTrustedSignature(const Pathname &file, const Pathname &signature)
Definition: KeyRing.cc:637
bool verifyFileTrustedSignature(const Pathname &file, const Pathname &signature)
Definition: KeyRing.cc:211
shared_ptr< KeyManagerCtx > Ptr
Definition: KeyManager.h:34
Wrapper class for ::stat/::lstat.
Definition: PathInfo.h:220
const std::list< PublicKeyData > & publicKeyData(const Pathname &keyring)
Definition: KeyRing.cc:232
CacheMap _cacheMap
Definition: KeyRing.cc:158
bool isKeyTrusted(const std::string &id)
true if the key id is trusted
Definition: KeyRing.cc:649
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
callback::SendReport< KeyRingSignals > _emitSignal
Definition: KeyRing.cc:279
std::string readSignatureKeyId(const Pathname &signature)
reads the public key id from a signature
Definition: KeyRing.cc:607
bool verifyFileSignature(const Pathname &file, const Pathname &signature)
Verifies a file against a signature, with no user interaction.
Definition: KeyRing.cc:634
std::string readSignatureKeyId(const Pathname &signature)
Definition: KeyRing.cc:555
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:613
filesystem::TmpDir _general_tmp_dir
Definition: KeyRing.cc:245