open-sesame 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.rvmrc +52 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +52 -0
- data/MIT-LICENSE +20 -0
- data/README.md +79 -0
- data/Rakefile +32 -0
- data/VERSION +1 -0
- data/init.rb +1 -0
- data/install.rb +1 -0
- data/lib/open-sesame.rb +77 -0
- data/open-sesame.gemspec +69 -0
- data/spec/open-sesame_spec.rb +98 -0
- data/spec/spec_helper.rb +5 -0
- data/uninstall.rb +1 -0
- metadata +177 -0
data/.rvmrc
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
# This is an RVM Project .rvmrc file, used to automatically load the ruby
|
4
|
+
# development environment upon cd'ing into the directory
|
5
|
+
|
6
|
+
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
|
7
|
+
# Only full ruby name is supported here, for short names use:
|
8
|
+
# echo "rvm use 1.9.3" > .rvmrc
|
9
|
+
environment_id="ruby-1.9.3-p194@open-sesame"
|
10
|
+
|
11
|
+
# Uncomment the following lines if you want to verify rvm version per project
|
12
|
+
# rvmrc_rvm_version="1.16.6 (stable)" # 1.10.1 seams as a safe start
|
13
|
+
# eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
|
14
|
+
# echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
|
15
|
+
# return 1
|
16
|
+
# }
|
17
|
+
|
18
|
+
# First we attempt to load the desired environment directly from the environment
|
19
|
+
# file. This is very fast and efficient compared to running through the entire
|
20
|
+
# CLI and selector. If you want feedback on which environment was used then
|
21
|
+
# insert the word 'use' after --create as this triggers verbose mode.
|
22
|
+
if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
|
23
|
+
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
|
24
|
+
then
|
25
|
+
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
|
26
|
+
[[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
|
27
|
+
\. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
|
28
|
+
if [[ $- == *i* ]] # check for interactive shells
|
29
|
+
then echo "Using: $(tput setaf 2)$GEM_HOME$(tput sgr0)" # show the user the ruby and gemset they are using in green
|
30
|
+
else echo "Using: $GEM_HOME" # don't use colors in non-interactive shells
|
31
|
+
fi
|
32
|
+
else
|
33
|
+
# If the environment file has not yet been created, use the RVM CLI to select.
|
34
|
+
rvm --create use "$environment_id" || {
|
35
|
+
echo "Failed to create RVM environment '${environment_id}'."
|
36
|
+
return 1
|
37
|
+
}
|
38
|
+
fi
|
39
|
+
|
40
|
+
# If you use bundler, this might be useful to you:
|
41
|
+
# if [[ -s Gemfile ]] && {
|
42
|
+
# ! builtin command -v bundle >/dev/null ||
|
43
|
+
# builtin command -v bundle | GREP_OPTIONS= \grep $rvm_path/bin/bundle >/dev/null
|
44
|
+
# }
|
45
|
+
# then
|
46
|
+
# printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
|
47
|
+
# gem install bundler
|
48
|
+
# fi
|
49
|
+
# if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
|
50
|
+
# then
|
51
|
+
# bundle install | GREP_OPTIONS= \grep -vE '^Using|Your bundle is complete'
|
52
|
+
# fi
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
chronic (0.8.0)
|
5
|
+
columnize (0.3.6)
|
6
|
+
debugger (1.2.0)
|
7
|
+
columnize (>= 0.3.1)
|
8
|
+
debugger-linecache (~> 1.1.1)
|
9
|
+
debugger-ruby_core_source (~> 1.1.3)
|
10
|
+
debugger-linecache (1.1.2)
|
11
|
+
debugger-ruby_core_source (>= 1.1.1)
|
12
|
+
debugger-ruby_core_source (1.1.3)
|
13
|
+
delorean (2.0.0)
|
14
|
+
chronic
|
15
|
+
diff-lcs (1.1.3)
|
16
|
+
git (1.2.5)
|
17
|
+
jeweler (1.8.4)
|
18
|
+
bundler (~> 1.0)
|
19
|
+
git (>= 1.2.5)
|
20
|
+
rake
|
21
|
+
rdoc
|
22
|
+
json (1.7.5)
|
23
|
+
multi_json (1.3.6)
|
24
|
+
rake (0.9.2.2)
|
25
|
+
rdoc (3.12)
|
26
|
+
json (~> 1.4)
|
27
|
+
redcarpet (2.1.1)
|
28
|
+
rspec (2.11.0)
|
29
|
+
rspec-core (~> 2.11.0)
|
30
|
+
rspec-expectations (~> 2.11.0)
|
31
|
+
rspec-mocks (~> 2.11.0)
|
32
|
+
rspec-core (2.11.1)
|
33
|
+
rspec-expectations (2.11.3)
|
34
|
+
diff-lcs (~> 1.1.3)
|
35
|
+
rspec-mocks (2.11.3)
|
36
|
+
simplecov (0.6.4)
|
37
|
+
multi_json (~> 1.0)
|
38
|
+
simplecov-html (~> 0.5.3)
|
39
|
+
simplecov-html (0.5.3)
|
40
|
+
yard (0.8.2.1)
|
41
|
+
|
42
|
+
PLATFORMS
|
43
|
+
ruby
|
44
|
+
|
45
|
+
DEPENDENCIES
|
46
|
+
debugger
|
47
|
+
delorean (~> 2.0.0)
|
48
|
+
jeweler (~> 1.8.4)
|
49
|
+
redcarpet (~> 2.1.1)
|
50
|
+
rspec (~> 2.11.0)
|
51
|
+
simplecov (~> 0.6.4)
|
52
|
+
yard (~> 0.8.2.1)
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Ryan Porter
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
# OpenSesame
|
2
|
+
|
3
|
+
A simple way to pass an authenticated user from one Ruby web app to another. The two web apps don't need to share a database or be on the same server. Does not depend on Rails, and works just as well with Sinatra or any other Ruby system.
|
4
|
+
|
5
|
+
# Mechanism
|
6
|
+
|
7
|
+
Web Site A has an authenticated user that it wants to send to a protected feature on Web Site B. It generates an authorization token that consists of a cryptographic hash of a timestamp plus a secret, plus the timestamp in plaintext.
|
8
|
+
|
9
|
+
Example:
|
10
|
+
|
11
|
+
timestamp: 2009-06-25T10:34:29-04:00
|
12
|
+
secret: "OPEN SESAME"
|
13
|
+
token: 20090625T1034-93a9d935fc64285645870a59db0d287b58f7caea
|
14
|
+
|
15
|
+
Web Site B then checks that the timestamp is not more than an hour old, and it checks to verify that the timestamp plus the shared secret produces the correct hash. Web Site B should deny access with a 401 response if the authentication token does not verify.
|
16
|
+
|
17
|
+
# Installation
|
18
|
+
|
19
|
+
cd your_app
|
20
|
+
script/plugin install git://github.com/endymion/open-sesame.git
|
21
|
+
|
22
|
+
# Usage
|
23
|
+
|
24
|
+
The default secret is "OPEN SESAME". You should change that because the default secret is public knowledge. Add the secret to your config/environment.rb:
|
25
|
+
|
26
|
+
OPEN_SESAME_SECRET = "Don't tell anybody, this is a secret!"
|
27
|
+
|
28
|
+
Or, if you want to keep that secret out of your source code then you can use an environment variable, like ```ENV['OPEN_SESAME_SECRET']```. You can configure that environment variable on Heroku, for example, by giving this command to the terminal:
|
29
|
+
|
30
|
+
heroku config:add OPEN_SESAME_SECRET="Don't tell anybody, this is a secret!"
|
31
|
+
|
32
|
+
For example, with Rails, you could do this in a controller in the first web app:
|
33
|
+
|
34
|
+
token = OpenSesame::Token.generate(OPEN_SESAME_SECRET)
|
35
|
+
redirect_to "http://second-app.net?token=#{token}"
|
36
|
+
|
37
|
+
In the second Rails app, you can verify the presence and validity of the token with:
|
38
|
+
|
39
|
+
before_filter :check_token
|
40
|
+
def check_token
|
41
|
+
return if session[:open_sesame_verified]
|
42
|
+
if params[:token].blank? || !OpenSesame::Token.verify(params[:token], OPEN_SESAME_SECRET)
|
43
|
+
render :text => 'access denied', :status => 401
|
44
|
+
end
|
45
|
+
session[:open_sesame_verified] = true
|
46
|
+
end
|
47
|
+
|
48
|
+
# Signing messages
|
49
|
+
|
50
|
+
You can also pass signed parameters. Let's say you want to identify each user and you don't want them to mess with the ID that you pass.
|
51
|
+
|
52
|
+
message: 123456789
|
53
|
+
secret: "OPEN SESAME"
|
54
|
+
token: 123456789-e349b9416e2b9f6954e80f03a5bb63d3f7401b70
|
55
|
+
|
56
|
+
From the first web app:
|
57
|
+
|
58
|
+
token = OpenSesame::Token.generate(OPEN_SESAME_SECRET)
|
59
|
+
username = OpenSesame::Message.generate('username', OPEN_SESAME_SECRET)
|
60
|
+
redirect_to "http://second-app.net?token=#{token}&username=#{username}"
|
61
|
+
|
62
|
+
In the second app, you can verify both the token and any parameters:
|
63
|
+
|
64
|
+
before_filter :check_token
|
65
|
+
def check_token
|
66
|
+
return if session[:open_sesame_verified]
|
67
|
+
if params[:token].blank? || !OpenSesame::Token.verify(params[:token], OPEN_SESAME_SECRET)
|
68
|
+
render :text => 'access denied', :status => 401
|
69
|
+
end
|
70
|
+
params.keys.each do |param|
|
71
|
+
if OpenSesame::Mesage.verify(params[param])
|
72
|
+
session[param] = OPenSesame::Message.message(params[param], OPEN_SESAME_SECRET)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
session[:open_sesame_verified] = true
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
Copyright (c) 2009 Ryan Porter, released under the MIT license
|
data/Rakefile
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
+
gem.name = "open-sesame"
|
16
|
+
gem.homepage = "http://www.ryanalynporter.com/2009/06/25/authorizing-users-between-web-sites-with-open-sesame/"
|
17
|
+
gem.license = "MIT"
|
18
|
+
gem.summary = %Q{Send authorized traffic from one web site to another with a cryptographic authorization token.}
|
19
|
+
gem.description = %Q{Use a time-sensitive cryptographic token based on a shared secret phrase to generate an authorization token for passing traffic from one web site to another.}
|
20
|
+
gem.authors = ["Ryan Alyn Porter"]
|
21
|
+
# dependencies defined in Gemfile
|
22
|
+
end
|
23
|
+
Jeweler::RubygemsDotOrgTasks.new
|
24
|
+
|
25
|
+
require 'rspec/core/rake_task'
|
26
|
+
desc "Run specs"
|
27
|
+
RSpec::Core::RakeTask.new
|
28
|
+
|
29
|
+
require 'yard'
|
30
|
+
YARD::Rake::YardocTask.new do |t|
|
31
|
+
t.files = ['lib/*.rb']
|
32
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Include hook code here
|
data/install.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Install hook code here
|
data/lib/open-sesame.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'date'
|
2
|
+
require 'digest/sha1'
|
3
|
+
|
4
|
+
module OpenSesame
|
5
|
+
|
6
|
+
# Used for generating time-sensitive, cryptographically secure authorization tokens.
|
7
|
+
class Token
|
8
|
+
# For really lazy people. You really should set your own secret phrase.
|
9
|
+
@@default_secret = "OPEN SESAME"
|
10
|
+
|
11
|
+
# Generate a token, which will automatically expire after one hour.
|
12
|
+
#
|
13
|
+
# @param [String] secret The shared secret, which should only be known by the
|
14
|
+
# sender and the receiver.
|
15
|
+
# @param [DateTime] timestamp Expire the token automatically one hour from this time.
|
16
|
+
# Defaults to now.
|
17
|
+
# @return [String] The token.
|
18
|
+
def self.generate(secret = @@default_secret, timestamp = Time.now.utc.to_datetime)
|
19
|
+
timestamp_string = timestamp.strftime('%Y%m%dT%H%M')
|
20
|
+
hash = (Digest::SHA1.new << secret + timestamp_string).to_s
|
21
|
+
timestamp_string + '-' + hash
|
22
|
+
end
|
23
|
+
|
24
|
+
# Verify a token.
|
25
|
+
#
|
26
|
+
# @param [String] token The token.
|
27
|
+
# @param [String] secret The shared secret.
|
28
|
+
def self.verify(token, secret = @@default_secret)
|
29
|
+
string = token.split /-/
|
30
|
+
timestamp = DateTime.strptime string.first, '%Y%m%dT%H%M'
|
31
|
+
one_hour_ago = (Time.now.utc - 3600).to_datetime
|
32
|
+
(timestamp >= one_hour_ago) && token.eql?(generate(secret, timestamp))
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
# Used for passing messages that cannot be altered. This is not for hiding a message
|
38
|
+
# from observers. The message is cryptographically signed but it is not encrypted.
|
39
|
+
class Message
|
40
|
+
@@default_secret = "OPEN SESAME"
|
41
|
+
|
42
|
+
# Generate a message string that can be verified by another computer that knows
|
43
|
+
# the shared secret.
|
44
|
+
#
|
45
|
+
# @param [String] message The message.
|
46
|
+
# @param [String] secret The shared secret phrase.
|
47
|
+
def self.generate(message, secret = @@default_secret)
|
48
|
+
hash = (Digest::SHA1.new << secret + message).to_s
|
49
|
+
message + '-' + hash
|
50
|
+
end
|
51
|
+
|
52
|
+
# Verify that the message has not been altered.
|
53
|
+
#
|
54
|
+
# @param [String] message The message to verify.
|
55
|
+
# @param [String] secret The shared secret phrase.
|
56
|
+
def self.verify(message, secret = @@default_secret)
|
57
|
+
string = message.split /-/
|
58
|
+
message.eql? generate(string.first, secret)
|
59
|
+
end
|
60
|
+
|
61
|
+
# Verify a message that was generated with OpenSesame and return just the message
|
62
|
+
# part. Returns nil if the message does not verify.
|
63
|
+
#
|
64
|
+
# @param [String] message The message that was generated by OpenSesame, which includes
|
65
|
+
# a cryptographic hash.
|
66
|
+
# @param [String] secret The secret to use for verifying the message.
|
67
|
+
def self.message(message, secret = @@default_secret)
|
68
|
+
if self.verify(message, secret)
|
69
|
+
(message.split /-/).first
|
70
|
+
else
|
71
|
+
nil
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
data/open-sesame.gemspec
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "open-sesame"
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Ryan Alyn Porter"]
|
12
|
+
s.date = "2012-10-13"
|
13
|
+
s.description = "Use a time-sensitive cryptographic token based on a shared secret phrase to generate an authorization token for passing traffic from one web site to another."
|
14
|
+
s.extra_rdoc_files = [
|
15
|
+
"README.md"
|
16
|
+
]
|
17
|
+
s.files = [
|
18
|
+
".rvmrc",
|
19
|
+
"Gemfile",
|
20
|
+
"Gemfile.lock",
|
21
|
+
"MIT-LICENSE",
|
22
|
+
"README.md",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION",
|
25
|
+
"init.rb",
|
26
|
+
"install.rb",
|
27
|
+
"lib/open-sesame.rb",
|
28
|
+
"open-sesame.gemspec",
|
29
|
+
"spec/open-sesame_spec.rb",
|
30
|
+
"spec/spec_helper.rb",
|
31
|
+
"uninstall.rb"
|
32
|
+
]
|
33
|
+
s.homepage = "http://www.ryanalynporter.com/2009/06/25/authorizing-users-between-web-sites-with-open-sesame/"
|
34
|
+
s.licenses = ["MIT"]
|
35
|
+
s.require_paths = ["lib"]
|
36
|
+
s.rubygems_version = "1.8.24"
|
37
|
+
s.summary = "Send authorized traffic from one web site to another with a cryptographic authorization token."
|
38
|
+
|
39
|
+
if s.respond_to? :specification_version then
|
40
|
+
s.specification_version = 3
|
41
|
+
|
42
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
43
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.11.0"])
|
44
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
|
45
|
+
s.add_development_dependency(%q<simplecov>, ["~> 0.6.4"])
|
46
|
+
s.add_development_dependency(%q<yard>, ["~> 0.8.2.1"])
|
47
|
+
s.add_development_dependency(%q<redcarpet>, ["~> 2.1.1"])
|
48
|
+
s.add_development_dependency(%q<delorean>, ["~> 2.0.0"])
|
49
|
+
s.add_development_dependency(%q<debugger>, [">= 0"])
|
50
|
+
else
|
51
|
+
s.add_dependency(%q<rspec>, ["~> 2.11.0"])
|
52
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
53
|
+
s.add_dependency(%q<simplecov>, ["~> 0.6.4"])
|
54
|
+
s.add_dependency(%q<yard>, ["~> 0.8.2.1"])
|
55
|
+
s.add_dependency(%q<redcarpet>, ["~> 2.1.1"])
|
56
|
+
s.add_dependency(%q<delorean>, ["~> 2.0.0"])
|
57
|
+
s.add_dependency(%q<debugger>, [">= 0"])
|
58
|
+
end
|
59
|
+
else
|
60
|
+
s.add_dependency(%q<rspec>, ["~> 2.11.0"])
|
61
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
62
|
+
s.add_dependency(%q<simplecov>, ["~> 0.6.4"])
|
63
|
+
s.add_dependency(%q<yard>, ["~> 0.8.2.1"])
|
64
|
+
s.add_dependency(%q<redcarpet>, ["~> 2.1.1"])
|
65
|
+
s.add_dependency(%q<delorean>, ["~> 2.0.0"])
|
66
|
+
s.add_dependency(%q<debugger>, [">= 0"])
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'open-sesame'
|
3
|
+
|
4
|
+
describe OpenSesame do
|
5
|
+
|
6
|
+
before(:all) do
|
7
|
+
@secret = "Don't tell anybody, this is a secret."
|
8
|
+
end
|
9
|
+
|
10
|
+
describe 'secure token' do
|
11
|
+
|
12
|
+
it 'can be generated.' do
|
13
|
+
token = OpenSesame::Token.generate(@secret)
|
14
|
+
token.should match /\d{8}T\d{4}-\w{40}/
|
15
|
+
|
16
|
+
token2 = OpenSesame::Token.generate # Default 'secret'.
|
17
|
+
token2.should match /\d{8}T\d{4}-\w{40}/
|
18
|
+
|
19
|
+
token.should_not == token2
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'can be verified.' do
|
23
|
+
token = OpenSesame::Token.generate(@secret)
|
24
|
+
OpenSesame::Token.verify(token, @secret).should be_true
|
25
|
+
|
26
|
+
token2 = OpenSesame::Token.generate # Default 'secret'.
|
27
|
+
OpenSesame::Token.verify(token2).should be_true
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'expires after one hour' do
|
31
|
+
token = OpenSesame::Token.generate @secret
|
32
|
+
Delorean.time_travel_to "59 minutes from now"
|
33
|
+
OpenSesame::Token.verify(token, @secret).should be_true
|
34
|
+
Delorean.time_travel_to "61 minutes from now"
|
35
|
+
OpenSesame::Token.verify(token, @secret).should_not be_true
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'cannot be verified if the time stamp is modified.' do
|
39
|
+
token = OpenSesame::Token.generate @secret
|
40
|
+
token.gsub!(/^(\d{8})/) {|match| match.to_i + 100 }
|
41
|
+
OpenSesame::Token.verify(token, @secret).should_not be_true
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'cannot be verified if the hash is modified.' do
|
45
|
+
token = OpenSesame::Token.generate @secret
|
46
|
+
token[token.length - 1] = 'z'
|
47
|
+
OpenSesame::Token.verify(token, @secret).should_not be_true
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
describe 'secure message' do
|
53
|
+
|
54
|
+
it 'can be generated.' do
|
55
|
+
message = OpenSesame::Message.generate 'WELL HELLO THERE', @secret
|
56
|
+
message.should match /WELL HELLO THERE-\w{40}/
|
57
|
+
|
58
|
+
message2 = OpenSesame::Message.generate 'WELL HELLO THERE' # Default 'secret'.
|
59
|
+
message2.should match /WELL HELLO THERE-\w{40}/
|
60
|
+
|
61
|
+
message.should_not == message2
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'can be verified.' do
|
65
|
+
message = OpenSesame::Message.generate 'WELL HELLO THERE', @secret
|
66
|
+
OpenSesame::Message.verify(message, @secret).should be_true
|
67
|
+
|
68
|
+
message2 = OpenSesame::Message.generate 'WELL HELLO THERE' # Default 'secret'.
|
69
|
+
OpenSesame::Message.verify(message2).should be_true
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'cannot be verified if the message is modified' do
|
73
|
+
message = OpenSesame::Message.generate 'WELL HELLO THERE', @secret
|
74
|
+
message.gsub!(/HELLO/, 'GOODBYE')
|
75
|
+
OpenSesame::Message.verify(message, @secret).should_not be_true
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'cannot be verified if the hash is modified' do
|
79
|
+
message = OpenSesame::Message.generate 'WELL HELLO THERE', @secret
|
80
|
+
message[message.length - 1] = 'z'
|
81
|
+
OpenSesame::Message.verify(message, @secret).should_not be_true
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'returns the message if it verifies' do
|
85
|
+
message = OpenSesame::Message.generate 'WELL HELLO THERE', @secret
|
86
|
+
OpenSesame::Message.message(message, @secret).should == 'WELL HELLO THERE'
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'returns nil if the message is modified' do
|
90
|
+
message = OpenSesame::Message.generate 'WELL HELLO THERE', @secret
|
91
|
+
message.gsub!(/HELLO/, 'GOODBYE')
|
92
|
+
OpenSesame::Message.message(message, @secret).should be_nil
|
93
|
+
end
|
94
|
+
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
data/spec/spec_helper.rb
ADDED
data/uninstall.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Uninstall hook code here
|
metadata
ADDED
@@ -0,0 +1,177 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: open-sesame
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ryan Alyn Porter
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-13 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.11.0
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.11.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: jeweler
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 1.8.4
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.8.4
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: simplecov
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.6.4
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.6.4
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: yard
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 0.8.2.1
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 0.8.2.1
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: redcarpet
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 2.1.1
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 2.1.1
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: delorean
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ~>
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 2.0.0
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ~>
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 2.0.0
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: debugger
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
description: Use a time-sensitive cryptographic token based on a shared secret phrase
|
127
|
+
to generate an authorization token for passing traffic from one web site to another.
|
128
|
+
email:
|
129
|
+
executables: []
|
130
|
+
extensions: []
|
131
|
+
extra_rdoc_files:
|
132
|
+
- README.md
|
133
|
+
files:
|
134
|
+
- .rvmrc
|
135
|
+
- Gemfile
|
136
|
+
- Gemfile.lock
|
137
|
+
- MIT-LICENSE
|
138
|
+
- README.md
|
139
|
+
- Rakefile
|
140
|
+
- VERSION
|
141
|
+
- init.rb
|
142
|
+
- install.rb
|
143
|
+
- lib/open-sesame.rb
|
144
|
+
- open-sesame.gemspec
|
145
|
+
- spec/open-sesame_spec.rb
|
146
|
+
- spec/spec_helper.rb
|
147
|
+
- uninstall.rb
|
148
|
+
homepage: http://www.ryanalynporter.com/2009/06/25/authorizing-users-between-web-sites-with-open-sesame/
|
149
|
+
licenses:
|
150
|
+
- MIT
|
151
|
+
post_install_message:
|
152
|
+
rdoc_options: []
|
153
|
+
require_paths:
|
154
|
+
- lib
|
155
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
156
|
+
none: false
|
157
|
+
requirements:
|
158
|
+
- - ! '>='
|
159
|
+
- !ruby/object:Gem::Version
|
160
|
+
version: '0'
|
161
|
+
segments:
|
162
|
+
- 0
|
163
|
+
hash: 1526642688662844779
|
164
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
165
|
+
none: false
|
166
|
+
requirements:
|
167
|
+
- - ! '>='
|
168
|
+
- !ruby/object:Gem::Version
|
169
|
+
version: '0'
|
170
|
+
requirements: []
|
171
|
+
rubyforge_project:
|
172
|
+
rubygems_version: 1.8.24
|
173
|
+
signing_key:
|
174
|
+
specification_version: 3
|
175
|
+
summary: Send authorized traffic from one web site to another with a cryptographic
|
176
|
+
authorization token.
|
177
|
+
test_files: []
|