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");
97 data.
set(
"Keys", keys_r);
112 const std::list<PublicKeyData> & operator()(
const Pathname & keyring_r )
const
113 {
return getData( keyring_r ); }
115 void setDirty(
const Pathname & keyring_r )
129 void assertCache(
const Pathname & keyring_r )
138 bool hasChanged()
const
152 typedef std::map<Pathname,Cache> CacheMap;
154 const std::list<PublicKeyData> & getData(
const Pathname & keyring_r )
const
158 cache.assertCache( keyring_r );
159 return getData( keyring_r, cache );
162 const std::list<PublicKeyData> & getData(
const Pathname & keyring_r, Cache & cache_r )
const
164 if ( cache_r.hasChanged() ) {
166 MIL <<
"Found keys: " << cache_r._data << endl;
168 return cache_r._data;
183 Impl(
const Pathname & baseTmpDir )
188 MIL <<
"Current KeyRing::DefaultAccept: " << _keyRingDefaultAccept << endl;
192 void multiKeyImport(
const Pathname & keyfile_r,
bool trusted_r =
false );
193 void deleteKey(
const std::string &
id,
bool trusted );
212 void dumpPublicKey(
const std::string &
id,
bool trusted, std::ostream & stream )
233 bool verifyFile(
const Pathname & file,
const Pathname & signature,
const Pathname & keyring );
234 void importKey(
const Pathname & keyfile,
const Pathname & keyring );
241 void dumpPublicKey(
const std::string &
id,
const Pathname & keyring, std::ostream & stream );
244 void deleteKey(
const std::string &
id,
const Pathname & keyring );
246 std::list<PublicKey>
publicKeys(
const Pathname & keyring);
276 struct ImportKeyCBHelper
278 void operator()(
const PublicKey & key_r )
286 ERR <<
"Could not import key into rpmdb: " << excp << endl;
302 MIL <<
"Imported key " << key <<
" to " << (trusted ?
"trustedKeyRing" :
"generalKeyRing" ) << endl;
306 ImportKeyCBHelper emitSignal;
323 importKey( keyfile_r, trusted_r ? trustedKeyRing() : generalKeyRing() );
328 PublicKeyData keyDataToDel( publicKeyExists(
id, trusted ? trustedKeyRing() : generalKeyRing() ) );
329 if ( ! keyDataToDel )
331 WAR <<
"Key to delete [" <<
id <<
"] is not in " << (trusted ?
"trustedKeyRing" :
"generalKeyRing" ) << endl;
334 deleteKey(
id, trusted ? trustedKeyRing() : generalKeyRing() );
335 MIL <<
"Deleted key [" <<
id <<
"] from " << (trusted ?
"trustedKeyRing" :
"generalKeyRing" ) << endl;
342 rpmdbEmitSignal->trustedKeyRemoved( key );
345 emitSignal->trustedKeyRemoved( key );
349 ERR <<
"Could not delete key from rpmmdb: " << excp << endl;
360 if ( key.providesKey(
id ) )
366 MIL << (ret ?
"Found" :
"No") <<
" key [" <<
id <<
"] in keyring " << keyring << endl;
372 return PublicKey( dumpPublicKeyToTmp( keyData.
id(), keyring ), keyData );
379 return PublicKey( dumpPublicKeyToTmp( keyData.
id(), keyring ), keyData );
382 WAR <<
"No key [" <<
id <<
"] to export from " << keyring << endl;
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;
411 if( signature.empty() || (!PathInfo( signature ).isExist()) )
413 bool res = report->askUserToAcceptUnsignedFile( filedesc, context );
414 MIL <<
"askUserToAcceptUnsignedFile: " << res << endl;
422 Pathname whichKeyring;
427 PublicKeyData trustedKeyData( publicKeyExists(
id, trustedKeyRing() ) );
428 if ( trustedKeyData )
430 MIL <<
"Key is trusted: " << trustedKeyData << endl;
434 PublicKeyData generalKeyData( publicKeyExists(
id, generalKeyRing() ) );
435 if ( generalKeyData )
448 MIL <<
"Key was updated. Saving new version into trusted keyring: " << generalKeyData << endl;
449 importKey( exportKey( generalKeyData, generalKeyRing() ),
true );
450 trustedKeyData = publicKeyExists(
id, trustedKeyRing() );
454 foundKey = trustedKeyData;
455 whichKeyring = trustedKeyRing();
459 PublicKeyData generalKeyData( publicKeyExists(
id, generalKeyRing() ) );
460 if ( generalKeyData )
462 PublicKey key( exportKey( generalKeyData, generalKeyRing() ) );
463 MIL <<
"Key [" <<
id <<
"] " << key.
name() <<
" is not trusted" << endl;
470 MIL <<
"User wants to trust key [" <<
id <<
"] " << key.
name() << endl;
474 MIL <<
"User wants to import key [" <<
id <<
"] " << key.
name() << endl;
476 whichKeyring = trustedKeyRing();
479 whichKeyring = generalKeyRing();
481 foundKey = generalKeyData;
485 MIL <<
"User does not want to trust key [" <<
id <<
"] " << key.
name() << endl;
489 else if ( ! context.
empty() )
493 whichKeyring = trustedKeyRing();
494 foundKey =
PublicKeyData( publicKeyExists(
id, trustedKeyRing() ) );
502 report->infoVerify( filedesc, foundKey, context );
503 if ( verifyFile( file, signature, whichKeyring ) )
505 return (sigValid_r=
true);
509 bool res = report->askUserToAcceptVerificationFailed( filedesc, exportKey( foundKey, whichKeyring ), context );
510 MIL <<
"askUserToAcceptVerificationFailed: " << res << endl;
515 MIL <<
"File [" << file <<
"] ( " << filedesc <<
" ) signed with unknown key [" <<
id <<
"]" << endl;
516 bool res = report->askUserToAcceptUnknownKey( filedesc,
id, context );
517 MIL <<
"askUserToAcceptUnknownKey: " << res << endl;
532 Pathname myKey = info_r.
provideKey( id_r, cacheDir );
548 ERR <<
"Key [" << id_r <<
"] from cache: " << cacheDir <<
" is not valid" << endl;
552 MIL <<
"Key [" << id_r <<
"] " << key.
name() <<
" loaded from cache" << endl;
556 if ( ! report->askUserToAcceptPackageKey( key, context ) ) {
560 MIL <<
"User wants to import key [" << id_r <<
"] " << key.
name() <<
" from cache" << endl;
565 ERR <<
"Failed to import key: "<<id_r;
574 const std::list<PublicKeyData> & keys(
publicKeyData( keyring ) );
575 std::list<PublicKey> ret;
577 for_( it, keys.begin(), keys.end() )
579 PublicKey key( exportKey( *it, keyring ) );
580 ret.push_back( key );
581 MIL <<
"Found key " << key << endl;
588 if ( ! PathInfo( keyfile ).isExist() )
592 % keyring.asString() ));
594 cachedPublicKeyData.setDirty( keyring );
601 cachedPublicKeyData.setDirty( keyring );
608 if ( ! PathInfo( signature ).isFile() )
611 MIL <<
"Determining key id of signature " << signature << endl;
614 if ( ! fprs.empty() ) {
615 std::string &
id = fprs.back();
616 MIL <<
"Determined key id [" <<
id <<
"] for signature " << signature << endl;
619 return std::string();