Skip to content

Commit fe1ebbc

Browse files
committed
[BugFix] Stricter check of api keys
1 parent 49aed0a commit fe1ebbc

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

bin/v-check-api-key

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,18 @@
1212
# Variable&Function #
1313
#----------------------------------------------------------#
1414

15-
if [ -z "$1" ]; then
15+
[[ -z $HESTIA ]] && HESTIA="/usr/local/hestia"
16+
17+
source $HESTIA/func/main.sh
18+
19+
new_timestamp
20+
21+
abort_missmatch() {
1622
echo "Error: key missmatch"
17-
exit 9
18-
fi
19-
key=$(basename $1)
23+
echo "$date $time api $ip failed to login" >> $HESTIA/log/auth.log
24+
exit $E_PASSWORD
25+
}
26+
2027
ip=${2-127.0.0.1}
2128
time_n_date=$(date +'%T %F')
2229
time=$(echo "$time_n_date" |cut -f 1 -d \ )
@@ -27,11 +34,20 @@ date=$(echo "$time_n_date" |cut -f 2 -d \ )
2734
# Action #
2835
#----------------------------------------------------------#
2936

30-
if [ ! -e $HESTIA/data/keys/$key ]; then
31-
echo "Error: key missmatch"
32-
echo "$date $time api $ip failed to login" >> $HESTIA/log/auth.log
33-
exit 9
34-
fi
37+
key="$(basename "$1")"
38+
39+
# Exit if Key is unset or to short
40+
[[ -z $key || ${#key} -lt 16 ]] && abort_missmatch
41+
42+
# Key file must exist
43+
maybe_key_path="$(readlink -e "${HESTIA}/data/keys/${key}")"
44+
[[ -z $maybe_key_path ]] && abort_missmatch
45+
46+
# Key file cannot be the key store
47+
[[ $maybe_key_path == "${HESTIA}/data/keys" ]] && abort_missmatch
48+
49+
# Key file must be in the key store
50+
[[ $maybe_key_path == "${HESTIA}/data/keys/"* ]] || abort_missmatch
3551

3652

3753
#----------------------------------------------------------#

0 commit comments

Comments
 (0)