3 [ -n "$include_session" ] && return 0
7 SESSION_TIMEOUT="${SESSION_TIMEOUT:-7200}"
10 IDFILE="${IDFILE:-${_DATA:-.}/serverkey}"
11 if [ "$(stat -c %s "$IDFILE")" -ne 512 ] || ! cat "$IDFILE"; then
12 dd count=1 bs=512 if=/dev/urandom \
18 # 6-Bit Code that retains sort order of input data, while beeing safe to use
19 # in ascii transmissions, unix file names, HTTP URLs, and HTML attributes
23 y;ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/;0123456789:=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz;
28 dd bs=12 count=1 if=/dev/urandom 2>&- \
33 d=$(($_DATE % 4294967296))
36 $((d / 16777216 % 256)) \
37 $((d / 65536 % 256)) \
41 dd bs=8 count=1 if=/dev/urandom 2>&-
45 checkid(){ grep -m 1 -xE '[0-9a-zA-Z:=]{16}'; }
48 # transaction ID to modify a given file
50 { stat -c %F%i%n%N%s%Y "$file" 2>&-
51 printf %s "$SESSION_ID"
53 } | sha256sum | cut -d\ -f1
57 local session sid time sig serverkey checksig
59 IFS=- read -r sid time sig <<-END
60 $(POST session_key || COOKIE session)
62 serverkey="$(server_key)"
64 checksig="$(printf %s "$sid" "$time" "$serverkey" | sha256sum)"
65 checksig="${checksig%% *}"
67 if ! [ "$checksig" = "$sig" \
68 -a "$time" -ge "$_DATE" \
69 -a "$(printf %s "$sid" |checkid)" ] 2>&-
71 debug "Setting up new session"
75 time=$(( $_DATE + $SESSION_TIMEOUT ))
76 sig="$(printf %s "$sid" "$time" "$serverkey" |sha256sum)"
78 printf %s\\n "${sid}-${time}-${sig}"
81 SESSION_KEY="$(update_session)"
82 SET_COOKIE 0 session="$SESSION_KEY" Path=/ SameSite=Strict HttpOnly
83 SESSION_ID="${SESSION_KEY%%-*}"