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 )
258 struct ImportKeyCBHelper
260 void operator()(
const PublicKey & key_r )
268 ERR <<
"Could not import key into rpmdb: " << excp << endl;
284 MIL <<
"Imported key " << key <<
" to " << (trusted ?
"trustedKeyRing" :
"generalKeyRing" ) << endl;
288 ImportKeyCBHelper emitSignal;
305 importKey( keyfile_r, trusted_r ? trustedKeyRing() : generalKeyRing() );
310 PublicKeyData keyDataToDel( publicKeyExists(
id, trusted ? trustedKeyRing() : generalKeyRing() ) );
311 if ( ! keyDataToDel )
313 WAR <<
"Key to delete [" <<
id <<
"] is not in " << (trusted ?
"trustedKeyRing" :
"generalKeyRing" ) << endl;
316 deleteKey(
id, trusted ? trustedKeyRing() : generalKeyRing() );
317 MIL <<
"Deleted key [" <<
id <<
"] from " << (trusted ?
"trustedKeyRing" :
"generalKeyRing" ) << endl;
324 rpmdbEmitSignal->trustedKeyRemoved( key );
327 emitSignal->trustedKeyRemoved( key );
331 ERR <<
"Could not delete key from rpmmdb: " << excp << endl;
342 if ( key.providesKey(
id ) )
348 MIL << (ret ?
"Found" :
"No") <<
" key [" <<
id <<
"] in keyring " << keyring << endl;
354 return PublicKey( dumpPublicKeyToTmp( keyData.
id(), keyring ), keyData );
361 return PublicKey( dumpPublicKeyToTmp( keyData.
id(), keyring ), keyData );
364 WAR <<
"No key [" <<
id <<
"] to export from " << keyring << endl;
372 if (!ctx || !ctx->setHomedir(keyring))
374 ctx->exportKey(
id, stream);
380 MIL <<
"Going to export key [" <<
id <<
"] from " << keyring <<
" to " << tmpFile.
path() << endl;
382 std::ofstream os( tmpFile.
path().
c_str() );
393 MIL <<
"Going to verify signature for " << filedesc <<
" ( " << file <<
" ) with " << signature << endl;
398 bool res =
report->askUserToAcceptUnsignedFile( filedesc, context );
399 MIL <<
"askUserToAcceptUnsignedFile: " << res << endl;
407 PublicKeyData trustedKeyData( publicKeyExists(
id, trustedKeyRing() ) );
408 if ( trustedKeyData )
410 MIL <<
"Key is trusted: " << trustedKeyData << endl;
414 PublicKeyData generalKeyData( publicKeyExists(
id, generalKeyRing() ) );
415 if ( generalKeyData )
428 MIL <<
"Key was updated. Saving new version into trusted keyring: " << generalKeyData << endl;
429 importKey( exportKey( generalKeyData, generalKeyRing() ),
true );
430 trustedKeyData = publicKeyExists(
id, trustedKeyRing() );
435 report->infoVerify( filedesc, trustedKeyData, context );
436 if ( verifyFile( file, signature, trustedKeyRing() ) )
438 return (sigValid_r=
true);
442 bool res =
report->askUserToAcceptVerificationFailed( filedesc, exportKey( trustedKeyData, trustedKeyRing() ), context );
443 MIL <<
"askUserToAcceptVerificationFailed: " << res << endl;
449 PublicKeyData generalKeyData( publicKeyExists(
id, generalKeyRing() ) );
450 if ( generalKeyData )
452 PublicKey key( exportKey( generalKeyData, generalKeyRing() ) );
453 MIL <<
"Key [" <<
id <<
"] " << key.
name() <<
" is not trusted" << endl;
460 MIL <<
"User wants to trust key [" <<
id <<
"] " << key.
name() << endl;
465 MIL <<
"User wants to import key [" <<
id <<
"] " << key.
name() << endl;
467 whichKeyring = trustedKeyRing();
470 whichKeyring = generalKeyRing();
473 report->infoVerify( filedesc, generalKeyData, context );
474 if ( verifyFile( file, signature, whichKeyring ) )
476 return (sigValid_r=
true);
480 bool res =
report->askUserToAcceptVerificationFailed( filedesc, key, context );
481 MIL <<
"askUserToAcceptVerificationFailed: " << res << endl;
487 MIL <<
"User does not want to trust key [" <<
id <<
"] " << key.
name() << endl;
494 MIL <<
"File [" << file <<
"] ( " << filedesc <<
" ) signed with unknown key [" <<
id <<
"]" << endl;
495 bool res =
report->askUserToAcceptUnknownKey( filedesc,
id, context );
496 MIL <<
"askUserToAcceptUnknownKey: " << res << endl;
505 const std::list<PublicKeyData> & keys(
publicKeyData( keyring ) );
506 std::list<PublicKey> ret;
508 for_( it, keys.begin(), keys.end() )
510 PublicKey key( exportKey( *it, keyring ) );
511 ret.push_back( key );
512 MIL <<
"Found key " << key << endl;
519 if ( !
PathInfo( keyfile ).isExist() )
526 if(!ctx || !ctx->setHomedir(keyring))
529 cachedPublicKeyData.setDirty( keyring );
530 if(!ctx->importKey(keyfile))
541 if(!ctx->setHomedir(keyring)) {
545 if(!ctx->deleteKey(
id)){
549 cachedPublicKeyData.setDirty( keyring );
554 if ( !
PathInfo( signature ).isFile() )
557 MIL <<
"Determining key id of signature " << signature << endl;
561 return std::string();
564 std::list<std::string> fprs = ctx->readSignatureFingerprints(signature);
566 std::string &
id = fprs.back();
567 MIL <<
"Determined key id [" <<
id <<
"] for signature " << signature << endl;
570 return std::string();
576 if (!ctx || !ctx->setHomedir(keyring))
579 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).
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