I need to set a sha1 hash in a cookie on redirect that I can check on every further request.
As far as I can see I can only set a Cookie on redirect with a RewriteRule:
RewriteRule ^(needCheck)$ /check [L,R=302,CO=myCookie:${sha1(%{myVar})}:.mydomain.com]
But this is not possible as I have no access to sha1 function in this context. But I can use an external function with a RewriteMap. Something like
RewriteMap sha1_map prg:/var/www/mydomain/sha1.sh
RewriteRule ^(needCheck)$ /check [L,R=302,CO=myCookie:${sha1_map:%{myVar}}:.mydomain.com]
But I cannot figure out how to write the external function, so that the sha1 hash matches the one generated by Apache. Can someone give me a hint?
Any further requests check the hash with
<If "sha1('%{myVar}') == ...>
Or can I achieve this simplier? Thanks for any help.
To answer myself. Yes, it works right like that. My sha1.sh was wrong. It should be
#!/bin/bash
while IFS= read -r line; do
echo -n $line | sha1sum | awk '{print $1}'\n
done
Then the hash is equal.