31 #include <zypp-core/fs/WatchFile> 40 #undef ZYPP_BASE_LOGGER_LOGGROUP 41 #define ZYPP_BASE_LOGGER_LOGGROUP "zypp::KeyRing" 48 , _keyring { std::move(keyring_r) }
58 _cache.setDirty( _keyring );
59 return _context.value();
81 bool k = _keyringK->hasChanged();
82 bool p = _keyringP->hasChanged();
87 {
return getData( keyring_r ); }
99 return getData( keyring_r, cache );
108 return cache_r.
_data;
113 : _trusted_tmp_dir( baseTmpDir,
"zypp-trusted-kr" )
114 , _general_tmp_dir( baseTmpDir,
"zypp-general-kr" )
115 , _base_dir( baseTmpDir )
123 pDBG(
"Import empty key to", ring,
"skipped" );
131 auto myMustUpdateData = [
this]( std::string_view prefix,
const PublicKeyData & keyData ) ->
bool {
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 {
173 trustedToUpdate.push_back( keyData );
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;
228 if ( !
PathInfo( keyfile ).isExist() )
235 if ( ! manip.keyManagerCtx().importKey( keyfile ) )
252 WAR <<
"No key [" <<
id <<
"] to export from " << keyring << endl;
259 if ( ! manip.keyManagerCtx().deleteKey(
id ) )
269 if ( key.providesKey(
id ) )
281 const std::list<PublicKeyData> & keys(
publicKeyData( keyring ) );
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;
336 cachedirs.insert( conf.pubkeyCachePath() );
337 cachedirs.insert(
"/usr/lib/rpm/gnupg/keys" );
338 if (
Pathname r = conf.systemRoot(); r !=
"/" && not r.
empty() ) {
339 cachedirs.insert( r / conf.pubkeyCachePath() );
340 cachedirs.insert( r /
"/usr/lib/rpm/gnupg/keys" );
342 if (
Pathname r = conf.repoManagerRoot(); r !=
"/" && not r.
empty() ) {
343 cachedirs.insert( r / conf.pubkeyCachePath() );
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;
bool verifyFile(const Pathname &file, const Pathname &signature, const Ring ring)
const std::list< PublicKeyData > & hiddenKeys() const
Additional keys data in case the ASCII armored blob contains multiple keys.
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
const PublicKeyData & keyData() const
The public keys data (.
Functor returning the keyrings data (cached).
static ZConfig & instance()
Singleton ctor.
Manip(CachedPublicKeyData &cache_r, Pathname keyring_r)
Class representing one GPG Public Keys data.
void preloadCachedKeys()
Load key files cached on the system into the generalKeyRing.
int dirForEach(const Pathname &dir_r, const StrMatcher &matcher_r, function< bool(const Pathname &, const char *const)> fnc_r)
const char * c_str() const
String representation.
void importKeys(const std::list< PublicKey > &keys, const Ring ring)
Manip manip(Pathname keyring_r)
Helper providing on demand a KeyManagerCtx to manip the cached 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.
Provide a new empty temporary file and delete it when no longer needed.
bool exportKey(const std::string &id, std::ostream &stream)
Exports the key with id into the given stream, returns true on success.
Remember a files attributes to detect content changes.
std::list< PublicKey > publicKeys(const Ring ring) const
zyppng::Signal< void(const PublicKey &)> _sigTrustedKeyAdded
bool empty() const
Test for an empty path.
std::string readSignatureKeyId(const Pathname &signature)
const std::string & asString() const
String representation.
KeyRingImpl(const Pathname &baseTmpDir)
MustUpdate mustUpdateData(const PublicKeyData &keyData, const Ring ring) const
Helper computing PublicKeyData's status in a Ring.
Interim helper class to collect global options and settings.
old version of Key is in Ring
const std::list< PublicKeyData > & getData(const Pathname &keyring_r) const
KeyManagerCtx & keyManagerCtx()
const Pathname keyRingPath(const Ring ring) const
void multiKeyImport(const Pathname &keyfile_r, const Ring ring)
Used by RpmDB to import the trusted keys.
filesystem::TmpFile dumpPublicKeyToTmp(const std::string &id, const Pathname &keyring) const
PublicKeyData publicKeyData(const std::string &id, const Ring ring) const
void assertCache(const Pathname &keyring_r)
std::list< PublicKeyData > listKeys()
Returns a list of all public keys found in the current keyring.
Regular expression match result.
Class representing one GPG Public Key (PublicKeyData + ASCII armored in a tempfile).
Pathname path() const
File containing the ASCII armored key.
std::string id() const
Key ID.
void deleteKey(const std::string &id, const Ring ring)
const std::list< PublicKeyData > & operator()(const Pathname &keyring_r) const
Wrapper class for ::stat/::lstat.
bool regex_match(const char *s, smatch &matches, const regex ®ex) ZYPP_API
Regular expression matching.
std::list< std::string > readSignatureFingerprints(const Pathname &signature)
Reads all fingerprints from the signature file , returns a list of all found fingerprints.
std::list< PublicKeyData > _data
void setDirty(const Pathname &keyring_r)
CachedPublicKeyData::Manip keyRingManip(const Pathname &keyring)
Impl helper providing on demand a KeyManagerCtx to manip a cached keyring.
Easy-to use interface to the ZYPP dependency resolver.
PublicKey exportKey(const std::string &id, const Ring ring) const
void importKey(const PublicKey &key, const Ring ring)
Import PublicKeys into a Ring.
Helper providing on demand a KeyManagerCtx to manip the cached keyring.
void dumpPublicKey(const std::string &id, const Ring ring, std::ostream &stream)