duo 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,11 @@
1
+ # .document is used by rdoc and yard to know how to generate documentation
2
+ # for example, it can be used to control how rdoc gets built when you do `gem install foo`
3
+
4
+ README.rdoc
5
+ lib/**/*.rb
6
+ bin/*
7
+
8
+ # Files below this - are treated as 'extra files', and aren't parsed for ruby code
9
+ -
10
+ features/**/*.feature
11
+ LICENSE
@@ -0,0 +1,40 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ # rcov generated
6
+ coverage
7
+
8
+ # rdoc generated
9
+ rdoc
10
+
11
+ # yard generated
12
+ doc
13
+ .yardoc
14
+
15
+ # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
16
+ #
17
+ # * Create a file at ~/.gitignore
18
+ # * Include files you want ignored
19
+ # * Run: git config --global core.excludesfile ~/.gitignore
20
+ #
21
+ # After doing this, these files will be ignored in all your git projects,
22
+ # saving you from having to 'pollute' every project you touch with them
23
+ #
24
+ # Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
25
+ #
26
+ # For MacOS:
27
+ #
28
+ #.DS_Store
29
+ #
30
+ # For TextMate
31
+ #*.tmproj
32
+ #tmtags
33
+ #
34
+ # For emacs:
35
+ #*~
36
+ #\#*
37
+ #.\#*
38
+ #
39
+ # For vim:
40
+ #*.swp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in duo.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Brandon Dimcheff
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.
@@ -0,0 +1,17 @@
1
+ = duo
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2011 Brandon Dimcheff. See LICENSE for details.
@@ -0,0 +1,42 @@
1
+ require 'rubygems'
2
+
3
+ begin
4
+ require 'bundler'
5
+ rescue LoadError
6
+ $stderr.puts "You must install bundler - run `gem install bundler`"
7
+ end
8
+
9
+ begin
10
+ Bundler.setup
11
+ rescue Bundler::BundlerError => e
12
+ $stderr.puts e.message
13
+ $stderr.puts "Run `bundle install` to install missing gems"
14
+ exit e.status_code
15
+ end
16
+ require 'rake'
17
+
18
+ require 'bueller'
19
+ Bueller::Tasks.new
20
+
21
+ require 'rspec/core/rake_task'
22
+ RSpec::Core::RakeTask.new(:examples) do |examples|
23
+ examples.rspec_opts = '-Ispec'
24
+ end
25
+
26
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
27
+ spec.rspec_opts = '-Ispec'
28
+ spec.rcov = true
29
+ end
30
+
31
+ task :default => :examples
32
+
33
+ require 'rake/rdoctask'
34
+ Rake::RDocTask.new do |rdoc|
35
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
36
+
37
+ rdoc.main = 'README.rdoc'
38
+ rdoc.rdoc_dir = 'rdoc'
39
+ rdoc.title = "duo #{version}"
40
+ rdoc.rdoc_files.include('README*')
41
+ rdoc.rdoc_files.include('lib/**/*.rb')
42
+ end
@@ -0,0 +1,34 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+ require 'duo/version'
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'duo'
6
+ s.version = Duo::VERSION
7
+ s.platform = Gem::Platform::RUBY
8
+ s.date = "2011-04-26"
9
+ s.authors = ['Brandon Dimcheff']
10
+ s.email = 'bdimchef-git@wieldim.com'
11
+ s.homepage = 'http://github.com/bdimcheff/duo'
12
+ s.summary = %Q{Duo Security 2-factor authentication in Ruby}
13
+ s.description = %Q{Check out http://duosecurity.com for more info}
14
+ s.extra_rdoc_files = [
15
+ 'LICENSE',
16
+ 'README.rdoc',
17
+ ]
18
+
19
+ s.required_rubygems_version = Gem::Requirement.new('>= 1.3.7')
20
+ s.rubygems_version = '1.3.7'
21
+ s.specification_version = 3
22
+
23
+ s.files = `git ls-files`.split("\n")
24
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
25
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
26
+ s.require_paths = ['lib']
27
+
28
+ s.add_development_dependency 'rspec'
29
+ s.add_development_dependency 'bundler'
30
+ s.add_development_dependency 'bueller'
31
+ s.add_development_dependency 'rake'
32
+ s.add_development_dependency 'rcov'
33
+ end
34
+
@@ -0,0 +1,45 @@
1
+ require 'openssl'
2
+ require 'base64'
3
+
4
+ module Duo
5
+
6
+ # Sign a Duo request with skey, ikey, and the local username
7
+ def sign_request(skey, ikey, username)
8
+ exp = Time.now.to_i + 300
9
+
10
+ val = [username, ikey, exp].join('|')
11
+
12
+ b64 = Base64.encode64(val).strip
13
+ cookie = "TX|#{b64}"
14
+
15
+ sig = hmac_sha1(skey, cookie)
16
+
17
+ [cookie, sig].join('|')
18
+ end
19
+
20
+ # Check a response from Duo with the skey.
21
+ def verify_response(skey, sig_response)
22
+ ts = Time.now.to_i
23
+ u_prefix, u_b64, u_sig = sig_response.to_s.split('|')
24
+
25
+ sig = OpenSSL::HMAC.hexdigest(OpenSSL::Digest::Digest.new('sha1'),
26
+ skey, [u_prefix, u_b64].join('|'))
27
+
28
+ return nil if hmac_sha1(skey, sig) != hmac_sha1(skey, u_sig)
29
+
30
+ return nil if u_prefix != 'AUTH'
31
+
32
+ user, ikey, exp = Base64.decode64(u_b64).to_s.split('|')
33
+
34
+ return nil if ts >= exp.to_i
35
+
36
+ return user
37
+ end
38
+
39
+ private
40
+ def hmac_sha1(key, data)
41
+ OpenSSL::HMAC.hexdigest(OpenSSL::Digest::Digest.new('sha1'), key, data.to_s)
42
+ end
43
+
44
+ extend self
45
+ end
@@ -0,0 +1,3 @@
1
+ module Duo
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+
3
+ IKEY = "DIXXXXXXXXXXXXXXXXXX"
4
+ SKEY = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"
5
+
6
+ USER = "testuser"
7
+
8
+ INVALID_RESPONSE = " |INVALID|SIG"
9
+ EXPIRED_RESPONSE = "AUTH|dGVzdHVzZXJ8RElYWFhYWFhYWFhYWFhYWFhYWFh8MTMwMDE1Nzg3NA==|cb8f4d60ec7c261394cd5ee5a17e46ca7440d702"
10
+ FUTURE_RESPONSE = "AUTH|dGVzdHVzZXJ8RElYWFhYWFhYWFhYWFhYWFhYWFh8MTYxNTcyNzI0Mw==|d20ad0d1e62d84b00a3e74ec201a5917e77b6aef"
11
+
12
+
13
+ describe Duo do
14
+
15
+ context "signing" do
16
+
17
+ it "doesn't fail spectacularly" do
18
+ lambda { Duo.sign_request(SKEY, IKEY, USER) }.should_not raise_error
19
+ end
20
+ pending "write tests, dug!!"
21
+ end
22
+
23
+ context "verifying" do
24
+ it "verifies a valid response" do
25
+ future_user = Duo.verify_response(SKEY, FUTURE_RESPONSE)
26
+ future_user.should == USER
27
+ end
28
+
29
+ it "rejects an invalid user" do
30
+ future_user = Duo.verify_response(SKEY, INVALID_RESPONSE)
31
+ future_user.should be_nil
32
+ end
33
+
34
+ it "rejects an expired user" do
35
+ future_user = Duo.verify_response(SKEY, EXPIRED_RESPONSE)
36
+ future_user.should be_nil
37
+ end
38
+
39
+ it "doesn't crash when nil" do
40
+ lambda { Duo.verify_response(SKEY, nil) }.should_not raise_error
41
+ end
42
+
43
+ it "doesn't crash when nonsense" do
44
+ lambda { Duo.verify_response(SKEY, 'abceaouhsnt') }.should_not raise_error
45
+ end
46
+
47
+ it "doesn't crash when pipey" do
48
+ lambda { Duo.verify_response(SKEY, '|') }.should_not raise_error
49
+ end
50
+
51
+ it "doesn't crash when 7" do
52
+ lambda { Duo.verify_response(SKEY, 7) }.should_not raise_error
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,19 @@
1
+ require 'bundler'
2
+ begin
3
+ Bundler.setup
4
+ rescue Bundler::BundlerError => e
5
+ $stderr.puts e.message
6
+ $stderr.puts "Run `bundle install` to install missing gems"
7
+ exit e.status_code
8
+ end
9
+
10
+ require 'rspec'
11
+ require 'duo'
12
+
13
+ # Requires supporting files with custom matchers and macros, etc,
14
+ # in ./support/ and its subdirectories.
15
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
16
+
17
+ RSpec.configure do |config|
18
+
19
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: duo
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.2
6
+ platform: ruby
7
+ authors:
8
+ - Brandon Dimcheff
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-04-26 00:00:00 -04:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: rspec
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ type: :development
25
+ prerelease: false
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: "0"
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: bueller
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ type: :development
47
+ prerelease: false
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: rake
51
+ requirement: &id004 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ type: :development
58
+ prerelease: false
59
+ version_requirements: *id004
60
+ - !ruby/object:Gem::Dependency
61
+ name: rcov
62
+ requirement: &id005 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: *id005
71
+ description: Check out http://duosecurity.com for more info
72
+ email: bdimchef-git@wieldim.com
73
+ executables: []
74
+
75
+ extensions: []
76
+
77
+ extra_rdoc_files:
78
+ - LICENSE
79
+ - README.rdoc
80
+ files:
81
+ - .document
82
+ - .gitignore
83
+ - Gemfile
84
+ - LICENSE
85
+ - README.rdoc
86
+ - Rakefile
87
+ - duo.gemspec
88
+ - lib/duo.rb
89
+ - lib/duo/version.rb
90
+ - spec/duo_spec.rb
91
+ - spec/spec_helper.rb
92
+ has_rdoc: true
93
+ homepage: http://github.com/bdimcheff/duo
94
+ licenses: []
95
+
96
+ post_install_message:
97
+ rdoc_options: []
98
+
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ hash: -180197569806200963
107
+ segments:
108
+ - 0
109
+ version: "0"
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: 1.3.7
116
+ requirements: []
117
+
118
+ rubyforge_project:
119
+ rubygems_version: 1.6.0
120
+ signing_key:
121
+ specification_version: 3
122
+ summary: Duo Security 2-factor authentication in Ruby
123
+ test_files:
124
+ - spec/duo_spec.rb
125
+ - spec/spec_helper.rb