Skip to content

Commit 88b3275

Browse files
authored
Improve default encoding dovecot with ARGON2ID (hestiacp#2421)
* Improve default encoding dovecot with ARGON2ID Instead of insecure md5 * Fix issue when ARGONID is not supported
1 parent 754a247 commit 88b3275

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

bin/v-add-mail-account

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,14 @@ check_hestia_demo_mode
5858
#----------------------------------------------------------#
5959

6060
# Generating hashed password
61-
salt=$(generate_password "$PW_MATRIX" "8")
62-
md5="{MD5}$($BIN/v-generate-password-hash md5 $salt <<<$password)"
63-
61+
if [ -n "$(doveadm pw -l | grep ARGON2ID)" ]; then
62+
set +H # disable ! style history substitution
63+
md5="$(doveadm pw -s ARGON2ID -p $password)"
64+
else
65+
# Fall back on MD5
66+
salt=$(generate_password "$PW_MATRIX" "8")
67+
md5="{MD5}$($BIN/v-generate-password-hash md5 $salt <<<$password)"
68+
fi
6469
# Adding account info into password file
6570
if [[ "$MAIL_SYSTEM" =~ exim ]]; then
6671
if [ "$quota" = 'unlimited' ]; then

bin/v-change-mail-account-password

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,13 @@ check_hestia_demo_mode
5656
#----------------------------------------------------------#
5757

5858
# Generating hashed password
59-
salt=$(generate_password "$PW_MATRIX" "8")
60-
md5="{MD5}$($BIN/v-generate-password-hash md5 $salt <<<$password)"
59+
if [ -n "$(doveadm pw -l | grep ARGON2ID)" ]; then
60+
set +H # disable ! style history substitution
61+
md5="$(doveadm pw -s ARGON2ID -p $password)"
62+
else
63+
salt=$(generate_password "$PW_MATRIX" "8")
64+
md5="{MD5}$($BIN/v-generate-password-hash md5 $salt <<<$password)"
65+
fi
6166

6267
if [[ "$MAIL_SYSTEM" =~ exim ]]; then
6368
quota=$(get_object_value "mail/$domain" 'ACCOUNT' "$account" '$QUOTA')

web/reset/mail/index.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,18 @@ function to64 ($v, $n)
143143
// Compare hashes
144144
if (!empty($v_hash)) {
145145
$salt = explode('$', $v_hash);
146+
if($salt[0] == "{MD5}"){
146147
$n_hash = md5crypt($v_password, $salt[2]);
147148
$n_hash = '{MD5}'.$n_hash;
148-
149+
}else{
150+
$v_password = escapeshellarg($v_password);
151+
exec("doveadm pw -s ARGON2ID -p $v_password -t '$v_hash'", $output, $return_var);
152+
if ($return_var == 0) {
153+
if (strpos($output, "(verified)") !== 0){
154+
$n_hash = $v_hash;
155+
}
156+
}
157+
}
149158
// Change password
150159
if ( $v_hash == $n_hash ) {
151160
$v_new_password = tempnam("/tmp","vst");

0 commit comments

Comments
 (0)