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:
parent
5cdf6eff36
commit
26e87b20b1
|
@ -114,16 +114,15 @@ config.o: ../templates/patterns.h ../templates/changepatterns.h
|
||||||
config.o: ../templates/htmltextstream.h ../core/sessionmanager.h
|
config.o: ../templates/htmltextstream.h ../core/sessionmanager.h
|
||||||
crypt.o: crypt.h run.h config.h ../../pikotools/space/spaceparser.h
|
crypt.o: crypt.h run.h config.h ../../pikotools/space/spaceparser.h
|
||||||
crypt.o: ../../pikotools/space/space.h ../../pikotools/textstream/types.h
|
crypt.o: ../../pikotools/space/space.h ../../pikotools/textstream/types.h
|
||||||
crypt.o: htmlfilter.h user.h ../../pikotools/utf8/utf8.h misc.h item.h
|
crypt.o: htmlfilter.h user.h ../../pikotools/utf8/utf8.h log.h textstream.h
|
||||||
|
crypt.o: logmanipulators.h ../../pikotools/textstream/textstream.h
|
||||||
crypt.o: ../../pikotools/space/space.h ../../pikotools/date/date.h
|
crypt.o: ../../pikotools/space/space.h ../../pikotools/date/date.h
|
||||||
crypt.o: requesttypes.h ../../pikotools/textstream/textstream.h
|
|
||||||
crypt.o: ../../pikotools/convert/convert.h ../../pikotools/convert/inttostr.h
|
crypt.o: ../../pikotools/convert/convert.h ../../pikotools/convert/inttostr.h
|
||||||
crypt.o: ../../pikotools/membuffer/membuffer.h
|
crypt.o: ../../pikotools/membuffer/membuffer.h
|
||||||
crypt.o: ../../pikotools/textstream/types.h log.h textstream.h
|
crypt.o: ../../pikotools/textstream/types.h slog.h cur.h request.h
|
||||||
crypt.o: logmanipulators.h slog.h cur.h request.h error.h
|
crypt.o: requesttypes.h item.h error.h ../templates/htmltextstream.h
|
||||||
crypt.o: ../templates/htmltextstream.h ../core/textstream.h
|
crypt.o: ../core/textstream.h misc.h ../../pikotools/space/spacetojson.h
|
||||||
crypt.o: ../../pikotools/space/spacetojson.h session.h plugindata.h rebus.h
|
crypt.o: session.h plugindata.h rebus.h mount.h ../templates/locale.h
|
||||||
crypt.o: mount.h ../templates/locale.h
|
|
||||||
dircontainer.o: dircontainer.h item.h ../../pikotools/space/space.h
|
dircontainer.o: dircontainer.h item.h ../../pikotools/space/space.h
|
||||||
dircontainer.o: ../../pikotools/date/date.h log.h textstream.h
|
dircontainer.o: ../../pikotools/date/date.h log.h textstream.h
|
||||||
dircontainer.o: logmanipulators.h ../../pikotools/textstream/textstream.h
|
dircontainer.o: logmanipulators.h ../../pikotools/textstream/textstream.h
|
||||||
|
|
|
@ -556,20 +556,18 @@ public:
|
||||||
// raw access to the config
|
// raw access to the config
|
||||||
PT::Space space;
|
PT::Space space;
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
PT::SpaceParser parser;
|
||||||
|
std::string default_str;
|
||||||
|
bool errors_to_stdout;
|
||||||
|
|
||||||
void ShowError();
|
void ShowError();
|
||||||
void AssignValues(bool stdout_is_closed);
|
void AssignValues(bool stdout_is_closed);
|
||||||
void SetAdditionalVariables();
|
void SetAdditionalVariables();
|
||||||
void CheckPasswd();
|
void CheckPasswd();
|
||||||
|
|
||||||
PT::SpaceParser parser;
|
|
||||||
|
|
||||||
std::string default_str;
|
|
||||||
int default_int;
|
|
||||||
bool default_bool;
|
|
||||||
|
|
||||||
bool errors_to_stdout;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
105
core/crypt.cpp
105
core/crypt.cpp
|
@ -10,7 +10,6 @@
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include "crypt.h"
|
#include "crypt.h"
|
||||||
#include "utf8/utf8.h"
|
#include "utf8/utf8.h"
|
||||||
#include "misc.h"
|
|
||||||
#include "log.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() )
|
if( val < 10 )
|
||||||
return;
|
return val + '0';
|
||||||
|
|
||||||
size_t i = str.size();
|
return val - 10 + 'a';
|
||||||
|
|
||||||
while( i > 0 && (IsWhite(str[i-1]) || str[i-1]==10) )
|
|
||||||
i -= 1;
|
|
||||||
|
|
||||||
if( i < str.size() )
|
|
||||||
str.erase(i);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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();
|
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);
|
PT::WideToUTF8(config->opensll_path, command);
|
||||||
run.Cmd(command);
|
run.Cmd(command);
|
||||||
run.Par("dgst");
|
run.Par("dgst");
|
||||||
|
run.Par("-binary");
|
||||||
|
|
||||||
switch(hash)
|
switch(hash)
|
||||||
{
|
{
|
||||||
|
@ -62,52 +59,96 @@ bool Crypt::Hash(int hash, const char * in, size_t inlen, std::string & out)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool result = run.Go(in, inlen, out) == 0;
|
return run.Go(in, inlen, out) == 0;
|
||||||
TrimLastWhite(out);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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);
|
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);
|
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;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Crypt::Hash(int hash, const wchar_t * in, std::wstring & out)
|
bool Crypt::HashBin(int hash, const wchar_t * in, std::string & out)
|
||||||
{
|
{
|
||||||
size_t len = wcslen(in);
|
size_t len = wcslen(in);
|
||||||
return Hash(hash, in, len, out);
|
return HashBin(hash, in, len, out);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Crypt::Hash(int hash, const std::wstring & in, std::wstring & out)
|
|
||||||
|
bool Crypt::HashBin(int hash, const std::wstring & in, std::string & out)
|
||||||
{
|
{
|
||||||
return Hash(hash, in.c_str(), in.size(), 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::HashHex(int hash, const char * in, std::string & out)
|
||||||
|
{
|
||||||
|
size_t len = strlen(in);
|
||||||
|
return HashHex(hash, in, len, out);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Crypt::HashHex(int hash, const std::string & in, std::string & 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 = up.pass;
|
||||||
pass_salted += salt;
|
pass_salted += salt;
|
||||||
|
|
||||||
if( Hash(up.pass_type, pass_salted, up.pass) )
|
if( HashHex(up.pass_type, pass_salted, up.pass) )
|
||||||
{
|
{
|
||||||
if( !salt.empty() )
|
if( !salt.empty() )
|
||||||
up.pass_hash_salted = true;
|
up.pass_hash_salted = true;
|
||||||
|
|
83
core/crypt.h
83
core/crypt.h
|
@ -2,7 +2,7 @@
|
||||||
* This file is a part of Winix
|
* This file is a part of Winix
|
||||||
* and is not publicly distributed
|
* and is not publicly distributed
|
||||||
*
|
*
|
||||||
* Copyright (c) 2011, Tomasz Sowa
|
* Copyright (c) 2011-2012, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@ -50,11 +50,11 @@ public:
|
||||||
in - input buffer
|
in - input buffer
|
||||||
inlen - the length of the buffer
|
inlen - the length of the buffer
|
||||||
output:
|
output:
|
||||||
out - the hash
|
out - the hash in binary form
|
||||||
*/
|
*/
|
||||||
bool Hash(int hash, const char * in, size_t inlen, std::string & out);
|
bool HashBin(int hash, const char * in, size_t inlen, std::string & out);
|
||||||
bool Hash(int hash, const char * in, std::string & out);
|
bool HashBin(int hash, const char * in, std::string & out);
|
||||||
bool Hash(int hash, const std::string & in, std::string & out);
|
bool HashBin(int hash, const std::string & in, std::string & out);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -66,11 +66,43 @@ public:
|
||||||
in - input buffer
|
in - input buffer
|
||||||
inlen - the length of the buffer
|
inlen - the length of the buffer
|
||||||
output:
|
output:
|
||||||
out - the hash
|
out - the hash in binary form
|
||||||
*/
|
*/
|
||||||
bool Hash(int hash, const wchar_t * in, size_t inlen, std::wstring & out);
|
bool HashBin(int hash, const wchar_t * in, size_t inlen, std::string & out);
|
||||||
bool Hash(int hash, const wchar_t * in, std::wstring & out);
|
bool HashBin(int hash, const wchar_t * in, std::string & out);
|
||||||
bool Hash(int hash, const std::wstring & in, std::wstring & out);
|
bool HashBin(int hash, const std::wstring & in, std::string & out);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
calculating a hash from a given input
|
||||||
|
|
||||||
|
input:
|
||||||
|
hash - the kind of the hash - WINIX_CRYPT_HASH_*
|
||||||
|
in - input buffer
|
||||||
|
inlen - the length of the buffer
|
||||||
|
output:
|
||||||
|
out - the hash in the hex form (one byte is saved as two hex digits)
|
||||||
|
*/
|
||||||
|
bool HashHex(int hash, const char * in, size_t inlen, std::string & out);
|
||||||
|
bool HashHex(int hash, const char * in, std::string & out);
|
||||||
|
bool HashHex(int hash, const std::string & in, std::string & out);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
calculating a hash from a given input
|
||||||
|
the input string is first changed to UTF8 and then hash is calculated
|
||||||
|
|
||||||
|
input:
|
||||||
|
hash - the kind of the hash - WINIX_CRYPT_HASH_*
|
||||||
|
in - input buffer
|
||||||
|
inlen - the length of the buffer
|
||||||
|
output:
|
||||||
|
out - the hash in the hex form (one byte is saved as two hex digits)
|
||||||
|
the 'out' here is std::wstring (not std::string like beforehand)
|
||||||
|
*/
|
||||||
|
bool HashHex(int hash, const wchar_t * in, size_t inlen, std::wstring & out);
|
||||||
|
bool HashHex(int hash, const wchar_t * in, std::wstring & out);
|
||||||
|
bool HashHex(int hash, const std::wstring & in, std::wstring & out);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -83,7 +115,7 @@ public:
|
||||||
inlen - the size of the buffer
|
inlen - the size of the buffer
|
||||||
|
|
||||||
output:
|
output:
|
||||||
out - encrypted or decrypted buffer
|
out - encrypted or decrypted buffer (always binary)
|
||||||
*/
|
*/
|
||||||
bool RSA(bool encrypt, const char * keypath, const char * in, size_t inlen, std::string & out);
|
bool RSA(bool encrypt, const char * keypath, const char * in, size_t inlen, std::string & out);
|
||||||
bool RSA(bool encrypt, const char * keypath, const std::string & in, std::string & out);
|
bool RSA(bool encrypt, const char * keypath, const std::string & in, std::string & out);
|
||||||
|
@ -179,22 +211,27 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void TrimLastWhite(std::string & str);
|
|
||||||
|
|
||||||
Config * config;
|
Config * config;
|
||||||
Run run;
|
Run run;
|
||||||
std::string command, bufina, bufouta, keypatha;
|
std::string command, bufina, keypatha;
|
||||||
//std::wstring pass_salted;//, pass_hashed;
|
//std::wstring pass_salted;//, pass_hashed;
|
||||||
//std::string pass_hasheda, pass_encrypteda;
|
//std::string pass_hasheda, pass_encrypteda;
|
||||||
|
|
||||||
std::wstring pass_salted, pass_org;
|
std::wstring pass_salted, pass_org;
|
||||||
std::string passa;
|
std::string passa, out_temp;
|
||||||
std::wstring empty;
|
std::wstring empty;
|
||||||
|
|
||||||
|
|
||||||
|
template<typename StringType>
|
||||||
|
void ConvertToHexForm(const std::string & in, StringType & out);
|
||||||
|
|
||||||
|
char ConvertToHexForm(int val);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template<class StringType>
|
template<typename StringType>
|
||||||
void Crypt::ClearString(StringType & str)
|
void Crypt::ClearString(StringType & str)
|
||||||
{
|
{
|
||||||
for(size_t i=0 ; i<str.size() ; ++i)
|
for(size_t i=0 ; i<str.size() ; ++i)
|
||||||
|
@ -204,6 +241,22 @@ void Crypt::ClearString(StringType & str)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<typename StringType>
|
||||||
|
void Crypt::ConvertToHexForm(const std::string & in, StringType & out)
|
||||||
|
{
|
||||||
|
out.clear();
|
||||||
|
|
||||||
|
if( in.size() * 2 > out.capacity() )
|
||||||
|
out.reserve(in.size() * 2);
|
||||||
|
|
||||||
|
for(size_t i=0 ; i<in.size() ; ++i)
|
||||||
|
{
|
||||||
|
out += ConvertToHexForm(((unsigned char)in[i]) >> 4);
|
||||||
|
out += ConvertToHexForm(((unsigned char)in[i]) & 0x0f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,6 @@ struct Request;
|
||||||
class Config;
|
class Config;
|
||||||
class Users;
|
class Users;
|
||||||
class Dirs;
|
class Dirs;
|
||||||
struct Synchro;
|
|
||||||
class ThreadManager;
|
class ThreadManager;
|
||||||
|
|
||||||
|
|
||||||
|
@ -53,7 +52,6 @@ private:
|
||||||
Config * config;
|
Config * config;
|
||||||
Dirs * dirs;
|
Dirs * dirs;
|
||||||
Users * users;
|
Users * users;
|
||||||
Synchro * synchro;
|
|
||||||
ThreadManager * thread_manager;
|
ThreadManager * thread_manager;
|
||||||
|
|
||||||
NotifyThread notify_thread;
|
NotifyThread notify_thread;
|
||||||
|
|
Loading…
Reference in New Issue