Project

hmac-uri

0.0
No commit activity in last 3 years
No release in over 3 years
OpenSSL based HMAC signing for request urls with shared secret
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0

Runtime

 Project Readme

HMAC URI

HMAC based request signing of URI.

Example

require 'hmac/uri'

mac = HMAC::URI.new(secret: 'some long shared secret')
uri = mac.sign "http://example.org/resource?id=1"

mac.signed?(uri)           #=> true
mac.signed?(uri, delta: 0) #=> false

Nonce

HMAC::URI generates nonces which can be used to prevent replay attacks.

require 'hmac/uri'

seen  = {}
check = proc {|nonce, ts, delta| (Time.now.to_i - ts) < delta && !seen.include?(nonce) && seen << nonce}
mac   = HMAC::URI.new(secret: 'some long shared secret', validator: check)
uri   = mac.sign "http://example.org/resource?id=1"

mac.signed?(uri)           #=> true
mac.signed?(uri, delta: 0) #=> false

License

MIT