32 #define GPG_BINARY "/usr/bin/gpg2"
42 inline bool isExpired(
const Date & expires_r )
43 {
return( expires_r && expires_r <
Date::now() ); }
45 inline int hasDaysToLive(
const Date & expires_r )
51 if ( exp < 0 ) ret -= 1;
57 inline std::string expiresDetail(
const Date & expires_r )
63 str <<
_(
"does not expire");
65 else if ( isExpired( expires_r ) )
68 str << ( str::Format(
_(
"expired: %1%") ) % expires_r.printDate() );
73 str << ( str::Format(
_(
"expires: %1%") ) % expires_r.printDate() );
78 inline std::string expiresDetailVerbose(
const Date & expires_r )
82 return _(
"(does not expire)");
84 std::string ret( expires_r.asString() );
85 int ttl( hasDaysToLive( expires_r ) );
91 ret +=
_(
"(EXPIRED)");
95 ret +=
_(
"(expires within 24h)");
99 ret +=
str::form(
_PL(
"(expires in %d day)",
"(expires in %d days)", ttl ), ttl );
122 static shared_ptr<Impl> _nullimpl(
new Impl );
127 friend Impl * rwcowClone<Impl>(
const Impl * rhs );
130 {
return new Impl( *
this ); }
138 : _pimpl(
Impl::nullimpl() )
144 PublicSubkeyData::operator
bool()
const
145 {
return !_pimpl->_id.empty(); }
187 if ( sub.id() == id_r )
200 static shared_ptr<Impl> _nullimpl(
new Impl );
205 friend Impl * rwcowClone<Impl>(
const Impl * rhs );
208 {
return new Impl( *
this ); }
216 : _pimpl(
Impl::nullimpl() )
222 PublicKeyData::operator
bool()
const
223 {
return !_pimpl->_fingerprint.empty(); }
260 str <<
", " << sub.id();
275 str <<
"[" << obj.
name() <<
"]" << endl;
277 str <<
" id " << obj.
id() << endl;
281 for (
auto && sub : obj.
_pimpl->_subkeys )
282 str <<
" sub " << sub << endl;
306 void scan( std::string & line_r, std::list<PublicKeyData> & keys_r )
316 if ( line_r.empty() )
324 if ( line_r[1] ==
'u' && line_r[2] ==
'b' && line_r[3] ==
':' )
333 if ( line_r[1] ==
'p' && line_r[2] ==
'r' && line_r[3] ==
':' )
338 if ( line_r[1] ==
'i' && line_r[2] ==
'd' && line_r[3] ==
':' )
343 if ( line_r[1] ==
'i' && line_r[2] ==
'g' && line_r[3] ==
':' )
345 else if ( line_r[1] ==
'u' && line_r[2] ==
'b' && line_r[3] ==
':' )
357 if ( line_r[line_r.size()-1] ==
'\n' )
358 line_r.erase( line_r.size()-1 );
378 Date cdate(str::strtonum<Date::ValueType>(
_words[5]));
390 if ( !
_words[9].empty() &&
_words[9] !=
"[User ID not found]" )
435 Impl(
const Pathname & keyFile_r )
437 PathInfo info( keyFile_r );
438 MIL <<
"Taking pubkey from " << keyFile_r <<
" of size " << info.size() <<
" and sha1 " <<
filesystem::checksum(keyFile_r,
"sha1") << endl;
440 if ( !info.isExist() )
441 ZYPP_THROW(
Exception(
"Can't read public key from " + keyFile_r.asString() +
", file not found"));
459 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;
481 std::string tmppath( dir.path().asString() );
488 "--no-default-keyring",
490 "--with-fingerprint",
507 scanner.
scan( line );
509 int ret = prog.
close();
511 switch ( scanner.
_keys.size() )
529 scanner.
_keys.pop_back();
534 MIL <<
"Read pubkey from " << info.path() <<
": " <<
_keyData << endl;
546 static shared_ptr<Impl> _nullimpl(
new Impl );
551 friend Impl * rwcowClone<Impl>(
const Impl * rhs );
554 {
return new Impl( *
this ); }
562 : _pimpl(
Impl::nullimpl() )
566 : _pimpl( new
Impl( file ) )
570 : _pimpl( new
Impl( sharedfile ) )
574 : _pimpl( new
Impl( sharedfile, keydata ) )
626 {
return sid ==
id(); }
std::string name() const
Key name.
static const ValueType day
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.
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.
#define _PL(MSG1, MSG2, N)
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.
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).
Provide a new empty temporary directory and recursively delete it when no longer needed.
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.
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.
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
unsigned splitFields(const C_Str &line_r, _OutputIterator result_r, const C_Str &sepchars_r=":")
Split line_r into fields.