}
session_mac(){
+ local info
+ [ $# -eq 0 ] && info="$(cat)" || info="$*"
+
if which openssl >/dev/null; then
- openssl dgst -sha1 -hmac "$(server_key)" -binary |slopecode
+ printf %s "$info" |openssl dgst -sha1 -hmac "$(server_key)" -binary |slopecode
else
- { cat; server_key; } |sha256sum |cut -d\ -f1
+ { printf %s "$info"; server_key; } |sha256sum |cut -d\ -f1
fi
}
transid(){
# transaction ID to modify a given file
local file="$1"
- { stat -c %F%i%n%N%s%Y "$file" 2>&-
- printf %s "$SESSION_ID"
- } | session_mac
+ session_mac "$(stat -c %F%i%n%N%s%Y "$file" 2>&-)" "$SESSION_ID"
}
update_session(){
- local session sid time sig serverkey checksig
+ local session sid time sig checksig
- IFS=- read -r sid time sig <<-END
+ read -r sid time sig <<-END
$(POST session_key || COOKIE session)
END
- serverkey="$(server_key)"
- checksig="$(printf %s "$sid" "$time" |session_mac)"
+ checksig="$(session_mac "$sid" "$time")"
if ! [ "$checksig" = "$sig" \
-a "$time" -ge "$_DATE" \
fi
time=$(( $_DATE + $SESSION_TIMEOUT ))
- sig="$(printf %s "$sid" "$time" |session_mac)"
- printf %s\\n "${sid}-${time}-${sig}"
+ sig="$(session_mac "$sid" "$time")"
+ printf %s\\n "${sid} ${time} ${sig}"
}
SESSION_KEY="$(update_session)"
SET_COOKIE 0 session="$SESSION_KEY" Path=/ SameSite=Strict HttpOnly
-SESSION_ID="${SESSION_KEY%%-*}"
+SESSION_ID="${SESSION_KEY%% *}"