31#include <zypp-core/fs/WatchFile>
40#undef ZYPP_BASE_LOGGER_LOGGROUP
41#define ZYPP_BASE_LOGGER_LOGGROUP "zypp::KeyRing"
87 {
return getData( keyring_r ); }
99 return getData( keyring_r, cache );
108 return cache_r.
_data;
123 pDBG(
"Import empty key to", ring,
"skipped" );
129 if ( ring == Ring::Trusted )
131 auto myMustUpdateData = [
this]( std::string_view prefix,
const PublicKeyData & keyData ) ->
bool {
133 pMIL( prefix, fate, keyData,
"to", Ring::Trusted );
140 bool mustUpdate = myMustUpdateData(
"Import Tkey", key.
keyData() );
142 mustUpdate |= myMustUpdateData(
" ", hkeyData );
165 std::vector<PublicKeyData> trustedToUpdate;
166 auto myMustUpdateData = [
this,&trustedToUpdate]( std::string_view prefix,
const PublicKeyData & keyData ) ->
bool {
169 pMIL( prefix, fate, keyData,
"to", Ring::General );
172 pMIL( prefix,
"U", keyData,
"to", Ring::General );
173 trustedToUpdate.push_back( keyData );
175 pMIL( prefix, fate, keyData,
"to", Ring::General );
180 bool mustUpdate = myMustUpdateData(
"Import Gkey", key.
keyData() );
182 mustUpdate |= myMustUpdateData(
" ", hkeyData );
198 pDBG(
"Import", keys.size(),
"keys to", ring );
212 if ( ! keyDataToDel )
214 WAR <<
"Key to delete [" <<
id <<
"] is not in " << ring << endl;
219 MIL <<
"Deleted key [" <<
id <<
"] from " << ring << endl;
221 if ( ring == Ring::Trusted ) {
228 if ( !
PathInfo( keyfile ).isExist() )
252 WAR <<
"No key [" <<
id <<
"] to export from " <<
keyring << endl;
269 if ( key.providesKey(
id ) )
282 std::list<PublicKey> ret;
287 ret.push_back( key );
288 MIL <<
"Found key " << key << endl;
302 MIL <<
"Going to export key [" <<
id <<
"] from " <<
keyring <<
" to " << tmpFile.
path() << endl;
304 std::ofstream os( tmpFile.
path().
c_str() );
312 if ( !
PathInfo( signature ).isFile() )
315 MIL <<
"Determining key id of signature " << signature << endl;
318 if ( ! fprs.empty() ) {
319 std::string &
id = fprs.back();
320 MIL <<
"Determined key id [" <<
id <<
"] for signature " << signature << endl;
323 return std::string();
334 std::set<Pathname> cachedirs;
337 cachedirs.insert(
"/usr/lib/rpm/gnupg/keys" );
340 cachedirs.insert( r /
"/usr/lib/rpm/gnupg/keys" );
344 cachedirs.insert( r /
"/usr/lib/rpm/gnupg/keys" );
352 std::list<PublicKey> newkeys;
353 for (
const auto & cache : cachedirs ) {
355 [&newkeys](
const Pathname & dir_r,
const char *
const file_r )->
bool {
356 static const str::regex rx {
"^gpg-pubkey-([[:xdigit:]]{8,})(-[[:xdigit:]]{8,})?\\.(asc|key)$" };
359 newkeys.push_back(
PublicKey( dir_r / file_r ) );
365 if ( not newkeys.empty() ) {
366 MIL <<
"Preload cached keys..." << endl;
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
bool exportKey(const std::string &id, std::ostream &stream)
Exports the key with id into the given stream, returns true on success.
std::list< PublicKeyData > listKeys()
Returns a list of all public keys found in the current keyring.
bool verify(const Pathname &file, const Pathname &signature)
Tries to verify file using signature, returns true on success.
static KeyManagerCtx createForOpenPGP()
Creates a new KeyManagerCtx for PGP using a volatile temp.
std::list< std::string > readSignatureFingerprints(const Pathname &signature)
Reads all fingerprints from the signature file , returns a list of all found fingerprints.
bool deleteKey(const std::string &id)
Tries to delete a key specified by id, returns true on success.
bool importKey(const Pathname &keyfile)
Tries to import a key from keyfile, returns true on success.
zyppng::Signal< void(const PublicKey &)> _sigTrustedKeyAdded
std::list< PublicKey > publicKeys(const Ring ring) const
@ Update
old version of Key is in Ring
void importKey(const PublicKey &key, const Ring ring)
Import PublicKeys into a Ring.
filesystem::TmpFile dumpPublicKeyToTmp(const std::string &id, const Pathname &keyring) const
MustUpdate mustUpdateData(const PublicKeyData &keyData, const Ring ring) const
Helper computing PublicKeyData's status in a Ring.
filesystem::TmpDir _general_tmp_dir
bool verifyFile(const Pathname &file, const Pathname &signature, const Ring ring)
KeyRingImpl(const Pathname &baseTmpDir)
PublicKeyData publicKeyData(const std::string &id, const Ring ring) const
void preloadCachedKeys()
Load key files cached on the system into the generalKeyRing.
void multiKeyImport(const Pathname &keyfile_r, const Ring ring)
Used by RpmDB to import the trusted keys.
const Pathname keyRingPath(const Ring ring) const
void deleteKey(const std::string &id, const Ring ring)
PublicKey exportKey(const std::string &id, const Ring ring) const
std::string readSignatureKeyId(const Pathname &signature)
void importKeys(const std::list< PublicKey > &keys, const Ring ring)
CachedPublicKeyData::Manip keyRingManip(const Pathname &keyring)
Impl helper providing on demand a KeyManagerCtx to manip a cached keyring.
void dumpPublicKey(const std::string &id, const Ring ring, std::ostream &stream)
filesystem::TmpDir _trusted_tmp_dir
Class representing one GPG Public Keys data.
std::string id() const
Key ID.
Class representing one GPG Public Key (PublicKeyData + ASCII armored in a tempfile).
Pathname path() const
File containing the ASCII armored key.
const std::list< PublicKeyData > & hiddenKeys() const
Additional keys data in case the ASCII armored blob contains multiple keys.
const PublicKeyData & keyData() const
The public keys data (.
Remember a files attributes to detect content changes.
Interim helper class to collect global options and settings.
Pathname repoManagerRoot() const
The RepoManager root directory.
Pathname systemRoot() const
The target root directory.
static ZConfig & instance()
Singleton ctor.
Pathname pubkeyCachePath() const
Path where the pubkey caches.
Wrapper class for stat/lstat.
const char * c_str() const
String representation.
const std::string & asString() const
String representation.
bool empty() const
Test for an empty path.
Provide a new empty temporary file and delete it when no longer needed.
Regular expression match result.
bool regex_match(const char *s, smatch &matches, const regex ®ex) ZYPP_API
Regular expression matching.
Easy-to use interface to the ZYPP dependency resolver.
scoped_ptr< WatchFile > _keyringP
void assertCache(const Pathname &keyring_r)
std::list< PublicKeyData > _data
scoped_ptr< WatchFile > _keyringK
Helper providing on demand a KeyManagerCtx to manip the cached keyring.
std::optional< KeyManagerCtx > _context
KeyManagerCtx & keyManagerCtx()
Manip(CachedPublicKeyData &cache_r, Pathname keyring_r)
CachedPublicKeyData & _cache
Functor returning the keyrings data (cached).
void setDirty(const Pathname &keyring_r)
const std::list< PublicKeyData > & operator()(const Pathname &keyring_r) const
const std::list< PublicKeyData > & getData(const Pathname &keyring_r) const
Manip manip(Pathname keyring_r)
Helper providing on demand a KeyManagerCtx to manip the cached keyring.