mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
fix passphrase generation, adding test to start
This commit is contained in:
parent
95f5460112
commit
517059d648
@ -15,6 +15,14 @@ using namespace Poco::Data::Keywords;
|
||||
|
||||
#define STR_BUFFER_SIZE 25
|
||||
|
||||
static std::vector<Poco::Tuple<int, std::string>> g_specialChars = {
|
||||
{ 0xa4, "auml" },{ 0x84, "Auml" },
|
||||
{ 0xbc, "uuml" },{ 0x9c, "Uuml" },
|
||||
{ 0xb6, "ouml" },{ 0x96, "Ouml" },
|
||||
{ 0x9f, "szlig" }
|
||||
};
|
||||
|
||||
|
||||
KeyPair::KeyPair()
|
||||
: mPrivateKey(nullptr), mSodiumSecret(nullptr)
|
||||
{
|
||||
@ -88,7 +96,7 @@ bool KeyPair::generateFromPassphrase(const char* passphrase, const Mnemonic* wor
|
||||
|
||||
|
||||
// debug passphrase
|
||||
printf("\passsphrase: <%s>\n", passphrase);
|
||||
/*printf("\passsphrase: <%s>\n", passphrase);
|
||||
printf("size word indices: %u\n", word_indices->size());
|
||||
std::string word_indicesHex = getHex(*word_indices, word_indices->size());
|
||||
printf("word_indices: \n%s\n", word_indicesHex.data());
|
||||
@ -100,9 +108,9 @@ bool KeyPair::generateFromPassphrase(const char* passphrase, const Mnemonic* wor
|
||||
}
|
||||
printf("\n");
|
||||
//*/
|
||||
printf("\nclear passphrase: \n%s\n", clearPassphrase.data());
|
||||
std::string hex_clearPassphrase = getHex((const unsigned char*)clearPassphrase.data(), clearPassphrase.size());
|
||||
printf("passphrase bin: \n%s\n\n", hex_clearPassphrase.data());
|
||||
//printf("\nclear passphrase: \n%s\n", clearPassphrase.data());
|
||||
//std::string hex_clearPassphrase = getHex((const unsigned char*)clearPassphrase.data(), clearPassphrase.size());
|
||||
//printf("passphrase bin: \n%s\n\n", hex_clearPassphrase.data());
|
||||
|
||||
|
||||
mm->releaseMemory(word_indices);
|
||||
@ -229,6 +237,7 @@ std::string KeyPair::filterPassphrase(const std::string& passphrase)
|
||||
{
|
||||
std::string filteredPassphrase;
|
||||
auto passphrase_size = passphrase.size();
|
||||
|
||||
for (int i = 0; i < passphrase_size; i++) {
|
||||
unsigned char c = passphrase.data()[i];
|
||||
// asci 128 even by utf8 (hex)
|
||||
@ -246,16 +255,11 @@ std::string KeyPair::filterPassphrase(const std::string& passphrase)
|
||||
// c3 9c => Ü
|
||||
// c3 9f => ß
|
||||
|
||||
std::vector<Poco::Tuple<int, std::string>> specialChars = {
|
||||
{0xa4, "auml"}, {0x84, "Auml"},
|
||||
{0xbc, "uuml"}, {0x9c, "Uuml"},
|
||||
{0xb6, "ouml"}, {0x96, "Ouml"},
|
||||
{0x9f, "szlig"}
|
||||
};
|
||||
|
||||
|
||||
unsigned char c2 = passphrase.data()[i + 1];
|
||||
bool insertedHtmlEntitie = false;
|
||||
for (auto it = specialChars.begin(); it != specialChars.end(); it++) {
|
||||
for (auto it = g_specialChars.begin(); it != g_specialChars.end(); it++) {
|
||||
if (c2 == it->get<0>()) {
|
||||
auto htmlEntitie = it->get<1>();
|
||||
filteredPassphrase += "&";
|
||||
|
||||
@ -142,12 +142,6 @@ int Gradido_LoginServer::main(const std::vector<std::string>& args)
|
||||
unsigned short json_port = (unsigned short)config().getInt("JSONServer.port", 1201);
|
||||
|
||||
|
||||
// load word lists
|
||||
if (!ServerConfig::loadMnemonicWordLists()) {
|
||||
//printf("[Gradido_LoginServer::%s] error loading mnemonic Word List\n", __FUNCTION__);
|
||||
errorLog.error("[Gradido_LoginServer::main] error loading mnemonic Word List");
|
||||
return Application::EXIT_CONFIG;
|
||||
}
|
||||
//printf("show mnemonic list: \n");
|
||||
//printf(ServerConfig::g_Mnemonic_WordLists[ServerConfig::MNEMONIC_BIP0039_SORTED_ORDER].getCompleteWordList().data());
|
||||
if (!ServerConfig::initServerCrypto(config())) {
|
||||
|
||||
@ -11,17 +11,18 @@ namespace ImportantTests {
|
||||
auto de_words = &ServerConfig::g_Mnemonic_WordLists[ServerConfig::MNEMONIC_GRADIDO_BOOK_GERMAN_RANDOM_ORDER];
|
||||
auto en_words = &ServerConfig::g_Mnemonic_WordLists[ServerConfig::MNEMONIC_BIP0039_SORTED_ORDER];
|
||||
|
||||
std::string passphrase_1_de = "beziffern Anbeginn häkeln Sozialabgaben Rasen fließen Frau weltweit Urlaub Urwissen Lohn plötzlich Gefrierpunkt Derartig Biedermeier getragen denken Realisierung Boden maximal voneinander Fördern Braten Entlastung";
|
||||
std::string passphrase_1_de = u8"beziffern Anbeginn häkeln Sozialabgaben Rasen fließen Frau weltweit Urlaub Urwissen Lohn plötzlich Gefrierpunkt Derartig Biedermeier getragen denken Realisierung Boden maximal voneinander Fördern Braten Entlastung";
|
||||
std::string passphrase_1_en = "boil banner regret since goat awful crane imitate myth clump rally offer train airport purpose machine helmet ahead alley gesture load scrub river glory";
|
||||
std::string passphrase_1_pubkey_hex = "cfce9cfad355ceb8c099a97f55a2bd7aa8d2bd0b86970f7d1e135be9e1da5eb7";
|
||||
|
||||
std::string passphrase_2_de = "dazu Zyklus Danach Auge losfliegen besprechen stoßen ohne heutige Begründung Dogma Erkenntnis genießen Medaille Äste Google woher Sprache Pädagoge Schweigen rasant Sekunde nahm Nordstern";
|
||||
std::string passphrase_2_de = u8"dazu Zyklus Danach Auge losfliegen besprechen stoßen ohne heutige Begründung Dogma Erkenntnis genießen Medaille Äste Google woher Sprache Pädagoge Schweigen rasant Sekunde nahm Nordstern";
|
||||
std::string passphrase_2_en = "place oblige gain jar neither note cry riot empty inform egg skate suffer garlic lake ladder liquid focus gorilla subject strong much oyster reduce";
|
||||
std::string passphrase_2_pubkey_hex = "3d547825bb53465579b95560981f444105495f2b6a68134fbec28ce518ac7b38";
|
||||
|
||||
KeyPair keys;
|
||||
bool errorsOccured = false;
|
||||
keys.generateFromPassphrase(passphrase_1_de.data(), de_words);
|
||||
std::string filtered_1_de = KeyPair::filterPassphrase(passphrase_1_de);
|
||||
keys.generateFromPassphrase(filtered_1_de.data(), de_words);
|
||||
if (keys.getPubkeyHex() != passphrase_1_pubkey_hex) {
|
||||
printf("1 de incorrect\n");
|
||||
errorsOccured = true;
|
||||
@ -31,8 +32,8 @@ namespace ImportantTests {
|
||||
printf("1 en incorrect\n");
|
||||
errorsOccured = true;
|
||||
}
|
||||
|
||||
keys.generateFromPassphrase(passphrase_2_de.data(), de_words);
|
||||
std::string filtered_2_de = KeyPair::filterPassphrase(passphrase_2_de);
|
||||
keys.generateFromPassphrase(filtered_2_de.data(), de_words);
|
||||
if (keys.getPubkeyHex() != passphrase_2_pubkey_hex) {
|
||||
printf("2 de incorrect\n");
|
||||
errorsOccured = true;
|
||||
|
||||
@ -29,9 +29,17 @@ int main(int argc, char** argv)
|
||||
ServerConfig::g_versionString = "0.20.KW08.04";
|
||||
printf("User size: %d Bytes, Session size: %d Bytes\n", sizeof(User), sizeof(Session));
|
||||
printf("model sizes: User: %d Bytes, EmailOptIn: %d Bytes\n", sizeof(model::table::User), sizeof(model::table::EmailOptIn));
|
||||
|
||||
// load word lists
|
||||
if (!ServerConfig::loadMnemonicWordLists()) {
|
||||
//printf("[Gradido_LoginServer::%s] error loading mnemonic Word List\n", __FUNCTION__);
|
||||
printf("[Gradido_LoginServer::main] error loading mnemonic Word List");
|
||||
return -2;
|
||||
}
|
||||
|
||||
if (!ImportantTests::passphraseGenerationAndTransformation()) {
|
||||
printf("test passphrase generation and transformation failed\n");
|
||||
return -2;
|
||||
return -3;
|
||||
}
|
||||
|
||||
Gradido_LoginServer app;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user