Documentation ¶
Overview ¶
Package urlsign contains a signed URL mechanism, where a URL can safely be passed through a third party and validated before being served. This is useful for passing a URL to a browser, for example, from one service and having a second service be certain the URL was as authorized. This is handled by generating a signing token for each URL based on all the other query parameters and the path. This does not validate the hostname or scheme from the passed URL. Expiration/bucket size is an external, agreed parameter between the services.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var HmacAlgorithm = sha1.New
Yes, SHA1-HMAC is still considered secure, despite attacks on SHA-1 itself: https://crypto.stackexchange.com/questions/26510/why-is-hmac-sha1-still-considered-secure
Functions ¶
func GenerateToken ¶
func GenerateToken(secret string, bucketSize time.Duration, baseTime time.Time, reqUrl string) string
generateToken takes the secret generated by timedSecret and uses it to sign the url that is passed in, returning a hex-encoded string containing the signature.
func IsValidSignature ¶
func IsValidSignature(secret string, bucketSize time.Duration, baseTime time.Time, reqUrl string) bool
isValidSignature takes a signed URL, grabs the token, generates an HMAC for the URL as expected, and compares the results. To work properly, this method assumes that the arguments in the URL are +sorted+ in string order. Additionally, it will test the current timeBucket and the previous and next buckets providing a 3*timeBucket window of validity for each signature.
Types ¶
This section is empty.