libzypp  13.10.6
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 <boost/format.hpp>
19 
20 #include "zypp/TmpPath.h"
21 #include "zypp/ZYppFactory.h"
22 #include "zypp/ZYpp.h"
23 
24 #include "zypp/base/LogTools.h"
25 #include "zypp/base/IOStream.h"
26 #include "zypp/base/String.h"
27 #include "zypp/base/Regex.h"
28 #include "zypp/base/Gettext.h"
29 #include "zypp/base/WatchFile.h"
30 #include "zypp/PathInfo.h"
31 #include "zypp/KeyRing.h"
32 #include "zypp/ExternalProgram.h"
33 #include "zypp/TmpPath.h"
34 
35 using std::endl;
36 
37 #undef ZYPP_BASE_LOGGER_LOGGROUP
38 #define ZYPP_BASE_LOGGER_LOGGROUP "zypp::KeyRing"
39 
40 #define GPG_BINARY "/usr/bin/gpg2"
41 
43 namespace zypp
44 {
45 
46  IMPL_PTR_TYPE(KeyRing);
47 
48  namespace
49  {
50  KeyRing::DefaultAccept _keyRingDefaultAccept( KeyRing::ACCEPT_NOTHING );
51  }
52 
53  KeyRing::DefaultAccept KeyRing::defaultAccept()
54  { return _keyRingDefaultAccept; }
55 
56  void KeyRing::setDefaultAccept( DefaultAccept value_r )
57  {
58  MIL << "Set new KeyRing::DefaultAccept: " << value_r << endl;
59  _keyRingDefaultAccept = value_r;
60  }
61 
62  bool KeyRingReport::askUserToAcceptUnsignedFile( const std::string & file, const KeyContext & keycontext )
63  { return _keyRingDefaultAccept.testFlag( KeyRing::ACCEPT_UNSIGNED_FILE ); }
64 
66  KeyRingReport::askUserToAcceptKey( const PublicKey & key, const KeyContext & keycontext )
67  {
68  if ( _keyRingDefaultAccept.testFlag( KeyRing::TRUST_KEY_TEMPORARILY ) )
69  return KEY_TRUST_TEMPORARILY;
70  if ( _keyRingDefaultAccept.testFlag( KeyRing::TRUST_AND_IMPORT_KEY ) )
71  return KEY_TRUST_AND_IMPORT;
72  return KEY_DONT_TRUST;
73  }
74 
75  bool KeyRingReport::askUserToAcceptUnknownKey( const std::string & file, const std::string & id, const KeyContext & keycontext )
76  { return _keyRingDefaultAccept.testFlag( KeyRing::ACCEPT_UNKNOWNKEY ); }
77 
78  bool KeyRingReport::askUserToAcceptVerificationFailed( const std::string & file, const PublicKey & key, const KeyContext & keycontext )
79  { return _keyRingDefaultAccept.testFlag( KeyRing::ACCEPT_VERIFICATION_FAILED ); }
80 
81  namespace
82  {
90  struct CachedPublicKeyData // : private base::NonCopyable - but KeyRing uses RWCOW though also NonCopyable :(
91  {
92  const std::list<PublicKeyData> & operator()( const Pathname & keyring_r ) const
93  { return getData( keyring_r ); }
94 
95  private:
96  struct Cache
97  {
99  std::list<PublicKeyData> _data;
100 
101  // Empty copy ctor to allow insert into std::map as
102  // scoped_ptr is noncopyable.
103  Cache() {}
104  Cache( const Cache & rhs ) {}
105  };
106 
107  typedef std::map<Pathname,Cache> CacheMap;
108 
109  const std::list<PublicKeyData> & getData( const Pathname & keyring_r ) const
110  {
111  Cache & cache( _cacheMap[keyring_r] );
112  if ( ! cache._keyringP )
113  {
114  // init new cache entry
115  cache._keyringP.reset( new WatchFile( keyring_r/"pubring.gpg", WatchFile::NO_INIT ) );
116  }
117  return getData( keyring_r, cache );
118  }
119 
120  const std::list<PublicKeyData> & getData( const Pathname & keyring_r, Cache & cache_r ) const
121  {
122  if ( cache_r._keyringP->hasChanged() )
123  {
124  const char* argv[] =
125  {
126  GPG_BINARY,
127  "--list-public-keys",
128  "--homedir", keyring_r.c_str(),
129  "--no-default-keyring",
130  "--quiet",
131  "--with-colons",
132  "--fixed-list-mode",
133  "--with-fingerprint",
134  "--with-sig-list",
135  "--no-tty",
136  "--no-greeting",
137  "--batch",
138  "--status-fd", "1",
139  NULL
140  };
141 
142  PublicKeyScanner scanner;
143  ExternalProgram prog( argv ,ExternalProgram::Discard_Stderr, false, -1, true );
144  for( std::string line = prog.receiveLine(); !line.empty(); line = prog.receiveLine() )
145  {
146  scanner.scan( line );
147  }
148  prog.close();
149 
150  cache_r._data.swap( scanner._keys );
151  MIL << "Found keys: " << cache_r._data << endl;
152  }
153  return cache_r._data;
154  }
155 
156  mutable CacheMap _cacheMap;
157  };
159  }
160 
162  //
163  // CLASS NAME : KeyRing::Impl
164  //
167  {
168  Impl( const Pathname & baseTmpDir )
169  : _trusted_tmp_dir( baseTmpDir, "zypp-trusted-kr" )
170  , _general_tmp_dir( baseTmpDir, "zypp-general-kr" )
171  , _base_dir( baseTmpDir )
172  {
173  MIL << "Current KeyRing::DefaultAccept: " << _keyRingDefaultAccept << endl;
174  }
175 
176  void importKey( const PublicKey & key, bool trusted = false );
177  void multiKeyImport( const Pathname & keyfile_r, bool trusted_r = false );
178  void deleteKey( const std::string & id, bool trusted );
179 
180  std::string readSignatureKeyId( const Pathname & signature );
181 
182  bool isKeyTrusted( const std::string & id )
183  { return bool(publicKeyExists( id, trustedKeyRing() )); }
184  bool isKeyKnown( const std::string & id )
185  { return publicKeyExists( id, trustedKeyRing() ) || publicKeyExists( id, generalKeyRing() ); }
186 
187  std::list<PublicKey> trustedPublicKeys()
188  { return publicKeys( trustedKeyRing() ); }
189  std::list<PublicKey> publicKeys()
190  { return publicKeys( generalKeyRing() ); }
191 
192  const std::list<PublicKeyData> & trustedPublicKeyData()
193  { return publicKeyData( trustedKeyRing() ); }
194  const std::list<PublicKeyData> & publicKeyData()
195  { return publicKeyData( generalKeyRing() ); }
196 
197  void dumpPublicKey( const std::string & id, bool trusted, std::ostream & stream )
198  { dumpPublicKey( id, ( trusted ? trustedKeyRing() : generalKeyRing() ), stream ); }
199 
201  { return exportKey( keyData, generalKeyRing() ); }
203  { return exportKey( keyData, trustedKeyRing() ); }
204 
206  const Pathname & file,
207  const std::string & filedesc,
208  const Pathname & signature,
209  const KeyContext & keycontext = KeyContext());
210 
211  bool verifyFileSignature( const Pathname & file, const Pathname & signature )
212  { return verifyFile( file, signature, generalKeyRing() ); }
213  bool verifyFileTrustedSignature( const Pathname & file, const Pathname & signature )
214  { return verifyFile( file, signature, trustedKeyRing() ); }
215 
216  private:
217  bool verifyFile( const Pathname & file, const Pathname & signature, const Pathname & keyring );
218  void importKey( const Pathname & keyfile, const Pathname & keyring );
219 
220  PublicKey exportKey( const std::string & id, const Pathname & keyring );
221  PublicKey exportKey( const PublicKeyData & keyData, const Pathname & keyring );
222 
223  void dumpPublicKey( const std::string & id, const Pathname & keyring, std::ostream & stream );
224  filesystem::TmpFile dumpPublicKeyToTmp( const std::string & id, const Pathname & keyring );
225 
226  void deleteKey( const std::string & id, const Pathname & keyring );
227 
228  std::list<PublicKey> publicKeys( const Pathname & keyring);
229  const std::list<PublicKeyData> & publicKeyData( const Pathname & keyring )
230  { return cachedPublicKeyData( keyring ); }
231 
233  PublicKeyData publicKeyExists( const std::string & id, const Pathname & keyring );
234 
235  const Pathname generalKeyRing() const
236  { return _general_tmp_dir.path(); }
237  const Pathname trustedKeyRing() const
238  { return _trusted_tmp_dir.path(); }
239 
240  // Used for trusted and untrusted keyrings
243  Pathname _base_dir;
244 
245  private:
251  CachedPublicKeyData cachedPublicKeyData;
252  };
254 
255 
256  void KeyRing::Impl::importKey( const PublicKey & key, bool trusted )
257  {
258  importKey( key.path(), trusted ? trustedKeyRing() : generalKeyRing() );
259 
260  if ( trusted )
261  {
264 
265  rpmdbEmitSignal->trustedKeyAdded( key );
266  emitSignal->trustedKeyAdded( key );
267  }
268  }
269 
270  void KeyRing::Impl::multiKeyImport( const Pathname & keyfile_r, bool trusted_r )
271  {
272  importKey( keyfile_r, trusted_r ? trustedKeyRing() : generalKeyRing() );
273  }
274 
275  void KeyRing::Impl::deleteKey( const std::string & id, bool trusted )
276  {
277  PublicKey key;
278 
279  if ( trusted )
280  {
281  key = exportKey( id, trustedKeyRing() );
282  }
283 
284  deleteKey( id, trusted ? trustedKeyRing() : generalKeyRing() );
285 
286  if ( trusted )
287  {
290 
291  rpmdbEmitSignal->trustedKeyRemoved( key );
292  emitSignal->trustedKeyRemoved( key );
293  }
294  }
295 
296  PublicKeyData KeyRing::Impl::publicKeyExists( const std::string & id, const Pathname & keyring )
297  {
298  MIL << "Searching key [" << id << "] in keyring " << keyring << endl;
299  const std::list<PublicKeyData> & keys( publicKeyData( keyring ) );
300  for_( it, keys.begin(), keys.end() )
301  {
302  if ( id == (*it).id() )
303  {
304  return *it;
305  }
306  }
307  return PublicKeyData();
308  }
309 
310  PublicKey KeyRing::Impl::exportKey( const PublicKeyData & keyData, const Pathname & keyring )
311  {
312  return PublicKey( dumpPublicKeyToTmp( keyData.id(), keyring ), keyData );
313  }
314 
315  PublicKey KeyRing::Impl::exportKey( const std::string & id, const Pathname & keyring )
316  {
317  PublicKeyData keyData( publicKeyExists( id, keyring ) );
318  if ( keyData )
319  return PublicKey( dumpPublicKeyToTmp( keyData.id(), keyring ), keyData );
320 
321  // Here: key not found
322  WAR << "No key " << id << " to export from " << keyring << endl;
323  return PublicKey();
324  }
325 
326 
327  void KeyRing::Impl::dumpPublicKey( const std::string & id, const Pathname & keyring, std::ostream & stream )
328  {
329  const char* argv[] =
330  {
331  GPG_BINARY,
332  "-a",
333  "--export",
334  "--homedir", keyring.asString().c_str(),
335  "--no-default-keyring",
336  "--quiet",
337  "--no-tty",
338  "--no-greeting",
339  "--no-permission-warning",
340  "--batch",
341  id.c_str(),
342  NULL
343  };
344  ExternalProgram prog( argv,ExternalProgram::Discard_Stderr, false, -1, true );
345  for ( std::string line = prog.receiveLine(); !line.empty(); line = prog.receiveLine() )
346  {
347  stream << line;
348  }
349  prog.close();
350  }
351 
352  filesystem::TmpFile KeyRing::Impl::dumpPublicKeyToTmp( const std::string & id, const Pathname & keyring )
353  {
354  filesystem::TmpFile tmpFile( _base_dir, "pubkey-"+id+"-" );
355  MIL << "Going to export key " << id << " from " << keyring << " to " << tmpFile.path() << endl;
356 
357  std::ofstream os( tmpFile.path().c_str() );
358  dumpPublicKey( id, keyring, os );
359  os.close();
360  return tmpFile;
361  }
362 
364  const Pathname & file,
365  const std::string & filedesc,
366  const Pathname & signature,
367  const KeyContext & context )
368  {
370  MIL << "Going to verify signature for " << filedesc << " ( " << file << " ) with " << signature << endl;
371 
372  // if signature does not exists, ask user if he wants to accept unsigned file.
373  if( signature.empty() || (!PathInfo( signature ).isExist()) )
374  {
375  bool res = report->askUserToAcceptUnsignedFile( filedesc, context );
376  MIL << "User decision on unsigned file: " << res << endl;
377  return res;
378  }
379 
380  // get the id of the signature
381  std::string id = readSignatureKeyId( signature );
382 
383  // doeskey exists in trusted keyring
384  PublicKeyData trustedKeyData( publicKeyExists( id, trustedKeyRing() ) );
385  if ( trustedKeyData )
386  {
387  MIL << "Key is trusted: " << trustedKeyData << endl;
388 
389  // lets look if there is an updated key in the
390  // general keyring
391  PublicKeyData generalKeyData( publicKeyExists( id, generalKeyRing() ) );
392  if ( generalKeyData )
393  {
394  // bnc #393160: Comment #30: Compare at least the fingerprint
395  // in case an attacker created a key the the same id.
396  if ( trustedKeyData.fingerprint() == generalKeyData.fingerprint()
397  && trustedKeyData.created() < generalKeyData.created() )
398  {
399  MIL << "Key was updated. Saving new version into trusted keyring: " << generalKeyData << endl;
400  importKey( exportKey( generalKeyData, generalKeyRing() ), true );
401  trustedKeyData = generalKeyData = PublicKeyData(); // invalidated by import.
402  }
403  }
404 
405  // it exists, is trusted, does it validates?
406  if ( verifyFile( file, signature, trustedKeyRing() ) )
407  return true;
408  else
409  {
410  if ( ! trustedKeyData ) // invalidated by previous import
411  trustedKeyData = publicKeyExists( id, trustedKeyRing() );
412  return report->askUserToAcceptVerificationFailed( filedesc, exportKey( trustedKeyData, trustedKeyRing() ), context );
413  }
414  }
415  else
416  {
417  PublicKeyData generalKeyData( publicKeyExists( id, generalKeyRing() ) );
418  if ( generalKeyData )
419  {
420  PublicKey key( exportKey( generalKeyData, generalKeyRing() ) );
421  MIL << "Exported key " << id << " to " << key.path() << endl;
422  MIL << "Key " << id << " " << key.name() << " is not trusted" << endl;
423 
424  // ok the key is not trusted, ask the user to trust it or not
425  KeyRingReport::KeyTrust reply = report->askUserToAcceptKey( key, context );
426  if ( reply == KeyRingReport::KEY_TRUST_TEMPORARILY ||
428  {
429  MIL << "User wants to trust key " << id << " " << key.name() << endl;
430  //dumpFile( unKey.path() );
431 
432  Pathname whichKeyring;
434  {
435  MIL << "User wants to import key " << id << " " << key.name() << endl;
436  importKey( key, true );
437  whichKeyring = trustedKeyRing();
438  }
439  else
440  whichKeyring = generalKeyRing();
441 
442  // emit key added
443  if ( verifyFile( file, signature, whichKeyring ) )
444  {
445  MIL << "File signature is verified" << endl;
446  return true;
447  }
448  else
449  {
450  MIL << "File signature check fails" << endl;
451  if ( report->askUserToAcceptVerificationFailed( filedesc, key, context ) )
452  {
453  MIL << "User continues anyway." << endl;
454  return true;
455  }
456  else
457  {
458  MIL << "User does not want to continue" << endl;
459  return false;
460  }
461  }
462  }
463  else
464  {
465  MIL << "User does not want to trust key " << id << " " << key.name() << endl;
466  return false;
467  }
468  }
469  else
470  {
471  // unknown key...
472  MIL << "File [" << file << "] ( " << filedesc << " ) signed with unknown key [" << id << "]" << endl;
473  if ( report->askUserToAcceptUnknownKey( filedesc, id, context ) )
474  {
475  MIL << "User wants to accept unknown key " << id << endl;
476  return true;
477  }
478  else
479  {
480  MIL << "User does not want to accept unknown key " << id << endl;
481  return false;
482  }
483  }
484  }
485  return false;
486  }
487 
488  std::list<PublicKey> KeyRing::Impl::publicKeys( const Pathname & keyring )
489  {
490  const std::list<PublicKeyData> & keys( publicKeyData( keyring ) );
491  std::list<PublicKey> ret;
492 
493  for_( it, keys.begin(), keys.end() )
494  {
495  PublicKey key( exportKey( *it, keyring ) );
496  ret.push_back( key );
497  MIL << "Found key " << key << endl;
498  }
499  return ret;
500  }
501 
502  void KeyRing::Impl::importKey( const Pathname & keyfile, const Pathname & keyring )
503  {
504  if ( ! PathInfo( keyfile ).isExist() )
505  // TranslatorExplanation first %s is key name, second is keyring name
506  ZYPP_THROW(KeyRingException(boost::str(boost::format(
507  _("Tried to import not existent key %s into keyring %s"))
508  % keyfile.asString() % keyring.asString())));
509 
510  const char* argv[] =
511  {
512  GPG_BINARY,
513  "--import",
514  "--homedir", keyring.asString().c_str(),
515  "--no-default-keyring",
516  "--quiet",
517  "--no-tty",
518  "--no-greeting",
519  "--no-permission-warning",
520  "--status-fd", "1",
521  keyfile.asString().c_str(),
522  NULL
523  };
524 
525  ExternalProgram prog( argv,ExternalProgram::Discard_Stderr, false, -1, true );
526  prog.close();
527  }
528 
529  void KeyRing::Impl::deleteKey( const std::string & id, const Pathname & keyring )
530  {
531  const char* argv[] =
532  {
533  GPG_BINARY,
534  "--delete-keys",
535  "--homedir", keyring.asString().c_str(),
536  "--no-default-keyring",
537  "--yes",
538  "--quiet",
539  "--no-tty",
540  "--batch",
541  "--status-fd", "1",
542  id.c_str(),
543  NULL
544  };
545 
546  ExternalProgram prog( argv,ExternalProgram::Discard_Stderr, false, -1, true );
547 
548  int code = prog.close();
549  if ( code )
550  ZYPP_THROW(Exception(_("Failed to delete key.")));
551  else
552  MIL << "Deleted key " << id << " from keyring " << keyring << endl;
553  }
554 
555 
556  std::string KeyRing::Impl::readSignatureKeyId( const Pathname & signature )
557  {
558  if ( ! PathInfo( signature ).isFile() )
559  ZYPP_THROW(Exception(boost::str(boost::format(
560  _("Signature file %s not found"))% signature.asString())));
561 
562  MIL << "Determining key id if signature " << signature << endl;
563  // HACK create a tmp keyring with no keys
564  filesystem::TmpDir dir( _base_dir, "fake-keyring" );
565 
566  const char* argv[] =
567  {
568  GPG_BINARY,
569  "--homedir", dir.path().asString().c_str(),
570  "--no-default-keyring",
571  "--quiet",
572  "--no-tty",
573  "--no-greeting",
574  "--batch",
575  "--status-fd", "1",
576  signature.asString().c_str(),
577  NULL
578  };
579 
580  ExternalProgram prog( argv,ExternalProgram::Discard_Stderr, false, -1, true );
581 
582  std::string line;
583  int count = 0;
584 
585  str::regex rxNoKey( "^\\[GNUPG:\\] NO_PUBKEY (.+)\n$" );
586  std::string id;
587  for( line = prog.receiveLine(), count=0; !line.empty(); line = prog.receiveLine(), count++ )
588  {
589  //MIL << "[" << line << "]" << endl;
590  str::smatch what;
591  if( str::regex_match( line, what, rxNoKey ) )
592  {
593  if ( what.size() >= 1 )
594  {
595  id = what[1];
596  break;
597  }
598  //dumpRegexpResults( what );
599  }
600  }
601 
602  if ( count == 0 )
603  {
604  MIL << "no output" << endl;
605  }
606 
607  MIL << "Determined key id [" << id << "] for signature " << signature << endl;
608  prog.close();
609  return id;
610  }
611 
612  bool KeyRing::Impl::verifyFile( const Pathname & file, const Pathname & signature, const Pathname & keyring )
613  {
614  const char* argv[] =
615  {
616  GPG_BINARY,
617  "--verify",
618  "--homedir", keyring.asString().c_str(),
619  "--no-default-keyring",
620  "--quiet",
621  "--no-tty",
622  "--batch",
623  "--no-greeting",
624  "--status-fd", "1",
625  signature.asString().c_str(),
626  file.asString().c_str(),
627  NULL
628  };
629 
630  // no need to parse output for now
631  // [GNUPG:] SIG_ID yCc4u223XRJnLnVAIllvYbUd8mQ 2006-03-29 1143618744
632  // [GNUPG:] GOODSIG A84EDAE89C800ACA SuSE Package Signing Key <build@suse.de>
633  // gpg: Good signature from "SuSE Package Signing Key <build@suse.de>"
634  // [GNUPG:] VALIDSIG 79C179B2E1C820C1890F9994A84EDAE89C800ACA 2006-03-29 1143618744 0 3 0 17 2 00 79C179B2E1C820C1890F9994A84EDAE89C800ACA
635  // [GNUPG:] TRUST_UNDEFINED
636 
637  // [GNUPG:] ERRSIG A84EDAE89C800ACA 17 2 00 1143618744 9
638  // [GNUPG:] NO_PUBKEY A84EDAE89C800ACA
639 
640  ExternalProgram prog( argv,ExternalProgram::Discard_Stderr, false, -1, true );
641 
642  return ( prog.close() == 0 ) ? true : false;
643  }
644 
646 
648  //
649  // CLASS NAME : KeyRing
650  //
652 
653  KeyRing::KeyRing( const Pathname & baseTmpDir )
654  : _pimpl( new Impl( baseTmpDir ) )
655  {}
656 
658  {}
659 
660 
661  void KeyRing::importKey( const PublicKey & key, bool trusted )
662  { _pimpl->importKey( key, trusted ); }
663 
664  void KeyRing::multiKeyImport( const Pathname & keyfile_r, bool trusted_r )
665  { _pimpl->multiKeyImport( keyfile_r, trusted_r ); }
666 
667  std::string KeyRing::readSignatureKeyId( const Pathname & signature )
668  { return _pimpl->readSignatureKeyId( signature ); }
669 
670  void KeyRing::deleteKey( const std::string & id, bool trusted )
671  { _pimpl->deleteKey( id, trusted ); }
672 
673  std::list<PublicKey> KeyRing::publicKeys()
674  { return _pimpl->publicKeys(); }
675 
676  std:: list<PublicKey> KeyRing::trustedPublicKeys()
677  { return _pimpl->trustedPublicKeys(); }
678 
679  std::list<PublicKeyData> KeyRing::publicKeyData()
680  { return _pimpl->publicKeyData(); }
681 
682  std::list<PublicKeyData> KeyRing::trustedPublicKeyData()
683  { return _pimpl->trustedPublicKeyData(); }
684 
686  const Pathname & file,
687  const std::string filedesc,
688  const Pathname & signature,
689  const KeyContext & keycontext )
690  { return _pimpl->verifyFileSignatureWorkflow( file, filedesc, signature, keycontext ); }
691 
692  bool KeyRing::verifyFileSignature( const Pathname & file, const Pathname & signature )
693  { return _pimpl->verifyFileSignature( file, signature ); }
694 
695  bool KeyRing::verifyFileTrustedSignature( const Pathname & file, const Pathname & signature )
696  { return _pimpl->verifyFileTrustedSignature( file, signature ); }
697 
698  void KeyRing::dumpPublicKey( const std::string & id, bool trusted, std::ostream & stream )
699  { _pimpl->dumpPublicKey( id, trusted, stream ); }
700 
702  { return _pimpl->exportPublicKey( keyData ); }
703 
705  { return _pimpl->exportTrustedPublicKey( keyData ); }
706 
707  bool KeyRing::isKeyTrusted( const std::string & id )
708  { return _pimpl->isKeyTrusted( id ); }
709 
710  bool KeyRing::isKeyKnown( const std::string & id )
711  { return _pimpl->isKeyKnown( id ); }
712 
714 } // namespace zypp
void importKey(const PublicKey &key, bool trusted=false)
imports a key from a file.
Definition: KeyRing.cc:661
const std::list< PublicKeyData > & publicKeyData()
Definition: KeyRing.cc:194
Interface to gettext.
#define MIL
Definition: Logger.h:47
PublicKey exportTrustedPublicKey(const PublicKeyData &keyData)
Export a trusted public key identified by its key data.
Definition: KeyRing.cc:704
PublicKey exportPublicKey(const PublicKeyData &keyData)
Definition: KeyRing.cc:200
const Pathname trustedKeyRing() const
Definition: KeyRing.cc:237
void dumpPublicKey(const std::string &id, bool trusted, std::ostream &stream)
Definition: KeyRing.cc:197
void deleteKey(const std::string &id, bool trusted)
Definition: KeyRing.cc:275
PublicKey exportKey(const std::string &id, const Pathname &keyring)
Definition: KeyRing.cc:315
bool isKeyTrusted(const std::string &id)
Definition: KeyRing.cc:182
bool verifyFileSignatureWorkflow(const Pathname &file, const std::string filedesc, const Pathname &signature, const KeyContext &keycontext=KeyContext())
Follows a signature verification interacting with the user.
Definition: KeyRing.cc:685
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Definition: Exception.h:320
const std::list< PublicKeyData > & trustedPublicKeyData()
Definition: KeyRing.cc:192
Regular expression.
Definition: Regex.h:86
Pathname path() const
Definition: TmpPath.cc:146
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:701
Class representing one GPG Public Keys data.
Definition: PublicKey.h:74
const std::string & asString() const
String representation.
Definition: Pathname.h:90
bool isKeyKnown(const std::string &id)
Definition: KeyRing.cc:184
void dumpPublicKey(const std::string &id, bool trusted, std::ostream &stream)
Definition: KeyRing.cc:698
PublicKeyData publicKeyExists(const std::string &id, const Pathname &keyring)
Get PublicKeyData for ID (false if ID is not found).
Definition: KeyRing.cc:296
void multiKeyImport(const Pathname &keyfile_r, bool trusted_r=false)
Definition: KeyRing.cc:270
std::list< PublicKey > trustedPublicKeys()
Get a list of trusted public keys in the keyring (incl.
Definition: KeyRing.cc:676
bool verifyFile(const Pathname &file, const Pathname &signature, const Pathname &keyring)
Definition: KeyRing.cc:612
virtual bool askUserToAcceptUnsignedFile(const std::string &file, const KeyContext &keycontext=KeyContext())
Definition: KeyRing.cc:62
KeyRing(const Pathname &baseTmpDir)
Default ctor.
Definition: KeyRing.cc:653
std::list< PublicKeyData > trustedPublicKeyData()
Get a list of trusted public key data in the keyring (key data only)
Definition: KeyRing.cc:682
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition: Easy.h:27
Provide a new empty temporary file and delete it when no longer needed.
Definition: TmpPath.h:126
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:75
CachedPublicKeyData cachedPublicKeyData
Functor returning the keyrings data (cached).
Definition: KeyRing.cc:251
unsigned size() const
Definition: Regex.cc:87
PublicKey exportTrustedPublicKey(const PublicKeyData &keyData)
Definition: KeyRing.cc:202
KeyTrust
User reply options for the askUserToTrustKey callback.
Definition: KeyRing.h:51
~KeyRing()
Dtor.
Definition: KeyRing.cc:657
Pathname path() const
File containig the ASCII armored key.
Definition: PublicKey.cc:444
static void setDefaultAccept(DefaultAccept value_r)
Set the active accept bits.
Definition: KeyRing.cc:56
Provide a new empty temporary directory and recursively delete it when no longer needed.
Definition: TmpPath.h:170
filesystem::TmpDir _trusted_tmp_dir
Definition: KeyRing.cc:241
bool verifyFileSignature(const Pathname &file, const Pathname &signature)
Definition: KeyRing.cc:211
Execute a program and give access to its io An object of this class encapsulates the execution of an ...
std::list< PublicKeyData > _data
Definition: KeyRing.cc:99
filesystem::TmpFile dumpPublicKeyToTmp(const std::string &id, const Pathname &keyring)
Definition: KeyRing.cc:352
const char * c_str() const
String representation.
Definition: Pathname.h:109
std::string fingerprint() const
Key fingerprint.
Definition: PublicKey.cc:85
#define WAR
Definition: Logger.h:48
KeyRing implementation.
Definition: KeyRing.cc:166
std::list< PublicKey > trustedPublicKeys()
Definition: KeyRing.cc:187
scoped_ptr< WatchFile > _keyringP
Definition: KeyRing.cc:98
void importKey(const PublicKey &key, bool trusted=false)
Definition: KeyRing.cc:256
#define _(MSG)
Return translated text.
Definition: Gettext.h:21
std::string receiveLine()
Read one line from the input stream.
Impl(const Pathname &baseTmpDir)
Definition: KeyRing.cc:168
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:710
Pathname _base_dir
Definition: KeyRing.cc:243
void multiKeyImport(const Pathname &keyfile_r, bool trusted_r=false)
Initial import from RpmDb.
Definition: KeyRing.cc:664
const Pathname generalKeyRing() const
Definition: KeyRing.cc:235
User has chosen not to trust the key.
Definition: KeyRing.h:56
int close()
Wait for the progamm to complete.
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:66
static DefaultAccept defaultAccept()
Get the active accept bits.
Definition: KeyRing.cc:53
RW_pointer< Impl > _pimpl
Pointer to implementation.
Definition: KeyRing.h:285
Regular expression match result.
Definition: Regex.h:145
Class representing one GPG Public Key (PublicKeyData + ASCII armored in a tempfile).
Definition: PublicKey.h:208
std::list< PublicKeyData > publicKeyData()
Get a list of public key data in the keyring (key data only)
Definition: KeyRing.cc:679
Base class for Exception.
Definition: Exception.h:143
callback::SendReport< DownloadProgressReport > * report
Definition: MediaCurl.cc:178
std::list< PublicKey > publicKeys()
Definition: KeyRing.cc:189
bool verifyFileSignatureWorkflow(const Pathname &file, const std::string &filedesc, const Pathname &signature, const KeyContext &keycontext=KeyContext())
Definition: KeyRing.cc:363
std::string id() const
Key ID.
Definition: PublicKey.cc:79
void deleteKey(const std::string &id, bool trusted=false)
removes a key from the keyring.
Definition: KeyRing.cc:670
bool verifyFileTrustedSignature(const Pathname &file, const Pathname &signature)
Definition: KeyRing.cc:695
bool verifyFileTrustedSignature(const Pathname &file, const Pathname &signature)
Definition: KeyRing.cc:213
bool regex_match(const std::string &s, smatch &matches, const regex &regex)
regex ZYPP_STR_REGEX regex ZYPP_STR_REGEX
Definition: Regex.h:70
const std::list< PublicKeyData > & publicKeyData(const Pathname &keyring)
Definition: KeyRing.cc:229
IMPL_PTR_TYPE(KeyRing)
CacheMap _cacheMap
Definition: KeyRing.cc:156
#define GPG_BINARY
Definition: KeyRing.cc:40
bool isKeyTrusted(const std::string &id)
true if the key id is trusted
Definition: KeyRing.cc:707
Date created() const
Creation / last modification date (latest selfsig).
Definition: PublicKey.cc:88
std::string readSignatureKeyId(const Pathname &signature)
reads the public key id from a signature
Definition: KeyRing.cc:667
bool verifyFileSignature(const Pathname &file, const Pathname &signature)
Verifies a file against a signature, with no user interaction.
Definition: KeyRing.cc:692
std::string name() const
Definition: PublicKey.cc:453
std::string readSignatureKeyId(const Pathname &signature)
Definition: KeyRing.cc:556
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:78
std::list< PublicKey > publicKeys()
Get a list of public keys in the keyring (incl.
Definition: KeyRing.cc:673
filesystem::TmpDir _general_tmp_dir
Definition: KeyRing.cc:242