3 [ -n "$include_session" ] && return 0
7 IDFILE="${IDFILE:-${_DATA:-.}/serverkey}"
8 if [ "$(stat -c %s "$IDFILE")" -ne 512 ] || ! cat "$IDFILE"; then
9 dd count=1 bs=512 if=/dev/urandom \
15 # 6-Bit Code that retains sort order of input data, while beeing safe to use
16 # in ascii transmissions, unix file names, HTTP URLs, and HTML attributes
20 y;ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/;0123456789:=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz;
25 dd bs=12 count=1 if=/dev/urandom 2>&- \
30 d=$(($(date +%s) % 4294967296))
33 $((d / 16777216 % 256)) \
34 $((d / 65536 % 256)) \
38 dd bs=8 count=1 if=/dev/urandom 2>&-
42 checkid(){ grep -m 1 -xE '[0-9a-zA-Z:=]{16}'; }
45 local session sid time sig serverkey checksig
47 IFS=- read -r sid time sig <<-END
50 serverkey="$(server_key)"
52 checksig="$(printf %s "$sid" "$time" "$serverkey" | sha256sum)"
53 checksig="${checksig%% *}"
56 if [ "$checksig" != "$sig" \
58 -o ! "$(printf %s "$sid" |checkid)" ] 2>&-
60 debug Setting up new session
64 time=$(( $(date +%s) + 7200 ))
65 sig="$(printf %s "$sid" "$time" "$serverkey" |sha256sum)"
67 printf %s\\n "${sid}-${time}-${sig}"
70 SESSION_ID="$(update_session)"
71 SET_COOKIE 0 session="$SESSION_ID" Path=/ SameSite=Strict HttpOnly
72 SESSION_ID="${SESSION_ID%%-*}"