libzypp  17.35.11
KeyRing.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
13 #include "zypp_detail/keyring_p.h"
14 
15 #include <iostream>
16 #include <fstream>
17 #include <optional>
18 #include <sys/file.h>
19 #include <cstdio>
20 #include <unistd.h>
21 
22 #include <zypp/TmpPath.h>
23 #include <zypp/ZYppFactory.h>
24 #include <zypp/ZYpp.h>
25 
26 #include <zypp/base/LogTools.h>
27 #include <zypp/base/IOStream.h>
28 #include <zypp/base/String.h>
29 #include <zypp/base/Regex.h>
30 #include <zypp/base/Gettext.h>
31 #include <zypp-core/fs/WatchFile>
32 #include <zypp/PathInfo.h>
33 #include <zypp/ExternalProgram.h>
34 #include <zypp/TmpPath.h>
35 #include <zypp/ZYppCallbacks.h> // JobReport::instance
36 #include <zypp/KeyManager.h>
37 
39 
40 using std::endl;
41 
42 #undef ZYPP_BASE_LOGGER_LOGGROUP
43 #define ZYPP_BASE_LOGGER_LOGGROUP "zypp::KeyRing"
44 
46 namespace zypp
47 {
48 
50 
51  namespace
52  {
53  KeyRing::DefaultAccept _keyRingDefaultAccept( KeyRing::ACCEPT_NOTHING );
54  }
55 
56  KeyRing::DefaultAccept KeyRing::defaultAccept()
57  { return _keyRingDefaultAccept; }
58 
59  void KeyRing::setDefaultAccept( DefaultAccept value_r )
60  {
61  MIL << "Set new KeyRing::DefaultAccept: " << value_r << endl;
62  _keyRingDefaultAccept = value_r;
63  }
64 
65  void KeyRingReport::infoVerify( const std::string & file_r, const PublicKeyData & keyData_r, const KeyContext & keycontext )
66  {}
67 
68  bool KeyRingReport::askUserToAcceptUnsignedFile( const std::string & file, const KeyContext & keycontext )
69  { return _keyRingDefaultAccept.testFlag( KeyRing::ACCEPT_UNSIGNED_FILE ); }
70 
72  KeyRingReport::askUserToAcceptKey( const PublicKey & key, const KeyContext & keycontext )
73  {
74  if ( _keyRingDefaultAccept.testFlag( KeyRing::TRUST_KEY_TEMPORARILY ) )
75  return KEY_TRUST_TEMPORARILY;
76  if ( _keyRingDefaultAccept.testFlag( KeyRing::TRUST_AND_IMPORT_KEY ) )
77  return KEY_TRUST_AND_IMPORT;
78  return KEY_DONT_TRUST;
79  }
80 
81  bool KeyRingReport::askUserToAcceptUnknownKey( const std::string & file, const std::string & id, const KeyContext & keycontext )
82  { return _keyRingDefaultAccept.testFlag( KeyRing::ACCEPT_UNKNOWNKEY ); }
83 
84  bool KeyRingReport::askUserToAcceptVerificationFailed( const std::string & file, const PublicKey & key, const KeyContext & keycontext )
85  { return _keyRingDefaultAccept.testFlag( KeyRing::ACCEPT_VERIFICATION_FAILED ); }
86 
87  bool KeyRingReport::askUserToAcceptPackageKey(const PublicKey &key_r, const KeyContext &keycontext_r)
88  {
90  data.set("PublicKey", key_r);
91  data.set("KeyContext", keycontext_r);
92  report(data);
93 
94  if ( data.hasvalue("TrustKey") )
95  return data.get<bool>("TrustKey");
96  return false;
97  }
98 
99  void KeyRingReport::reportNonImportedKeys(const std::set<Edition> &keys_r)
100  {
102  data.set("Keys", keys_r);
103  report(data);
104  }
105 
106  void KeyRingReport::reportAutoImportKey( const std::list<PublicKeyData> & keyDataList_r,
107  const PublicKeyData & keySigning_r,
108  const KeyContext &keyContext_r )
109  {
111  data.set( "KeyDataList", keyDataList_r );
112  data.set( "KeySigning", keySigning_r );
113  data.set( "KeyContext", keyContext_r );
114  report( data );
115  }
116 
118 
120  : _cache { cache_r }
121  , _keyring { std::move(keyring_r) }
122  {}
123 
125  if ( not _context ) {
126  _context = KeyManagerCtx::createForOpenPGP( _keyring );
127  }
128  // frankly: don't remember why an explicit setDirty was introduced and
129  // why WatchFile was not enough. Maybe some corner case when the keyrings
130  // are created?
131  _cache.setDirty( _keyring );
132  return _context.value();
133  }
134 
136 
138  {
139  _keyringK.reset();
140  _keyringP.reset();
141  }
142 
144  {
145  // .kbx since gpg2-2.1
146  if ( !_keyringK )
147  _keyringK.reset( new WatchFile( keyring_r/"pubring.kbx", WatchFile::NO_INIT ) );
148  if ( !_keyringP )
149  _keyringP.reset( new WatchFile( keyring_r/"pubring.gpg", WatchFile::NO_INIT ) );
150  }
151 
153  {
154  bool k = _keyringK->hasChanged(); // be sure both files are checked
155  bool p = _keyringP->hasChanged();
156  return k || p;
157  }
158 
159  const std::list<PublicKeyData> &CachedPublicKeyData::operator()(const filesystem::Pathname &keyring_r) const
160  { return getData( keyring_r ); }
161 
163  { _cacheMap[keyring_r].setDirty(); }
164 
165  CachedPublicKeyData::Manip CachedPublicKeyData::manip(filesystem::Pathname keyring_r) { return Manip( *this, std::move(keyring_r) ); }
166 
167  const std::list<PublicKeyData> &CachedPublicKeyData::getData(const filesystem::Pathname &keyring_r) const
168  {
169  Cache & cache( _cacheMap[keyring_r] );
170  // init new cache entry
171  cache.assertCache( keyring_r );
172  return getData( keyring_r, cache );
173  }
174 
175  const std::list<PublicKeyData> &CachedPublicKeyData::getData(const filesystem::Pathname &keyring_r, Cache &cache_r) const
176  {
177  if ( cache_r.hasChanged() ) {
178  cache_r._data = KeyManagerCtx::createForOpenPGP( keyring_r ).listKeys();
179  MIL << "Found keys: " << cache_r._data << std::endl;
180  }
181  return cache_r._data;
182  }
183 
184 
186 
187  namespace
188  {
190  struct ImportKeyCBHelper
191  {
192  void operator()( const PublicKey & key_r )
193  {
194  try {
195  _rpmdbEmitSignal->trustedKeyAdded( key_r );
196  _emitSignal->trustedKeyAdded( key_r );
197  }
198  catch ( const Exception & excp )
199  {
200  ERR << "Could not import key into rpmdb: " << excp << endl;
201  // TODO: JobReport as hotfix for bsc#1057188; should bubble up and go through some callback
202  JobReport::error( excp.asUserHistory() );
203  }
204  }
205 
206  private:
207  callback::SendReport<target::rpm::KeyRingSignals> _rpmdbEmitSignal;
208  callback::SendReport<KeyRingSignals> _emitSignal;
209  };
210  } // namespace
211 
213  : _trusted_tmp_dir( baseTmpDir, "zypp-trusted-kr" )
214  , _general_tmp_dir( baseTmpDir, "zypp-general-kr" )
215  , _base_dir( baseTmpDir )
216  {
217  MIL << "Current KeyRing::DefaultAccept: " << _keyRingDefaultAccept << std::endl;
218  }
219 
220  void KeyRing::Impl::importKey( const PublicKey & key, bool trusted )
221  {
222  importKey( key.path(), trusted ? trustedKeyRing() : generalKeyRing() );
223  MIL << "Imported key " << key << " to " << (trusted ? "trustedKeyRing" : "generalKeyRing" ) << endl;
224 
225  if ( trusted )
226  {
227  ImportKeyCBHelper emitSignal;
228  if ( key.hiddenKeys().empty() )
229  {
230  emitSignal( key );
231  }
232  else
233  {
234  // multiple keys: Export individual keys ascii armored to import in rpmdb
235  emitSignal( exportKey( key, trustedKeyRing() ) );
236  for ( const PublicKeyData & hkey : key.hiddenKeys() )
237  emitSignal( exportKey( hkey, trustedKeyRing() ) );
238  }
239  }
240  }
241 
242  void KeyRing::Impl::multiKeyImport( const Pathname & keyfile_r, bool trusted_r )
243  {
244  importKey( keyfile_r, trusted_r ? trustedKeyRing() : generalKeyRing() );
245  }
246 
247  void KeyRing::Impl::deleteKey( const std::string & id, bool trusted )
248  {
249  PublicKeyData keyDataToDel( publicKeyExists( id, trusted ? trustedKeyRing() : generalKeyRing() ) );
250  if ( ! keyDataToDel )
251  {
252  WAR << "Key to delete [" << id << "] is not in " << (trusted ? "trustedKeyRing" : "generalKeyRing" ) << endl;
253  return;
254  }
255  deleteKey( id, trusted ? trustedKeyRing() : generalKeyRing() );
256  MIL << "Deleted key [" << id << "] from " << (trusted ? "trustedKeyRing" : "generalKeyRing" ) << endl;
257 
258  if ( trusted )
259  try {
260  PublicKey key( keyDataToDel );
261 
263  rpmdbEmitSignal->trustedKeyRemoved( key );
264 
266  emitSignal->trustedKeyRemoved( key );
267  }
268  catch ( const Exception & excp )
269  {
270  ERR << "Could not delete key from rpmmdb: " << excp << endl;
271  // TODO: JobReport as hotfix for bsc#1057188; should bubble up and go through some callback
273  }
274  }
275 
276  PublicKeyData KeyRing::Impl::publicKeyExists( const std::string & id, const Pathname & keyring )
277  {
278  if ( _allowPreload && keyring == generalKeyRing() ) {
279  _allowPreload = false;
280  preloadCachedKeys();
281  }
282 
283  PublicKeyData ret;
284  for ( const PublicKeyData & key : publicKeyData( keyring ) )
285  {
286  if ( key.providesKey( id ) )
287  {
288  ret = key;
289  break;
290  }
291  }
292  DBG << (ret ? "Found" : "No") << " key [" << id << "] in keyring " << keyring << endl;
293  return ret;
294  }
295 
297  {
298  MIL << "preloadCachedKeys into general keyring..." << endl;
299  CachedPublicKeyData::Manip manip { keyRingManip( generalKeyRing() ) }; // Provides the context if we want to manip a cached keyring.
300 
301  // For now just load the 'gpg-pubkey-*.{asc,key}' files into the general keyring,
302  // if their id (derived from the filename) is not in the trusted ring.
303  // TODO: Head for a persistent general keyring.
304  std::set<Pathname> cachedirs;
305  ZConfig & conf { ZConfig::instance() };
306  cachedirs.insert( conf.pubkeyCachePath() );
307  cachedirs.insert( "/usr/lib/rpm/gnupg/keys" );
308  if ( Pathname r = conf.systemRoot(); r != "/" && not r.empty() ) {
309  cachedirs.insert( r / conf.pubkeyCachePath() );
310  cachedirs.insert( r / "/usr/lib/rpm/gnupg/keys" );
311  }
312  if ( Pathname r = conf.repoManagerRoot(); r != "/" && not r.empty() ) {
313  cachedirs.insert( r / conf.pubkeyCachePath() );
314  cachedirs.insert( r / "/usr/lib/rpm/gnupg/keys" );
315  }
316 
317  std::map<std::string,Pathname> keyCandidates; // Collect one file path per keyid
318  const str::regex rx { "^gpg-pubkey-([[:xdigit:]]{8,})(-[[:xdigit:]]{8,})?\\.(asc|key)$" };
319  for ( const auto & cache : cachedirs ) {
320  dirForEach( cache,
321  [&rx,&keyCandidates]( const Pathname & dir_r, const char *const file_r )->bool {
322  str::smatch what;
323  if ( str::regex_match( file_r, what, rx ) ) {
324  Pathname & remember { keyCandidates[what[1]] };
325  if ( remember.empty() ) {
326  remember = dir_r / file_r;
327  }
328  }
329  return true;
330  }
331  );
332  }
333 
334  for ( const auto & p : keyCandidates ) {
335  // Avoid checking the general keyring while it is flagged dirty.
336  // Checking the trusted ring is ok, and most keys will be there anyway.
337  const std::string & id { p.first };
338  const Pathname & path { p.second };
339  if ( isKeyTrusted(id) )
340  continue;
341  if ( manip.keyManagerCtx().importKey( path ) ) {
342  DBG << "preload key file " << path << endl;
343  }
344  else {
345  WAR << "Skipping: Can't preload key file " << path << endl;
346  }
347  }
348  }
349 
350  PublicKey KeyRing::Impl::exportKey( const PublicKeyData & keyData, const Pathname & keyring )
351  {
352  return PublicKey( dumpPublicKeyToTmp( keyData.id(), keyring ), keyData );
353  }
354 
355  PublicKey KeyRing::Impl::exportKey( const std::string & id, const Pathname & keyring )
356  {
357  PublicKeyData keyData( publicKeyExists( id, keyring ) );
358  if ( keyData )
359  return PublicKey( dumpPublicKeyToTmp( keyData.id(), keyring ), keyData );
360 
361  // Here: key not found
362  WAR << "No key [" << id << "] to export from " << keyring << endl;
363  return PublicKey();
364  }
365 
366 
367  void KeyRing::Impl::dumpPublicKey( const std::string & id, const Pathname & keyring, std::ostream & stream )
368  {
369  KeyManagerCtx::createForOpenPGP( keyring ).exportKey(id, stream);
370  }
371 
372  filesystem::TmpFile KeyRing::Impl::dumpPublicKeyToTmp( const std::string & id, const Pathname & keyring )
373  {
374  filesystem::TmpFile tmpFile( _base_dir, "pubkey-"+id+"-" );
375  MIL << "Going to export key [" << id << "] from " << keyring << " to " << tmpFile.path() << endl;
376 
377  std::ofstream os( tmpFile.path().c_str() );
378  dumpPublicKey( id, keyring, os );
379  os.close();
380  return tmpFile;
381  }
382 
383  std::list<PublicKey> KeyRing::Impl::publicKeys( const Pathname & keyring )
384  {
385  const std::list<PublicKeyData> & keys( publicKeyData( keyring ) );
386  std::list<PublicKey> ret;
387 
388  for_( it, keys.begin(), keys.end() )
389  {
390  PublicKey key( exportKey( *it, keyring ) );
391  ret.push_back( key );
392  MIL << "Found key " << key << endl;
393  }
394  return ret;
395  }
396 
397  void KeyRing::Impl::importKey( const Pathname & keyfile, const Pathname & keyring )
398  {
399  if ( ! PathInfo( keyfile ).isExist() )
400  // TranslatorExplanation first %s is key name, second is keyring name
401  ZYPP_THROW(KeyRingException( str::Format(_("Tried to import not existent key %s into keyring %s"))
402  % keyfile.asString()
403  % keyring.asString() ));
404 
405  CachedPublicKeyData::Manip manip { keyRingManip( keyring ) }; // Provides the context if we want to manip a cached keyring.
406  if ( ! manip.keyManagerCtx().importKey( keyfile ) )
407  ZYPP_THROW(KeyRingException(_("Failed to import key.")));
408  }
409 
410  void KeyRing::Impl::deleteKey( const std::string & id, const Pathname & keyring )
411  {
412  CachedPublicKeyData::Manip manip { keyRingManip( keyring ) }; // Provides the context if we want to manip a cached keyring.
413  if ( ! manip.keyManagerCtx().deleteKey( id ) )
414  ZYPP_THROW(KeyRingException(_("Failed to delete key.")));
415  }
416 
417  std::string KeyRing::Impl::readSignatureKeyId( const Pathname & signature )
418  {
419  if ( ! PathInfo( signature ).isFile() )
420  ZYPP_THROW(KeyRingException( str::Format(_("Signature file %s not found")) % signature.asString() ));
421 
422  MIL << "Determining key id of signature " << signature << endl;
423 
424  std::list<std::string> fprs = KeyManagerCtx::createForOpenPGP().readSignatureFingerprints( signature );
425  if ( ! fprs.empty() ) {
426  std::string &id = fprs.back();
427  MIL << "Determined key id [" << id << "] for signature " << signature << endl;
428  return id;
429  }
430  return std::string();
431  }
432 
433  bool KeyRing::Impl::verifyFile( const Pathname & file, const Pathname & signature, const Pathname & keyring )
434  {
435  return KeyManagerCtx::createForOpenPGP( keyring ).verify( file, signature );
436  }
437 
439 
441  //
442  // CLASS NAME : KeyRing
443  //
445 
446  KeyRing::KeyRing( const Pathname & baseTmpDir )
447  : _pimpl( new Impl( baseTmpDir ) )
448  {}
449 
451  {}
452 
454  {
455  return *_pimpl;
456  }
457 
458  void KeyRing::allowPreload( bool yesno_r )
459  { _pimpl->allowPreload( yesno_r ); }
460 
461 
462  void KeyRing::importKey( const PublicKey & key, bool trusted )
463  { _pimpl->importKey( key, trusted ); }
464 
465  void KeyRing::multiKeyImport( const Pathname & keyfile_r, bool trusted_r )
466  { _pimpl->multiKeyImport( keyfile_r, trusted_r ); }
467 
468  std::string KeyRing::readSignatureKeyId( const Pathname & signature )
469  { return _pimpl->readSignatureKeyId( signature ); }
470 
471  void KeyRing::deleteKey( const std::string & id, bool trusted )
472  { _pimpl->deleteKey( id, trusted ); }
473 
474  std::list<PublicKey> KeyRing::publicKeys()
475  { return _pimpl->publicKeys(); }
476 
477  std:: list<PublicKey> KeyRing::trustedPublicKeys()
478  { return _pimpl->trustedPublicKeys(); }
479 
480  std::list<PublicKeyData> KeyRing::publicKeyData()
481  { return _pimpl->publicKeyData(); }
482 
483  std::list<PublicKeyData> KeyRing::trustedPublicKeyData()
484  { return _pimpl->trustedPublicKeyData(); }
485 
486  PublicKeyData KeyRing::publicKeyData( const std::string &id_r )
487  { return _pimpl->publicKeyExists( id_r ); }
488 
490  { return _pimpl->trustedPublicKeyExists( id_r ); }
491 
492  bool KeyRing::verifyFileSignature( const Pathname & file, const Pathname & signature )
493  { return _pimpl->verifyFileSignature( file, signature ); }
494 
495  bool KeyRing::verifyFileTrustedSignature( const Pathname & file, const Pathname & signature )
496  { return _pimpl->verifyFileTrustedSignature( file, signature ); }
497  void KeyRing::dumpPublicKey( const std::string & id, bool trusted, std::ostream & stream )
498  { _pimpl->dumpPublicKey( id, trusted, stream ); }
499 
501  { return _pimpl->exportPublicKey( keyData ); }
502 
504  { return _pimpl->exportTrustedPublicKey( keyData ); }
505 
506  bool KeyRing::isKeyTrusted( const std::string & id )
507  { return _pimpl->isKeyTrusted( id ); }
508 
509  bool KeyRing::isKeyKnown( const std::string & id )
510  { return _pimpl->isKeyKnown( id ); }
511 
513 } // namespace zypp
void allowPreload(bool yesno_r)
Definition: keyring_p.h:137
void importKey(const PublicKey &key, bool trusted=false)
imports a key from a file.
Definition: KeyRing.cc:462
const std::list< PublicKeyData > & publicKeyData()
Definition: keyring_p.h:116
Interface to gettext.
#define MIL
Definition: Logger.h:98
PublicKey exportTrustedPublicKey(const PublicKeyData &keyData)
Export a trusted public key identified by its key data.
Definition: KeyRing.cc:503
PublicKey exportPublicKey(const PublicKeyData &keyData)
Definition: keyring_p.h:122
void dumpPublicKey(const std::string &id, bool trusted, std::ostream &stream)
Definition: keyring_p.h:119
zypp::KeyRing KeyRing
Definition: context.h:28
void deleteKey(const std::string &id, bool trusted)
Definition: KeyRing.cc:247
PublicKey exportKey(const std::string &id, const Pathname &keyring)
Definition: KeyRing.cc:355
static bool error(const std::string &msg_r, const UserData &userData_r=UserData())
send error text
bool isKeyTrusted(const std::string &id)
Definition: keyring_p.h:104
#define _(MSG)
Definition: Gettext.h:39
const std::list< PublicKeyData > & hiddenKeys() const
Additional keys data in case the ASCII armored blob contains multiple keys.
Definition: PublicKey.cc:649
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Definition: Exception.h:424
const std::list< PublicKeyData > & trustedPublicKeyData()
Definition: keyring_p.h:114
Regular expression.
Definition: Regex.h:94
Functor returning the keyrings data (cached).
Definition: keyring_p.h:32
static ZConfig & instance()
Singleton ctor.
Definition: ZConfig.cc:925
~KeyRing() override
Dtor.
Definition: KeyRing.cc:450
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:500
Manip(CachedPublicKeyData &cache_r, Pathname keyring_r)
Definition: KeyRing.cc:119
Class representing one GPG Public Keys data.
Definition: PublicKey.h:207
bool isKeyKnown(const std::string &id)
Definition: keyring_p.h:106
void reportNonImportedKeys(const std::set< Edition > &keys_r)
Notify the user about keys that were not imported from the rpm key database into zypp keyring...
Definition: KeyRing.cc:99
void dumpPublicKey(const std::string &id, bool trusted, std::ostream &stream)
Definition: KeyRing.cc:497
int dirForEach(const Pathname &dir_r, const StrMatcher &matcher_r, function< bool(const Pathname &, const char *const)> fnc_r)
Definition: PathInfo.cc:32
void multiKeyImport(const Pathname &keyfile_r, bool trusted_r=false)
Definition: KeyRing.cc:242
std::list< PublicKey > trustedPublicKeys()
Get a list of trusted public keys in the keyring (incl.
Definition: KeyRing.cc:477
bool verifyFile(const Pathname &file, const Pathname &signature, const Pathname &keyring)
Definition: KeyRing.cc:433
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition: Easy.h:28
virtual bool askUserToAcceptUnsignedFile(const std::string &file, const KeyContext &keycontext=KeyContext())
Definition: KeyRing.cc:68
const char * c_str() const
String representation.
Definition: Pathname.h:112
KeyRing(const Pathname &baseTmpDir)
Default ctor.
Definition: KeyRing.cc:446
KeyRing::Impl & pimpl()
Access to private functions for the KeyRingWorkflow implementations.
Definition: KeyRing.cc:453
std::list< PublicKeyData > trustedPublicKeyData()
Get a list of trusted public key data in the keyring (key data only)
Definition: KeyRing.cc:483
bool askUserToAcceptPackageKey(const PublicKey &key_r, const KeyContext &keycontext_r=KeyContext())
Ask user to trust and/or import the package key to trusted keyring, using ReportBase::report.
Definition: KeyRing.cc:87
Pathname path() const
Definition: TmpPath.cc:150
Manip manip(Pathname keyring_r)
Helper providing on demand a KeyManagerCtx to manip the cached keyring.
Definition: KeyRing.cc:165
bool verify(const Pathname &file, const Pathname &signature)
Tries to verify file using signature, returns true on success.
Definition: KeyManager.cc:378
Convenient building of std::string with boost::format.
Definition: String.h:252
static KeyManagerCtx createForOpenPGP()
Creates a new KeyManagerCtx for PGP using a volatile temp.
Definition: KeyManager.cc:276
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:81
#define ERR
Definition: Logger.h:100
callback::SendReport< target::rpm::KeyRingSignals > _rpmdbEmitSignal
Definition: KeyRing.cc:207
bool exportKey(const std::string &id, std::ostream &stream)
Exports the key with id into the given stream, returns true on success.
Definition: KeyManager.cc:383
Remember a files attributes to detect content changes.
Definition: watchfile.h:49
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:65
PublicKey exportTrustedPublicKey(const PublicKeyData &keyData)
Definition: keyring_p.h:124
virtual void report(const UserData &userData_r=UserData())
The most generic way of sending/receiving data.
Definition: Callback.h:155
KeyTrust
User reply options for the askUserToTrustKey callback.
Definition: KeyRing.h:51
bool empty() const
Test for an empty path.
Definition: Pathname.h:116
bool trusted
Definition: keyringwf.cc:135
PublicKeyData trustedPublicKeyExists(const std::string &id)
Definition: keyring_p.h:134
static void setDefaultAccept(DefaultAccept value_r)
Set the active accept bits.
Definition: KeyRing.cc:59
bool verifyFileSignature(const Pathname &file, const Pathname &signature)
Definition: keyring_p.h:127
bool set(const std::string &key_r, AnyType val_r)
Set the value for key (nonconst version always returns true).
Definition: UserData.h:119
const std::string & asString() const
String representation.
Definition: Pathname.h:93
std::string asUserHistory() const
A single (multiline) string composed of asUserString and historyAsString.
Definition: Exception.cc:127
filesystem::TmpFile dumpPublicKeyToTmp(const std::string &id, const Pathname &keyring)
Definition: KeyRing.cc:372
bool verifyFileSignature(const Pathname &file, const Pathname &signature) ZYPP_API
Verifies a file against a signature, with no user interaction.
Definition: KeyRing.cc:492
Interim helper class to collect global options and settings.
Definition: ZConfig.h:68
#define WAR
Definition: Logger.h:99
IMPL_PTR_TYPE(Application)
KeyRing implementation.
Definition: keyring_p.h:94
std::list< PublicKey > trustedPublicKeys()
Definition: keyring_p.h:109
const std::list< PublicKeyData > & getData(const Pathname &keyring_r) const
Definition: KeyRing.cc:167
void importKey(const PublicKey &key, bool trusted=false)
Definition: KeyRing.cc:220
KeyManagerCtx & keyManagerCtx()
Definition: KeyRing.cc:124
Impl(const Pathname &baseTmpDir)
Definition: KeyRing.cc:212
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:509
void multiKeyImport(const Pathname &keyfile_r, bool trusted_r=false)
Initial import from RpmDb.
Definition: KeyRing.cc:465
User has chosen not to trust the key.
Definition: KeyRing.h:56
void assertCache(const Pathname &keyring_r)
Definition: KeyRing.cc:143
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:72
std::list< PublicKeyData > listKeys()
Returns a list of all public keys found in the current keyring.
Definition: KeyManager.cc:325
static DefaultAccept defaultAccept()
Get the active accept bits.
Definition: KeyRing.cc:56
RW_pointer< Impl > _pimpl
Pointer to implementation.
Definition: KeyRing.h:325
Regular expression match result.
Definition: Regex.h:167
void preloadCachedKeys()
Load key files cached on the system into the generalKeyRing.
Definition: KeyRing.cc:296
Class representing one GPG Public Key (PublicKeyData + ASCII armored in a tempfile).
Definition: PublicKey.h:364
std::list< PublicKeyData > publicKeyData()
Get a list of public key data in the keyring (key data only)
Definition: KeyRing.cc:480
Base class for Exception.
Definition: Exception.h:146
Pathname path() const
File containing the ASCII armored key.
Definition: PublicKey.cc:646
std::string id() const
Key ID.
Definition: PublicKey.cc:418
const Tp & get(const std::string &key_r) const
Pass back a const Tp & reference to key_r value.
Definition: UserData.h:176
std::list< PublicKey > publicKeys()
Definition: keyring_p.h:111
Typesafe passing of user data via callbacks.
Definition: UserData.h:39
void deleteKey(const std::string &id, bool trusted=false)
removes a key from the keyring.
Definition: KeyRing.cc:471
static constexpr const char * KEYS_NOT_IMPORTED_REPORT
Definition: KeyRing.h:130
void reportAutoImportKey(const std::list< PublicKeyData > &keyDataList_r, const PublicKeyData &keySigning_r, const KeyContext &keyContext_r)
Notify that a repository auto imported new package signing keys.
Definition: KeyRing.cc:106
bool verifyFileTrustedSignature(const Pathname &file, const Pathname &signature)
Definition: keyring_p.h:129
const std::list< PublicKeyData > & operator()(const Pathname &keyring_r) const
Definition: KeyRing.cc:159
Wrapper class for ::stat/::lstat.
Definition: PathInfo.h:221
bool regex_match(const std::string &s, smatch &matches, const regex &regex)
regex ZYPP_STR_REGEX regex ZYPP_STR_REGEX
Definition: Regex.h:70
std::list< std::string > readSignatureFingerprints(const Pathname &signature)
Reads all fingerprints from the signature file , returns a list of all found fingerprints.
Definition: KeyManager.cc:538
std::list< PublicKeyData > _data
Definition: keyring_p.h:70
void setDirty(const Pathname &keyring_r)
Definition: KeyRing.cc:162
bool hasvalue(const std::string &key_r) const
Whether key_r is in data and value is not empty.
Definition: UserData.h:102
bool isKeyTrusted(const std::string &id)
true if the key id is trusted
Definition: KeyRing.cc:506
static constexpr const char * REPORT_AUTO_IMPORT_KEY
Definition: KeyRing.h:149
void allowPreload(bool yesno_r)
The general keyring may be populated with known keys stored on the system.
Definition: KeyRing.cc:458
Easy-to use interface to the ZYPP dependency resolver.
Definition: Application.cc:19
callback::SendReport< KeyRingSignals > _emitSignal
Definition: KeyRing.cc:208
PublicKeyData publicKeyExists(const std::string &id)
Definition: keyring_p.h:132
std::string readSignatureKeyId(const Pathname &signature)
reads the public key id from a signature
Definition: KeyRing.cc:468
static constexpr const char * ACCEPT_PACKAGE_KEY_REQUEST
Definition: KeyRing.h:117
std::string readSignatureKeyId(const Pathname &signature)
Definition: KeyRing.cc:417
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:84
std::list< PublicKey > publicKeys()
Get a list of public keys in the keyring (incl.
Definition: KeyRing.cc:474
bool verifyFileTrustedSignature(const Pathname &file, const Pathname &signature) ZYPP_API
Definition: KeyRing.cc:495
Helper providing on demand a KeyManagerCtx to manip the cached keyring.
Definition: keyring_p.h:44
#define DBG
Definition: Logger.h:97