- rename "hash" into ExpectedHash in pkgAcqFile, pkgAcqIndex
- add missing HashSum() call to class pkgAcqIndex
- use the data provided by acquire-method (and send via the
{SHA256,SHA1,MD5Sum}-Hash tag when comparing the hash, this
avoids calculating the hash twice (just like old libapt)
* apt-pkg/acquire-method.cc:
- send MD5Sum-Hash tag to libapt to be consistant with
HashString::SupportedHashes()
* apt-pkg/acquire-worker.cc:
- check with "Owner->HashSum().HashType()" what hash the frontend
is expecting and pass it to pkgAcquireItem::Done() in the new
HashString format
- add some debugging output
* apt-pkg/contrib/hashes.cc:
- fix off-by-one error when constructing a HashString from a single
input string
* apt-pkg/contrib/hashes.h:
- add "HashType()" method
* apt-pkg/init.h, apt-pkg/makefile, methods/makefile:
- break ABI
std::cerr << " Expected Hash: " << ExpectedHash.toStr() << std::endl;
}
std::cerr << " Expected Hash: " << ExpectedHash.toStr() << std::endl;
}
- if (!ExpectedHash.empty() && !ExpectedHash.VerifyFile(DestFile))
+ if (!ExpectedHash.empty() && ExpectedHash.toStr() != Hash)
{
Status = StatAuthError;
ErrorText = _("Hash Sum mismatch");
{
Status = StatAuthError;
ErrorText = _("Hash Sum mismatch");
string PkgFile = Parse.FileName();
if(Parse.SHA256Hash() != "")
string PkgFile = Parse.FileName();
if(Parse.SHA256Hash() != "")
- hash = HashString("SHA256", Parse.SHA256Hash());
+ ExpectedHash = HashString("SHA256", Parse.SHA256Hash());
else if (Parse.SHA1Hash() != "")
else if (Parse.SHA1Hash() != "")
- hash = HashString("SHA1", Parse.SHA1Hash());
+ ExpectedHash = HashString("SHA1", Parse.SHA1Hash());
- hash = HashString("MD5Sum", Parse.MD5Hash());
+ ExpectedHash = HashString("MD5Sum", Parse.MD5Hash());
if (PkgFile.empty() == true)
return _error->Error(_("The package index files are corrupted. No Filename: "
"field for package %s."),
if (PkgFile.empty() == true)
return _error->Error(_("The package index files are corrupted. No Filename: "
"field for package %s."),
- if(!hash.VerifyFile(DestFile))
+ if(ExpectedHash.toStr() != CalcHash)
{
Status = StatError;
ErrorText = _("Hash Sum mismatch");
{
Status = StatError;
ErrorText = _("Hash Sum mismatch");
// AcqFile::pkgAcqFile - Constructor /*{{{*/
// ---------------------------------------------------------------------
/* The file is added to the queue */
// AcqFile::pkgAcqFile - Constructor /*{{{*/
// ---------------------------------------------------------------------
/* The file is added to the queue */
-pkgAcqFile::pkgAcqFile(pkgAcquire *Owner,string URI,string MD5,
+pkgAcqFile::pkgAcqFile(pkgAcquire *Owner,string URI,string Hash,
unsigned long Size,string Dsc,string ShortDesc,
const string &DestDir, const string &DestFilename) :
unsigned long Size,string Dsc,string ShortDesc,
const string &DestDir, const string &DestFilename) :
+ Item(Owner), ExpectedHash(Hash)
{
Retries = _config->FindI("Acquire::Retries",0);
{
Retries = _config->FindI("Acquire::Retries",0);
{
Item::Done(Message,Size,CalcHash,Cnf);
{
Item::Done(Message,Size,CalcHash,Cnf);
- // Check the md5
- if(!hash.VerifyFile(DestFile))
+ // Check the hash
+ if(ExpectedHash.toStr() != CalcHash)
{
Status = StatError;
ErrorText = "Hash Sum mismatch";
{
Status = StatError;
ErrorText = "Hash Sum mismatch";
pkgAcquire::MethodConfig *Cnf);
virtual string Custom600Headers();
virtual string DescURI() {return RealURI + CompressionExtension;};
pkgAcquire::MethodConfig *Cnf);
virtual string Custom600Headers();
virtual string DescURI() {return RealURI + CompressionExtension;};
+ virtual string HashSum() {return ExpectedHash.toStr(); };
/** \brief Create a pkgAcqIndex.
*
/** \brief Create a pkgAcqIndex.
*
pkgRecords *Recs;
/** \brief The hashsum of this package. */
pkgRecords *Recs;
/** \brief The hashsum of this package. */
+ HashString ExpectedHash;
/** \brief A location in which the actual filename of the package
* should be stored.
/** \brief A location in which the actual filename of the package
* should be stored.
virtual string DescURI() {return Desc.URI;};
virtual string ShortDesc() {return Desc.ShortDesc;};
virtual void Finished();
virtual string DescURI() {return Desc.URI;};
virtual string ShortDesc() {return Desc.ShortDesc;};
virtual void Finished();
- virtual string HashSum() {return hash.toStr(); };
+ virtual string HashSum() {return ExpectedHash.toStr(); };
virtual bool IsTrusted();
/** \brief Create a new pkgAcqArchive.
virtual bool IsTrusted();
/** \brief Create a new pkgAcqArchive.
pkgAcquire::ItemDesc Desc;
/** \brief The hashsum of the file to download, if it is known. */
pkgAcquire::ItemDesc Desc;
/** \brief The hashsum of the file to download, if it is known. */
+ HashString ExpectedHash;
/** \brief How many times to retry the download, set from
* Acquire::Retries.
/** \brief How many times to retry the download, set from
* Acquire::Retries.
virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
virtual void Done(string Message,unsigned long Size,string CalcHash,
pkgAcquire::MethodConfig *Cnf);
virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
virtual void Done(string Message,unsigned long Size,string CalcHash,
pkgAcquire::MethodConfig *Cnf);
- virtual string HashSum() {return hash.toStr(); };
virtual string DescURI() {return Desc.URI;};
virtual string DescURI() {return Desc.URI;};
+ virtual string HashSum() {return ExpectedHash.toStr(); };
/** \brief Create a new pkgAcqFile object.
*
/** \brief Create a new pkgAcqFile object.
*
TimeRFC1123(Res.LastModified).c_str());
if (Res.MD5Sum.empty() == false)
TimeRFC1123(Res.LastModified).c_str());
if (Res.MD5Sum.empty() == false)
End += snprintf(End,sizeof(S)-50 - (End - S),"MD5-Hash: %s\n",Res.MD5Sum.c_str());
End += snprintf(End,sizeof(S)-50 - (End - S),"MD5-Hash: %s\n",Res.MD5Sum.c_str());
+ End += snprintf(End,sizeof(S)-50 - (End - S),"MD5Sum-Hash: %s\n",Res.MD5Sum.c_str());
+ }
if (Res.SHA1Sum.empty() == false)
End += snprintf(End,sizeof(S)-50 - (End - S),"SHA1-Hash: %s\n",Res.SHA1Sum.c_str());
if (Res.SHA256Sum.empty() == false)
if (Res.SHA1Sum.empty() == false)
End += snprintf(End,sizeof(S)-50 - (End - S),"SHA1-Hash: %s\n",Res.SHA1Sum.c_str());
if (Res.SHA256Sum.empty() == false)
_error->Warning("Bizarre Error - File size is not what the server reported %s %lu",
LookupTag(Message,"Size","0").c_str(),TotalSize);
_error->Warning("Bizarre Error - File size is not what the server reported %s %lu",
LookupTag(Message,"Size","0").c_str(),TotalSize);
+ // see if there is a hash to verify
+ string RecivedHash;
+ HashString expectedHash(Owner->HashSum());
+ if(!expectedHash.empty())
+ {
+ string hashTag = expectedHash.HashType()+"-Hash";
+ RecivedHash = expectedHash.HashType() + ":" + LookupTag(Message, hashTag.c_str());
+ if(_config->FindB("Debug::pkgAcquire::Auth", false) == true)
+ {
+ clog << "201 URI Done: " << Owner->DescURI() << endl
+ << "RecivedHash: " << RecivedHash << endl
+ << "ExpectedHash: " << expectedHash.toStr()
+ << endl << endl;
+ }
+ }
Owner->Done(Message,atoi(LookupTag(Message,"Size","0").c_str()),
Owner->Done(Message,atoi(LookupTag(Message,"Size","0").c_str()),
- LookupTag(Message,"MD5-Hash"),Config);
+ RecivedHash.c_str(), Config);
ItemDone();
// Log that we are done
ItemDone();
// Log that we are done
return;
}
string::size_type pos = StringedHash.find(":");
return;
}
string::size_type pos = StringedHash.find(":");
- Type = StringedHash.substr(0,pos-1);
+ Type = StringedHash.substr(0,pos);
Hash = StringedHash.substr(pos+1, StringedHash.size() - pos);
if(_config->FindB("Debug::Hashes",false) == true)
Hash = StringedHash.substr(pos+1, StringedHash.size() - pos);
if(_config->FindB("Debug::Hashes",false) == true)
HashString(string StringedHashString); // init from str as "type:hash"
HashString();
HashString(string StringedHashString); // init from str as "type:hash"
HashString();
+ // get hash type used
+ string HashType() { return Type; };
+
// verify the given filename against the currently loaded hash
bool VerifyFile(string filename) const;
// verify the given filename against the currently loaded hash
bool VerifyFile(string filename) const;
// See the makefile
#define APT_PKG_MAJOR 4
// See the makefile
#define APT_PKG_MAJOR 4
#define APT_PKG_RELEASE 0
extern const char *pkgVersion;
#define APT_PKG_RELEASE 0
extern const char *pkgVersion;
# methods/makefile - FIXME
LIBRARY=apt-pkg
LIBEXT=$(GLIBC_VER)$(LIBSTDCPP_VER)
# methods/makefile - FIXME
LIBRARY=apt-pkg
LIBEXT=$(GLIBC_VER)$(LIBSTDCPP_VER)
MINOR=0
SLIBS=$(PTHREADLIB) $(INTLLIBS)
APT_DOMAIN:=libapt-pkg$(MAJOR)
MINOR=0
SLIBS=$(PTHREADLIB) $(INTLLIBS)
APT_DOMAIN:=libapt-pkg$(MAJOR)
BIN := $(BIN)/methods
# FIXME..
BIN := $(BIN)/methods
# FIXME..
APT_DOMAIN := libapt-pkg$(LIB_APT_PKG_MAJOR)
# The file method
APT_DOMAIN := libapt-pkg$(LIB_APT_PKG_MAJOR)
# The file method