changed: in Crypt:
renamed Hash() -> HashBin()
HashBin() is using a binary output from OpenSSL now
previously we are using the hex output and with the new OpenSSL version
the text has additional characters and causes some problems
added: HashHex() - it is using the HashBin() and then converts the output
to hex format itself
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@891 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
105
core/crypt.cpp
105
core/crypt.cpp
@@ -10,7 +10,6 @@
|
||||
#include <cstring>
|
||||
#include "crypt.h"
|
||||
#include "utf8/utf8.h"
|
||||
#include "misc.h"
|
||||
#include "log.h"
|
||||
|
||||
|
||||
@@ -21,22 +20,19 @@ void Crypt::SetConfig(Config * pconfig)
|
||||
}
|
||||
|
||||
|
||||
void Crypt::TrimLastWhite(std::string & str)
|
||||
|
||||
char Crypt::ConvertToHexForm(int val)
|
||||
{
|
||||
if( str.empty() )
|
||||
return;
|
||||
if( val < 10 )
|
||||
return val + '0';
|
||||
|
||||
size_t i = str.size();
|
||||
|
||||
while( i > 0 && (IsWhite(str[i-1]) || str[i-1]==10) )
|
||||
i -= 1;
|
||||
|
||||
if( i < str.size() )
|
||||
str.erase(i);
|
||||
return val - 10 + 'a';
|
||||
}
|
||||
|
||||
|
||||
bool Crypt::Hash(int hash, const char * in, size_t inlen, std::string & out)
|
||||
|
||||
|
||||
bool Crypt::HashBin(int hash, const char * in, size_t inlen, std::string & out)
|
||||
{
|
||||
out.clear();
|
||||
|
||||
@@ -47,6 +43,7 @@ bool Crypt::Hash(int hash, const char * in, size_t inlen, std::string & out)
|
||||
PT::WideToUTF8(config->opensll_path, command);
|
||||
run.Cmd(command);
|
||||
run.Par("dgst");
|
||||
run.Par("-binary");
|
||||
|
||||
switch(hash)
|
||||
{
|
||||
@@ -62,52 +59,96 @@ bool Crypt::Hash(int hash, const char * in, size_t inlen, std::string & out)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool result = run.Go(in, inlen, out) == 0;
|
||||
TrimLastWhite(out);
|
||||
|
||||
return result;
|
||||
return run.Go(in, inlen, out) == 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Crypt::Hash(int hash, const char * in, std::string & out)
|
||||
bool Crypt::HashBin(int hash, const char * in, std::string & out)
|
||||
{
|
||||
size_t len = strlen(in);
|
||||
return Hash(hash, in, len, out);
|
||||
return HashBin(hash, in, len, out);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Crypt::Hash(int hash, const std::string & in, std::string & out)
|
||||
bool Crypt::HashBin(int hash, const std::string & in, std::string & out)
|
||||
{
|
||||
return Hash(hash, in.c_str(), in.size(), out);
|
||||
return HashBin(hash, in.c_str(), in.size(), out);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Crypt::Hash(int hash, const wchar_t * in, size_t inlen, std::wstring & out)
|
||||
bool Crypt::HashBin(int hash, const wchar_t * in, size_t inlen, std::string & out)
|
||||
{
|
||||
PT::WideToUTF8(in, inlen, bufina);
|
||||
int res = Hash(hash, bufina.c_str(), bufina.size(), bufouta);
|
||||
int res = HashBin(hash, bufina.c_str(), bufina.size(), out);
|
||||
bufina.clear();
|
||||
|
||||
// the output hash is not a UTF8 string
|
||||
// it consists only from ascii letters
|
||||
AssignString(bufouta, out);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
bool Crypt::HashBin(int hash, const wchar_t * in, std::string & out)
|
||||
{
|
||||
size_t len = wcslen(in);
|
||||
return HashBin(hash, in, len, out);
|
||||
}
|
||||
|
||||
|
||||
bool Crypt::HashBin(int hash, const std::wstring & in, std::string & out)
|
||||
{
|
||||
return HashBin(hash, in.c_str(), in.size(), out);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Crypt::HashHex(int hash, const char * in, size_t inlen, std::string & out)
|
||||
{
|
||||
int res = HashBin(hash, in, inlen, out_temp);
|
||||
|
||||
ConvertToHexForm(out_temp, out);
|
||||
out_temp.clear();
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
bool Crypt::Hash(int hash, const wchar_t * in, std::wstring & out)
|
||||
bool Crypt::HashHex(int hash, const char * in, std::string & out)
|
||||
{
|
||||
size_t len = wcslen(in);
|
||||
return Hash(hash, in, len, out);
|
||||
|
||||
size_t len = strlen(in);
|
||||
return HashHex(hash, in, len, out);
|
||||
}
|
||||
|
||||
bool Crypt::Hash(int hash, const std::wstring & in, std::wstring & out)
|
||||
|
||||
bool Crypt::HashHex(int hash, const std::string & in, std::string & out)
|
||||
{
|
||||
return Hash(hash, in.c_str(), in.size(), out);
|
||||
return HashHex(hash, in.c_str(), in.size(), out);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Crypt::HashHex(int hash, const wchar_t * in, size_t inlen, std::wstring & out)
|
||||
{
|
||||
int res = HashBin(hash, in, inlen, out_temp);
|
||||
|
||||
ConvertToHexForm(out_temp, out);
|
||||
out_temp.clear();
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
bool Crypt::HashHex(int hash, const wchar_t * in, std::wstring & out)
|
||||
{
|
||||
size_t len = wcslen(in);
|
||||
return HashHex(hash, in, len, out);
|
||||
}
|
||||
|
||||
|
||||
bool Crypt::HashHex(int hash, const std::wstring & in, std::wstring & out)
|
||||
{
|
||||
return HashHex(hash, in.c_str(), in.size(), out);
|
||||
}
|
||||
|
||||
|
||||
@@ -199,7 +240,7 @@ bool Crypt::PassHash(const std::wstring & salt, UserPass & up)
|
||||
pass_salted = up.pass;
|
||||
pass_salted += salt;
|
||||
|
||||
if( Hash(up.pass_type, pass_salted, up.pass) )
|
||||
if( HashHex(up.pass_type, pass_salted, up.pass) )
|
||||
{
|
||||
if( !salt.empty() )
|
||||
up.pass_hash_salted = true;
|
||||
|
||||
Reference in New Issue
Block a user