Giter Site home page Giter Site logo

nginx-simple-secure-link-module's Introduction

nginx-simple-secure-link

configuration

	server {
		...
		secure_link  $arg_token,$arg_ts,$arg_e;
        	secure_link_hmac_secret password; 
        	secure_link_hmac_message $arg_uid$arg_ts$arg_e;
		...
		location / {
			secure_link_enabled on;
			....
		}

usage

This module is use SHA256, it can be an option but i removed to make it simple

To generate a secure link, please read below.

For example your url has format like this:

http://github.com/downloads/document.pdf?ts=1523084400&e=30&uid=328945

And you configured secure_link_hmac_message to be:

secure_link $arg_token,$arg_ts,$arg_e;
secure_link_hmac_secret password;
secure_link_hmac_message $arg_uid$arg_ts$arg_e;

To generate secure link in php, use following example code:

PHP

<?php
$secret = 'password';
$expire = 30;
$algo = 'sha256';
$uid = 328945 ; 
$timestamp = 1523084400;
$stringtosign = "{$uid}{$timestamp}{$expire}";
$hashmac = base64_encode(hash_hmac($algo, $stringtosign, $secret, true));
$hashmac = strtr($hashmac, '+/', '-_');
$hashmac = str_replace('=', '', $hashmac);
$host = "http://github.com";
$loc = "https://{$host}/downloads/document.pdf?token={$hashmac}&ts={$timestamp}&e={$expire}&uid={$uid}";

Golang

func computeHMac(uid, timeStamp, expire int) string {
    url := "http://github.com/downloads/document.pdf";
    sha256Object := hmac.New(sha256.New, []byte("password"))
    message := fmt.Sprintf("%v%v%v", uid, timeStamp, expire)
    sha256Object.Write([]byte(message))
    hmac := strings.Replace(base64.StdEncoding.EncodeToString(sha256Object.Sum(nil)), "=", "", -1)
    hmac = strings.Replace(hmac, "/", "_", -1)
    return url+"?token="+strings.Replace(hmac, "+", "-", -1)+"&uid="+uid"+"&e="+expire+"&ts="+timeStamp
}

nginx-simple-secure-link-module's People

Contributors

whatvn avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.