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;
93 const std::list<PublicKeyData> & operator()(
const Pathname & keyring_r )
const 94 {
return getData( keyring_r ); }
96 void setDirty(
const Pathname & keyring_r )
110 void assertCache(
const Pathname & keyring_r )
119 bool hasChanged()
const 133 typedef std::map<Pathname,Cache> CacheMap;
135 const std::list<PublicKeyData> & getData(
const Pathname & keyring_r )
const 139 cache.assertCache( keyring_r );
140 return getData( keyring_r, cache );
143 const std::list<PublicKeyData> & getData(
const Pathname & keyring_r, Cache & cache_r )
const 145 if ( cache_r.hasChanged() ) {
148 if (ctx->setHomedir(keyring_r)) {
149 std::list<PublicKeyData> foundKeys = ctx->listKeys();
150 cache_r._data.swap(foundKeys);
153 MIL <<
"Found keys: " << cache_r._data << endl;
155 return cache_r._data;
175 MIL <<
"Current KeyRing::DefaultAccept: " << _keyRingDefaultAccept << endl;
180 void deleteKey(
const std::string &
id,
bool trusted );
199 void dumpPublicKey(
const std::string &
id,
bool trusted, std::ostream & stream )
261 struct ImportKeyCBHelper
263 void operator()(
const PublicKey & key_r )
271 ERR <<
"Could not import key into rpmdb: " << excp << endl;
287 MIL <<
"Imported key " << key <<
" to " << (trusted ?
"trustedKeyRing" :
"generalKeyRing" ) << endl;
291 ImportKeyCBHelper emitSignal;
308 importKey( keyfile_r, trusted_r ? trustedKeyRing() : generalKeyRing() );
313 PublicKeyData keyDataToDel( publicKeyExists(
id, trusted ? trustedKeyRing() : generalKeyRing() ) );
314 if ( ! keyDataToDel )
316 WAR <<
"Key to delete [" <<
id <<
"] is not in " << (trusted ?
"trustedKeyRing" :
"generalKeyRing" ) << endl;
319 deleteKey(
id, trusted ? trustedKeyRing() : generalKeyRing() );
320 MIL <<
"Deleted key [" <<
id <<
"] from " << (trusted ?
"trustedKeyRing" :
"generalKeyRing" ) << endl;
327 rpmdbEmitSignal->trustedKeyRemoved( key );
330 emitSignal->trustedKeyRemoved( key );
334 ERR <<
"Could not delete key from rpmmdb: " << excp << endl;
345 if ( key.providesKey(
id ) )
351 MIL << (ret ?
"Found" :
"No") <<
" key [" <<
id <<
"] in keyring " << keyring << endl;
357 return PublicKey( dumpPublicKeyToTmp( keyData.
id(), keyring ), keyData );
364 return PublicKey( dumpPublicKeyToTmp( keyData.
id(), keyring ), keyData );
367 WAR <<
"No key [" <<
id <<
"] to export from " << keyring << endl;
375 if (!ctx || !ctx->setHomedir(keyring))
377 ctx->exportKey(
id, stream);
383 MIL <<
"Going to export key [" <<
id <<
"] from " << keyring <<
" to " << tmpFile.
path() << endl;
385 std::ofstream os( tmpFile.
path().
c_str() );
396 MIL <<
"Going to verify signature for " << filedesc <<
" ( " << file <<
" ) with " << signature << endl;
401 bool res =
report->askUserToAcceptUnsignedFile( filedesc, context );
402 MIL <<
"askUserToAcceptUnsignedFile: " << res << endl;
410 PublicKeyData trustedKeyData( publicKeyExists(
id, trustedKeyRing() ) );
411 if ( trustedKeyData )
413 MIL <<
"Key is trusted: " << trustedKeyData << endl;
417 PublicKeyData generalKeyData( publicKeyExists(
id, generalKeyRing() ) );
418 if ( generalKeyData )
431 MIL <<
"Key was updated. Saving new version into trusted keyring: " << generalKeyData << endl;
432 importKey( exportKey( generalKeyData, generalKeyRing() ),
true );
433 trustedKeyData = publicKeyExists(
id, trustedKeyRing() );
438 report->infoVerify( filedesc, trustedKeyData, context );
439 if ( verifyFile( file, signature, trustedKeyRing() ) )
441 return (sigValid_r=
true);
445 bool res =
report->askUserToAcceptVerificationFailed( filedesc, exportKey( trustedKeyData, trustedKeyRing() ), context );
446 MIL <<
"askUserToAcceptVerificationFailed: " << res << endl;
452 PublicKeyData generalKeyData( publicKeyExists(
id, generalKeyRing() ) );
453 if ( generalKeyData )
455 PublicKey key( exportKey( generalKeyData, generalKeyRing() ) );
456 MIL <<
"Key [" <<
id <<
"] " << key.
name() <<
" is not trusted" << endl;
463 MIL <<
"User wants to trust key [" <<
id <<
"] " << key.
name() << endl;
468 MIL <<
"User wants to import key [" <<
id <<
"] " << key.
name() << endl;
470 whichKeyring = trustedKeyRing();
473 whichKeyring = generalKeyRing();
476 report->infoVerify( filedesc, generalKeyData, context );
477 if ( verifyFile( file, signature, whichKeyring ) )
479 return (sigValid_r=
true);
483 bool res =
report->askUserToAcceptVerificationFailed( filedesc, key, context );
484 MIL <<
"askUserToAcceptVerificationFailed: " << res << endl;
490 MIL <<
"User does not want to trust key [" <<
id <<
"] " << key.
name() << endl;
497 MIL <<
"File [" << file <<
"] ( " << filedesc <<
" ) signed with unknown key [" <<
id <<
"]" << endl;
498 bool res =
report->askUserToAcceptUnknownKey( filedesc,
id, context );
499 MIL <<
"askUserToAcceptUnknownKey: " << res << endl;
508 const std::list<PublicKeyData> & keys(
publicKeyData( keyring ) );
509 std::list<PublicKey> ret;
511 for_( it, keys.begin(), keys.end() )
513 PublicKey key( exportKey( *it, keyring ) );
514 ret.push_back( key );
515 MIL <<
"Found key " << key << endl;
522 if ( !
PathInfo( keyfile ).isExist() )
529 if(!ctx || !ctx->setHomedir(keyring))
532 cachedPublicKeyData.setDirty( keyring );
533 if(!ctx->importKey(keyfile))
544 if(!ctx->setHomedir(keyring)) {
548 if(!ctx->deleteKey(
id)){
552 cachedPublicKeyData.setDirty( keyring );
557 if ( !
PathInfo( signature ).isFile() )
560 MIL <<
"Determining key id of signature " << signature << endl;
564 return std::string();
567 std::list<std::string> fprs = ctx->readSignatureFingerprints(signature);
569 std::string &
id = fprs.back();
570 MIL <<
"Determined key id [" <<
id <<
"] for signature " << signature << endl;
573 return std::string();
579 if (!ctx || !ctx->setHomedir(keyring))
582 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.
#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)
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
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
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 Pathname trustedKeyRing() const
std::list< PublicKey > publicKeys()
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 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