fixed checking checksum of YUM metadata, added sha1 vs. sha256 detection
authorJiri Srain <jsrain@suse.cz>
Wed, 29 Mar 2006 21:29:00 +0000 (21:29 +0000)
committerJiri Srain <jsrain@suse.cz>
Wed, 29 Mar 2006 21:29:00 +0000 (21:29 +0000)
devel/devel.jsrain/SourceRead.cc
package/libzypp.changes
zypp/source/yum/YUMSourceImpl.cc
zypp/source/yum/YUMSourceImpl.h

index 9f02478..d1f6c51 100644 (file)
@@ -7,6 +7,7 @@
 #include "zypp/source/SourceImpl.h"
 #include "zypp/SourceCache.h"
 #include "zypp/Package.h"
+#include "zypp/Message.h"
 
 using namespace std;
 using namespace zypp;
@@ -25,23 +26,26 @@ int main( int argc, char * argv[] )
   SourceFactory _f;
   Pathname p = "/";
 //  Url url = Url("ftp://cml.suse.cz/netboot/find/SUSE-10.1-CD-OSS-i386-Beta1-CD1");
-  Url url = Url("http://lide.suse.cz/~~jsrain/devel.jsrain");
+//  Url url = Url("http://users.suse.cz/~jsrain/devel.jsrain");
 //  Url url = Url("dir:/local/zypp/libzypp/devel/devel.jsrain");
+  Url url = Url("http://armstrong.suse.de/download/Code/10/update/i386/");
   Source_Ref s = _f.createFrom( url, p );
   ResStore store = s.resolvables();
   for (ResStore::const_iterator it = store.begin();
        it != store.end(); it++)
   {
     ERR << **it << endl;
-    if (isKind<Package>(*it))
+    if (isKind<Message>(*it))
     {
-      ERR << "Package" << endl;
-      Package::constPtr pkg = boost::dynamic_pointer_cast<const Package>( *it );
-      ERR << "License: " << pkg->licenseToConfirm() << endl;
+      ERR << "Message" << endl;
+      Message::constPtr pkg = boost::dynamic_pointer_cast<const Message>( *it );
+      ERR << "Patch PTR: " << pkg->patch() << endl;
+      if (pkg->patch())
+        ERR << "Patch: " << *(pkg->patch()) << endl;
     }
   }
 //  SourceCache().storeSource(s);
-  ERR << store << endl;
+//  ERR << store << endl;
   INT << "===[END]============================================" << endl;
   return 0;
 }
index 6ca9fd6..e0e1cde 100644 (file)
@@ -1,4 +1,10 @@
 -------------------------------------------------------------------
+Wed Mar 29 23:28:13 CEST 2006 - jsrain@suse.de
+
+- fixed checking checksum of YUM metadata, added sha1 vs. sha256
+  detection
+
+-------------------------------------------------------------------
 Wed Mar 29 09:13:51 CEST 2006 - visnov@suse.de
 
 - added support for external scripts to metadata (#159928) (jsrain)
index 0a6bd8f..81379af 100644 (file)
@@ -213,7 +213,7 @@ namespace zypp
              {
                string filename = (*patch)->location;
                src = provideFile(_path + filename);
-               if (! checkCheckSum(provideFile(_path + filename), (*patch)->checksumType, (*patch)->checksum))
+               if (! checkCheckSum(src, (*patch)->checksumType, (*patch)->checksum))
                {
                    ZYPP_THROW(Exception(N_("Failed check for the metadata file check sum")));
                }
@@ -316,7 +316,7 @@ namespace zypp
              : _cache_dir + (*it)->location;
            if (_cache_dir.empty())
            {
-             if (! checkCheckSum((*it)->location, (*it)->checksumType, (*it)->checksum))
+             if (! checkCheckSum(filename, (*it)->checksumType, (*it)->checksum))
              {
                ZYPP_THROW(Exception(N_("Failed check for the metadata file check sum")));
              }
@@ -350,7 +350,7 @@ namespace zypp
              : _cache_dir + (*it)->location;
            if (_cache_dir.empty())
            {
-             if (! checkCheckSum((*it)->location, (*it)->checksumType, (*it)->checksum))
+             if (! checkCheckSum(filename, (*it)->checksumType, (*it)->checksum))
              {
                ZYPP_THROW(Exception(N_("Failed check for the metadata file check sum")));
              }
@@ -388,7 +388,7 @@ namespace zypp
                              : _cache_dir + (*it)->location;
            if (_cache_dir.empty())
            {
-             if (! checkCheckSum((*it)->location, (*it)->checksumType, (*it)->checksum))
+             if (! checkCheckSum(filename, (*it)->checksumType, (*it)->checksum))
              {
                ZYPP_THROW(Exception(N_("Failed check for the metadata file check sum")));
              }
@@ -454,7 +454,7 @@ namespace zypp
              : _cache_dir + (*it)->location;
            if (_cache_dir.empty())
            {
-             if (! checkCheckSum((*it)->location, (*it)->checksumType, (*it)->checksum))
+             if (! checkCheckSum(filename, (*it)->checksumType, (*it)->checksum))
              {
                ZYPP_THROW(Exception(N_("Failed check for the metadata file check sum")));
              }
@@ -494,7 +494,7 @@ namespace zypp
              : _cache_dir + (*it)->location;
            if (_cache_dir.empty())
            {
-             if (! checkCheckSum((*it)->location, (*it)->checksumType, (*it)->checksum))
+             if (! checkCheckSum(filename, (*it)->checksumType, (*it)->checksum))
              {
                ZYPP_THROW(Exception(N_("Failed check for the metadata file check sum")));
              }
@@ -534,7 +534,7 @@ namespace zypp
              : _cache_dir + (*it)->location;
            if (_cache_dir.empty())
            {
-             if (! checkCheckSum((*it)->location, (*it)->checksumType, (*it)->checksum))
+             if (! checkCheckSum(filename, (*it)->checksumType, (*it)->checksum))
              {
                ZYPP_THROW(Exception(N_("Failed check for the metadata file check sum")));
              }
@@ -574,7 +574,7 @@ namespace zypp
              : _cache_dir + (*it)->location;
            if (_cache_dir.empty())
            {
-             if (! checkCheckSum((*it)->location, (*it)->checksumType, (*it)->checksum))
+             if (! checkCheckSum(filename, (*it)->checksumType, (*it)->checksum))
              {
                ZYPP_THROW(Exception(N_("Failed check for the metadata file check sum")));
              }
@@ -590,7 +590,7 @@ namespace zypp
                string filename = (*patch)->location;
                if (_cache_dir.empty())
                {
-                 if (! checkCheckSum(filename, (*patch)->checksumType, (*patch)->checksum))
+                 if (! checkCheckSum(provideFile(_path + filename), (*patch)->checksumType, (*patch)->checksum))
                  {
                    ZYPP_THROW(Exception(N_("Failed check for the metadata file check sum")));
                  }
@@ -1147,9 +1147,17 @@ namespace zypp
     }
     return cap;
   }
-      bool YUMSourceImpl::checkCheckSum (const Pathname & filename, const std::string & csum_type, const std::string & csum)
+      bool YUMSourceImpl::checkCheckSum (const Pathname & filename, std::string csum_type, const std::string & csum)
       {
        MIL << "Checking checksum for " << filename << " as type: " << csum_type << "; value: " << csum << endl;
+       if (str::toLower(csum_type) == "sha")
+       {
+         if (csum.size() == 40)
+           csum_type = "sha1";
+         else if (csum.size() == 64)
+           csum_type = "sha256";
+         DBG << "Checksum size is " << csum.size() << ", checksum type set to " << csum_type << endl;
+       }
        ifstream st(filename.asString().c_str());
        std::string dig = Digest::digest (csum_type, st, 4096);
        if (dig == "")
index 8d42b0f..b42d9b6 100644 (file)
@@ -128,7 +128,7 @@ namespace zypp
        typedef std::map<zypp::NVRA, ImplAndPackage> PackageImplMapT;
        PackageImplMapT _package_impl;
 
-       static bool checkCheckSum (const Pathname & filename, const std::string & csum_type, const std::string & csum);
+       static bool checkCheckSum (const Pathname & filename, std::string csum_type, const std::string & csum);
        static bool checkAscIntegrity (const Pathname & filename, const Pathname & asc_file);
 
       };