From a40a31f6adc36147e26858afd45a9d12eef93e53 Mon Sep 17 00:00:00 2001 From: David Leverton Date: Thu, 6 Oct 2011 23:28:08 +0100 Subject: Support verifying arbitrary (supported) Manifest hashes --- .../repositories/e/check_fetched_files_visitor.cc | 103 ++++++--------------- paludis/repositories/e/manifest2_reader.cc | 21 +---- paludis/repositories/e/manifest2_reader.hh | 11 +-- 3 files changed, 38 insertions(+), 97 deletions(-) diff --git a/paludis/repositories/e/check_fetched_files_visitor.cc b/paludis/repositories/e/check_fetched_files_visitor.cc index d80bd4a0b..7c91b13c2 100644 --- a/paludis/repositories/e/check_fetched_files_visitor.cc +++ b/paludis/repositories/e/check_fetched_files_visitor.cc @@ -36,12 +36,10 @@ #include #include #include -#include -#include -#include -#include +#include #include #include +#include #include #include #include @@ -216,7 +214,7 @@ CheckFetchedFilesVisitor::check_distfile_manifest(const FSPath & distfile) if (manifest_ignore == _imp->use_manifest) return true; - bool found(false); + bool found(false), hashed(false); for (Manifest2Reader::ConstIterator m(_imp->m2r->begin()), m_end(_imp->m2r->end()) ; m != m_end ; ++m) @@ -250,88 +248,35 @@ CheckFetchedFilesVisitor::check_distfile_manifest(const FSPath & distfile) MemoisedHashes * hashes = MemoisedHashes::get_instance(); - if (! m->rmd160().empty()) + for (Map::ConstIterator it(m->hashes()->begin()), + it_end(m->hashes()->end()); it_end != it; ++it) { - std::string rmd160hexsum(hashes->get("RMD160", distfile, file_stream)); - - if (rmd160hexsum != m->rmd160()) + if (! DigestRegistry::get_instance()->get(it->first)) { - Log::get_instance()->message("e.manifest.rmd160.failure", ll_debug, lc_context) - << "Malformed Manifest: failed RMD160 checksum"; - _imp->output_manager->stdout_stream() << "failed RMD160"; - _imp->failures->push_back(make_named_values( - n::failed_automatic_fetching() = false, - n::failed_integrity_checks() = "Failed RMD160 checksum", - n::requires_manual_fetching() = false, - n::target_file() = stringify(distfile.basename()) - )); - return false; + Log::get_instance()->message("e.manifest.checksum.unsupported", ll_warning, lc_context) + << "Manifest hash function '" + it->first + "' is not supported"; + continue; } - Log::get_instance()->message("e.manifest.rmd160.result", ll_debug, lc_context) - << "Actual RMD160 = " << rmd160hexsum; - } - if (! m->sha1().empty()) - { - std::string sha1hexsum(hashes->get("SHA1", distfile, file_stream)); + std::string hexsum(hashes->get(it->first, distfile, file_stream)); - if (sha1hexsum != m->sha1()) + if (hexsum != it->second) { - Log::get_instance()->message("e.manifest.sha1.failure", ll_debug, lc_context) - << "Malformed Manifest: failed SHA1 checksum"; - _imp->output_manager->stdout_stream() << "failed SHA1"; + Log::get_instance()->message("e.manifest.checksum.failure", ll_debug, lc_context) + << "Malformed Manifest: failed " << it->first << " checksum"; + _imp->output_manager->stdout_stream() << "failed " << it->first; _imp->failures->push_back(make_named_values( n::failed_automatic_fetching() = false, - n::failed_integrity_checks() = "Failed SHA1 checksum", + n::failed_integrity_checks() = "Failed " + it->first + " checksum", n::requires_manual_fetching() = false, n::target_file() = stringify(distfile.basename()) )); return false; } - Log::get_instance()->message("e.manifest.sha1.result", ll_debug, lc_context) - << "Actual SHA1 = " << sha1hexsum; - } - - if (! m->sha256().empty()) - { - std::string sha256hexsum(hashes->get("SHA256", distfile, file_stream)); - - if (sha256hexsum != m->sha256()) - { - Log::get_instance()->message("e.manifest.sha256.failure", ll_debug, lc_context) - << "Malformed Manifest: failed SHA256 checksum"; - _imp->output_manager->stdout_stream() << "failed SHA256"; - _imp->failures->push_back(make_named_values( - n::failed_automatic_fetching() = false, - n::failed_integrity_checks() = "Failed SHA256 checksum", - n::requires_manual_fetching() = false, - n::target_file() = stringify(distfile.basename()) - )); - return false; - } - Log::get_instance()->message("e.manifest.sha256.result", ll_debug, lc_context) - << "Actual SHA256 = " << sha256hexsum; - } - if (! m->md5().empty()) - { - std::string md5hexsum(hashes->get("MD5", distfile, file_stream)); - - if (md5hexsum != m->md5()) - { - Log::get_instance()->message("e.manifest.md5.failure", ll_debug, lc_context) - << "Malformed Manifest: failed MD5 checksum"; - _imp->output_manager->stdout_stream() << "failed MD5"; - _imp->failures->push_back(make_named_values( - n::failed_automatic_fetching() = false, - n::failed_integrity_checks() = "Failed MD5 checksum", - n::requires_manual_fetching() = false, - n::target_file() = stringify(distfile.basename()) - )); - return false; - } - Log::get_instance()->message("e.manifest.md5.result", ll_debug, lc_context) - << "Actual MD5 = " << md5hexsum; + Log::get_instance()->message("e.manifest.checksum.result", ll_debug, lc_context) + << "Actual " << it->first << " = " << hexsum; + hashed = true; } } catch (const SafeIFStreamError &) @@ -359,6 +304,18 @@ CheckFetchedFilesVisitor::check_distfile_manifest(const FSPath & distfile) return false; } + if (found && ! hashed) + { + _imp->output_manager->stdout_stream() << "no supported hashes in Manifest"; + _imp->failures->push_back(make_named_values( + n::failed_automatic_fetching() = false, + n::failed_integrity_checks() = "No supported hashes in Manifest", + n::requires_manual_fetching() = false, + n::target_file() = stringify(distfile.basename()) + )); + return false; + } + return true; } diff --git a/paludis/repositories/e/manifest2_reader.cc b/paludis/repositories/e/manifest2_reader.cc index b16ea6a68..fb883c989 100644 --- a/paludis/repositories/e/manifest2_reader.cc +++ b/paludis/repositories/e/manifest2_reader.cc @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -80,8 +81,9 @@ Manifest2Reader::Manifest2Reader(const FSPath & f) : tokenise_whitespace((*l), create_inserter(std::back_inserter(tokens))); std::list::const_iterator t(tokens.begin()), t_end(tokens.end()); - std::string type, name, sha1, sha256, rmd160, md5; + std::string type, name; off_t size; + std::shared_ptr > hashes(std::make_shared >()); if (t_end == t) continue; @@ -114,25 +116,12 @@ Manifest2Reader::Manifest2Reader(const FSPath & f) : if (t_end == t) throw Manifest2Error("no checksum for: " + checksum_type); - if ("SHA1" == checksum_type) - sha1 = (*t); - else if ("SHA256" == checksum_type) - sha256 = (*t); - else if ("RMD160" == checksum_type) - rmd160 = (*t); - else if ("MD5" == checksum_type) - md5 = (*t); - else - Log::get_instance()->message("e.manifest.unknown_checksum", ll_debug, lc_no_context) - << "Skipping unknown checksum type " << checksum_type; + hashes->insert(checksum_type, *t); } _imp->entries.insert(std::make_pair(std::make_pair(type,name), make_named_values( - n::md5() = md5, + n::hashes() = hashes, n::name() = name, - n::rmd160() = rmd160, - n::sha1() = sha1, - n::sha256() = sha256, n::size() = size, n::type() = type ))); diff --git a/paludis/repositories/e/manifest2_reader.hh b/paludis/repositories/e/manifest2_reader.hh index b35abc55e..cacd8f062 100644 --- a/paludis/repositories/e/manifest2_reader.hh +++ b/paludis/repositories/e/manifest2_reader.hh @@ -23,6 +23,7 @@ #include #include #include +#include #include /** \file @@ -35,11 +36,8 @@ namespace paludis { namespace n { - typedef Name md5; + typedef Name hashes; typedef Name name; - typedef Name rmd160; - typedef Name sha1; - typedef Name sha256; typedef Name size; typedef Name type; } @@ -48,11 +46,8 @@ namespace paludis { struct Manifest2Entry { - NamedValue md5; + NamedValue > > hashes; NamedValue name; - NamedValue rmd160; - NamedValue sha1; - NamedValue sha256; NamedValue size; NamedValue type; }; -- cgit v1.2.3