The md5 hash value of “your_secret_word$uri” will compare with the
string specified by “secure_link”. If the result is the same, the
variable of $secure_link is ‘1’, else it’s null string.
Thanks, for the replies but when i test this configuration users
continue to download files from this url
“http://127.0.0.1/subdir1/subdir2/movie.flv” without problem.
Nginx doesn’t return 403;
/usr/local/etc/rc.d/nginx configtest
Performing sanity check on nginx configuration:
the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
configuration file /usr/local/etc/nginx/nginx.conf test is successful
Thanks, for the replies but when i test this configuration users
continue to download files from this url
“http://127.0.0.1/subdir1/subdir2/movie.flv” without problem.
Nginx doesn’t return 403;
Are you sure the request is processed in this location? Could you show
the debug log? (Debugging | NGINX)
Add expire_time in security link. http://wiki.nginx.org/HttpSecureLinkModule:
secure_link
syntax: secure_link $md5_hash[,$expire_time]
This directive specifies the MD5 hash value and the expired time of this
link URL’s. The $md5_hash should be encoded by modified Base64 for URL.
The $expired_time is the seconds since 1970-01-01 00:00:00 UTC. If you
did not add the $expire_time, then the link URL will never be expired.
this show me err 403
download is complete
3. F96syvsfhvPq54ME2VEX4A
this show me err 403
4.F96syvsfhvPq54ME2VEX4
Is this right ?
Yes, you are right.
The character of ‘=’ in the base64 code is the padding character, it’s
meaningless but for pad. So if you delete the ‘=’, it’s the same string.
see this url for detail: Base64 - Wikipedia
The base64 encode should be base64 for
url(Base64 - Wikipedia). It means no
padding ‘=’ will be used and the characters of ‘+’ and ‘/’ in the base64
string should be respectively replace by ‘-’ and ‘_’. I don’t know if
there is a function like base64_encode_url() for this encode
transformation. You can find it or try it manually.
By the way, the string of ‘your_secret_word’ should be your own secret
string. It’s used to protect anyone can’t guess the transformation
procedure of md5 hash.
It seems that the new secure link module(above Nginx-0.8.50) uses the
raw binary format MD5 instead. And the php CLI is like this:
php -r ‘print str_replace(“=”, “”,
strtr(base64_encode(md5(“segredo/p/files/top_secret.pdf13245277231161”,
true)), “+/”, “-_”)) . “\n”;’
And the configuration (have not tested yet):
location /p/ {
secure_link $arg_st,$arg_e; # this must match the URI part related
to the MD5 hash and expiration
secure_link_md5 segredo$uri$arg_e; # this is how the MD5 hash is
built from a secret token and an URI
## If the hash is incorrect then $secure_link is a null string.
if ($secure_link = "") {
return 403;
}
## The current local time is greater than the specified expiration
time.
if ($secure_link = “0”) {
return 403;
}
## If everything is ok $secure_link is 1.
## This needs to be here otherwise you'll get a 404.
rewrite ^/p/(.*)$ /p/$1 break;
It seems that the new secure link module(above Nginx-0.8.50) uses
the raw binary format MD5 instead. And the php CLI is like this: php
-r ‘print str_replace(“=”, “”,
strtr(base64_encode(md5(“segredo/p/files/top_secret.pdf13245277231161”,
true)), “+/”, “-_”)) . “\n”;’
Yes. This differs from when using secure_link_secret, that uses the
string
form of the MD5 hash.
may i suggest to do it like mod_secdownload from lighttpd? Instead of
re-inventing
the wheel you would also have compatibility which could/would make it
easier to
switch.
The URL are in form of:
$prefix/$hash/$timestamp/$path/to/file
$prefix can be anything to seperate different secret areas
$hash is a md5hash from $secret$file$timestamp
$timestamp is a unixtimestamp in hex
$path/to/file is the complete path with file you want to request
On the server side you have to set variables like the expiration time,
the secret
and maybe the “real” path per location if you not want to have the files
stored
inside root to be sure that it cannot be requested by accident.
On the Serverside you would have to do the following:
parse the url for $prefix/$hash/$timestamp/$path/to/file, convert the
timestamp
from hex back to unixtime and check if $unixtimestamp+$timeout <
$timenow,
otherwise return 410 (gone). If not, check if provided md5hash matches
local
generated hash with $secret$file$timestamp where $timestamp is used from
the
requst (since this provides you the timestamp when the url was
generated).
This would make clear urls (no uuencoding etc.), having expiration time,
and
compatibility to “other well known solution”. Having lighty beside nginx
would
be no problem and you could use well known code / modules for other cms
systems
etc. which already support mod_secdownload.