Imported Upstream version 17.0.3 upstream/17.0.3
authorDongHun Kwak <dh0128.kwak@samsung.com>
Mon, 2 Sep 2019 07:14:06 +0000 (16:14 +0900)
committerDongHun Kwak <dh0128.kwak@samsung.com>
Mon, 2 Sep 2019 07:14:06 +0000 (16:14 +0900)
VERSION.cmake
package/libzypp.changes
tests/zypp/KeyRing_test.cc
tests/zypp/data/KeyRing/installkey.gpg [new file with mode: 0644]
zypp/KeyRing.cc

index 016c7cb..be393d8 100644 (file)
@@ -61,8 +61,8 @@
 SET(LIBZYPP_MAJOR "17")
 SET(LIBZYPP_COMPATMINOR "0")
 SET(LIBZYPP_MINOR "0")
-SET(LIBZYPP_PATCH "2")
+SET(LIBZYPP_PATCH "3")
 #
-# LAST RELEASED: 17.0.2 (0)
+# LAST RELEASED: 17.0.3 (0)
 # (The number in parenthesis is LIBZYPP_COMPATMINOR)
 #=======
index d79bc08..68141c9 100644 (file)
@@ -1,4 +1,11 @@
 -------------------------------------------------------------------
+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)
index a29854c..4a5cb93 100644 (file)
@@ -208,4 +208,31 @@ BOOST_AUTO_TEST_CASE(signature_test)
   }
 }
 
+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() );
+}
 
diff --git a/tests/zypp/data/KeyRing/installkey.gpg b/tests/zypp/data/KeyRing/installkey.gpg
new file mode 100644 (file)
index 0000000..434c899
Binary files /dev/null and b/tests/zypp/data/KeyRing/installkey.gpg differ
index 0eb28dd..c3e1169 100644 (file)
@@ -240,6 +240,8 @@ namespace zypp
 
     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 );
@@ -273,6 +275,31 @@ namespace zypp
   };
   ///////////////////////////////////////////////////////////////////
 
+  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 )
   {
@@ -280,18 +307,19 @@ namespace zypp
     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() ) );
+      }
     }
   }