27define(
'MAIN_SECURITY_REVERSIBLE_ALGO',
'AES-256-CTR');
41 if (isset($_SERVER[
'HTTPS']) && $_SERVER[
'HTTPS'] ==
'on') {
43 } elseif (!empty($_SERVER[
'HTTP_X_FORWARDED_PROTO']) && $_SERVER[
'HTTP_X_FORWARDED_PROTO'] ==
'https' || !empty($_SERVER[
'HTTP_X_FORWARDED_SSL']) && $_SERVER[
'HTTP_X_FORWARDED_SSL'] ==
'on') {
63function dolEncrypt($chain, $key =
'', $ciphering =
'', $forceseed =
'', $obfuscationmode =
'dolcrypt')
66 global $dolibarr_disable_dolcrypt_for_debug;
68 if ($chain ===
'' || is_null($chain)) {
73 if (preg_match(
'/^(dolobfuscationv1[^:]+|dolcrypt):([^:]+):(.+)$/', $chain, $reg)) {
79 if (!empty(
$conf->file->dolcrypt_key)) {
80 $key =
$conf->file->dolcrypt_key;
83 $key =
$conf->file->instance_unique_id;
86 if (empty($ciphering)) {
87 $ciphering = constant(
'MAIN_SECURITY_REVERSIBLE_ALGO');
92 if (function_exists(
'openssl_encrypt') && empty($dolibarr_disable_dolcrypt_for_debug)) {
98 if (function_exists(
'openssl_cipher_iv_length')) {
99 $ivlen = openssl_cipher_iv_length($ciphering);
101 if ($ivlen ===
false || $ivlen < 1 || $ivlen > 32) {
104 if (empty($forceseed)) {
107 $ivseed =
dol_substr(md5($forceseed), 0, $ivlen,
'ascii', 1);
111 $key = preg_replace(
'/,.*$/',
'', $key);
113 $newchain = openssl_encrypt($chain, $ciphering, $key, 0, $ivseed);
115 return $obfuscationmode.
':'.$ciphering.
':'.$ivseed.
':'.$newchain;
136 if ($chain ===
'' || is_null($chain)) {
143 if (!empty(
$conf->file->dolcrypt_key)) {
145 $key =
$conf->file->dolcrypt_key;
148 $key = !empty(
$conf->file->instance_unique_id) ?
$conf->file->instance_unique_id :
"";
155 if (preg_match(
'/^crypted:(.+)$/', $chain, $reg)) {
160 if (preg_match(
'/^dol[^:]+:([^:]+):(.+)$/', $chain, $reg)) {
164 $ciphering = $reg[1];
165 if (function_exists(
'openssl_decrypt')) {
167 dol_syslog(
"Error dolDecrypt decrypt key is empty", LOG_WARNING);
170 $tmpexplode = explode(
':', $reg[2]);
171 if (!empty($tmpexplode[1])) {
172 $data = $tmpexplode[1];
173 $iv = $tmpexplode[0];
175 $data = (
string) $tmpexplode[0];
179 $keys = explode(
',', $key);
182 foreach ($keys as $tmpkey) {
183 $newchain = openssl_decrypt($data, $ciphering, $tmpkey, 0, $iv);
184 if (!empty($patterntotest) && preg_match(
'/^'.preg_quote($patterntotest,
'/').
'/', $newchain)) {
194 if (empty($savkey)) {
195 dol_syslog(
"Error dolDecrypt failed: The key dolibarr_main_dolcrypt or dolibarr_main_instance_unique_id, found in conf.php file, is the the one used to encrypt this encrypted string", LOG_ERR);
197 dol_syslog(
"Error dolDecrypt failed: The string decoded with the key return a non valid value (not ascii)", LOG_ERR);
202 dol_syslog(
"Error dolDecrypt openssl_decrypt is not available", LOG_ERR);
232function dol_hash($chain, $type =
'0', $nosalt = 0, $mode = 0)
235 if (($type ==
'0' || $type ==
'auto') &&
getDolGlobalString(
'MAIN_SECURITY_HASH_ALGO') ==
'password_hash' && function_exists(
'password_hash')) {
237 if (strpos($chain,
"\0") !==
false) {
239 return array(
'pass_encrypted' =>
'Invalid string to encrypt. Contains a null character',
'pass_encoding' =>
'');
241 return 'Invalid string to encrypt. Contains a null character.';
247 return array(
'pass_encrypted' => password_hash($chain, PASSWORD_DEFAULT),
'pass_encoding' =>
'password_hash');
249 return password_hash($chain, PASSWORD_DEFAULT);
254 if (
getDolGlobalString(
'MAIN_SECURITY_SALT') && $type !=
'4' && $type !==
'openldap' && empty($nosalt)) {
258 if ($type ==
'1' || $type ==
'sha1') {
260 return array(
'pass_encrypted' => sha1($chain),
'pass_encoding' =>
'sha1');
264 } elseif ($type ==
'2' || $type ==
'sha1md5') {
266 return array(
'pass_encrypted' => sha1(md5($chain)),
'pass_encoding' =>
'sha1md5');
268 return sha1(md5($chain));
270 } elseif ($type ==
'3' || $type ==
'md5') {
272 return array(
'pass_encrypted' => md5($chain),
'pass_encoding' =>
'md5');
276 } elseif ($type ==
'4' || $type ==
'openldap') {
282 } elseif ($type ==
'5' || $type ==
'sha256') {
284 return array(
'pass_encrypted' => hash(
'sha256', $chain),
'pass_encoding' =>
'sha256');
286 return hash(
'sha256', $chain);
288 } elseif ($type ==
'6' || $type ==
'password_hash') {
290 return array(
'pass_encrypted' => password_hash($chain, PASSWORD_DEFAULT),
'pass_encoding' =>
'password_hash');
292 return password_hash($chain, PASSWORD_DEFAULT);
296 return array(
'pass_encrypted' => sha1($chain),
'pass_encoding' =>
'sha1');
302 return array(
'pass_encrypted' => sha1(md5($chain)),
'pass_encoding' =>
'sha1md5');
304 return sha1(md5($chain));
310 return array(
'pass_encrypted' => md5($chain),
'pass_encoding' =>
'md5');
330 if ($type ==
'0' &&
getDolGlobalString(
'MAIN_SECURITY_HASH_ALGO') ==
'password_hash' && function_exists(
'password_verify')) {
332 if (! empty($hash[0]) && $hash[0] ==
'$') {
333 return password_verify($chain, $hash);
343 return dol_hash($chain, $type) == $hash;
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_substr($string, $start, $length=null, $stringencoding='', $trunconbytes=0)
Make a substring.
ascii_check($str)
Check if a string is in ASCII.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
dolGetRandomBytes($length)
Return a string of random bytes (hexa string) with length = $length for cryptographic purposes.
dol_decode($chain, $key='1')
Decode a base 64 encoded + specific delta change.
dolGetLdapPasswordHash($password, $type='md5')
Returns a specific ldap hash of a password.
dol_hash($chain, $type='0', $nosalt=0, $mode=0)
Returns a hash (non reversible encryption) of a string.
dolDecrypt($chain, $key='', $patterntotest='')
Decode a string with a symmetric encryption.
isHTTPS()
Return if we are using a HTTPS connection Check HTTPS (no way to be modified by user but may be empty...
dol_verifyHash($chain, $hash, $type='0')
Compute a hash and compare it to the given one For backward compatibility reasons,...
dolEncrypt($chain, $key='', $ciphering='', $forceseed='', $obfuscationmode='dolcrypt')
Encode a string with a symmetric encryption.