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() )
143 friend Impl * rwcowClone<Impl>(
const Impl * rhs );
150 static shared_ptr<Impl> _nullimpl(
new Impl );
156 return new Impl( *
this );
178 PublicSubkeyData::operator
bool()
const 179 {
return !_pimpl->_id.empty(); }
218 friend Impl * rwcowClone<Impl>(
const Impl * rhs );
225 static shared_ptr<Impl> _nullimpl(
new Impl );
231 return new Impl( *
this );
254 PublicKeySignatureData::operator
bool()
const 255 {
return !_pimpl->_keyid.empty(); }
278 if (!
name().empty()) {
282 nameStr =
"[User ID not found] ";
287 <<
" [" << expiresDetail(
expires() ) <<
"]";
291 {
return getZYpp()->keyRing()->isKeyTrusted(
id()); }
294 {
return getZYpp()->keyRing()->isKeyKnown(
id()); }
314 bool hasSubkeyId(
const std::string & id_r )
const;
319 static shared_ptr<Impl>
fromGpgmeKey(gpgme_key_t rawData);
322 friend Impl * rwcowClone<Impl>(
const Impl * rhs );
331 if ( shorterIsSuffixCI( sub.id(), id_r ) ) {
341 static shared_ptr<Impl> _nullimpl(
new Impl );
350 gpgme_subkey_t sKey = rawData->subkeys;
352 shared_ptr<PublicKeyData::Impl> data(
new Impl);
354 if ( rawData->uids && rawData->uids->signatures ) {
355 data->_created =
zypp::Date(rawData->uids->signatures->timestamp);
359 for (
auto t = rawData->uids->signatures->next; t; t = t->next ) {
360 if (t->keyid !=
nullptr) {
364 if ( t->timestamp > data->_created )
365 data->_created = t->timestamp;
373 data->_algoName = keyAlgoName( sKey );
394 return new Impl( *
this );
406 : _pimpl(
std::move(data) )
415 PublicKeyData::operator
bool()
const 416 {
return !_pimpl->_fingerprint.empty(); }
462 str <<
", " << sub.id();
491 str <<
"[" << obj.
name() <<
"]" << endl;
493 str <<
" id " << obj.
id() << endl;
498 for (
auto && sub : obj.
_pimpl->_subkeys )
499 str <<
" sub " << sub << endl;
521 MIL <<
"Taking pubkey from " << keyFile_r <<
" of size " << info.
size() <<
" and sha1 " <<
filesystem::checksum(keyFile_r,
"sha1") << endl;
543 WAR <<
"Invalid PublicKeyData supplied: scanning from file" << endl;
570 switch ( keys.size() )
583 WAR <<
"File " <<
path().
asString() <<
" contains multiple keys: " << keys << endl;
602 static shared_ptr<Impl> _nullimpl(
new Impl );
607 friend Impl * rwcowClone<Impl>(
const Impl * rhs );
610 {
return new Impl( *
this ); }
618 : _pimpl(
Impl::nullimpl() )
622 : _pimpl( new
Impl( file ) )
626 : _pimpl( new
Impl( sharedfile ) )
630 : _pimpl( new
Impl( sharedfile, keyData_r ) )
634 : _pimpl( new
Impl( keyData_r ) )
657 if ( keydata.providesKey( id_r ) )
std::string asString() const
Simple string representation.
static const ValueType day
PublicKeySignatureData()
Default constructed: empty data.
static shared_ptr< Impl > nullimpl()
Offer default Impl.
Impl(const filesystem::TmpFile &sharedFile_r, const PublicKeyData &keyData_r)
static bool isSafeKeyId(const std::string &id_r)
Whether this is a long id (64bit/16byte) or even better a fingerprint.
int daysToLive() const
Number of days (24h) until the key expires (or since it exired).
std::list< PublicKeyData > readKeyFromFile(const Pathname &file)
Returns a list of all PublicKeyData found in file.
const Pathname & path() const
Return current Pathname.
const std::list< PublicKeyData > & hiddenKeys() const
Additional keys data in case the ASCII armored blob contains multiple keys.
std::list< PublicKeyData > _hiddenKeys
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
const PublicKeyData & keyData() const
The public keys data (.
static shared_ptr< Impl > nullimpl()
Offer default Impl.
Iterable< KeySignatureIterator > signatures() const
Iterate all key signatures.
RWCOW_pointer< Impl > _pimpl
std::string gpgPubkeyRelease() const
Gpg-pubkey release as computed by rpm (hexencoded created)
PublicSubkeyData implementation.
bool fileProvidesKey(const std::string &id_r) const
Extends providesKey to look at the hidden keys too.
Class representing one GPG Public Keys data.
bool expired() const
Whether the key has expired.
std::string asString() const
Simple string representation.
const PublicKeyData & keyData() const
Exception thrown when the supplied key is not a valid gpg key.
std::string algoName() const
Key algorithm string like RSA 2048
PublicSubkeyData()
Default constructed: empty data.
base::DrunkenBishop AsciiArt
Random art fingerprint visualization type (base::DrunkenBishop).
std::string name() const
Key name.
String related utilities and Regular expression matching.
RWCOW_pointer< Impl > _pimpl
const std::string & asString(const std::string &t)
Global asString() that works with std::string too.
std::string asString() const
Simple string representation.
Date created() const
Creation date.
static shared_ptr< Impl > nullimpl()
Offer default Impl.
static KeyManagerCtx createForOpenPGP()
Creates a new KeyManagerCtx for PGP using a volatile temp.
bool operator==(const SetRelation::Enum &lhs, const SetCompare &rhs)
Provide a new empty temporary file and delete it when no longer needed.
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
Iterable< SubkeyIterator > subkeys() const
Iterate any subkeys.
Date expires() const
Expiry date, or Date() if the key never expires.
PublicKeyData()
Default constructed: empty data.
PublicKeySignatureData implementation.
bool inTrustedRing() const
Whether the signature is trusted in rpmdb.
bool endsWithCI(const C_Str &str_r, const C_Str &prefix_r)
std::string expiresAsString() const
std::string gpgPubkeyVersion() const
Gpg-pubkey version as computed by rpm (trailing 8 byte id)
const std::list< PublicKeyData > & hiddenKeys() const
std::string id() const
Subkey ID.
bool operator==(const PublicKey &rhs) const
std::string expiresAsString() const
int daysToLive() const
Number of days (24h) until the key expires (or since it exired).
RWCOW_pointer< Impl > _pimpl
Pointer to implementation.
std::string rpmName() const
Gpg-pubkey name as computed by rpm.
Store and operate on date (time_t).
Date created() const
Creation / last modification date (latest selfsig).
bool expired() const
Whether the key has expired.
std::string name() const
The user ID associated with this key, if present.
Convenient building of std::string via std::ostringstream Basically a std::ostringstream autoconverti...
Impl(const Pathname &keyFile_r)
std::string gpgPubkeyVersion() const
std::string rpmName() const
const std::string & asString() const
String representation.
bool isExist() const
Return whether valid stat info exists.
Impl * clone() const
clone for RWCOW_pointer
bool providesKey(const std::string &id_r) const
!<
int hardlinkCopy(const Pathname &oldpath, const Pathname &newpath)
Create newpath as hardlink or copy of oldpath.
bool inKnownRing() const
Whether the key has been seen before.
shared_ptr< filesystem::TmpFile > _dontUseThisPtrDirectly
static shared_ptr< Impl > nullimpl()
Offer default Impl.
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
int daysToLive() const
Number of days (24h) until the key expires (or since it expired).
Impl * clone() const
clone for RWCOW_pointer
std::string toLower(const std::string &s)
Return lowercase version of s.
Impl(const PublicKeyData &keyData_r)
Date created() const
Creation date.
Impl * clone() const
clone for RWCOW_pointer
PublicKey implementation.
std::string fingerprint() const
Key fingerprint.
bool expired() const
Whether the key has expired.
std::string gpgPubkeyRelease() const
Class representing a GPG Public Keys subkeys.
Class representing one GPG Public Key (PublicKeyData + ASCII armored in a tempfile).
Date expires() const
Expiry date, or Date() if the key never expires.
AsciiArt asciiArt() const
Random art fingerprint visualization (base::DrunkenBishop).
Base class for Exception.
static bool isSafeKeyId(const std::string &id_r)
!<
Pathname path() const
File containing the ASCII armored key.
std::string id() const
Key ID.
Impl(const filesystem::TmpFile &sharedFile_r)
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
#define PL_(MSG1, MSG2, N)
std::string fingerprint() const
std::string asString() const
PublicKeyData implementation.
Wrapper class for ::stat/::lstat.
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...
static shared_ptr< Impl > fromGpgmeKey(gpgme_key_t rawData)
bool hasSubkeyId(const std::string &id_r) const
static PublicKey noThrow(const Pathname &keyFile_r)
Static ctor returning an empty PublicKey rather than throwing.
std::vector< PublicKeySignatureData > _signatures
static PublicKeyData fromGpgmeKey(_gpgme_key *data)
std::vector< PublicSubkeyData > _subkeys
Easy-to use interface to the ZYPP dependency resolver.
bool providesKey(const std::string &id_r) const
Whether id_r is the id or fingerprint of the primary key or of a subkey.
Class representing a signature on a GPG Public Key.
Date expires() const
Expiry date, or Date() if the key never expires.
std::string hexstring(char n, int w=4)
std::string algoName() const
std::string id() const
The key ID of key used to create the signature.
bool hasSubkeys() const
Whether subkeys is not empty.
Impl * clone() const
clone for RWCOW_pointer
Random art fingerprint visualization Visualize fingerprint data on a [17x9] (SSH) or [19x11] (GPG) or...
~PublicKeySignatureData()