libzypp  17.38.7
PublicKey.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #include <climits>
13 
14 #include <iostream>
15 #include <utility>
16 #include <vector>
17 
18 #include "PublicKey.h"
19 #include "KeyManager.h"
20 
21 #include <zypp-core/base/Gettext.h>
22 #include <zypp-core/base/String.h>
23 #include <zypp-core/base/Regex.h>
25 #include <zypp-core/fs/TmpPath.h>
26 #include <zypp-core/fs/PathInfo.h>
29 #include <zypp-core/Date.h>
30 
31 #include <gpgme.h>
32 
33 using std::endl;
34 
35 #undef ZYPP_BASE_LOGGER_LOGGROUP
36 #define ZYPP_BASE_LOGGER_LOGGROUP "zypp::gpg"
37 
39 namespace zypp
40 {
42  namespace
43  {
44  inline bool isExpired( const Date & expires_r )
45  { return( expires_r && expires_r < Date::now() ); }
46 
47  inline int hasDaysToLive( const Date & expires_r )
48  {
49  if ( expires_r )
50  {
51  Date exp( expires_r - Date::now() );
52  int ret = exp / Date::day;
53  if ( exp < 0 ) ret -= 1;
54  return ret;
55  }
56  return INT_MAX;
57  }
58 
59  inline std::string expiresDetail( const Date & expires_r )
60  {
61  str::Str str;
62  if ( ! expires_r )
63  {
64  // translators: an annotation to a gpg keys expiry date
65  str << _("does not expire");
66  }
67  else if ( isExpired( expires_r ) )
68  {
69  // translators: an annotation to a gpg keys expiry date: "expired: 1999-04-12"
70  str << ( str::Format(_("expired: %1%") ) % expires_r.printDate() );
71  }
72  else
73  {
74  // translators: an annotation to a gpg keys expiry date: "expires: 2111-04-12"
75  str << ( str::Format(_("expires: %1%") ) % expires_r.printDate() );
76  }
77  return str;
78  }
79 
80  inline std::string expiresDetailVerbose( const Date & expires_r )
81  {
82  if ( !expires_r )
83  { // translators: an annotation to a gpg keys expiry date
84  return _("(does not expire)");
85  }
86  std::string ret( expires_r.asString() );
87  int ttl( hasDaysToLive( expires_r ) );
88  if ( ttl <= 90 )
89  {
90  ret += " ";
91  if ( ttl < 0 )
92  { // translators: an annotation to a gpg keys expiry date
93  ret += _("(EXPIRED)");
94  }
95  else if ( ttl == 0 )
96  { // translators: an annotation to a gpg keys expiry date
97  ret += _("(expires within 24h)");
98  }
99  else
100  { // translators: an annotation to a gpg keys expiry date
101  ret += str::form( PL_("(expires in %d day)", "(expires in %d days)", ttl ), ttl );
102  }
103  }
104  return ret;
105  }
106 
107  inline std::string keyAlgoName( const gpgme_subkey_t & key_r )
108  {
109  std::string ret;
110  if ( const char * n = ::gpgme_pubkey_algo_name( key_r->pubkey_algo ) )
111  ret = str::Str() << n << ' ' << key_r->length;
112  else
113  ret = "?";
114  return ret;
115  }
116 
117  inline bool shorterIsSuffixCI( const std::string & lhs, const std::string & rhs )
118  {
119  if ( lhs.size() >= rhs.size() )
120  return str::endsWithCI( lhs, rhs );
121  return str::endsWithCI( rhs, lhs );
122  }
123  } //namespace
125 
126 
131 
133  {
134  std::string _id;
137 
138  public:
140  static shared_ptr<Impl> nullimpl();
141 
142  private:
143  friend Impl * rwcowClone<Impl>( const Impl * rhs );
145  Impl * clone() const;
146  };
147 
148  shared_ptr<zypp::PublicSubkeyData::Impl> PublicSubkeyData::Impl::nullimpl()
149  {
150  static shared_ptr<Impl> _nullimpl( new Impl );
151  return _nullimpl;
152  }
153 
155  {
156  return new Impl( *this );
157  }
158 
162 
164  : _pimpl( Impl::nullimpl() )
165  {}
166 
167  PublicSubkeyData::PublicSubkeyData(const _gpgme_subkey *rawSubKeyData)
168  : _pimpl (new Impl)
169  {
170  _pimpl->_created = zypp::Date(rawSubKeyData->timestamp);
171  _pimpl->_expires = zypp::Date(rawSubKeyData->expires);
172  _pimpl->_id = str::asString(rawSubKeyData->keyid);
173  }
174 
176  {}
177 
178  PublicSubkeyData::operator bool() const
179  { return !_pimpl->_id.empty(); }
180 
181  std::string PublicSubkeyData::id() const
182  { return _pimpl->_id; }
183 
185  { return _pimpl->_created; }
186 
188  { return _pimpl->_expires; }
189 
191  { return isExpired( _pimpl->_expires ); }
192 
194  { return hasDaysToLive( _pimpl->_expires ); }
195 
196  std::string PublicSubkeyData::asString() const
197  {
198  return str::Str() << id() << " " << created().printDate() << " [" << expiresDetail( expires() ) << "]";
199  }
200 
205 
207  {
208  std::string _keyid;
209  std::string _name;
212 
213  public:
215  static shared_ptr<Impl> nullimpl();
216 
217  private:
218  friend Impl * rwcowClone<Impl>( const Impl * rhs );
220  Impl * clone() const;
221  };
222 
223  shared_ptr<zypp::PublicKeySignatureData::Impl> PublicKeySignatureData::Impl::nullimpl()
224  {
225  static shared_ptr<Impl> _nullimpl( new Impl );
226  return _nullimpl;
227  }
228 
230  {
231  return new Impl( *this );
232  }
233 
237 
239  : _pimpl( Impl::nullimpl() )
240  {}
241 
242  PublicKeySignatureData::PublicKeySignatureData(const _gpgme_key_sig *rawKeySignatureData)
243  : _pimpl (new Impl)
244  {
245  _pimpl->_keyid = str::asString(rawKeySignatureData->keyid);
246  _pimpl->_name = str::asString(rawKeySignatureData->uid);
247  _pimpl->_created = zypp::Date(rawKeySignatureData->timestamp);
248  _pimpl->_expires = zypp::Date(rawKeySignatureData->expires);
249  }
250 
252  {}
253 
254  PublicKeySignatureData::operator bool() const
255  { return !_pimpl->_keyid.empty(); }
256 
257  std::string PublicKeySignatureData::id() const
258  { return _pimpl->_keyid; }
259 
260  std::string PublicKeySignatureData::name() const
261  { return _pimpl->_name; }
262 
264  { return _pimpl->_created; }
265 
267  { return _pimpl->_expires; }
268 
270  { return isExpired( _pimpl->_expires ); }
271 
273  { return hasDaysToLive( _pimpl->_expires ); }
274 
276  {
277  std::string nameStr;
278  if (!name().empty()) {
279  nameStr = str::Str() << name() << " ";
280  }
281  else {
282  nameStr = "[User ID not found] ";
283  }
284  return str::Str() << nameStr
285  << id() << " "
286  << created().printDate()
287  << " [" << expiresDetail( expires() ) << "]";
288  }
289 
296  {
297  std::string _id;
298  std::string _name;
299  std::string _fingerprint;
300  std::string _algoName;
303 
304  std::vector<PublicSubkeyData> _subkeys;
305  std::vector<PublicKeySignatureData> _signatures;
306 
307  public:
308  bool hasSubkeyId( const std::string & id_r ) const;
309 
310  public:
312  static shared_ptr<Impl> nullimpl();
313  static shared_ptr<Impl> fromGpgmeKey(gpgme_key_t rawData);
314 
315  private:
316  friend Impl * rwcowClone<Impl>( const Impl * rhs );
318  Impl * clone() const;
319  };
320 
321  bool PublicKeyData::Impl::hasSubkeyId( const std::string &id_r) const
322  {
323  bool ret = false;
324  for ( const PublicSubkeyData & sub : _subkeys ) {
325  if ( shorterIsSuffixCI( sub.id(), id_r ) ) {
326  ret = true;
327  break;
328  }
329  }
330  return ret;
331  }
332 
333  shared_ptr<PublicKeyData::Impl> PublicKeyData::Impl::nullimpl()
334  {
335  static shared_ptr<Impl> _nullimpl( new Impl );
336  return _nullimpl;
337  }
338 
339  shared_ptr<PublicKeyData::Impl> PublicKeyData::Impl::fromGpgmeKey(gpgme_key_t rawData)
340  {
341  //gpgme stores almost nothing in the top level key
342  //the information we look for is stored in the subkey, where subkey[0]
343  //is always the primary key
344  gpgme_subkey_t sKey = rawData->subkeys;
345  if (sKey) {
346  shared_ptr<PublicKeyData::Impl> data(new Impl);
347  //libzypp expects the date of the latest signature on the first uid
348  if ( rawData->uids && rawData->uids->signatures ) {
349  data->_created = zypp::Date(rawData->uids->signatures->timestamp);
350  // bsc#1179222: The keyring does not order the signatures when multiple
351  // versions of the same key are imported. We take the last signature here,
352  // the one GPGME_EXPORT_MODE_MINIMAL will later use in export.
353  for ( auto t = rawData->uids->signatures->next; t; t = t->next ) {
354  if (t->keyid != nullptr) {
355  data->_signatures.push_back(PublicKeySignatureData(t));
356  }
357 
358  if ( t->timestamp > data->_created )
359  data->_created = t->timestamp;
360  }
361  }
362  else
363  data->_created = zypp::Date(sKey->timestamp);
364 
365  data->_expires = zypp::Date(sKey->expires);
366  data->_fingerprint = str::asString(sKey->fpr);
367  data->_algoName = keyAlgoName( sKey );
368  data->_id = str::asString(sKey->keyid);
369 
370  //get the primary user ID
371  if (rawData->uids) {
372  data->_name = str::asString(rawData->uids->uid);
373  }
374 
375  //the rest of the keys
376  sKey = sKey->next;
377  while (sKey) {
378  data->_subkeys.push_back( PublicSubkeyData(sKey) );
379  sKey = sKey->next;
380  }
381  return data;
382  }
383  return nullimpl();
384  }
385 
387  {
388  return new Impl( *this );
389  }
390 
394 
396  : _pimpl( Impl::nullimpl() )
397  {}
398 
399  PublicKeyData::PublicKeyData(shared_ptr<Impl> data)
400  : _pimpl( std::move(data) )
401  {}
402 
404  {}
405 
407  { return PublicKeyData(Impl::fromGpgmeKey(data)); }
408 
409  PublicKeyData::operator bool() const
410  { return !_pimpl->_fingerprint.empty(); }
411 
412  std::string PublicKeyData::id() const
413  { return _pimpl->_id; }
414 
415  std::string PublicKeyData::name() const
416  { return _pimpl->_name; }
417 
418  std::string PublicKeyData::fingerprint() const
419  { return _pimpl->_fingerprint; }
420 
421  std::string PublicKeyData::algoName() const
422  { return _pimpl->_algoName; }
423 
425  { return _pimpl->_created; }
426 
428  { return _pimpl->_expires; }
429 
431  { return isExpired( _pimpl->_expires ); }
432 
434  { return hasDaysToLive( _pimpl->_expires ); }
435 
436  std::string PublicKeyData::expiresAsString() const
437  { return expiresDetailVerbose( _pimpl->_expires ); }
438 
440  { return _pimpl->_id.empty() ? _pimpl->_id : str::toLower( _pimpl->_id.substr(8,8) ); }
441 
443  { return _pimpl->_created ? str::hexstring( _pimpl->_created ).substr(2) : std::string(); }
444 
445  std::string PublicKeyData::rpmName() const
446  { return str::Format( "gpg-pubkey-%1%-%2%" ) % gpgPubkeyVersion() % gpgPubkeyRelease(); }
447 
448  std::string PublicKeyData::asString() const
449  {
450  if ( not *this )
451  return "[NO_KEY]";
452 
453  str::Str str;
454  str << "[" << _pimpl->_id << "-" << gpgPubkeyRelease();
455  for ( auto && sub : _pimpl->_subkeys )
456  str << ", " << sub.id();
457  return str << "] [" << _pimpl->_name.c_str() << "] [" << expiresDetail( _pimpl->_expires ) << "]";
458  }
459 
461  { return !_pimpl->_subkeys.empty(); }
462 
464  { return makeIterable( &(*_pimpl->_subkeys.begin()), &(*_pimpl->_subkeys.end()) ); }
465 
467  { return makeIterable( &(*_pimpl->_signatures.begin()), &(*_pimpl->_signatures.end()) ); }
468 
469  bool PublicKeyData::providesKey( const std::string & id_r ) const
470  {
471  if ( not isSafeKeyId( id_r ) )
472  return( id_r.size() == 8 && str::endsWithCI( _pimpl->_id, id_r ) );
473 
474  if ( str::endsWithCI( _pimpl->_fingerprint, id_r ) )
475  return true;
476 
477  return _pimpl->hasSubkeyId( id_r );
478  }
479 
481  { return AsciiArt( fingerprint(), algoName() ); }
482 
483  std::ostream & dumpOn( std::ostream & str, const PublicKeyData & obj )
484  {
485  str << "[" << obj.name() << "]" << endl;
486  str << " fpr " << obj.fingerprint() << endl;
487  str << " id " << obj.id() << endl;
488  str << " alg " << obj.algoName() << endl;
489  str << " cre " << Date::ValueType(obj.created()) << ' ' << obj.created() << endl;
490  str << " exp " << Date::ValueType(obj.expires()) << ' ' << obj.expiresAsString() << endl;
491  str << " ttl " << obj.daysToLive() << endl;
492  for ( auto && sub : obj._pimpl->_subkeys )
493  str << " sub " << sub << endl;
494  str << " rpm " << obj.gpgPubkeyVersion() << "-" << obj.gpgPubkeyRelease() << endl;
495  return str;
496  }
497 
498  bool operator==( const PublicKeyData & lhs, const PublicKeyData & rhs )
499  { return ( lhs.fingerprint() == rhs.fingerprint() && lhs.created() == rhs.created() ); }
500 
501 
507  {
509  {}
510 
511  Impl( const Pathname & keyFile_r )
512  : _dontUseThisPtrDirectly( new filesystem::TmpFile )
513  {
514  PathInfo info( keyFile_r );
515  MIL << "Taking pubkey from " << keyFile_r << " of size " << info.size() << " and sha1 " << filesystem::checksum(keyFile_r, "sha1") << endl;
516 
517  if ( !info.isExist() )
518  ZYPP_THROW(Exception("Can't read public key from " + keyFile_r.asString() + ", file not found"));
519 
520  if ( filesystem::hardlinkCopy( keyFile_r, path() ) != 0 )
521  ZYPP_THROW(Exception("Can't copy public key data from " + keyFile_r.asString() + " to " + path().asString() ));
522 
523  readFromFile();
524  }
525 
526  Impl( const filesystem::TmpFile & sharedFile_r )
527  : _dontUseThisPtrDirectly( new filesystem::TmpFile( sharedFile_r ) )
528  { readFromFile(); }
529 
530  // private from keyring
531  Impl( const filesystem::TmpFile & sharedFile_r, const PublicKeyData & keyData_r )
532  : _dontUseThisPtrDirectly( new filesystem::TmpFile( sharedFile_r ) )
533  , _keyData( keyData_r )
534  {
535  if ( ! keyData_r )
536  {
537  WAR << "Invalid PublicKeyData supplied: scanning from file" << endl;
538  readFromFile();
539  }
540  }
541 
542  // private from keyring
543  Impl( const PublicKeyData & keyData_r )
544  : _keyData( keyData_r )
545  {}
546 
547  public:
548  const PublicKeyData & keyData() const
549  { return _keyData; }
550 
551  Pathname path() const
552  { return( /*the one and only intended use*/_dontUseThisPtrDirectly ? _dontUseThisPtrDirectly->path() : Pathname() ); }
553 
554  const std::list<PublicKeyData> & hiddenKeys() const
555  { return _hiddenKeys; }
556 
557  protected:
559  {
560  PathInfo info( path() );
561  MIL << "Reading pubkey from " << info.path() << " of size " << info.size() << " and sha1 " << filesystem::checksum(info.path(), "sha1") << endl;
562 
563  std::list<PublicKeyData> keys = KeyManagerCtx::createForOpenPGP().readKeyFromFile( path() );
564  switch ( keys.size() )
565  {
566  case 0:
567  ZYPP_THROW( BadKeyException( "File " + path().asString() + " doesn't contain public key data" , path() ) );
568  break;
569 
570  case 1:
571  // ok.
572  _keyData = keys.back();
573  _hiddenKeys.clear();
574  break;
575 
576  default:
577  WAR << "File " << path().asString() << " contains multiple keys: " << keys << endl;
578  _keyData = keys.back();
579  keys.pop_back();
580  _hiddenKeys.swap( keys );
581  break;
582  }
583 
584  MIL << "Read pubkey from " << info.path() << ": " << _keyData << endl;
585  }
586 
587  private:
588  shared_ptr<filesystem::TmpFile> _dontUseThisPtrDirectly; // shared_ptr ok because TmpFile itself is a refernce type (no COW)
590  std::list<PublicKeyData> _hiddenKeys;
591 
592  public:
594  static shared_ptr<Impl> nullimpl()
595  {
596  static shared_ptr<Impl> _nullimpl( new Impl );
597  return _nullimpl;
598  }
599 
600  private:
601  friend Impl * rwcowClone<Impl>( const Impl * rhs );
603  Impl * clone() const
604  { return new Impl( *this ); }
605  };
607 
609  // class PublicKey
612  : _pimpl( Impl::nullimpl() )
613  {}
614 
616  : _pimpl( new Impl( file ) )
617  {}
618 
620  : _pimpl( new Impl( sharedfile ) )
621  {}
622 
623  PublicKey::PublicKey( const filesystem::TmpFile & sharedfile, const PublicKeyData & keyData_r )
624  : _pimpl( new Impl( sharedfile, keyData_r ) )
625  {}
626 
627  PublicKey::PublicKey( const PublicKeyData & keyData_r )
628  : _pimpl( new Impl( keyData_r ) )
629  {}
630 
632  {}
633 
634  PublicKey PublicKey::noThrow( const Pathname & keyFile_r )
635  try { return PublicKey( keyFile_r ); } catch(...) { return PublicKey(); }
636 
638  { return _pimpl->keyData(); }
639 
641  { return _pimpl->path(); }
642 
643  const std::list<PublicKeyData> & PublicKey::hiddenKeys() const
644  { return _pimpl->hiddenKeys(); }
645 
646  bool PublicKey::fileProvidesKey( const std::string & id_r ) const
647  {
648  if ( providesKey( id_r ) )
649  return true;
650  for ( const auto & keydata : hiddenKeys() ) {
651  if ( keydata.providesKey( id_r ) )
652  return true;
653  }
654  return false;
655  }
656 
657  std::string PublicKey::id() const
658  { return keyData().id(); }
659 
660  std::string PublicKey::name() const
661  { return keyData().name(); }
662 
663  std::string PublicKey::fingerprint() const
664  { return keyData().fingerprint(); }
665 
666  std::string PublicKey::algoName() const
667  { return keyData().algoName(); }
668 
670  { return keyData().created(); }
671 
673  { return keyData().expires(); }
674 
675  bool PublicKey::expired() const
676  { return keyData().expired(); }
677 
679  { return keyData().daysToLive(); }
680 
681  std::string PublicKey::expiresAsString() const
682  { return keyData().expiresAsString(); }
683 
684  std::string PublicKey::gpgPubkeyVersion() const
685  { return keyData().gpgPubkeyVersion(); }
686 
687  std::string PublicKey::gpgPubkeyRelease() const
688  { return keyData().gpgPubkeyRelease(); }
689 
690  std::string PublicKey::asString() const
691  { return keyData().asString(); }
692 
693  std::string PublicKey::rpmName() const
694  { return keyData().rpmName(); }
695 
696  bool PublicKey::operator==( const PublicKey & rhs ) const
697  { return rhs.keyData() == keyData(); }
698 
699  bool PublicKey::operator==( const std::string & sid ) const
700  { return ( isSafeKeyId( sid ) || sid.size() == 8 ) && str::endsWithCI( fingerprint(), sid ); }
701 
702  std::ostream & dumpOn( std::ostream & str, const PublicKey & obj )
703  { return dumpOn( str, obj.keyData() ); }
704 
706 } // namespace zypp
std::string asString() const
Simple string representation.
Definition: PublicKey.cc:196
std::string toLower(const std::string &s)
Return lowercase version of s.
Definition: String.cc:180
static const ValueType day
Definition: Date.h:44
PublicKeySignatureData()
Default constructed: empty data.
Definition: PublicKey.cc:238
static shared_ptr< Impl > nullimpl()
Offer default Impl.
Definition: PublicKey.cc:148
#define MIL
Definition: Logger.h:103
Impl(const filesystem::TmpFile &sharedFile_r, const PublicKeyData &keyData_r)
Definition: PublicKey.cc:531
static bool isSafeKeyId(const std::string &id_r)
Whether this is a long id (64bit/16byte) or even better a fingerprint.
Definition: PublicKey.h:318
int daysToLive() const
Number of days (24h) until the key expires (or since it exired).
Definition: PublicKey.cc:193
bool operator==(const Capability &lhs, const Capability &rhs)
relates: Capability
Definition: Capability.h:309
std::list< PublicKeyData > readKeyFromFile(const Pathname &file)
Returns a list of all PublicKeyData found in file.
Definition: KeyManager.cc:405
Pathname path() const
Definition: PublicKey.cc:551
const Pathname & path() const
Return current Pathname.
Definition: PathInfo.h:251
const std::list< PublicKeyData > & hiddenKeys() const
Additional keys data in case the ASCII armored blob contains multiple keys.
Definition: PublicKey.cc:643
std::list< PublicKeyData > _hiddenKeys
Definition: PublicKey.cc:590
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Definition: Exception.h:459
const PublicKeyData & keyData() const
The public keys data (.
Definition: PublicKey.cc:637
std::string name() const
Definition: PublicKey.cc:660
static shared_ptr< Impl > nullimpl()
Offer default Impl.
Definition: PublicKey.cc:333
Iterable< KeySignatureIterator > signatures() const
Iterate all key signatures.
Definition: PublicKey.cc:466
RWCOW_pointer< Impl > _pimpl
Definition: PublicKey.h:119
std::string gpgPubkeyRelease() const
Gpg-pubkey release as computed by rpm (hexencoded created)
Definition: PublicKey.cc:442
PublicSubkeyData implementation.
Definition: PublicKey.cc:132
Iterable< TIterator > makeIterable(TIterator &&begin_r, TIterator &&end_r)
relates: Iterable convenient construction.
Definition: Iterable.h:88
bool fileProvidesKey(const std::string &id_r) const
Extends providesKey to look at the hidden keys too.
Definition: PublicKey.cc:646
Class representing one GPG Public Keys data.
Definition: PublicKey.h:200
bool expired() const
Whether the key has expired.
Definition: PublicKey.cc:190
std::string asString() const
Simple string representation.
Definition: PublicKey.cc:448
const PublicKeyData & keyData() const
Definition: PublicKey.cc:548
Exception thrown when the supplied key is not a valid gpg key.
Definition: PublicKey.h:48
std::string algoName() const
Key algorithm string like RSA 2048
Definition: PublicKey.cc:421
PublicSubkeyData()
Default constructed: empty data.
Definition: PublicKey.cc:163
std::string id() const
Definition: PublicKey.cc:657
base::DrunkenBishop AsciiArt
Random art fingerprint visualization type (base::DrunkenBishop).
Definition: PublicKey.h:327
std::string name() const
Key name.
Definition: PublicKey.cc:415
String related utilities and Regular expression matching.
RWCOW_pointer< Impl > _pimpl
Definition: PublicKey.h:179
const std::string & asString(const std::string &t)
Global asString() that works with std::string too.
Definition: String.h:140
Definition: ansi.h:854
std::string asString() const
Simple string representation.
Definition: PublicKey.cc:275
Date created() const
Creation date.
Definition: PublicKey.cc:184
static shared_ptr< Impl > nullimpl()
Offer default Impl.
Definition: PublicKey.cc:223
int daysToLive() const
Definition: PublicKey.cc:678
Convenient building of std::string with boost::format.
Definition: String.h:253
static KeyManagerCtx createForOpenPGP()
Creates a new KeyManagerCtx for PGP using a volatile temp.
Definition: KeyManager.cc:320
Provide a new empty temporary file and delete it when no longer needed.
Definition: TmpPath.h:117
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
Definition: String.cc:39
Iterable< SubkeyIterator > subkeys() const
Iterate any subkeys.
Definition: PublicKey.cc:463
Date expires() const
Expiry date, or Date() if the key never expires.
Definition: PublicKey.cc:266
PublicKeyData()
Default constructed: empty data.
Definition: PublicKey.cc:395
PublicKeySignatureData implementation.
Definition: PublicKey.cc:206
int hardlinkCopy(const Pathname &oldpath, const Pathname &newpath)
Create newpath as hardlink or copy of oldpath.
Definition: PathInfo.cc:902
#define PL_(MSG1, MSG2, N)
Definition: Gettext.h:42
bool endsWithCI(const C_Str &str_r, const C_Str &prefix_r)
Definition: String.h:1166
std::string expiresAsString() const
Definition: PublicKey.cc:681
std::string gpgPubkeyVersion() const
Gpg-pubkey version as computed by rpm (trailing 8 byte id)
Definition: PublicKey.cc:439
const std::list< PublicKeyData > & hiddenKeys() const
Definition: PublicKey.cc:554
std::string id() const
Subkey ID.
Definition: PublicKey.cc:181
time_t ValueType
Definition: Date.h:38
Date expires() const
Definition: PublicKey.cc:672
bool operator==(const PublicKey &rhs) const
Definition: PublicKey.cc:696
std::string expiresAsString() const
Definition: PublicKey.cc:436
int daysToLive() const
Number of days (24h) until the key expires (or since it exired).
Definition: PublicKey.cc:433
RWCOW_pointer< Impl > _pimpl
Pointer to implementation.
Definition: PublicKey.h:483
std::string rpmName() const
Gpg-pubkey name as computed by rpm.
Definition: PublicKey.cc:445
Store and operate on date (time_t).
Definition: Date.h:32
Date created() const
Creation / last modification date (latest selfsig).
Definition: PublicKey.cc:424
bool expired() const
Whether the key has expired.
Definition: PublicKey.cc:269
PublicKeyData _keyData
Definition: PublicKey.cc:589
std::string name() const
The user ID associated with this key, if present.
Definition: PublicKey.cc:260
Convenient building of std::string via std::ostringstream Basically a std::ostringstream autoconverti...
Definition: String.h:212
Impl(const Pathname &keyFile_r)
Definition: PublicKey.cc:511
std::string gpgPubkeyVersion() const
Definition: PublicKey.cc:684
std::string rpmName() const
Definition: PublicKey.cc:693
const std::string & asString() const
String representation.
Definition: Pathname.h:94
bool isExist() const
Return whether valid stat info exists.
Definition: PathInfo.h:286
Impl * clone() const
clone for RWCOW_pointer
Definition: PublicKey.cc:386
#define WAR
Definition: Logger.h:104
bool providesKey(const std::string &id_r) const
!<
Definition: PublicKey.h:439
shared_ptr< filesystem::TmpFile > _dontUseThisPtrDirectly
Definition: PublicKey.cc:588
static shared_ptr< Impl > nullimpl()
Offer default Impl.
Definition: PublicKey.cc:594
#define _(MSG)
Definition: Gettext.h:39
int daysToLive() const
Number of days (24h) until the key expires (or since it expired).
Definition: PublicKey.cc:272
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
relates: Capability Detailed stream output
Definition: Capability.cc:589
Impl * clone() const
clone for RWCOW_pointer
Definition: PublicKey.cc:229
Impl(const PublicKeyData &keyData_r)
Definition: PublicKey.cc:543
PublicKey()
Default ctor.
Definition: PublicKey.cc:611
Date created() const
Creation date.
Definition: PublicKey.cc:263
Impl * clone() const
clone for RWCOW_pointer
Definition: PublicKey.cc:154
PublicKey implementation.
Definition: PublicKey.cc:506
std::string fingerprint() const
Key fingerprint.
Definition: PublicKey.cc:418
bool expired() const
Whether the key has expired.
Definition: PublicKey.cc:430
std::string gpgPubkeyRelease() const
Definition: PublicKey.cc:687
Class representing a GPG Public Keys subkeys.
Definition: PublicKey.h:79
Class representing one GPG Public Key (PublicKeyData + ASCII armored in a tempfile).
Definition: PublicKey.h:374
Date expires() const
Expiry date, or Date() if the key never expires.
Definition: PublicKey.cc:187
AsciiArt asciiArt() const
Random art fingerprint visualization (base::DrunkenBishop).
Definition: PublicKey.cc:480
Date created() const
Definition: PublicKey.cc:669
Base class for Exception.
Definition: Exception.h:152
static bool isSafeKeyId(const std::string &id_r)
!<
Definition: PublicKey.h:442
Pathname path() const
File containing the ASCII armored key.
Definition: PublicKey.cc:640
std::string id() const
Key ID.
Definition: PublicKey.cc:412
Impl(const filesystem::TmpFile &sharedFile_r)
Definition: PublicKey.cc:526
static Date now()
Return the current time.
Definition: Date.h:78
std::string checksum(const Pathname &file, const std::string &algorithm)
Compute a files checksum.
Definition: PathInfo.cc:1070
RWCOW_pointer< Impl > _pimpl
Definition: PublicKey.h:338
std::string fingerprint() const
Definition: PublicKey.cc:663
std::string asString() const
Definition: PublicKey.cc:690
bool expired() const
Definition: PublicKey.cc:675
PublicKeyData implementation.
Definition: PublicKey.cc:295
Wrapper class for ::stat/::lstat.
Definition: PathInfo.h:225
std::string printDate(DateFormat dateFormat_r=DateFormat::calendar, TimeBase base_r=TB_LOCALTIME) const
Convenience for printing the date only [&#39;2014-02-07&#39;] The default is DateFormat::calendar and TB_LOCA...
Definition: Date.h:192
static shared_ptr< Impl > fromGpgmeKey(gpgme_key_t rawData)
Definition: PublicKey.cc:339
bool hasSubkeyId(const std::string &id_r) const
Definition: PublicKey.cc:321
static PublicKey noThrow(const Pathname &keyFile_r)
Static ctor returning an empty PublicKey rather than throwing.
Definition: PublicKey.cc:634
std::vector< PublicKeySignatureData > _signatures
Definition: PublicKey.cc:305
static PublicKeyData fromGpgmeKey(_gpgme_key *data)
Definition: PublicKey.cc:406
std::vector< PublicSubkeyData > _subkeys
Definition: PublicKey.cc:304
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
bool providesKey(const std::string &id_r) const
Whether id_r is the id or fingerprint of the primary key or of a subkey.
Definition: PublicKey.cc:469
Class representing a signature on a GPG Public Key.
Definition: PublicKey.h:136
Date expires() const
Expiry date, or Date() if the key never expires.
Definition: PublicKey.cc:427
std::string hexstring(char n, int w=4)
Definition: String.h:325
std::string algoName() const
Definition: PublicKey.cc:666
std::string id() const
The key ID of key used to create the signature.
Definition: PublicKey.cc:257
bool hasSubkeys() const
Whether subkeys is not empty.
Definition: PublicKey.cc:460
Impl * clone() const
clone for RWCOW_pointer
Definition: PublicKey.cc:603
Random art fingerprint visualization Visualize fingerprint data on a [17x9] (SSH) or [19x11] (GPG) or...
Definition: DrunkenBishop.h:61