Add sha256 support

This imports the sha256 code from http://www.ouah.org/ogay/sha2/ (The other
hashes from sha-2 were removed). sha256 is a much stronger hashing algorithm
than md5 is (There were successful birthday attacks against md5).

All the code now defaults to creating sha256 salted hashes (The salting used is
the same as before).

Old znc.conf files can still be read.


git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1618 726aef4b-f618-498e-8847-2d620e286838
This commit is contained in:
psychon
2009-09-07 18:55:07 +00:00
parent 570946624c
commit 1430cd3659
13 changed files with 380 additions and 34 deletions
+14 -9
View File
@@ -706,7 +706,7 @@ bool CZNC::WriteNewConfig(const CString& sConfigFile) {
vsLines.push_back("<User " + sUser + ">");
CString sSalt;
sAnswer = CUtils::GetSaltedHashPass(sSalt);
vsLines.push_back("\tPass = md5#" + sAnswer + "#" + sSalt + "#");
vsLines.push_back("\tPass = " + CUtils::sDefaultHash + "#" + sAnswer + "#" + sSalt + "#");
if (CUtils::GetBoolInput("Would you like this user to be an admin?", bFirstUser)) {
vsLines.push_back("\tAdmin = true");
@@ -1236,24 +1236,29 @@ bool CZNC::DoRehash(CString& sError)
// Pass = <plain text>
// Pass = <md5 hash> -
// Pass = plain#<plain text>
// Pass = md5#<md5 hash>
// Pass = md5#<salted md5 hash>#<salt>#
// The last one is the md5 hash of 'password' + 'salt'
// Pass = <hash name>#<hash>
// Pass = <hash name>#<salted hash>#<salt>#
// 'Salted hash' means hash of 'password' + 'salt'
// Possible hashes are md5 and sha256
if (sValue.Right(1) == "-") {
sValue.RightChomp();
sValue.Trim();
pUser->SetPass(sValue, true);
pUser->SetPass(sValue, CUser::HASH_MD5);
} else {
CString sMethod = sValue.Token(0, false, "#");
CString sPass = sValue.Token(1, true, "#");
if (sMethod == "md5") {
if (sMethod == "md5" || sMethod == "sha256") {
CUser::eHashType type = CUser::HASH_MD5;
if (sMethod == "sha256")
type = CUser::HASH_SHA256;
CString sSalt = sPass.Token(1, false, "#");
sPass = sPass.Token(0, false, "#");
pUser->SetPass(sPass, true, sSalt);
pUser->SetPass(sPass, type, sSalt);
} else if (sMethod == "plain") {
pUser->SetPass(sPass, false);
pUser->SetPass(sPass, CUser::HASH_NONE);
} else {
pUser->SetPass(sValue, false);
pUser->SetPass(sValue, CUser::HASH_NONE);
}
}