- Fixes for the checksum/signature subsystem (#302059)
authorDuncan Mac-Vicar P <dmacvicar@suse.de>
Thu, 23 Aug 2007 22:38:52 +0000 (22:38 +0000)
committerDuncan Mac-Vicar P <dmacvicar@suse.de>
Thu, 23 Aug 2007 22:38:52 +0000 (22:38 +0000)
tests/repo/susetags/CMakeLists.txt
tests/repo/susetags/Downloader_test.cc
tests/repo/susetags/data/stable-x86-subset-gz/content.asc
tests/repo/susetags/data/stable-x86-subset/content.asc
tests/repo/yum/YUMDownloader_test.cc
tests/zypp/KeyRing.cc
zypp/Fetcher.cc
zypp/Fetcher.h
zypp/FileChecker.cc
zypp/KeyRing.cc

index a0dfed908a2948edfc32b657a144f1b9c1a33972..30e747b4d9522a6b371d40ef3bdccb9577dfc461 100644 (file)
@@ -1,4 +1,7 @@
-ADD_EXECUTABLE( Downloader Downloader_test.cc )
+ADD_EXECUTABLE( 
+  Downloader
+  Downloader_test.cc
+)
 TARGET_LINK_LIBRARIES( Downloader zypp boost_unit_test_framework )
 
 ADD_TEST(Downloader ${CMAKE_CURRENT_BINARY_DIR}/Downloader ${CMAKE_CURRENT_SOURCE_DIR}/data )
\ No newline at end of file
index 79a5004e73b38bcaa812a648d5d6724fa2d37979..f05df92f3d80feb0dc7b4dbe9cc3a41d1fe4a889 100644 (file)
@@ -13,6 +13,7 @@
 #include "zypp/TmpPath.h"
 #include "zypp/repo/susetags/Downloader.h"
 
+#include "tests/zypp/KeyRingTestReceiver.h"
 
 using std::cout;
 using std::endl;
@@ -24,6 +25,9 @@ using namespace zypp::repo;
 
 void susetags_download_test(const string &dir)
 {
+  KeyRingTestReceiver keyring_callbacks;
+  keyring_callbacks.answerTrustKey(true);
+
   Pathname p = dir + "/stable-x86-subset";
   Url url("dir:" + p.asString());
   MediaSetAccess media(url);
@@ -77,6 +81,9 @@ void susetags_download_test(const string &dir)
 
 void susetags_gz_download_test(const string &dir)
 {
+  KeyRingTestReceiver keyring_callbacks;
+  keyring_callbacks.answerTrustKey(true);
+
   Pathname p = dir + "/stable-x86-subset-gz";
   Url url("dir:" + p.asString());
   MediaSetAccess media(url);
index c5ff0d5d50c15e093d5505cbafe7c2a4ba4425e7..989ecc3c86e95f9a783d3acdafaeb6f97388f71d 100644 (file)
@@ -1,32 +1,7 @@
------BEGIN PGP MESSAGE-----
-Version: GnuPG v1.4.6 (GNU/Linux)
+-----BEGIN PGP SIGNATURE-----
+Version: GnuPG v1.9.22 (GNU/Linux)
 
-owGdlsuLI1UUxtsZRAkozMaNm4sLQZxU7vvRjkjSST8wdsZUMs64ae4zHTupCqkK
-3T1LF4PuZi+I4MKV6MY/QBcD7gSX4sqtGxFEXHkr6XaSVhkYSKpInXN+de93vlOp
-hy9c37p245Nfv/vm56/FnWe+fP7UPGfzrPRZufv9w+ntfq893BmAfOazdJh26kHb
-Mp+f1+50+ulB7xAgmJBa+yAdXGami5jVHWeLs3o6aLa6nfpdyZcZayU4oXgNddju
-9UGFB92Dw+FdcHueu4UtC7A3Nfs3weHCzzPj56ObYM/Ppzo7r/U73cPeoJMO+11w
-XJaz7Ubj9PQ0KRaFT2w+bcz9JMtLXzTGRPLG5eobu82dQa9/rwp7Xfj6MieZz6a1
-Zn9nPzmT/IhTcHEac8nBmFUHWh0iCWS5ntvjVfYq/qQk9oQ4/f8QuXK13dltDruD
-VjMKVSGjCu8OD/qd9HF7LjYG3lw2Bsx0WUbttk28VpwXpZ/WYp/uHLRjzWwl8vZl
-7aqm6kyt10p73c5gLalKOFo15191t1aFtRjeGzZTYAvgNHAe+Cx+jvZawBcgjEGY
-g+MFGJfgAw1OpiCbgMyA2QTMyqNWH9w/Pto5rI6D92rpfq8/6DZbnS646Fht9euf
-e15cXtlvGUviDf873Lk76DejUdJLp7j8NJvk2iVV/tIy+XzUcOOinI/NohznWaPa
-UHTJLG/kRdGo9W4PonOb3aemZHlWr0hPVey8WYwasf3pTr990AdVfqPw5WIWQ4Wd
-19rNQfMyUNvtNvdSsJg5XfooTdWTvU7ViGFae6czaIJ0v4kAMURTAwOUzDnCITMc
-Wect5EISww3WKCDHEQAnztcrHesCLd2cRFMlo/trLGwJQx7ByKTCB6wktRGgOZHa
-2uC1C9oHJkH0oz3Rozhy7eEVBJSaB+mRVdwro7HXwgpqIUOIWISsIEJKTNYQPttE
-MOU4M5IJZjTyznkkEQlxOV4pqrSXLFBHLVpHFJsIGDUgPBYHjpgwlmJBpMCQMYkj
-xiHBuZGWriE26hElgjBGJKKaBEksdtZzy52mUFCofSUR5AxcDuay/u3OvVW5hYRR
-yJVFUCLFBXVaCsireyNHjYMWCSW8AmA0G9VnC3Piz+vQBUOQlHUa162wMoku7GMm
-9kR6BomlhFvmIMTGWYIEY1biWAYpdcphtMEkUHjiGK1TiiFyzG0yBcRMEezjo4/H
-c6BSUYyUglCwQLwjCENMvN5kOswccapOuEfYQbrJDNFrlFttpUVUEMsMwyyCCXde
-iLgYYxzjCG4whY/bM5DFdQoqtdGbTOuEjg2IdgieORFdJQwTVAkkBSVIYSdxkBBv
-MJWVEGqr6xQ6CTnxV/bOSEQpT5APwlAcZWBRDGOocgpRrIQ00Spsg6mRQjhaPK6T
-ayiVWjL3m+n+hW8ENsQGITCXgXIfRzB+NWdEwcjnxBqFvIqCTsY2Pi98Uup5ZZ3H
-CKq1dN5xEgu4t5JxBTVDOvCqwyHEoYotqgao+nef55PkbDpZq49KxIEX1gsaoHUk
-WE1lNXqismJ0mAhWMewAGGdFqScTXT2krkC4dMrErsVeVgJJ7KUkNK4knqkOUX/B
-EJYCgKl3Y52gxjgLeVKelbXaR29df3areuW4fBe5ce2Hl7c+fe2P7Qfdvx7RVz9P
-XvntpW97b4wfgK3PPvzqxdGDax8//OLR77+8//pPZ7daf/74Nw==
-=3cih
------END PGP MESSAGE-----
+iD8DBQBGzZ7Vm+zCtd2wN1YRAvrYAJ4or9MtpTiRk57EiGkd3YBvgoIN5QCfX969
+j0d5j3iteCP3nR/N39nrdMo=
+=w2Lh
+-----END PGP SIGNATURE-----
index e4b185aa1cf88d60a352f52f73e840a951e1c3d3..8a3bd485cb949ab34c712c19d320021687d9bfdf 100644 (file)
@@ -1,32 +1,7 @@
------BEGIN PGP MESSAGE-----
-Version: GnuPG v1.4.6 (GNU/Linux)
+-----BEGIN PGP SIGNATURE-----
+Version: GnuPG v1.9.22 (GNU/Linux)
 
-owGdVjuPG1UU3iRCIEsUaaCguYIiEort+35EvLxr70Mx6+CxQ6BZ3eeuWXtsecba
-3TR0CLr0FKmJhKBBoqZBlCAigQQVLRI/AAlxZr1LvAEUKZI9V55zvu/e833njOfe
-81fWLl/99Pdvvvr1S3X70ufPRfesn+ZlzMvN7+69cavfaw83Bmg6i3k2zDr1ZH05
-nZ/Ubnf62U5vFxHcYLX2TjY4z8wWkNUd5YvjejZorXc79TtanmasQGiD0xWq3Xav
-jyp61N3ZHd5Bt+bTsPBlgbYmbvs62l3Eee7ifP862orzic1Pav1Od7c36GTDfhcd
-lOXsRrN5dHTUKBZFbPjppDmP43xaxqI5Ylo2z0/f3GxtDHr996pwtEWsn+Y05rNJ
-rdXf2G4ca7knOTpbRlJLNBLVhVcXYEL51M79wTJ7GX9SknhCnP9/iD12t93ZbA27
-g/UWCFVRggrvDHf6neyRPWeFoddPjUEzW5ag3Q0H94qTooyTGvh0e6cNmNlS5Bvn
-2CWmcqbWW8963c5gJalK2Fua8y/ca0tgDcJbw1aGfIGCRSGimMNnb2sdxQKlEUpz
-dLBAoxJ9YNHhBOVjlDs0G6NZubfeR3cP9jZ2q+vg3Vq23esPuq31ThedOVZb/vpn
-z7Pby/Y7jTVgw/8Od+4M+i1olOy8U8L0KB9PbWhU+actM53vN8OoKOcjtyhH07xZ
-FQRdMps2p0XRrPVuDaBzW92nZsmneb1ieipwiG6x3wT7s41+e6ePqvxmEcvFDEKF
-n9farUHrPFDb7La2MrSYBVtGkKbyZKtTGTHMam93Bi2UbbcI8kwl7iynVEiBNedM
-MkWIItgzTbkV2htMQkDoMMR6pWNdkdNubkBTrRBpnIxzJJloRHQ+uhSMozQxppNS
-JlLMfRDYIWhGf2j3Y7ECNp5xEgwjFCYAJ8wcxkRqIgjzFivHA/ZWK/YI3GgPV/CW
-62QFVjZ5D3sr6QQ3AGSGx4pYExalw2QFH/MVvJLCYJxEtR8kJm4knBVLF1LiImks
-oiTGqFX86vmTc9LSII2SIKg3VrroBPWWiaSE4TaymBKJ6HwSi9rNzntnDmAmOJbG
-E6yJkYoHqBRLTWkkgTuonCijokFof7Zfny3cYTyp45AcI1rXOYnBUOMatvCPOGlk
-OgrMPNjpRcCYuuAZUUJ4TQGGOQ8mUHKBk2EVWRC8zjkFy0W4yKkwFYbRCA86CWvi
-2nAKomCsRGIxgHmYsmgvcgYqAgumzmQkNGB+kTMFSbj01mtPuGJegGgCiJkMUSk4
-jHNBSIIvcKoI5Tks4JyKa+vsRU4flA3Qf5akKIJylionFDeKaMUZMTRoCo7SC5zG
-a4ytt3WOg8aSxcdqFwyoTGQkJuhGCjIIEMM5boIhnBqlHYXGv8BpiSGUYvCIS4u1
-Maec261se0lKFHXMw3BQqROXUWkGXysFMxj4JfPOkGhA0PHIw9MhNko7b+zfXaHg
-1uoQg2QAkNFrIQ22gtgkK4dTijCCUDHMTfVfPp+OG8eT8QoelCCJKJgYnrAPLHmY
-JJgBoqpWhA5TyRtBYfpHeVHa8dhWj6THSKSGSQfXwMtKIE2j1ozDSWDlNoH+ShCq
-YXgmMYxsgzRHeZo2yuOyVvv4zSvPrFUvGOdvHlcv7369dv/mg2voz8/ev/Ti7R+u
-vfyFunb8x88frd133z544eFPv3y49v3ll1595bcf//rkrYd/Aw==
-=/aaM
------END PGP MESSAGE-----
+iD8DBQBGzZ7Im+zCtd2wN1YRAvQ2AJ9S5chSnjnFR0P2IZO7485uodmb1QCeJzuj
+Ta+M4yWexFiqyaFmWRjdAuQ=
+=lrpc
+-----END PGP SIGNATURE-----
index 84e09b989427d91fe0379579f70ec599ec1629c0..1e4263a31588ea8d0f722674654213fbfa2affc2 100644 (file)
@@ -7,12 +7,12 @@
 #include <boost/test/parameterized_test.hpp>
 #include <boost/test/unit_test_log.hpp>
 
+#include "zypp/base/Logger.h"
 #include "zypp/Url.h"
 #include "zypp/PathInfo.h"
 #include "zypp/TmpPath.h"
 #include "zypp/repo/yum/Downloader.h"
 
-
 using std::cout;
 using std::endl;
 using std::string;
@@ -21,8 +21,13 @@ using namespace boost::unit_test;
 
 using namespace zypp::repo;
 
+#include "tests/zypp/KeyRingTestReceiver.h"
+
 void yum_download_test(const string &dir)
 {
+  KeyRingTestReceiver keyring_callbacks;
+  keyring_callbacks.answerTrustKey(true);
+
   Pathname p = dir + "/10.2-updates-subset";
   Url url("dir:" + p.asString());
   MediaSetAccess media(url);
index c723c567cfc607d77e8c4ef3769430950b1db33a..43387648a8c0ba8b7e7f2c4549987baceb2141a2 100644 (file)
@@ -201,7 +201,9 @@ void keyring_test( const string &dir )
     KeyRing keyring( tmp_dir.path() );
     
     BOOST_CHECK_EQUAL( keyring.readSignatureKeyId( Pathname(dir) + "repomd.xml.asc" ), "BD61D89BD98821BE" );
-    BOOST_CHECK_EQUAL( keyring.readSignatureKeyId(Pathname()), "" );
+    BOOST_CHECK_THROW( keyring.readSignatureKeyId(Pathname()), Exception );
+    TmpFile tmp;
+    BOOST_CHECK_EQUAL( keyring.readSignatureKeyId(tmp.path()), "" );
   }
 }
 
index 84399d5db21063d80c33a96efa5df3d592c0876c..31e49034e5882f15b31c95daa51f36954e0feb43 100644 (file)
@@ -13,6 +13,7 @@
 #include <list>
 
 #include "zypp/base/Logger.h"
+#include "zypp/base/PtrTypes.h"
 #include "zypp/base/DefaultIntegral.h"
 #include "zypp/Fetcher.h"
 #include "zypp/base/UserRequestException.h"
@@ -32,13 +33,21 @@ namespace zypp
     FetcherJob( const OnMediaLocation &loc )
       : location(loc)
     {
+      //MIL << location << endl;
+    }
 
+    ~FetcherJob()
+    {
+      //MIL << location << " | * " << checkers.size() << endl;
     }
 
     OnMediaLocation location;
-    CompositeFileChecker checkers;
+    //CompositeFileChecker checkers;
+    list<FileChecker> checkers;
   };
 
+  typedef shared_ptr<FetcherJob> FetcherJob_Ptr;
+
   ///////////////////////////////////////////////////////////////////
   //
   //   CLASS NAME : Fetcher::Impl
@@ -70,7 +79,7 @@ namespace zypp
     Impl * clone() const
     { return new Impl( *this ); }
 
-    std::list<FetcherJob> _resources;
+    std::list<FetcherJob_Ptr> _resources;
     std::list<Pathname> _caches;
   };
   ///////////////////////////////////////////////////////////////////
@@ -78,18 +87,21 @@ namespace zypp
 
   void Fetcher::Impl::enqueueDigested( const OnMediaLocation &resource, const FileChecker &checker )
   {
-    CompositeFileChecker composite;
-    composite.add(ChecksumFileChecker(resource.checksum()));
-    composite.add(checker);
-    FetcherJob job(resource);
-    job.checkers = composite;
+    FetcherJob_Ptr job;
+    job.reset(new FetcherJob(resource));
+    ChecksumFileChecker digest_check(resource.checksum());
+    job->checkers.push_back(digest_check);
+    if ( checker )
+      job->checkers.push_back(checker);
     _resources.push_back(job);
   }
 
   void Fetcher::Impl::enqueue( const OnMediaLocation &resource, const FileChecker &checker )
   {
-    FetcherJob job(resource);
-    job.checkers.add(checker);
+    FetcherJob_Ptr job;
+    job.reset(new FetcherJob(resource));
+    if ( checker )
+      job->checkers.push_back(checker);
     _resources.push_back(job);
   }
 
@@ -120,25 +132,25 @@ namespace zypp
     ProgressData progress(_resources.size());
     progress.sendTo(progress_receiver);
 
-    for ( list<FetcherJob>::const_iterator it_res = _resources.begin(); it_res != _resources.end(); ++it_res )
+    for ( list<FetcherJob_Ptr>::const_iterator it_res = _resources.begin(); it_res != _resources.end(); ++it_res )
     {
       bool got_from_cache = false;
       for ( list<Pathname>::const_iterator it_cache = _caches.begin(); it_cache != _caches.end(); ++it_cache )
       {
         // does the current file exists in the current cache?
-        Pathname cached_file = *it_cache + (*it_res).location.filename();
+        Pathname cached_file = *it_cache + (*it_res)->location.filename();
         if ( PathInfo( cached_file ).isExist() )
         {
           // check the checksum
-          if ( is_checksum( cached_file, (*it_res).location.checksum() ) && (! (*it_res).location.checksum().empty() ) )
+          if ( is_checksum( cached_file, (*it_res)->location.checksum() ) && (! (*it_res)->location.checksum().empty() ) )
           {
             // cached
-            MIL << "file " << (*it_res).location.filename() << " found in previous cache. Using cached copy." << endl;
+            MIL << "file " << (*it_res)->location.filename() << " found in previous cache. Using cached copy." << endl;
             // checksum is already checked.
             // we could later implement double failover and try to download if file copy fails.
 
             // replicate the complete path in the target directory
-            Pathname dest_full_path = dest_dir + (*it_res).location.filename();
+            Pathname dest_full_path = dest_dir + (*it_res)->location.filename();
             if ( assert_dir( dest_full_path.dirname() ) != 0 )
               ZYPP_THROW( Exception("Can't create " + dest_full_path.dirname().asString()));
 
@@ -161,8 +173,8 @@ namespace zypp
         // try to get the file from the net
         try
         {
-          Pathname tmp_file = media.provideFile((*it_res).location);
-          Pathname dest_full_path = dest_dir + (*it_res).location.filename();
+          Pathname tmp_file = media.provideFile((*it_res)->location);
+          Pathname dest_full_path = dest_dir + (*it_res)->location.filename();
           if ( assert_dir( dest_full_path.dirname() ) != 0 )
                 ZYPP_THROW( Exception("Can't create " + dest_full_path.dirname().asString()));
           if ( filesystem::copy(tmp_file, dest_full_path ) != 0 )
@@ -174,10 +186,10 @@ namespace zypp
         }
         catch (const Exception & excpt_r)
         {
-         ZYPP_CAUGHT(excpt_r);
-         Exception nexcpt("Can't provide " + (*it_res).location.filename().asString() + " : " + excpt_r.msg());
-         nexcpt.remember(excpt_r);
-         ZYPP_THROW(nexcpt);
+          ZYPP_CAUGHT(excpt_r);
+          Exception nexcpt("Can't provide " + (*it_res)->location.filename().asString() + " : " + excpt_r.msg());
+          nexcpt.remember(excpt_r);
+          ZYPP_THROW(nexcpt);
         }
       }
       else
@@ -188,11 +200,24 @@ namespace zypp
       }
 
       // no matter where did we got the file, try to validate it:
-      Pathname localfile = dest_dir + (*it_res).location.filename();
+      Pathname localfile = dest_dir + (*it_res)->location.filename();
       // call the checker function
       try {
-       MIL << "Checking " << localfile << endl;
-       (*it_res).checkers(localfile);
+        MIL << "Checking job [" << localfile << "] (" << (*it_res)->checkers.size() << " checkers )" << endl;
+        for ( list<FileChecker>::const_iterator it = (*it_res)->checkers.begin();
+              it != (*it_res)->checkers.end();
+              ++it )
+        {
+          if (*it)
+          {
+            (*it)(localfile);
+          }
+          else
+          {
+            ERR << "Invalid checker for '" << localfile << "'" << endl;
+          }
+        }
+        
       }
       catch ( const FileCheckException &e )
       {
@@ -204,7 +229,7 @@ namespace zypp
       }
       catch (...)
       {
-        ZYPP_THROW(Exception("Unknown error while validating " + (*it_res).location.filename().asString()));
+        ZYPP_THROW(Exception("Unknown error while validating " + (*it_res)->location.filename().asString()));
       }
 
       if ( ! progress.incr() )
@@ -243,7 +268,7 @@ namespace zypp
 
   void Fetcher::enqueueDigested( const OnMediaLocation &resource, const FileChecker &checker )
   {
-    _pimpl->enqueue(resource, checker);
+    _pimpl->enqueueDigested(resource, checker);
   }
 
   void Fetcher::enqueue( const OnMediaLocation &resource, const FileChecker &checker  )
index 718d810555c6200785e2c047b537429ef49d10b8..78dd5e8dd35f9cde4c86810847d205ebffddece4 100644 (file)
@@ -82,7 +82,7 @@ namespace zypp
     *
     */
     void enqueue( const OnMediaLocation &resource,
-                  const FileChecker &checker = NullFileChecker() );
+                  const FileChecker &checker = FileChecker() );
     
     /**
     * Enqueue a object for transferal, they will not
@@ -96,7 +96,7 @@ namespace zypp
     * \todo FIXME implement checker == operator to avoid this.
     */
     void enqueueDigested( const OnMediaLocation &resource,
-                          const FileChecker &checker = NullFileChecker() );
+                          const FileChecker &checker = FileChecker() );
     
     /**
     * adds a directory to the list of directories
index 15bfa21007605129656adb851ba9339f8c2b190f..a8fea0179f2afe404ed3c7b20217a97f4a182493 100644 (file)
@@ -29,6 +29,7 @@ namespace zypp
 
   void ChecksumFileChecker::operator()( const Pathname &file ) const
   {
+    MIL << "checking " << file << " file against checksum '" << _checksum << "'" << endl;
     callback::SendReport<DigestReport> report;
     CheckSum real_checksum( _checksum.type(), filesystem::checksum( file, _checksum.type() ));
     
@@ -64,16 +65,24 @@ namespace zypp
 
   void NullFileChecker::operator()(const Pathname &file ) const
   {
+    MIL << "+ null check on " << file << endl;
     return;
   }
 
   void CompositeFileChecker::operator()(const Pathname &file ) const
   {
-    MIL << _checkers.size() << " checkers" << endl;
+    //MIL << _checkers.size() << " checkers" << endl;
     for ( list<FileChecker>::const_iterator it = _checkers.begin(); it != _checkers.end(); ++it )
-    { 
-      MIL << "checking..." << endl;
-      (*it)(file);
+    {
+      if ( *it )
+      {
+        //MIL << "+ chk" << endl;
+        (*it)(file);
+      }
+      else
+      {
+        ERR << "Invalid checker" << endl;
+      }
     }
   }
   
index 1be12e8b26210f7e11bffbd63f803de4486c4927..13fdbf5a4ad2ddac5edc2a5066d3b9731e6f11f2 100644 (file)
@@ -534,7 +534,10 @@ namespace zypp
 
   string KeyRing::Impl::readSignatureKeyId(const Pathname &signature )
   {
-    MIL << "Deetermining key id if signature " << signature << endl;
+    if ( ! PathInfo(signature).isFile() )
+      ZYPP_THROW(Exception("Signature file " + signature.asString() + " not found"));
+
+    MIL << "Determining key id if signature " << signature << endl;
     // HACK create a tmp keyring with no keys
     TmpDir dir(_base_dir, "fake-keyring");
     TmpFile fakeData(_base_dir, "fake-data");
@@ -574,7 +577,17 @@ namespace zypp
           id = what[1];
         //dumpRegexpResults(what);
       }
+      else
+      {
+        MIL << "'" << line << "'" << endl;
+      }
     }
+
+    if ( count == 0 )
+    {
+      MIL << "no output" << endl;
+    }
+
     MIL << "Determined key id [" << id << "] for signature " << signature << endl;
     prog.close();
     return id;