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