30#include <zypp-core/fs/WatchFile>
38#undef ZYPP_BASE_LOGGER_LOGGROUP
39#define ZYPP_BASE_LOGGER_LOGGROUP "zypp::KeyRing"
85 {
return getData( keyring_r ); }
97 return getData( keyring_r, cache );
104 MIL <<
"Found keys: " << cache_r.
_data << std::endl;
106 return cache_r.
_data;
120 MIL <<
"Imported key " << key <<
" to " << (trusted ?
"trustedKeyRing" :
"generalKeyRing" ) << endl;
146 if ( ! keyDataToDel )
148 WAR <<
"Key to delete [" <<
id <<
"] is not in " << (trusted ?
"trustedKeyRing" :
"generalKeyRing" ) << endl;
153 MIL <<
"Deleted key [" <<
id <<
"] from " << (trusted ?
"trustedKeyRing" :
"generalKeyRing" ) << endl;
170 if ( key.providesKey(
id ) )
176 DBG << (ret ?
"Found" :
"No") <<
" key [" <<
id <<
"] in keyring " <<
keyring << endl;
182 MIL <<
"preloadCachedKeys into general keyring..." << endl;
188 std::set<Pathname> cachedirs;
191 cachedirs.insert(
"/usr/lib/rpm/gnupg/keys" );
194 cachedirs.insert( r /
"/usr/lib/rpm/gnupg/keys" );
198 cachedirs.insert( r /
"/usr/lib/rpm/gnupg/keys" );
201 std::map<std::string,Pathname> keyCandidates;
202 const str::regex rx {
"^gpg-pubkey-([[:xdigit:]]{8,})(-[[:xdigit:]]{8,})?\\.(asc|key)$" };
203 for (
const auto & cache : cachedirs ) {
205 [&rx,&keyCandidates](
const Pathname & dir_r,
const char *
const file_r )->
bool {
208 Pathname & remember { keyCandidates[what[1]] };
209 if ( remember.
empty() ) {
210 remember = dir_r / file_r;
218 for (
const auto & p : keyCandidates ) {
221 const std::string &
id { p.first };
226 DBG <<
"preload key file " << path << endl;
229 WAR <<
"Skipping: Can't preload key file " << path << endl;
246 WAR <<
"No key [" <<
id <<
"] to export from " <<
keyring << endl;
259 MIL <<
"Going to export key [" <<
id <<
"] from " <<
keyring <<
" to " << tmpFile.
path() << endl;
261 std::ofstream os( tmpFile.
path().
c_str() );
270 std::list<PublicKey> ret;
275 ret.push_back( key );
276 MIL <<
"Found key " << key << endl;
283 if ( !
PathInfo( keyfile ).isExist() )
303 if ( !
PathInfo( signature ).isFile() )
306 MIL <<
"Determining key id of signature " << signature << endl;
309 if ( ! fprs.empty() ) {
310 std::string &
id = fprs.back();
311 MIL <<
"Determined key id [" <<
id <<
"] for signature " << signature << endl;
314 return std::string();
#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
PublicKeyData publicKeyExists(const std::string &id)
void importKey(const PublicKey &key, bool trusted=false)
filesystem::TmpDir _general_tmp_dir
KeyRingImpl(const Pathname &baseTmpDir)
const std::list< PublicKeyData > & publicKeyData()
void multiKeyImport(const Pathname &keyfile_r, bool trusted_r=false)
std::list< PublicKey > publicKeys()
void preloadCachedKeys()
Load key files cached on the system into the generalKeyRing.
void dumpPublicKey(const std::string &id, bool trusted, std::ostream &stream)
const Pathname generalKeyRing() const
const Pathname trustedKeyRing() const
std::string readSignatureKeyId(const Pathname &signature)
CachedPublicKeyData::Manip keyRingManip(const Pathname &keyring)
Impl helper providing on demand a KeyManagerCtx to manip a cached keyring.
PublicKey exportKey(const std::string &id, const Pathname &keyring)
bool isKeyTrusted(const std::string &id)
bool verifyFile(const Pathname &file, const Pathname &signature, const Pathname &keyring)
void deleteKey(const std::string &id, bool trusted)
filesystem::TmpDir _trusted_tmp_dir
filesystem::TmpFile dumpPublicKeyToTmp(const std::string &id, const Pathname &keyring)
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.
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 std::string &s, smatch &matches, const regex ®ex)
\relates regex \ingroup ZYPP_STR_REGEX \relates regex \ingroup ZYPP_STR_REGEX
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.