Skip to content
Browse files

add executable to sign and validate urls

  • Loading branch information...
1 parent 24d31b1 commit 43ed4a7e5c8f94af38c5b75bde75e74eb773b762 @Xylakant Xylakant committed Jul 16, 2011
Showing with 62 additions and 3 deletions.
  1. +4 −2 Gemfile.lock
  2. +54 −0 bin/warden-hmac-authentication
  3. +4 −1 warden-hmac-authentication.gemspec
View
6 Gemfile.lock
@@ -1,9 +1,10 @@
PATH
remote: .
specs:
- hmac (1.0)
+ warden-hmac-authentication (0.2.0)
addressable
rack
+ trollop
GEM
remote: http://rubygems.org/
@@ -21,6 +22,7 @@ GEM
simplecov-html (~> 0.4.4)
simplecov-html (0.4.5)
timecop (0.3.5)
+ trollop (1.16.2)
warden (1.0.3)
rack (>= 1.0.0)
yard (0.7.2)
@@ -29,7 +31,6 @@ PLATFORMS
ruby
DEPENDENCIES
- hmac!
rack
rack-test
rake
@@ -39,4 +40,5 @@ DEPENDENCIES
simplecov-html
timecop
warden
+ warden-hmac-authentication!
yard
View
54 bin/warden-hmac-authentication
@@ -0,0 +1,54 @@
+#!/usr/bin/env ruby
+
+require 'trollop'
+require 'hmac_signer'
+
+opts = Trollop::options do
+
+ version "warden-hmac-sign 0.3.0 (c) 2011 Felix Gilcher, Florian Gilcher"
+ banner <<-EOS
+ warden-hmac-authentication is used to create and validate signed urls for
+ usage with the HMAC authentication scheme used by
+ https://github.com/Asquera/warden-hmac-authentication
+
+ Usage:
+ warden-hmac-authentication [options] <command> url
+
+ where command is one of
+
+ sign: signs the given url
+ validate: validates the given url
+
+ and where [options] are:
+
+ EOS
+
+ opt :algorithm, "The hashing algorithm to use for the HMAC", :type => :string, :default => "sha1"
+ opt :secret, "The shared secret for the HMAC", :type => :string, :required => true
+ opt :"auth-param", "The name for the auth param in the url", :default => "auth"
+ opt :"date", "The date to use for the signature (defaults to now)"
+end
+
+cmd = ARGV.shift
+Trollop::die "You must give a command" if cmd.nil?
+Trollop::die "You command must be one of [sign, validate]" unless ["sign", "validate"].include? cmd
+Trollop::die "You must provide a URL" if ARGV.empty?
+url = ARGV.shift
+
+secret = opts.delete(:secret)
+algorithm = opts.delete(:algorithm)
+
+signer = HMACSigner.new(algorithm)
+
+if "sign" == cmd
+ puts signer.sign_url(url, secret, opts)
+else
+ success = signer.validate_url_signature(url, secret, opts)
+ if success
+ puts "URL #{url} is valid"
+ exit 0
+ else
+ puts "URL #{url} does not contain a valid signature"
+ exit 1
+ end
+end
View
5 warden-hmac-authentication.gemspec
@@ -2,7 +2,7 @@
Gem::Specification.new do |s|
s.name = "warden-hmac-authentication"
- s.version = "0.2.0"
+ s.version = "0.3.0"
s.platform = Gem::Platform::RUBY
s.authors = ["Felix Gilcher", "Florian Gilcher"]
s.email = ["felix.gilcher@asquera.de", "florian.gilcher@asquera.de"]
@@ -21,8 +21,11 @@ Gem::Specification.new do |s|
s.require_paths = ["lib"]
+ s.executables = ["warden-hmac-authentication"]
+
s.add_runtime_dependency(%q<addressable>)
s.add_runtime_dependency(%q<rack>)
+ s.add_runtime_dependency(%q<trollop>)
s.add_development_dependency(%q<yard>)
s.add_development_dependency(%q<rdiscount>)
s.add_development_dependency(%q<simplecov>)

0 comments on commit 43ed4a7

Please sign in to comment.
Something went wrong with that request. Please try again.