29 #define GPG_BINARY "/usr/bin/gpg2"
39 inline bool isExpired(
const Date & expires_r )
40 {
return( expires_r && expires_r <
Date::now() ); }
42 inline int hasDaysToLive(
const Date & expires_r )
48 if ( exp < 0 ) ret -= 1;
54 inline std::string expiresDetail(
const Date & expires_r )
60 str <<
_(
"does not expire");
62 else if ( isExpired( expires_r ) )
65 str << ( str::Format(
_(
"expired: %1%") ) % expires_r.printDate() );
70 str << ( str::Format(
_(
"expires: %1%") ) % expires_r.printDate() );
75 inline std::string expiresDetailVerbose(
const Date & expires_r )
79 return _(
"(does not expire)");
81 std::string ret( expires_r.asString() );
82 int ttl( hasDaysToLive( expires_r ) );
88 ret +=
_(
"(EXPIRED)");
92 ret +=
_(
"(expires within 24h)");
96 ret +=
str::form(
PL_(
"(expires in %d day)",
"(expires in %d days)", ttl ), ttl );
119 static shared_ptr<Impl> _nullimpl(
new Impl );
124 friend Impl * rwcowClone<Impl>(
const Impl * rhs );
127 {
return new Impl( *
this ); }
135 : _pimpl(
Impl::nullimpl() )
141 PublicSubkeyData::operator
bool()
const
142 {
return !_pimpl->_id.empty(); }
184 if ( sub.id() == id_r )
197 static shared_ptr<Impl> _nullimpl(
new Impl );
202 friend Impl * rwcowClone<Impl>(
const Impl * rhs );
205 {
return new Impl( *
this ); }
213 : _pimpl(
Impl::nullimpl() )
219 PublicKeyData::operator
bool()
const
220 {
return !_pimpl->_fingerprint.empty(); }
257 str <<
", " << sub.id();
272 str <<
"[" << obj.
name() <<
"]" << endl;
274 str <<
" id " << obj.
id() << endl;
278 for (
auto && sub : obj.
_pimpl->_subkeys )
279 str <<
" sub " << sub << endl;
303 void scan( std::string & line_r, std::list<PublicKeyData> & keys_r )
313 if ( line_r.empty() )
321 if ( line_r[1] ==
'u' && line_r[2] ==
'b' && line_r[3] ==
':' )
330 if ( line_r[1] ==
'p' && line_r[2] ==
'r' && line_r[3] ==
':' )
335 if ( line_r[1] ==
'i' && line_r[2] ==
'd' && line_r[3] ==
':' )
340 if ( line_r[1] ==
'i' && line_r[2] ==
'g' && line_r[3] ==
':' )
342 else if ( line_r[1] ==
'u' && line_r[2] ==
'b' && line_r[3] ==
':' )
354 if ( line_r[line_r.size()-1] ==
'\n' )
355 line_r.erase( line_r.size()-1 );
375 Date cdate(str::strtonum<Date::ValueType>(
_words[5]));
387 if ( !
_words[9].empty() &&
_words[9] !=
"[User ID not found]" )
432 Impl(
const Pathname & keyFile_r )
434 PathInfo info( keyFile_r );
435 MIL <<
"Taking pubkey from " << keyFile_r <<
" of size " << info.size() <<
" and sha1 " <<
filesystem::checksum(keyFile_r,
"sha1") << endl;
437 if ( !info.isExist() )
438 ZYPP_THROW(
Exception(
"Can't read public key from " + keyFile_r.asString() +
", file not found"));
456 WAR <<
"Invalid PublicKeyData supplied: scanning from file" << endl;
478 MIL <<
"Reading pubkey from " << info.path() <<
" of size " << info.size() <<
" and sha1 " <<
filesystem::checksum(info.path(),
"sha1") << endl;
487 "--no-default-keyring",
489 "--with-fingerprint",
506 scanner.
scan( line );
508 int ret = prog.
close();
510 switch ( scanner.
_keys.size() )
528 scanner.
_keys.pop_back();
533 MIL <<
"Read pubkey from " << info.path() <<
": " <<
_keyData << endl;
545 static shared_ptr<Impl> _nullimpl(
new Impl );
550 friend Impl * rwcowClone<Impl>(
const Impl * rhs );
553 {
return new Impl( *
this ); }
561 : _pimpl(
Impl::nullimpl() )
565 : _pimpl( new
Impl( file ) )
569 : _pimpl( new
Impl( sharedfile ) )
573 : _pimpl( new
Impl( sharedfile, keydata ) )
625 {
return sid ==
id(); }
std::string name() const
Key name.
static const ValueType day
int assert_dir(const Pathname &path, unsigned mode)
Like 'mkdir -p'.
Date expires() const
Expiry date, or Date() if the key never expires.
Impl(const filesystem::TmpFile &sharedFile_r, const PublicKeyData &keyData_r)
bool hasSubkeyId(const std::string &id_r) const
std::string gpgPubkeyRelease() const
Gpg-pubkey release as computed by rpm (hexencoded created)
Date created() const
Creation date.
int daysToLive() const
Number of days (24h) until the key expires (or since it exired).
std::list< PublicKeyData > _hiddenKeys
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
std::string _initHomeDir()
RWCOW_pointer< Impl > _pimpl
std::list< PublicKeyData > _keys
Extracted keys.
Impl * clone() const
clone for RWCOW_pointer
PublicSubkeyData implementation.
Iterable< SubkeyIterator > subkeys() const
Iterate any subkeys.
Class representing one GPG Public Keys data.
const std::string & asString() const
String representation.
Exception thrown when the supplied key is not a valid gpg key.
bool hasSubkeys() const
Whether subkeys is not empty.
PublicSubkeyData()
Default constructed: empty data.
const std::list< PublicKeyData > & hiddenKeys() const
Additional keys data in case the ASCII armored blob containes multiple keys.
Date expires() const
Expiry date, or Date() if the key never expires.
std::string printDate(DateFormat dateFormat_r=DateFormat::calendar, TimeBase base_r=TB_LOCALTIME) const
Convenience for printing the date only ['2014-02-07'] The default is DateFormat::calendar and TB_LOCA...
bool providesKey(const std::string &id_r) const
Whether id_r is the id of the primary key or of a subkey.
std::string asString() const
PublicKeyData::Impl * _keyDataPtr
void scan(std::string line_r)
Feed gpg output line by line into scan.
RW_pointer< Impl, rw_pointer::Scoped< Impl > > _pimpl
std::string gpgPubkeyVersion() const
Gpg-pubkey version as computed by rpm (trailing 8 byte id)
PublicKeyScanner implementation.
std::string expiresAsString() const
bool operator==(const SetRelation::Enum &lhs, const SetCompare &rhs)
Provide a new empty temporary file and delete it when no longer needed.
const std::list< PublicKeyData > & hiddenKeys() const
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
Impl * clone() const
clone for RWCOW_pointer
PublicKeyData()
Default constructed: empty data.
#define PL_(MSG1, MSG2, N)
std::string gpgPubkeyVersion() const
std::string & replaceAll(std::string &str_r, const std::string &from_r, const std::string &to_r)
Replace all occurrences of from_r with to_r in str_r (inplace).
enum zypp::PublicKeyScanner::Impl::@1 _parseEntry
Pathname path() const
File containig the ASCII armored key.
RWCOW_pointer< Impl > _pimpl
Pointer to implementation.
Store and operate on date (time_t).
Convenient building of std::string via std::ostringstream Basically a std::ostringstream autoconverti...
Impl(const Pathname &keyFile_r)
Execute a program and give access to its io An object of this class encapsulates the execution of an ...
std::string fingerprint() const
Key fingerprint.
std::string expiresAsString() const
bool expired() const
Whether the key has expired.
int hardlinkCopy(const Pathname &oldpath, const Pathname &newpath)
Create newpath as hardlink or copy of oldpath.
Pathname myTmpDir()
Global access to the zypp.TMPDIR (created on demand, deleted when libzypp is unloaded) ...
static shared_ptr< Impl > nullimpl()
Offer default Impl.
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
std::string receiveLine()
Read one line from the input stream.
Scan abstract from 'gpg –with-colons' key listings.
std::string toLower(const std::string &s)
Return lowercase version of s.
std::vector< std::string > _words
std::string asString() const
Simple string representation.
PublicKey implementation.
int close()
Wait for the progamm to complete.
unsigned splitFields(const C_Str &line_r, TOutputIterator result_r, const C_Str &sepchars_r=":")
Split line_r into fields.
int daysToLive() const
Number of days (24h) until the key expires (or since it exired).
Class representing a GPG Public Keys subkeys.
Class representing one GPG Public Key (PublicKeyData + ASCII armored in a tempfile).
Base class for Exception.
Impl(const filesystem::TmpFile &sharedFile_r)
const PublicKeyData & keyData() const
The public keys data (.
static Date now()
Return the current time.
std::string checksum(const Pathname &file, const std::string &algorithm)
Compute a files checksum.
RWCOW_pointer< Impl > _pimpl
Impl * clone() const
clone for RWCOW_pointer
std::string id() const
Key ID.
static shared_ptr< Impl > nullimpl()
Offer default Impl.
bool expired() const
Whether the key has expired.
void scan(std::string &line_r, std::list< PublicKeyData > &keys_r)
PublicKeyData implementation.
std::string fingerprint() const
static shared_ptr< Impl > nullimpl()
Offer default Impl.
std::vector< PublicSubkeyData > _subkeys
filesystem::TmpFile _dataFile
Date created() const
Creation / last modification date (latest selfsig).
std::string gpgPubkeyRelease() const
std::string hexstring(char n, int w=4)
bool operator==(const PublicKey &rhs) const
std::string asString() const
Simple string representation.
std::string id() const
Subkey ID.
const PublicKeyData & keyData() const