From: Michael Andres Date: Thu, 8 May 2014 17:01:19 +0000 (+0200) Subject: Notify user about expiring trusted keys; show trusted keys in verbose mode. X-Git-Tag: upstream/1.11.11~35 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=29deb6310846938fc61de98cdeaffa222d0706e2;p=platform%2Fupstream%2Fzypper.git Notify user about expiring trusted keys; show trusted keys in verbose mode. --- diff --git a/src/callbacks/keyring.h b/src/callbacks/keyring.h index 881fe4f..1ffca57 100644 --- a/src/callbacks/keyring.h +++ b/src/callbacks/keyring.h @@ -18,12 +18,38 @@ #include #include -#include "utils/prompt.h" +#include "Zypper.h" +#include "Table.h" /////////////////////////////////////////////////////////////////// namespace zypp { ///////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////// + namespace + { + std::ostream & dumpKeyInfo( std::ostream & str, const PublicKeyData & key, const KeyContext & context = KeyContext() ) + { + Table t; + t.lineStyle( none ); + if ( !context.empty() ) + { + t << ( TableRow() << "" << _("Repository:") << context.repoInfo().asUserString() ); + } + t << ( TableRow() << "" << _("Key Name:") << key.name() ) + << ( TableRow() << "" << _("Key Fingerprint:") << key.fingerprint() ) + << ( TableRow() << "" << _("Key Created:") << key.created() ) + << ( TableRow() << "" << _("Key Expires:") << key.expiresAsString() ) + << ( TableRow() << "" << _("Rpm Name:") << (boost::format( "gpg-pubkey-%1%-%2%" ) % key.gpgPubkeyVersion() % key.gpgPubkeyRelease()).str() ); + + return str << t; + } + + inline std::ostream & dumpKeyInfo( std::ostream & str, const PublicKey & key, const KeyContext & context = KeyContext() ) + { return dumpKeyInfo( str, key.keyData(), context ); } + } // namespace + /////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////// // KeyRingReceive /////////////////////////////////////////////////////////////////// @@ -36,6 +62,28 @@ namespace zypp //////////////////////////////////////////////////////////////////// + virtual void infoVerify( const std::string & file_r, const PublicKeyData & keyData_r, const KeyContext & context = KeyContext() ) + { + if ( keyData_r.expired() ) + { + Zypper::instance()->out().warning( boost::format(_("The gpg key signing file '%1%' has expired.")) % file_r ); + dumpKeyInfo( colNote(), keyData_r, context ); + } + else if ( keyData_r.daysToLive() < 15 ) + { + Zypper::instance()->out().info( boost::format( + _PL( "The gpg key signing file '%1%' will expire in %2% day.", + "The gpg key signing file '%1%' will expire in %2% days.", + keyData_r.daysToLive() )) % file_r % keyData_r.daysToLive() ); + dumpKeyInfo( std::cout, keyData_r, context ); + } + else if ( Zypper::instance()->out().verbosity() > Out::NORMAL ) + { + dumpKeyInfo( std::cout, keyData_r, context ); + } + } + + //////////////////////////////////////////////////////////////////// virtual bool askUserToAcceptUnsignedFile( const std::string & file, const KeyContext & context) { @@ -120,8 +168,6 @@ namespace zypp { Zypper & zypper = *Zypper::instance(); std::ostringstream s; - const std::string & keyid = key.id(), keyname = key.name(), - fingerprint = key.fingerprint(); s << std::endl; if (_gopts.gpg_auto_import_keys) @@ -132,28 +178,18 @@ namespace zypp s << _("New repository or package signing key received:") << std::endl; // gpg key info - s - << str::form(_("Key ID: %s"), keyid.c_str()) << std::endl - << str::form(_("Key Name: %s"), keyname.c_str()) << std::endl - << str::form(_("Key Fingerprint: %s"), fingerprint.c_str()) << std::endl - << str::form(_("Key Created: %s"), key.created().asString().c_str()) << std::endl - << str::form(_("Key Expires: %s"), key.expiresAsString().c_str()) << std::endl; - if (!context.empty()) - s << str::form(_("Repository: %s"), context.repoInfo().asUserString().c_str()) - << std::endl; + dumpKeyInfo( s << std::endl, key, context ) << std::endl; // if --gpg-auto-import-keys or --no-gpg-checks print info and don't ask if (_gopts.gpg_auto_import_keys) { - MIL << boost::format("Automatically importing key id '%s', '%s', fingerprint '%s'") - % keyid % keyname % fingerprint << std::endl; + MIL << "Automatically importing key " << key << std::endl; zypper.out().info(s.str()); return KeyRingReport::KEY_TRUST_AND_IMPORT; } else if (_gopts.no_gpg_checks) { - MIL << boost::format("Automatically trusting key id '%s', '%s', fingerprint '%s'") - % keyid % keyname % fingerprint << std::endl; + MIL << "Automatically trusting key " << key << std::endl; zypper.out().info(s.str()); return KeyRingReport::KEY_TRUST_TEMPORARILY; }