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 # transaction ID to modify a given file
47 { stat -c %F%i%n%N%s%Y "$file" 2>&-
48 printf %s "$SESSION_ID"
50 } | sha256sum | cut -d\ -f1
54 local session sid time sig serverkey checksig
56 IFS=- read -r sid time sig <<-END
59 serverkey="$(server_key)"
61 checksig="$(printf %s "$sid" "$time" "$serverkey" | sha256sum)"
62 checksig="${checksig%% *}"
65 if ! [ "$checksig" = "$sig" \
67 -a "$(printf %s "$sid" |checkid)" ] 2>&-
69 debug Setting up new session
73 time=$(( $(date +%s) + 7200 ))
74 sig="$(printf %s "$sid" "$time" "$serverkey" |sha256sum)"
76 printf %s\\n "${sid}-${time}-${sig}"
79 SESSION_ID="$(update_session)"
80 SET_COOKIE 0 session="$SESSION_ID" Path=/ SameSite=Strict HttpOnly
81 SESSION_ID="${SESSION_ID%%-*}"