37 #undef ZYPP_BASE_LOGGER_LOGGROUP 38 #define ZYPP_BASE_LOGGER_LOGGROUP "zypp::KeyRing" 52 {
return _keyRingDefaultAccept; }
56 MIL <<
"Set new KeyRing::DefaultAccept: " << value_r << endl;
57 _keyRingDefaultAccept = value_r;
85 data.
set(
"PublicKey", key_r);
86 data.
set(
"KeyContext", keycontext_r);
90 return data.
get<
bool>(
"TrustKey");
105 const std::list<PublicKeyData> & operator()(
const Pathname & keyring_r )
const 106 {
return getData( keyring_r ); }
108 void setDirty(
const Pathname & keyring_r )
122 void assertCache(
const Pathname & keyring_r )
131 bool hasChanged()
const 145 typedef std::map<Pathname,Cache> CacheMap;
147 const std::list<PublicKeyData> & getData(
const Pathname & keyring_r )
const 151 cache.assertCache( keyring_r );
152 return getData( keyring_r, cache );
155 const std::list<PublicKeyData> & getData(
const Pathname & keyring_r, Cache & cache_r )
const 157 if ( cache_r.hasChanged() ) {
160 if (ctx->setHomedir(keyring_r)) {
161 std::list<PublicKeyData> foundKeys = ctx->listKeys();
162 cache_r._data.swap(foundKeys);
165 MIL <<
"Found keys: " << cache_r._data << endl;
167 return cache_r._data;
187 MIL <<
"Current KeyRing::DefaultAccept: " << _keyRingDefaultAccept << endl;
192 void deleteKey(
const std::string &
id,
bool trusted );
211 void dumpPublicKey(
const std::string &
id,
bool trusted, std::ostream & stream )
273 struct ImportKeyCBHelper
275 void operator()(
const PublicKey & key_r )
283 ERR <<
"Could not import key into rpmdb: " << excp << endl;
299 MIL <<
"Imported key " << key <<
" to " << (trusted ?
"trustedKeyRing" :
"generalKeyRing" ) << endl;
303 ImportKeyCBHelper emitSignal;
320 importKey( keyfile_r, trusted_r ? trustedKeyRing() : generalKeyRing() );
325 PublicKeyData keyDataToDel( publicKeyExists(
id, trusted ? trustedKeyRing() : generalKeyRing() ) );
326 if ( ! keyDataToDel )
328 WAR <<
"Key to delete [" <<
id <<
"] is not in " << (trusted ?
"trustedKeyRing" :
"generalKeyRing" ) << endl;
331 deleteKey(
id, trusted ? trustedKeyRing() : generalKeyRing() );
332 MIL <<
"Deleted key [" <<
id <<
"] from " << (trusted ?
"trustedKeyRing" :
"generalKeyRing" ) << endl;
339 rpmdbEmitSignal->trustedKeyRemoved( key );
342 emitSignal->trustedKeyRemoved( key );
346 ERR <<
"Could not delete key from rpmmdb: " << excp << endl;
357 if ( key.providesKey(
id ) )
363 MIL << (ret ?
"Found" :
"No") <<
" key [" <<
id <<
"] in keyring " << keyring << endl;
369 return PublicKey( dumpPublicKeyToTmp( keyData.
id(), keyring ), keyData );
376 return PublicKey( dumpPublicKeyToTmp( keyData.
id(), keyring ), keyData );
379 WAR <<
"No key [" <<
id <<
"] to export from " << keyring << endl;
387 if (!ctx || !ctx->setHomedir(keyring))
389 ctx->exportKey(
id, stream);
395 MIL <<
"Going to export key [" <<
id <<
"] from " << keyring <<
" to " << tmpFile.
path() << endl;
397 std::ofstream os( tmpFile.
path().
c_str() );
408 MIL <<
"Going to verify signature for " << filedesc <<
" ( " << file <<
" ) with " << signature << endl;
413 bool res =
report->askUserToAcceptUnsignedFile( filedesc, context );
414 MIL <<
"askUserToAcceptUnsignedFile: " << res << endl;
422 PublicKeyData trustedKeyData( publicKeyExists(
id, trustedKeyRing() ) );
423 if ( trustedKeyData )
425 MIL <<
"Key is trusted: " << trustedKeyData << endl;
429 PublicKeyData generalKeyData( publicKeyExists(
id, generalKeyRing() ) );
430 if ( generalKeyData )
443 MIL <<
"Key was updated. Saving new version into trusted keyring: " << generalKeyData << endl;
444 importKey( exportKey( generalKeyData, generalKeyRing() ),
true );
445 trustedKeyData = publicKeyExists(
id, trustedKeyRing() );
450 report->infoVerify( filedesc, trustedKeyData, context );
451 if ( verifyFile( file, signature, trustedKeyRing() ) )
453 return (sigValid_r=
true);
457 bool res =
report->askUserToAcceptVerificationFailed( filedesc, exportKey( trustedKeyData, trustedKeyRing() ), context );
458 MIL <<
"askUserToAcceptVerificationFailed: " << res << endl;
464 PublicKeyData generalKeyData( publicKeyExists(
id, generalKeyRing() ) );
465 if ( generalKeyData )
467 PublicKey key( exportKey( generalKeyData, generalKeyRing() ) );
468 MIL <<
"Key [" <<
id <<
"] " << key.
name() <<
" is not trusted" << endl;
475 MIL <<
"User wants to trust key [" <<
id <<
"] " << key.
name() << endl;
480 MIL <<
"User wants to import key [" <<
id <<
"] " << key.
name() << endl;
482 whichKeyring = trustedKeyRing();
485 whichKeyring = generalKeyRing();
488 report->infoVerify( filedesc, generalKeyData, context );
489 if ( verifyFile( file, signature, whichKeyring ) )
491 return (sigValid_r=
true);
495 bool res =
report->askUserToAcceptVerificationFailed( filedesc, key, context );
496 MIL <<
"askUserToAcceptVerificationFailed: " << res << endl;
502 MIL <<
"User does not want to trust key [" <<
id <<
"] " << key.
name() << endl;
509 MIL <<
"File [" << file <<
"] ( " << filedesc <<
" ) signed with unknown key [" <<
id <<
"]" << endl;
510 bool res =
report->askUserToAcceptUnknownKey( filedesc,
id, context );
511 MIL <<
"askUserToAcceptUnknownKey: " << res << endl;
520 const std::list<PublicKeyData> & keys(
publicKeyData( keyring ) );
521 std::list<PublicKey> ret;
523 for_( it, keys.begin(), keys.end() )
525 PublicKey key( exportKey( *it, keyring ) );
526 ret.push_back( key );
527 MIL <<
"Found key " << key << endl;
534 if ( !
PathInfo( keyfile ).isExist() )
541 if(!ctx || !ctx->setHomedir(keyring))
544 cachedPublicKeyData.setDirty( keyring );
545 if(!ctx->importKey(keyfile))
556 if(!ctx->setHomedir(keyring)) {
560 if(!ctx->deleteKey(
id)){
564 cachedPublicKeyData.setDirty( keyring );
569 if ( !
PathInfo( signature ).isFile() )
572 MIL <<
"Determining key id of signature " << signature << endl;
576 return std::string();
579 std::list<std::string> fprs = ctx->readSignatureFingerprints(signature);
581 std::string &
id = fprs.back();
582 MIL <<
"Determined key id [" <<
id <<
"] for signature " << signature << endl;
585 return std::string();
591 if (!ctx || !ctx->setHomedir(keyring))
594 return ctx->verify(file, signature);
void importKey(const PublicKey &key, bool trusted=false)
imports a key from a file.
const std::list< PublicKeyData > & publicKeyData()
static Ptr createForOpenPGP()
Creates a new KeyManagerCtx for PGP.
PublicKey exportTrustedPublicKey(const PublicKeyData &keyData)
Export a trusted public key identified by its key data.
PublicKey exportPublicKey(const PublicKeyData &keyData)
void dumpPublicKey(const std::string &id, bool trusted, std::ostream &stream)
void deleteKey(const std::string &id, bool trusted)
PublicKey exportKey(const std::string &id, const Pathname &keyring)
static bool error(const std::string &msg_r, const UserData &userData_r=UserData())
send error text
bool isKeyTrusted(const std::string &id)
const std::list< PublicKeyData > & hiddenKeys() const
Additional keys data in case the ASCII armored blob containes multiple keys.
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
const std::list< PublicKeyData > & trustedPublicKeyData()
const PublicKeyData & keyData() const
The public keys data (.
PublicKey exportKey(const PublicKey &key, const Pathname &keyring)
This basically means, we knew the key, but it was not trusted.
PublicKey exportPublicKey(const PublicKeyData &keyData)
Export a public key identified by its key data.
Class representing one GPG Public Keys data.
bool isKeyKnown(const std::string &id)
void dumpPublicKey(const std::string &id, bool trusted, std::ostream &stream)
PublicKeyData publicKeyExists(const std::string &id, const Pathname &keyring)
Get PublicKeyData for ID (false if ID is not found).
void multiKeyImport(const Pathname &keyfile_r, bool trusted_r=false)
std::list< PublicKey > trustedPublicKeys()
Get a list of trusted public keys in the keyring (incl.
bool verifyFile(const Pathname &file, const Pathname &signature, const Pathname &keyring)
virtual bool askUserToAcceptUnsignedFile(const std::string &file, const KeyContext &keycontext=KeyContext())
const char * c_str() const
String representation.
KeyRing(const Pathname &baseTmpDir)
Default ctor.
std::list< PublicKeyData > trustedPublicKeyData()
Get a list of trusted public key data in the keyring (key data only)
bool verifyFileSignatureWorkflow(const Pathname &file, const std::string &filedesc, const Pathname &signature, bool &sigValid_r, const KeyContext &keycontext=KeyContext())
Follows a signature verification interacting with the user.
bool askUserToAcceptPackageKey(const PublicKey &key_r, const KeyContext &keycontext_r=KeyContext())
Ask user to trust and/or import the package key to trusted keyring, using ReportBase::report.
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Provide a new empty temporary file and delete it when no longer needed.
virtual bool askUserToAcceptUnknownKey(const std::string &file, const std::string &id, const KeyContext &keycontext=KeyContext())
we DONT know the key, only its id, but we have never seen it, the difference with trust key is that i...
CachedPublicKeyData cachedPublicKeyData
Functor returning the keyrings data (cached).
callback::SendReport< target::rpm::KeyRingSignals > _rpmdbEmitSignal
virtual void infoVerify(const std::string &file_r, const PublicKeyData &keyData_r, const KeyContext &keycontext=KeyContext())
Informal callback showing the trusted key that will be used for verification.
PublicKey exportTrustedPublicKey(const PublicKeyData &keyData)
virtual void report(const UserData &userData_r=UserData())
The most generic way of sending/receiving data.
KeyTrust
User reply options for the askUserToTrustKey callback.
bool empty() const
Test for an empty path.
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
Date created() const
Creation / last modification date (latest selfsig).
PublicKeyData trustedPublicKeyExists(const std::string &id)
static void setDefaultAccept(DefaultAccept value_r)
Set the active accept bits.
Provide a new empty temporary directory and recursively delete it when no longer needed.
filesystem::TmpDir _trusted_tmp_dir
bool verifyFileSignature(const Pathname &file, const Pathname &signature)
std::list< PublicKeyData > _data
bool set(const std::string &key_r, AnyType val_r)
Set the value for key (nonconst version always returns true).
const std::string & asString() const
String representation.
bool verifyFileSignatureWorkflow(const Pathname &file, const std::string &filedesc, const Pathname &signature, bool &sigValid_r, const KeyContext &keycontext=KeyContext())
bool isExist() const
Return whether valid stat info exists.
std::string asUserHistory() const
A single (multiline) string composed of asUserString and historyAsString.
const Pathname generalKeyRing() const
filesystem::TmpFile dumpPublicKeyToTmp(const std::string &id, const Pathname &keyring)
IMPL_PTR_TYPE(Application)
std::list< PublicKey > trustedPublicKeys()
scoped_ptr< WatchFile > _keyringP
void importKey(const PublicKey &key, bool trusted=false)
Impl(const Pathname &baseTmpDir)
bool isKeyKnown(const std::string &id)
true if the key id is knows, that means at least exist on the untrusted keyring
static constexpr const char * ACCEPT_PACKAGE_KEY_REQUEST
void multiKeyImport(const Pathname &keyfile_r, bool trusted_r=false)
Initial import from RpmDb.
User has chosen not to trust the key.
std::string fingerprint() const
Key fingerprint.
virtual KeyTrust askUserToAcceptKey(const PublicKey &key, const KeyContext &keycontext=KeyContext())
Ask user to trust and/or import the key to trusted keyring.
scoped_ptr< WatchFile > _keyringK
static DefaultAccept defaultAccept()
Get the active accept bits.
RW_pointer< Impl > _pimpl
Pointer to implementation.
Class representing one GPG Public Key (PublicKeyData + ASCII armored in a tempfile).
std::list< PublicKeyData > publicKeyData()
Get a list of public key data in the keyring (key data only)
Base class for Exception.
Pathname path() const
File containig the ASCII armored key.
std::string id() const
Key ID.
const Tp & get(const std::string &key_r) const
Pass back a const Tp & reference to key_r value.
const Pathname trustedKeyRing() const
std::list< PublicKey > publicKeys()
Typesafe passing of user data via callbacks.
void deleteKey(const std::string &id, bool trusted=false)
removes a key from the keyring.
bool verifyFileTrustedSignature(const Pathname &file, const Pathname &signature)
bool verifyFileTrustedSignature(const Pathname &file, const Pathname &signature)
shared_ptr< KeyManagerCtx > Ptr
Wrapper class for ::stat/::lstat.
const std::list< PublicKeyData > & publicKeyData(const Pathname &keyring)
bool hasvalue(const std::string &key_r) const
Whether key_r is in data and value is not empty.
bool isKeyTrusted(const std::string &id)
true if the key id is trusted
Easy-to use interface to the ZYPP dependency resolver.
callback::SendReport< KeyRingSignals > _emitSignal
std::string readSignatureKeyId(const Pathname &signature)
reads the public key id from a signature
bool verifyFileSignature(const Pathname &file, const Pathname &signature)
Verifies a file against a signature, with no user interaction.
std::string readSignatureKeyId(const Pathname &signature)
virtual bool askUserToAcceptVerificationFailed(const std::string &file, const PublicKey &key, const KeyContext &keycontext=KeyContext())
The file filedesc is signed but the verification failed.
std::list< PublicKey > publicKeys()
Get a list of public keys in the keyring (incl.
filesystem::TmpDir _general_tmp_dir