LDAP: enable ldap admin password encryption to avoid having clear password in the configuration file -refs BT#20849
parent
66e8f9d63b
commit
a528ca1375
@ -0,0 +1,52 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
/** |
||||
* This script is to generate the encrypted password for LDAP admin to be used |
||||
* when the parameter "ldap_encrypt_admin_password" is set to true |
||||
* this encrypted password will be decrypted by the function api_decrypt_ldap_password |
||||
*/ |
||||
|
||||
//exit; |
||||
|
||||
require_once __DIR__.'/../../main/inc/global.inc.php'; |
||||
|
||||
// Usage |
||||
echo "This generate the encryption of the password passed in parameter.".PHP_EOL; |
||||
|
||||
$password = ''; |
||||
if (!empty($argv[1])) { |
||||
$password = $argv[1]; |
||||
} else { |
||||
echo "Password not defined in parameter. Please try again, passing it as argument to this script".PHP_EOL; |
||||
echo "Usage: php ldap_encrypt_admin_password.php password".PHP_EOL; |
||||
echo " password The original clear ldap admin's password".PHP_EOL; |
||||
exit(); |
||||
} |
||||
|
||||
if (!empty(api_get_configuration_value('ldap_encrypt_admin_password'))) { |
||||
echo "The encrypted password is : " . encrypt(api_get_configuration_value('ldap_encrypt_admin_password'), $password) .PHP_EOL; |
||||
} else { |
||||
echo "There is no salt defined in app/config/configuration.php for variable 'ldap_admin_password_salt'".PHP_EOL.PHP_EOL; |
||||
} |
||||
|
||||
|
||||
function encrypt($secret, $data) |
||||
{ |
||||
$secret = hex2bin($secret); |
||||
$iv = random_bytes(12); |
||||
$tag = ''; |
||||
|
||||
$encrypted = openssl_encrypt( |
||||
$data, |
||||
'aes-256-gcm', |
||||
$secret, |
||||
OPENSSL_RAW_DATA, |
||||
$iv, |
||||
$tag, |
||||
'', |
||||
16 |
||||
); |
||||
|
||||
return base64_encode($iv) . base64_encode($encrypted . $tag); |
||||
} |
Loading…
Reference in new issue