-------------------------------------------------------------------
+Tue Nov 28 18:21:51 CET 2017 - ma@suse.de
+
+- When importing multiple keys, export the individual keys
+ ascii armored for import into the rpmdb (bsc#1069381)
+- version 17.0.3 (0)
+
+-------------------------------------------------------------------
Thu Nov 23 12:33:51 CET 2017 - ma@suse.de
- Don't filter procs with a different mnt namespace (bsc#1068708)
}
}
+BOOST_AUTO_TEST_CASE(keyring_import)
+{
+ // base sandbox for playing
+ TmpDir tmp_dir;
+ KeyRing keyring( tmp_dir.path() );
+ struct Receiver: public callback::ReceiveReport<KeyRingSignals>
+ {
+ Receiver()
+ { connect(); }
+
+ virtual void trustedKeyAdded( const PublicKey & key_r )
+ { ++_cbcnt; }
+
+ unsigned _cbcnt = 0;
+ } receiver;
+
+ ///////////////////////////////////////////////////////////////////
+ // Make sure we get a proper callback notification if multiple
+ // keys are imported at once.
+ ///////////////////////////////////////////////////////////////////
+ PublicKey key( DATADIR + "installkey.gpg" );
+ BOOST_CHECK_EQUAL( key.hiddenKeys().size(), 2 );
+ BOOST_CHECK_EQUAL( keyring.trustedPublicKeys().size(), 0 );
+ keyring.importKey( key, true );
+ BOOST_CHECK_EQUAL( keyring.trustedPublicKeys().size(), 3 );
+ BOOST_CHECK_EQUAL( receiver._cbcnt, keyring.trustedPublicKeys().size() );
+}
PublicKey exportKey( const std::string & id, const Pathname & keyring );
PublicKey exportKey( const PublicKeyData & keyData, const Pathname & keyring );
+ PublicKey exportKey( const PublicKey & key, const Pathname & keyring )
+ { return exportKey( key.keyData(), keyring ); }
void dumpPublicKey( const std::string & id, const Pathname & keyring, std::ostream & stream );
filesystem::TmpFile dumpPublicKeyToTmp( const std::string & id, const Pathname & keyring );
};
///////////////////////////////////////////////////////////////////
+ namespace
+ {
+ /// Handle signal emission from within KeyRing::Impl::importKey
+ struct ImportKeyCBHelper
+ {
+ void operator()( const PublicKey & key_r )
+ {
+ try {
+ _rpmdbEmitSignal->trustedKeyAdded( key_r );
+ _emitSignal->trustedKeyAdded( key_r );
+ }
+ catch ( const Exception & excp )
+ {
+ ERR << "Could not import key into rpmdb: " << excp << endl;
+ // TODO: JobReport as hotfix for bsc#1057188; should bubble up and go through some callback
+ JobReport::error( excp.asUserHistory() );
+ }
+ }
+
+ private:
+ callback::SendReport<target::rpm::KeyRingSignals> _rpmdbEmitSignal;
+ callback::SendReport<KeyRingSignals> _emitSignal;
+ };
+ } // namespace
+
void KeyRing::Impl::importKey( const PublicKey & key, bool trusted )
{
MIL << "Imported key " << key << " to " << (trusted ? "trustedKeyRing" : "generalKeyRing" ) << endl;
if ( trusted )
- try {
- callback::SendReport<target::rpm::KeyRingSignals> rpmdbEmitSignal;
- rpmdbEmitSignal->trustedKeyAdded( key );
-
- callback::SendReport<KeyRingSignals> emitSignal;
- emitSignal->trustedKeyAdded( key );
- }
- catch ( const Exception & excp )
{
- ERR << "Could not import key into rpmdb: " << excp << endl;
- // TODO: JobReport as hotfix for bsc#1057188; should bubble up and go through some callback
- JobReport::error( excp.asUserHistory() );
+ ImportKeyCBHelper emitSignal;
+ if ( key.hiddenKeys().empty() )
+ {
+ emitSignal( key );
+ }
+ else
+ {
+ // multiple keys: Export individual keys ascii armored to import in rpmdb
+ emitSignal( exportKey( key, trustedKeyRing() ) );
+ for ( const PublicKeyData & hkey : key.hiddenKeys() )
+ emitSignal( exportKey( hkey, trustedKeyRing() ) );
+ }
}
}