some refactoring
This commit is contained in:
@@ -361,7 +361,8 @@ void savePassword(resp_https_t response, req_https_t request) {
|
|||||||
pt::write_json(config::sunshine.credentials_file, fileTree);
|
pt::write_json(config::sunshine.credentials_file, fileTree);
|
||||||
http::reload_user_creds(config::sunshine.credentials_file);
|
http::reload_user_creds(config::sunshine.credentials_file);
|
||||||
outputTree.put("status", true);
|
outputTree.put("status", true);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
outputTree.put("status", false);
|
outputTree.put("status", false);
|
||||||
outputTree.put("error", "Invalid Current Credentials");
|
outputTree.put("error", "Invalid Current Credentials");
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-11
@@ -340,21 +340,13 @@ void md_ctx_destroy(EVP_MD_CTX *ctx) {
|
|||||||
EVP_MD_CTX_destroy(ctx);
|
EVP_MD_CTX_destroy(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string rand_string(std::size_t bytes) {
|
std::string rand_alphabet(std::size_t bytes, const std::string_view &alphabet) {
|
||||||
std::string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!%&()=-";
|
auto value = rand(bytes);
|
||||||
std::string value = rand(bytes);
|
|
||||||
for(std::size_t i = 0; i != value.size(); ++i) {
|
for(std::size_t i = 0; i != value.size(); ++i) {
|
||||||
value[i] = alphabet[value[i] % alphabet.length()];
|
value[i] = alphabet[value[i] % alphabet.length()];
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string hash_hexstr(const std::string_view &plaintext) {
|
|
||||||
sha256_t hashBytes = crypto::hash(plaintext);
|
|
||||||
std::ostringstream hashStream;
|
|
||||||
hashStream << std::hex << std::setfill('0');
|
|
||||||
std::for_each(hashBytes.cbegin(), hashBytes.cend(), [&](int c) { hashStream << std::setw(2) << c; });
|
|
||||||
std::string hashString = hashStream.str();
|
|
||||||
return hashString;
|
|
||||||
}
|
|
||||||
} // namespace crypto
|
} // namespace crypto
|
||||||
+3
-2
@@ -36,7 +36,7 @@ using bio_t = util::safe_ptr<BIO, BIO_free_all>;
|
|||||||
using pkey_t = util::safe_ptr<EVP_PKEY, EVP_PKEY_free>;
|
using pkey_t = util::safe_ptr<EVP_PKEY, EVP_PKEY_free>;
|
||||||
|
|
||||||
sha256_t hash(const std::string_view &plaintext);
|
sha256_t hash(const std::string_view &plaintext);
|
||||||
std::string hash_hexstr(const std::string_view &plaintext);
|
|
||||||
aes_t gen_aes_key(const std::array<uint8_t, 16> &salt, const std::string_view &pin);
|
aes_t gen_aes_key(const std::array<uint8_t, 16> &salt, const std::string_view &pin);
|
||||||
|
|
||||||
x509_t x509(const std::string_view &x);
|
x509_t x509(const std::string_view &x);
|
||||||
@@ -52,7 +52,8 @@ creds_t gen_creds(const std::string_view &cn, std::uint32_t key_bits);
|
|||||||
std::string_view signature(const x509_t &x);
|
std::string_view signature(const x509_t &x);
|
||||||
|
|
||||||
std::string rand(std::size_t bytes);
|
std::string rand(std::size_t bytes);
|
||||||
std::string rand_string(std::size_t bytes);
|
std::string rand_alphabet(std::size_t bytes,
|
||||||
|
const std::string_view &alphabet = std::string_view { "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!%&()=-" });
|
||||||
|
|
||||||
class cert_chain_t {
|
class cert_chain_t {
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -68,8 +68,8 @@ int generate_user_creds(const std::string &file) {
|
|||||||
pt::ptree outputTree;
|
pt::ptree outputTree;
|
||||||
try {
|
try {
|
||||||
std::string username = "sunshine";
|
std::string username = "sunshine";
|
||||||
std::string plainPassword = crypto::rand_string(16);
|
std::string plainPassword = crypto::rand_alphabet(16);
|
||||||
std::string salt = crypto::rand_string(16);
|
std::string salt = crypto::rand_alphabet(16);
|
||||||
outputTree.put("username", "sunshine");
|
outputTree.put("username", "sunshine");
|
||||||
outputTree.put("salt", salt);
|
outputTree.put("salt", salt);
|
||||||
outputTree.put("password", util::hex(crypto::hash(plainPassword + salt)).to_string());
|
outputTree.put("password", util::hex(crypto::hash(plainPassword + salt)).to_string());
|
||||||
|
|||||||
Reference in New Issue
Block a user