Skip to content

Commit 59b7a81

Browse files
authored
Allow the use of yescrypt (hestiacp#2499)
* Allow yescrypt to be used * Add support for Yescrypt for user login * Fix comment Add option to return hash if needed for next script * Remove downgrade from yesscrypt to sha512 * Fix php error
1 parent 1084a16 commit 59b7a81

File tree

5 files changed

+41
-20
lines changed

5 files changed

+41
-20
lines changed

bin/v-check-user-hash

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ if echo "$shadow" | grep -qE '^\$[0-9a-z]+\$[^\$]+\$'
6262
then
6363
salt=$(echo "$shadow" |cut -f 3 -d \$)
6464
method=$(echo "$shadow" |cut -f 2 -d \$)
65-
if [ "$method" -eq '1' ]; then
65+
if [ "$method" = "y" ]; then
66+
method="yescrypt"
67+
elif [ "$method" -eq '1' ]; then
6668
method='md5'
6769
elif [ "$method" -eq '6' ]; then
6870
method='sha-512'

bin/v-check-user-password

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22
# info: check user password
3-
# options: USER PASSWORD [IP]
3+
# options: USER PASSWORD [IP] [RETURN_HASH]
44
#
55
# example: v-check-user-password admin qwerty1234
66
#
@@ -14,6 +14,7 @@
1414
user=$1
1515
password=$2; HIDE=2
1616
ip=${3-127.0.0.1}
17+
return_hash=$4
1718

1819
# Includes
1920
# shellcheck source=/etc/hestiacp/hestia.conf
@@ -31,11 +32,11 @@ date=$(echo "$time_n_date" |cut -f 2 -d \ )
3132
# Verifications #
3233
#----------------------------------------------------------#
3334

34-
check_args '2' "$#" 'USER PASSWORD'
35+
check_args '2' "$#" 'USER PASSWORD RETURN_HASH'
3536
is_format_valid 'user'
3637

3738
# Checking user
38-
if [ ! -d "$HESTIA/data/users/$user" ] && [ "$user" != 'root' ]; then
39+
if [ ! -d "$HESTIA/data/users/$user" ]; then
3940
echo "Error: password missmatch"
4041
echo "$date $time $user $ip failed to login" >> $HESTIA/log/auth.log
4142
exit 9
@@ -63,8 +64,7 @@ then
6364
salt=$(echo "$shadow" |cut -f 3 -d \$)
6465
method=$(echo "$shadow" |cut -f 2 -d \$)
6566
if [ "$method" = "y" ]; then
66-
echo "Unsuported hash method";
67-
exit 1;
67+
method="yescrypt"
6868
elif [ "$method" -eq '1' ]; then
6969
method='md5'
7070
elif [ "$method" -eq '6' ]; then
@@ -85,13 +85,22 @@ if [ -z "$salt" ]; then
8585
exit 9
8686
fi
8787

88-
# Generating hash
89-
set -o noglob
90-
hash=$($BIN/v-generate-password-hash "$method" "$salt" <<< "$password")
91-
if [[ -z "$hash" ]]; then
92-
echo "Error: password missmatch"
93-
echo "$date $time $user $ip failed to login" >> $HESTIA/log/auth.log
94-
exit 9
88+
if [ "$method" = "yescrypt" ]; then
89+
hash=$(mkpasswd "$password" "$shadow")
90+
if [ $? -ne 0 ]; then
91+
echo "Error: password missmatch"
92+
echo "$date $time $user $ip failed to login" >> $HESTIA/log/auth.log
93+
exit 9
94+
fi
95+
else
96+
# Generating hash
97+
set -o noglob
98+
hash=$($BIN/v-generate-password-hash "$method" "$salt" <<< "$password")
99+
if [[ -z "$hash" ]]; then
100+
echo "Error: password missmatch"
101+
echo "$date $time $user $ip failed to login" >> $HESTIA/log/auth.log
102+
exit 9
103+
fi
95104
fi
96105

97106
# Checking hash
@@ -106,6 +115,9 @@ fi
106115
# Hestia #
107116
#----------------------------------------------------------#
108117

118+
if [ -n "$return_hash" ]; then
119+
echo $hash;
120+
fi
109121
# Logging
110122
echo "$date $time $user $ip successfully logged in" >> $HESTIA/log/auth.log
111123

bin/v-get-user-salt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,10 @@ if echo "$shadow" | grep -qE '^\$[0-9a-z]+\$[^\$]+\$'
8484
then
8585
salt=$(echo "$shadow" |cut -f 3 -d \$)
8686
method=$(echo "$shadow" |cut -f 2 -d \$)
87-
if [ "$method" -eq '1' ]; then
87+
if [ "$method" = "y" ]; then
88+
method='yescrypt'
89+
salt=$(echo "$shadow" |cut -f 4 -d \$)
90+
elif [ "$method" -eq '1' ]; then
8891
method='md5'
8992
elif [ "$method" -eq '6' ]; then
9093
method='sha-512'

install/hst-install-debian.sh

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,12 +1300,6 @@ echo "[ * ] Enable SFTP jail..."
13001300
$HESTIA/bin/v-add-sys-sftp-jail > /dev/null 2>&1
13011301
check_result $? "can't enable sftp jail"
13021302

1303-
# Switch to sha512 for deb11.
1304-
if [ "$release" -eq 11 ]; then
1305-
# Switching to sha512
1306-
sed -i "s/ yescrypt/ sha512/g" /etc/pam.d/common-password
1307-
fi
1308-
13091303
# Adding Hestia admin account
13101304
$HESTIA/bin/v-add-user admin $vpass $email "system" "System Administrator"
13111305
check_result $? "can't create admin user"

web/login/index.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ function authenticate_user($user, $password, $twofa = '')
107107
$output = '';
108108
exec(HESTIA_CMD . 'v-get-user-salt ' . $v_user . ' ' . $v_ip . ' json', $output, $return_var);
109109
$pam = json_decode(implode('', $output), true);
110+
unset($output);
110111
if ($return_var > 0) {
111112
sleep(2);
112113
if ($return_var == 5) {
@@ -128,6 +129,15 @@ function authenticate_user($user, $password, $twofa = '')
128129
$hash = crypt($password, '$6$rounds=5000$' . $salt . '$');
129130
$hash = str_replace('$rounds=5000', '', $hash);
130131
}
132+
if ($method == 'yescrypt') {
133+
$v_password = tempnam("/tmp", "vst");
134+
$fp = fopen($v_password, "w");
135+
fwrite($fp, $_POST['password']."\n");
136+
fclose($fp);
137+
exec(HESTIA_CMD . 'v-check-user-password '. $v_user.' '. $v_password. ' '.$v_ip.' yes', $output, $return_var);
138+
$hash = $output[0];
139+
unset($output);
140+
}
131141
if ($method == 'des') {
132142
$hash = crypt($password, $salt);
133143
}

0 commit comments

Comments
 (0)