forked from psychogenic/SerialUI
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
psychogenic
committed
Jun 10, 2019
1 parent
528b0a0
commit cbb1976
Showing
18 changed files
with
773 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* AuthSimple.cpp | ||
* | ||
* Created on: Jun 6, 2019 | ||
* Author: malcalypse | ||
*/ | ||
|
||
#include "includes/auth/AuthSimple.h" | ||
|
||
#ifdef SERIALUI_AUTHENTICATOR_ENABLE | ||
|
||
namespace SerialUI { | ||
namespace Auth { | ||
|
||
Simple::Simple(Passphrase adminPass, Passphrase userPass, | ||
Passphrase guestPass) : | ||
pass_store(adminPass, userPass, guestPass), | ||
eq_validator(&pass_store), | ||
Authenticator(&eq_validator) | ||
{ | ||
|
||
|
||
} | ||
|
||
|
||
} /* namespace Auth */ | ||
} /* namespace SerialUI */ | ||
|
||
|
||
#endif /* SERIALUI_AUTHENTICATOR_ENABLE */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* AuthStorage.cpp | ||
* | ||
* Created on: Jun 6, 2019 | ||
* Author: malcalypse | ||
*/ | ||
|
||
#include "includes/auth/AuthStorage.h" | ||
|
||
namespace SerialUI { | ||
namespace Auth { | ||
|
||
Storage::Storage() { | ||
|
||
} | ||
|
||
Storage::~Storage() { | ||
} | ||
|
||
} /* namespace Auth */ | ||
} /* namespace SerialUI */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* AuthStoragePython.cpp | ||
* | ||
* Created on: Jun 7, 2019 | ||
* Author: malcalypse | ||
*/ | ||
|
||
#include "includes/auth/AuthStoragePython.h" | ||
|
||
#if defined(SERIALUI_AUTHENTICATOR_ENABLE) and defined(SERIALUI_PYTHONMODULES_SUPPORT_ENABLE) | ||
#include "includes/SUIGlobals.h" | ||
|
||
#define SUIHAVE_EXTERNAL_STORAGE_AVAILABLE() \ | ||
(Globals::pythonModule() && Globals::pythonModule()->authStorage()) | ||
|
||
namespace SerialUI { | ||
namespace Auth { | ||
|
||
StoragePython::StoragePython() : Storage() { | ||
} | ||
|
||
bool StoragePython::configured(Level::Value forLevel) { | ||
if (! SUIHAVE_EXTERNAL_STORAGE_AVAILABLE()) { | ||
return false; | ||
} | ||
return Globals::pythonModule()->authStorage()->configured(forLevel); | ||
|
||
} | ||
|
||
Passphrase StoragePython::passphrase(Level::Value forLevel) { | ||
if (! SUIHAVE_EXTERNAL_STORAGE_AVAILABLE()) { | ||
return NULL; | ||
} | ||
return Globals::pythonModule()->authStorage()->passphrase(forLevel); | ||
|
||
} | ||
|
||
bool StoragePython::setPassphrase(Passphrase pass, Level::Value forLevel) { | ||
if (! SUIHAVE_EXTERNAL_STORAGE_AVAILABLE()) { | ||
return false; | ||
} | ||
return Globals::pythonModule()->authStorage()->setPassphrase(pass, forLevel); | ||
|
||
} | ||
|
||
} /* namespace Auth */ | ||
} /* namespace SerialUI */ | ||
|
||
#endif /* SERIALUI_AUTHENTICATOR_ENABLE and SERIALUI_PYTHONMODULES_SUPPORT_ENABLE */ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* AuthStorageStatic.cpp | ||
* | ||
* Created on: Jun 6, 2019 | ||
* Author: malcalypse | ||
*/ | ||
|
||
#include "includes/auth/AuthStorageStatic.h" | ||
|
||
#ifdef SERIALUI_AUTHENTICATOR_ENABLE | ||
namespace SerialUI { | ||
namespace Auth { | ||
|
||
StorageStatic::StorageStatic(Passphrase adminPass, | ||
Passphrase userPass, | ||
Passphrase guestPass) : Storage() | ||
{ | ||
stored_pass[(uint8_t)Level::NoAccess] = NULL; | ||
stored_pass[(uint8_t)Level::Guest] = guestPass; | ||
stored_pass[(uint8_t)Level::User] = userPass; | ||
stored_pass[(uint8_t)Level::Admin] = adminPass; | ||
for (uint8_t i=0; i<4; i++) { | ||
uconfiged_pass[i] = NULL; | ||
} | ||
|
||
} | ||
|
||
bool StorageStatic::setPassphrase(Passphrase pass, Level::Value forLevel) { | ||
uint8_t levIdx = (uint8_t)forLevel; | ||
if (uconfiged_pass[levIdx]) { | ||
delete[] uconfiged_pass[levIdx]; | ||
} | ||
if (! pass) { | ||
uconfiged_pass[levIdx] = NULL; | ||
stored_pass[levIdx] = NULL; | ||
return true; | ||
} | ||
uint8_t passLen = strlen(pass); | ||
|
||
uconfiged_pass[levIdx] = new char[passLen + 1]; | ||
if (! uconfiged_pass[levIdx]) { | ||
return false; | ||
} | ||
uconfiged_pass[levIdx][passLen] = 0; | ||
strcpy(uconfiged_pass[levIdx], pass); | ||
stored_pass[levIdx] = uconfiged_pass[levIdx]; | ||
return true; | ||
} | ||
bool StorageStatic::configured(Level::Value forLevel) { | ||
if (! stored_pass[(uint8_t)forLevel]) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
Passphrase StorageStatic::passphrase(Level::Value forLevel) { | ||
return stored_pass[(uint8_t)forLevel]; | ||
} | ||
|
||
} /* namespace Auth */ | ||
} /* namespace SerialUI */ | ||
|
||
|
||
#endif /* SERIALUI_AUTHENTICATOR_ENABLE */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* AuthValidator.cpp | ||
* | ||
* Created on: Jun 6, 2019 | ||
* Author: malcalypse | ||
*/ | ||
|
||
#include "includes/auth/AuthValidator.h" | ||
|
||
namespace SerialUI { | ||
namespace Auth { | ||
|
||
Validator::Validator(Storage * storage) : auth_store(storage) { | ||
|
||
|
||
} | ||
|
||
Validator::~Validator() { | ||
} | ||
|
||
} /* namespace Auth */ | ||
} /* namespace SerialUI */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* AuthValidatorEquality.cpp | ||
* | ||
* Created on: Jun 6, 2019 | ||
* Author: malcalypse | ||
*/ | ||
|
||
#include "includes/auth/AuthValidatorEquality.h" | ||
|
||
#ifdef SERIALUI_AUTHENTICATOR_ENABLE | ||
namespace SerialUI { | ||
namespace Auth { | ||
|
||
ValidatorEquality::ValidatorEquality(Storage * storage) : Validator(storage) { | ||
|
||
} | ||
|
||
|
||
Level::Value ValidatorEquality::grantAccess(ChallengeResponse resp) { | ||
Level::Value testLevels[] = { | ||
Level::Guest, | ||
Level::User, | ||
Level::Admin, | ||
Level::NoAccess | ||
}; | ||
SERIALUI_DEBUG_OUT(SUI_STR("ValidatorEQ ")); | ||
if (! (resp && strlen(resp))) { | ||
SERIALUI_DEBUG_OUTLN(SUI_STR("nothing2chk")); | ||
return Level::NoAccess; | ||
} | ||
|
||
if (!storage()->configured()) { | ||
SERIALUI_DEBUG_OUTLN(SUI_STR("unconfig")); | ||
return Level::NoAccess; | ||
} | ||
uint8_t idx = 0; | ||
while (testLevels[idx] != Level::NoAccess) { | ||
Passphrase pass = storage()->passphrase(testLevels[idx]); | ||
|
||
if (pass) { | ||
SERIALUI_DEBUG_OUT(SUI_STR("comparing '")); | ||
SERIALUI_DEBUG_OUT(resp); | ||
SERIALUI_DEBUG_OUT(SUI_STR("' to ")); | ||
SERIALUI_DEBUG_OUTLN(pass); | ||
int cmpval = strcmp(pass, resp) ; | ||
if (cmpval == 0) { | ||
SERIALUI_DEBUG_OUTLN(SUI_STR("HUZZAH")); | ||
return testLevels[idx]; | ||
} else { | ||
SERIALUI_DEBUG_OUTLN(cmpval); | ||
} | ||
} | ||
idx++; | ||
} | ||
return Level::NoAccess; | ||
|
||
} | ||
|
||
} /* namespace Auth */ | ||
} /* namespace SerialUI */ | ||
|
||
|
||
#endif /* SERIALUI_AUTHENTICATOR_ENABLE */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* AuthValidatorPython.cpp | ||
* | ||
* Created on: Jun 7, 2019 | ||
* Author: malcalypse | ||
*/ | ||
|
||
#include "includes/auth/AuthValidatorPython.h" | ||
|
||
#if defined(SERIALUI_AUTHENTICATOR_ENABLE) and defined(SERIALUI_PYTHONMODULES_SUPPORT_ENABLE) | ||
#include "includes/SUIGlobals.h" | ||
|
||
#define SUIHAVE_EXTERNAL_VALIDATOR_AVAILABLE() \ | ||
(Globals::pythonModule() && Globals::pythonModule()->authValidator()) | ||
|
||
namespace SerialUI { | ||
namespace Auth { | ||
|
||
ValidatorPython::ValidatorPython(Storage * storage) : Validator(storage) { | ||
|
||
|
||
} | ||
|
||
Challenge ValidatorPython::challenge(Level::Value forLevel) { | ||
if (! SUIHAVE_EXTERNAL_VALIDATOR_AVAILABLE()) { | ||
SERIALUI_DEBUG_OUTLN(F("No ext validator")); | ||
return NULL; | ||
} | ||
|
||
return Globals::pythonModule()->authValidator()->challenge(forLevel); | ||
|
||
} | ||
|
||
Level::Value ValidatorPython::grantAccess(ChallengeResponse resp) { | ||
if (! SUIHAVE_EXTERNAL_VALIDATOR_AVAILABLE()) { | ||
SERIALUI_DEBUG_OUTLN(F("No ext validator")); | ||
return Level::NoAccess; | ||
} | ||
|
||
return Globals::pythonModule()->authValidator()->grantAccess(resp); | ||
|
||
} | ||
|
||
Transmission::Type::Value ValidatorPython::communicationType() { | ||
if (! SUIHAVE_EXTERNAL_VALIDATOR_AVAILABLE()) { | ||
SERIALUI_DEBUG_OUTLN(F("No ext validator")); | ||
return Transmission::Type::Custom; | ||
} | ||
|
||
return Globals::pythonModule()->authValidator()->communicationType(); | ||
|
||
} | ||
|
||
} /* namespace Auth */ | ||
} /* namespace SerialUI */ | ||
|
||
#endif /* SERIALUI_AUTHENTICATOR_ENABLE and SERIALUI_PYTHONMODULES_SUPPORT_ENABLE */ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Authenticator.cpp | ||
* | ||
* Created on: Jun 6, 2019 | ||
* Author: malcalypse | ||
*/ | ||
|
||
#include "includes/auth/Authenticator.h" | ||
|
||
#ifdef SERIALUI_AUTHENTICATOR_ENABLE | ||
|
||
namespace SerialUI { | ||
namespace Auth { | ||
|
||
Authenticator::Authenticator(Validator * validator) : | ||
auth_validator(validator), | ||
current_level(Level::NoAccess) | ||
{ | ||
|
||
} | ||
|
||
|
||
bool Authenticator::configured() { return auth_validator->configured();} | ||
bool Authenticator::setPassphrase(Passphrase pass, Level::Value forLevel) { | ||
return auth_validator->storage()->setPassphrase(pass, forLevel); | ||
} | ||
|
||
Challenge Authenticator::challenge(Level::Value forLevel) { | ||
return auth_validator->challenge(forLevel); | ||
} | ||
Level::Value Authenticator::grantAccess(ChallengeResponse resp) { | ||
current_level = auth_validator->grantAccess(resp); | ||
return current_level; | ||
} | ||
|
||
bool Authenticator::accessIsAtLeast(Level::Value lev) { | ||
return ((uint8_t)current_level >= lev); | ||
|
||
} | ||
|
||
Transmission::Type::Value Authenticator::encoding() { | ||
return auth_validator->communicationType(); | ||
} | ||
|
||
|
||
} /* namespace Auth */ | ||
} /* namespace SerialUI */ | ||
|
||
#endif /* SERIALUI_AUTHENTICATOR_ENABLE */ |
Oops, something went wrong.