33 #undef ZYPP_BASE_LOGGER_LOGGROUP
34 #define ZYPP_BASE_LOGGER_LOGGROUP "zypp::gpg"
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 );
125 friend Impl * rwcowClone<Impl>(
const Impl * rhs );
132 static shared_ptr<Impl> _nullimpl(
new Impl );
138 return new Impl( *
this );
160 PublicSubkeyData::operator
bool()
const
161 {
return !_pimpl->_id.empty(); }
199 bool hasSubkeyId(
const std::string & id_r )
const;
204 static shared_ptr<Impl>
fromGpgmeKey(gpgme_key_t rawData);
207 friend Impl * rwcowClone<Impl>(
const Impl * rhs );
217 if ( sub.id() == id_r )
228 static shared_ptr<Impl> _nullimpl(
new Impl );
237 gpgme_subkey_t sKey = rawData->subkeys;
239 shared_ptr<PublicKeyData::Impl> data(
new Impl);
241 if(rawData->uids && rawData->uids->signatures)
242 data->_created =
zypp::Date(rawData->uids->signatures->timestamp);
268 return new Impl( *
this );
289 PublicKeyData::operator
bool()
const
290 {
return !_pimpl->_fingerprint.empty(); }
330 str <<
", " << sub.id();
342 if ( id_r.size() == 8 )
352 str <<
"[" << obj.
name() <<
"]" << endl;
354 str <<
" id " << obj.
id() << endl;
358 for (
auto && sub : obj.
_pimpl->_subkeys )
359 str <<
" sub " << sub << endl;
377 Impl(
const Pathname & keyFile_r )
380 PathInfo info( keyFile_r );
381 MIL <<
"Taking pubkey from " << keyFile_r <<
" of size " << info.size() <<
" and sha1 " <<
filesystem::checksum(keyFile_r,
"sha1") << endl;
383 if ( !info.isExist() )
384 ZYPP_THROW(
Exception(
"Can't read public key from " + keyFile_r.asString() +
", file not found"));
387 ZYPP_THROW(
Exception(
"Can't copy public key data from " + keyFile_r.asString() +
" to " +
path().asString() ));
402 WAR <<
"Invalid PublicKeyData supplied: scanning from file" << endl;
427 PathInfo info(
path() );
428 MIL <<
"Reading pubkey from " << info.path() <<
" of size " << info.size() <<
" and sha1 " <<
filesystem::checksum(info.path(),
"sha1") << endl;
434 if (!ctx || !ctx->setHomedir(tmppath)) {
435 ZYPP_THROW(
Exception( std::string(
"Can't read public key data: Setting the keyring path failed!")) );
438 std::list<PublicKeyData> keys = ctx->readKeyFromFile(
path());
439 switch ( keys.size() )
452 WAR <<
"File " <<
path().asString() <<
" contains multiple keys: " << keys << endl;
459 MIL <<
"Read pubkey from " << info.path() <<
": " <<
_keyData << endl;
471 static shared_ptr<Impl> _nullimpl(
new Impl );
476 friend Impl * rwcowClone<Impl>(
const Impl * rhs );
479 {
return new Impl( *
this ); }
487 : _pimpl(
Impl::nullimpl() )
491 : _pimpl( new
Impl( file ) )
495 : _pimpl( new
Impl( sharedfile ) )
499 : _pimpl( new
Impl( sharedfile, keyData_r ) )
503 : _pimpl( new
Impl( keyData_r ) )
558 {
return sid ==
id(); }
std::string rpmName() const
Gpg-pubkey name as computed by rpm.
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.
static shared_ptr< Impl > nullimpl()
Offer default Impl.
static Ptr createForOpenPGP()
Creates a new KeyManagerCtx for PGP.
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()
static shared_ptr< Impl > nullimpl()
Offer default Impl.
RWCOW_pointer< Impl > _pimpl
PublicSubkeyData implementation.
Iterable< SubkeyIterator > subkeys() const
Iterate any subkeys.
Class representing one GPG Public Keys data.
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.
Impl * clone() const
clone for RWCOW_pointer
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
const std::string & asString(const std::string &t)
Global asString() that works with std::string too.
std::string gpgPubkeyVersion() const
Gpg-pubkey version as computed by rpm (trailing 8 byte id)
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.
PublicKeyData()
Default constructed: empty data.
Impl * clone() const
clone for RWCOW_pointer
#define PL_(MSG1, MSG2, N)
bool endsWithCI(const C_Str &str_r, const C_Str &prefix_r)
std::string gpgPubkeyVersion() const
Pathname path() const
File containig the ASCII armored key.
RWCOW_pointer< Impl > _pimpl
Pointer to implementation.
Store and operate on date (time_t).
base::DrunkenBishop AsciiArt
Random art fingerprint visualization type (base::DrunkenBishop).
Convenient building of std::string via std::ostringstream Basically a std::ostringstream autoconverti...
Impl(const Pathname &keyFile_r)
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) ...
AsciiArt asciiArt() const
Random art fingerprint visualization (base::DrunkenBishop).
shared_ptr< filesystem::TmpFile > _dontUseThisPtrDirectly
static shared_ptr< Impl > nullimpl()
Offer default Impl.
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
std::string toLower(const std::string &s)
Return lowercase version of s.
Impl(const PublicKeyData &keyData_r)
std::string asString() const
Simple string representation.
PublicKey implementation.
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 rpmName() const
std::string id() const
Key ID.
bool expired() const
Whether the key has expired.
PublicKeyData implementation.
shared_ptr< KeyManagerCtx > Ptr
std::string fingerprint() const
static shared_ptr< Impl > fromGpgmeKey(gpgme_key_t rawData)
static PublicKeyData fromGpgmeKey(_gpgme_key *data)
std::vector< PublicSubkeyData > _subkeys
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
Random art fingerprint visualization Visualize fingerprint data on a [17x9] (SSH) or [19x11] (GPG) or...