35#undef ZYPP_BASE_LOGGER_LOGGROUP
36#define ZYPP_BASE_LOGGER_LOGGROUP "zypp::gpg"
44 inline bool isExpired(
const Date & expires_r )
45 {
return( expires_r && expires_r <
Date::now() ); }
47 inline int hasDaysToLive(
const Date & expires_r )
53 if ( exp < 0 ) ret -= 1;
59 inline std::string expiresDetail(
const Date & expires_r )
65 str <<
_(
"does not expire");
67 else if ( isExpired( expires_r ) )
70 str << ( str::Format(
_(
"expired: %1%") ) % expires_r.printDate() );
75 str << ( str::Format(
_(
"expires: %1%") ) % expires_r.printDate() );
80 inline std::string expiresDetailVerbose(
const Date & expires_r )
84 return _(
"(does not expire)");
86 std::string ret( expires_r.asString() );
87 int ttl( hasDaysToLive( expires_r ) );
93 ret +=
_(
"(EXPIRED)");
97 ret +=
_(
"(expires within 24h)");
101 ret +=
str::form(
PL_(
"(expires in %d day)",
"(expires in %d days)", ttl ), ttl );
107 inline std::string keyAlgoName(
const gpgme_subkey_t & key_r )
110 if (
const char * n = ::gpgme_pubkey_algo_name( key_r->pubkey_algo ) )
111 ret = str::Str() << n <<
' ' << key_r->length;
117 inline bool shorterIsSuffixCI(
const std::string & lhs,
const std::string & rhs )
119 if ( lhs.size() >= rhs.size() )
156 return new Impl( *
this );
178 PublicSubkeyData::operator
bool()
const
179 {
return !
_pimpl->_id.empty(); }
185 {
return _pimpl->_created; }
188 {
return _pimpl->_expires; }
191 {
return isExpired(
_pimpl->_expires ); }
194 {
return hasDaysToLive(
_pimpl->_expires ); }
231 return new Impl( *
this );
254 PublicKeySignatureData::operator
bool()
const
255 {
return !
_pimpl->_keyid.empty(); }
258 {
return _pimpl->_keyid; }
264 {
return _pimpl->_created; }
267 {
return _pimpl->_expires; }
270 {
return isExpired(
_pimpl->_expires ); }
273 {
return hasDaysToLive(
_pimpl->_expires ); }
278 if (!
name().empty()) {
282 nameStr =
"[User ID not found] ";
287 <<
" [" << expiresDetail(
expires() ) <<
"]";
308 bool hasSubkeyId(
const std::string & id_r )
const;
325 if ( shorterIsSuffixCI( sub.id(), id_r ) ) {
344 gpgme_subkey_t sKey = rawData->subkeys;
348 if ( rawData->uids && rawData->uids->signatures ) {
349 data->_created =
zypp::Date(rawData->uids->signatures->timestamp);
353 for (
auto t = rawData->uids->signatures->next; t; t = t->next ) {
354 if (t->keyid !=
nullptr) {
358 if ( t->timestamp > data->_created )
359 data->_created = t->timestamp;
367 data->_algoName = keyAlgoName( sKey );
388 return new Impl( *
this );
409 PublicKeyData::operator
bool()
const
410 {
return !
_pimpl->_fingerprint.empty(); }
419 {
return _pimpl->_fingerprint; }
422 {
return _pimpl->_algoName; }
425 {
return _pimpl->_created; }
428 {
return _pimpl->_expires; }
431 {
return isExpired(
_pimpl->_expires ); }
434 {
return hasDaysToLive(
_pimpl->_expires ); }
437 {
return expiresDetailVerbose(
_pimpl->_expires ); }
455 for (
auto && sub :
_pimpl->_subkeys )
456 str <<
", " << sub.id();
457 return str <<
"] [" <<
_pimpl->_name.c_str() <<
"] [" << expiresDetail(
_pimpl->_expires ) <<
"]";
461 {
return !
_pimpl->_subkeys.empty(); }
477 return _pimpl->hasSubkeyId( id_r );
485 str <<
"[" << obj.
name() <<
"]" << endl;
487 str <<
" id " << obj.
id() << endl;
492 for (
auto && sub : obj.
_pimpl->_subkeys )
493 str <<
" sub " << sub << endl;
515 MIL <<
"Taking pubkey from " << keyFile_r <<
" of size " << info.
size() <<
" and sha1 " <<
filesystem::checksum(keyFile_r,
"sha1") << endl;
537 WAR <<
"Invalid PublicKeyData supplied: scanning from file" << endl;
564 switch ( keys.size() )
577 WAR <<
"File " <<
path().
asString() <<
" contains multiple keys: " << keys << endl;
604 {
return new Impl( *
this ); }
638 {
return _pimpl->keyData(); }
641 {
return _pimpl->path(); }
644 {
return _pimpl->hiddenKeys(); }
651 if ( keydata.providesKey( id_r ) )
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
#define PL_(MSG1, MSG2, N)
Exception thrown when the supplied key is not a valid gpg key.
Store and operate on date (time_t).
static const ValueType day
static Date now()
Return the current time.
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...
Base class for Exception.
Iterable< TIterator > makeIterable(TIterator &&begin_r, TIterator &&end_r)
convenient construction.
static KeyManagerCtx createForOpenPGP()
Creates a new KeyManagerCtx for PGP using a volatile temp.
std::list< PublicKeyData > readKeyFromFile(const Pathname &file)
Returns a list of all PublicKeyData found in file.
Class representing one GPG Public Keys data.
Iterable< KeySignatureIterator > signatures() const
Iterate all key signatures.
Date created() const
Creation / last modification date (latest selfsig).
bool expired() const
Whether the key has expired.
std::string name() const
Key name.
Iterable< SubkeyIterator > subkeys() const
Iterate any subkeys.
int daysToLive() const
Number of days (24h) until the key expires (or since it exired).
std::string rpmName() const
Gpg-pubkey name as computed by rpm.
bool hasSubkeys() const
Whether subkeys is not empty.
PublicKeyData()
Default constructed: empty data.
Date expires() const
Expiry date, or Date() if the key never expires.
std::string algoName() const
Key algorithm string like RSA 2048.
static bool isSafeKeyId(const std::string &id_r)
Whether this is a long id (64bit/16byte) or even better a fingerprint.
RWCOW_pointer< Impl > _pimpl
bool providesKey(const std::string &id_r) const
Whether id_r is the id or fingerprint of the primary key or of a subkey.
std::string id() const
Key ID.
std::string fingerprint() const
Key fingerprint.
std::string gpgPubkeyRelease() const
Gpg-pubkey release as computed by rpm (hexencoded created).
std::string gpgPubkeyVersion() const
Gpg-pubkey version as computed by rpm (trailing 8 byte id).
static PublicKeyData fromGpgmeKey(_gpgme_key *data)
std::string expiresAsString() const
AsciiArt asciiArt() const
Random art fingerprint visualization (base::DrunkenBishop).
std::string asString() const
Simple string representation.
base::DrunkenBishop AsciiArt
Random art fingerprint visualization type (base::DrunkenBishop).
Class representing a signature on a GPG Public Key.
Date created() const
Creation date.
~PublicKeySignatureData()
std::string asString() const
Simple string representation.
PublicKeySignatureData()
Default constructed: empty data.
RWCOW_pointer< Impl > _pimpl
int daysToLive() const
Number of days (24h) until the key expires (or since it expired).
bool expired() const
Whether the key has expired.
std::string id() const
The key ID of key used to create the signature.
std::string name() const
The user ID associated with this key, if present.
Date expires() const
Expiry date, or Date() if the key never expires.
Class representing one GPG Public Key (PublicKeyData + ASCII armored in a tempfile).
Pathname path() const
File containing the ASCII armored key.
std::string expiresAsString() const
bool fileProvidesKey(const std::string &id_r) const
Extends providesKey to look at the hidden keys too.
bool operator==(const PublicKey &rhs) const
RWCOW_pointer< Impl > _pimpl
Pointer to implementation.
const std::list< PublicKeyData > & hiddenKeys() const
Additional keys data in case the ASCII armored blob contains multiple keys.
static bool isSafeKeyId(const std::string &id_r)
!<
std::string rpmName() const
const PublicKeyData & keyData() const
The public keys data (.
std::string gpgPubkeyRelease() const
std::string asString() const
std::string fingerprint() const
std::string algoName() const
std::string gpgPubkeyVersion() const
static PublicKey noThrow(const Pathname &keyFile_r)
Static ctor returning an empty PublicKey rather than throwing.
bool providesKey(const std::string &id_r) const
!<
Class representing a GPG Public Keys subkeys.
RWCOW_pointer< Impl > _pimpl
std::string id() const
Subkey ID.
PublicSubkeyData()
Default constructed: empty data.
int daysToLive() const
Number of days (24h) until the key expires (or since it exired).
Date expires() const
Expiry date, or Date() if the key never expires.
friend class PublicKeyData
std::string asString() const
Simple string representation.
Date created() const
Creation date.
bool expired() const
Whether the key has expired.
Wrapper class for stat/lstat.
const Pathname & path() const
Return current Pathname.
bool isExist() const
Return whether valid stat info exists.
const std::string & asString() const
String representation.
Provide a new empty temporary file and delete it when no longer needed.
String related utilities and Regular expression matching.
Types and functions for filesystem operations.
std::string checksum(const Pathname &file, const std::string &algorithm)
Compute a files checksum.
int hardlinkCopy(const Pathname &oldpath, const Pathname &newpath)
Create newpath as hardlink or copy of oldpath.
const std::string & asString(const std::string &t)
Global asString() that works with std::string too.
std::string toLower(const std::string &s)
Return lowercase version of s.
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
std::string hexstring(char n, int w=4)
bool endsWithCI(const C_Str &str_r, const C_Str &prefix_r)
Easy-to use interface to the ZYPP dependency resolver.
bool operator==(const SetRelation::Enum &lhs, const SetCompare &rhs)
This is an overloaded member function, provided for convenience. It differs from the above function o...
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
PublicKeyData implementation.
static shared_ptr< Impl > fromGpgmeKey(gpgme_key_t rawData)
std::vector< PublicSubkeyData > _subkeys
static shared_ptr< Impl > nullimpl()
Offer default Impl.
Impl * clone() const
clone for RWCOW_pointer
bool hasSubkeyId(const std::string &id_r) const
friend Impl * rwcowClone(const Impl *rhs)
std::vector< PublicKeySignatureData > _signatures
PublicKeySignatureData implementation.
static shared_ptr< Impl > nullimpl()
Offer default Impl.
Impl * clone() const
clone for RWCOW_pointer
friend Impl * rwcowClone(const Impl *rhs)
PublicKey implementation.
Impl(const Pathname &keyFile_r)
const PublicKeyData & keyData() const
friend Impl * rwcowClone(const Impl *rhs)
std::list< PublicKeyData > _hiddenKeys
static shared_ptr< Impl > nullimpl()
Offer default Impl.
Impl(const PublicKeyData &keyData_r)
Impl(const filesystem::TmpFile &sharedFile_r)
Impl(const filesystem::TmpFile &sharedFile_r, const PublicKeyData &keyData_r)
shared_ptr< filesystem::TmpFile > _dontUseThisPtrDirectly
Impl * clone() const
clone for RWCOW_pointer
const std::list< PublicKeyData > & hiddenKeys() const
PublicSubkeyData implementation.
friend Impl * rwcowClone(const Impl *rhs)
static shared_ptr< Impl > nullimpl()
Offer default Impl.
Impl * clone() const
clone for RWCOW_pointer
Convenient building of std::string via std::ostringstream Basically a std::ostringstream autoconverti...