|
Removed
Link Here
|
| 1 |
--- credentials.cc.orig 2021-11-23 18:39:17 UTC |
| 2 |
+++ credentials.cc |
| 3 |
@@ -28,7 +28,7 @@ |
| 4 |
#include <sodium.h> |
| 5 |
#endif |
| 6 |
|
| 7 |
-#ifdef HAVE_EVP_PKEY_CTX_SET1_SCRYPT_SALT |
| 8 |
+#if defined(HAVE_EVP_PKEY_CTX_SET1_SCRYPT_SALT) && defined(EVP_PKEY_SCRYPT) |
| 9 |
#include <openssl/evp.h> |
| 10 |
#include <openssl/kdf.h> |
| 11 |
#include <openssl/rand.h> |
| 12 |
@@ -42,7 +42,7 @@ |
| 13 |
#include "credentials.hh" |
| 14 |
#include "misc.hh" |
| 15 |
|
| 16 |
-#ifdef HAVE_EVP_PKEY_CTX_SET1_SCRYPT_SALT |
| 17 |
+#if defined(HAVE_EVP_PKEY_CTX_SET1_SCRYPT_SALT) && defined(EVP_PKEY_SCRYPT) |
| 18 |
static size_t const pwhash_max_size = 128U; /* maximum size of the output */ |
| 19 |
static size_t const pwhash_output_size = 32U; /* size of the hashed output (before base64 encoding) */ |
| 20 |
static unsigned int const pwhash_salt_size = 16U; /* size of the salt (before base64 encoding */ |
| 21 |
@@ -95,7 +95,7 @@ void SensitiveData::clear() |
| 22 |
|
| 23 |
static std::string hashPasswordInternal(const std::string& password, const std::string& salt, uint64_t workFactor, uint64_t parallelFactor, uint64_t blockSize) |
| 24 |
{ |
| 25 |
-#ifdef HAVE_EVP_PKEY_CTX_SET1_SCRYPT_SALT |
| 26 |
+#if defined(HAVE_EVP_PKEY_CTX_SET1_SCRYPT_SALT) && defined(EVP_PKEY_SCRYPT) |
| 27 |
auto pctx = std::unique_ptr<EVP_PKEY_CTX, void (*)(EVP_PKEY_CTX*)>(EVP_PKEY_CTX_new_id(EVP_PKEY_SCRYPT, nullptr), EVP_PKEY_CTX_free); |
| 28 |
if (!pctx) { |
| 29 |
throw std::runtime_error("Error getting a scrypt context to hash the supplied password"); |
| 30 |
@@ -142,7 +142,7 @@ static std::string hashPasswordInternal(const std::str |
| 31 |
|
| 32 |
static std::string generateRandomSalt() |
| 33 |
{ |
| 34 |
-#ifdef HAVE_EVP_PKEY_CTX_SET1_SCRYPT_SALT |
| 35 |
+#if defined(HAVE_EVP_PKEY_CTX_SET1_SCRYPT_SALT) && defined(EVP_PKEY_SCRYPT) |
| 36 |
/* generate a random salt */ |
| 37 |
std::string salt; |
| 38 |
salt.resize(pwhash_salt_size); |
| 39 |
@@ -159,7 +159,7 @@ static std::string generateRandomSalt() |
| 40 |
|
| 41 |
std::string hashPassword(const std::string& password, uint64_t workFactor, uint64_t parallelFactor, uint64_t blockSize) |
| 42 |
{ |
| 43 |
-#ifdef HAVE_EVP_PKEY_CTX_SET1_SCRYPT_SALT |
| 44 |
+#if defined(HAVE_EVP_PKEY_CTX_SET1_SCRYPT_SALT) && defined(EVP_PKEY_SCRYPT) |
| 45 |
std::string result; |
| 46 |
result.reserve(pwhash_max_size); |
| 47 |
|
| 48 |
@@ -187,7 +187,7 @@ std::string hashPassword(const std::string& password, |
| 49 |
|
| 50 |
std::string hashPassword(const std::string& password) |
| 51 |
{ |
| 52 |
-#ifdef HAVE_EVP_PKEY_CTX_SET1_SCRYPT_SALT |
| 53 |
+#if defined(HAVE_EVP_PKEY_CTX_SET1_SCRYPT_SALT) && defined(EVP_PKEY_SCRYPT) |
| 54 |
return hashPassword(password, CredentialsHolder::s_defaultWorkFactor, CredentialsHolder::s_defaultParallelFactor, CredentialsHolder::s_defaultBlockSize); |
| 55 |
#else |
| 56 |
throw std::runtime_error("Hashing a password requires scrypt support in OpenSSL, and it is not available"); |
| 57 |
@@ -196,7 +196,7 @@ std::string hashPassword(const std::string& password) |
| 58 |
|
| 59 |
bool verifyPassword(const std::string& binaryHash, const std::string& salt, uint64_t workFactor, uint64_t parallelFactor, uint64_t blockSize, const std::string& binaryPassword) |
| 60 |
{ |
| 61 |
-#ifdef HAVE_EVP_PKEY_CTX_SET1_SCRYPT_SALT |
| 62 |
+#if defined(HAVE_EVP_PKEY_CTX_SET1_SCRYPT_SALT) && defined(EVP_PKEY_SCRYPT) |
| 63 |
auto expected = hashPasswordInternal(binaryPassword, salt, workFactor, parallelFactor, blockSize); |
| 64 |
return constantTimeStringEquals(expected, binaryHash); |
| 65 |
#else |
| 66 |
@@ -207,7 +207,7 @@ bool verifyPassword(const std::string& binaryHash, con |
| 67 |
/* parse a hashed password in PHC string format */ |
| 68 |
static void parseHashed(const std::string& hash, std::string& salt, std::string& hashedPassword, uint64_t& workFactor, uint64_t& parallelFactor, uint64_t& blockSize) |
| 69 |
{ |
| 70 |
-#ifdef HAVE_EVP_PKEY_CTX_SET1_SCRYPT_SALT |
| 71 |
+#if defined(HAVE_EVP_PKEY_CTX_SET1_SCRYPT_SALT) && defined(EVP_PKEY_SCRYPT) |
| 72 |
auto parametersEnd = hash.find('$', pwhash_prefix.size()); |
| 73 |
if (parametersEnd == std::string::npos || parametersEnd == hash.size()) { |
| 74 |
throw std::runtime_error("Invalid hashed password format, no parameters"); |
| 75 |
@@ -276,7 +276,7 @@ bool verifyPassword(const std::string& hash, const std |
| 76 |
return false; |
| 77 |
} |
| 78 |
|
| 79 |
-#ifdef HAVE_EVP_PKEY_CTX_SET1_SCRYPT_SALT |
| 80 |
+#if defined(HAVE_EVP_PKEY_CTX_SET1_SCRYPT_SALT) && defined(EVP_PKEY_SCRYPT) |
| 81 |
std::string salt; |
| 82 |
std::string hashedPassword; |
| 83 |
uint64_t workFactor = 0; |
| 84 |
@@ -294,7 +294,7 @@ bool verifyPassword(const std::string& hash, const std |
| 85 |
|
| 86 |
bool isPasswordHashed(const std::string& password) |
| 87 |
{ |
| 88 |
-#ifdef HAVE_EVP_PKEY_CTX_SET1_SCRYPT_SALT |
| 89 |
+#if defined(HAVE_EVP_PKEY_CTX_SET1_SCRYPT_SALT) && defined(EVP_PKEY_SCRYPT) |
| 90 |
if (password.size() < pwhash_prefix_size || password.size() > pwhash_max_size) { |
| 91 |
return false; |
| 92 |
} |
| 93 |
@@ -389,7 +389,7 @@ bool CredentialsHolder::matches(const std::string& pas |
| 94 |
|
| 95 |
bool CredentialsHolder::isHashingAvailable() |
| 96 |
{ |
| 97 |
-#ifdef HAVE_EVP_PKEY_CTX_SET1_SCRYPT_SALT |
| 98 |
+#if defined(HAVE_EVP_PKEY_CTX_SET1_SCRYPT_SALT) && defined(EVP_PKEY_SCRYPT) |
| 99 |
return true; |
| 100 |
#else |
| 101 |
return false; |