omniauth-yubikey 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (C) 2011 by Steve Hoeksema.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
@@ -0,0 +1,22 @@
1
+ OmniAuth strategy for authenticating against the Yubico API with a Yubikey OTP.
2
+
3
+ To Do
4
+ -----
5
+
6
+ * More RSpec coverage
7
+ * Verify the hash returned by Yubico
8
+ * Use Faraday
9
+ * Require valid SSL certificate
10
+
11
+
12
+ Contains portions of code from:
13
+
14
+ ruby-yubico
15
+ by Jenecai 'Seven' Corvina <seven@ofhearts.org>
16
+ http://code.google.com/p/ruby-yubico/
17
+ BSD license
18
+
19
+ yubikey
20
+ by Jonathan Rudenberg <jon335@gmail.com>
21
+ https://github.com/titanous/yubikey
22
+ MIT license
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,24 @@
1
+ require "rubygems"
2
+ require "sinatra"
3
+ require "omniauth-yubikey"
4
+
5
+ use Rack::Session::Cookie
6
+
7
+ use OmniAuth::Strategies::Yubikey, "XXXX", "XXXXXXXXXXXXXXXXXXXXXXXXX"
8
+
9
+ enable :sessions
10
+
11
+ get "/" do
12
+ <<-HTML
13
+ <form action="/auth/yubikey" method="post">
14
+ <input type="text" name="otp" />
15
+ <input type="submit" value="Sign in with Yubikey" />
16
+ </form>
17
+ HTML
18
+ end
19
+
20
+ get "/auth/:name/callback" do
21
+ auth = request.env["omniauth.auth"]
22
+
23
+ auth.inspect
24
+ end
@@ -0,0 +1,5 @@
1
+ require "omniauth-yubikey/version"
2
+ require "omniauth-yubikey/verifier"
3
+ require "omniauth-yubikey/result"
4
+ require "omniauth-yubikey/otp_error"
5
+ require "omniauth/strategies/yubikey"
@@ -0,0 +1,6 @@
1
+ module OmniAuth
2
+ module Yubikey
3
+ class OtpError < StandardError
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,34 @@
1
+ require "time"
2
+
3
+ module OmniAuth
4
+ module Yubikey
5
+ class Result
6
+
7
+ attr_reader :otp, :id, :hash, :timestamp, :status, :info
8
+
9
+ def initialize(otp, response)
10
+ @otp = otp
11
+ @id = otp[0, otp.length-32] if otp.length > 32
12
+
13
+ response.gsub!("\r\n", "\n")
14
+
15
+ hashes = response.scan(/^h=([\w_\=\/\+]+)$/)[0]
16
+ statuses = response.scan(/^status=([a-zA-Z0-9_]+)$/)[0]
17
+ timestamps = response.scan(/^t=(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})Z(\d{4})$/)[0]
18
+
19
+ @hash = hashes[0] if hashes && hashes[0]
20
+ @status = statuses[0] if statuses && statuses[0]
21
+
22
+ if timestamps
23
+ parts = timestamps.map(&:to_i)
24
+ @timestamp = Time.utc(*parts)
25
+ end
26
+ end
27
+
28
+ def valid?
29
+ status == "OK"
30
+ end
31
+
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,44 @@
1
+ require "net/http"
2
+ require "openssl"
3
+
4
+ module OmniAuth
5
+ module Yubikey
6
+ class Verifier
7
+
8
+ attr_reader :api_id, :api_key, :api_url
9
+
10
+ def initialize(api_id, api_key, api_url)
11
+ @api_id, @api_key, @api_url = api_id, api_key, api_url
12
+ end
13
+
14
+ def verify(otp)
15
+ response = get_response(otp)
16
+ Result.new(otp, response)
17
+ end
18
+
19
+ def verify!(otp)
20
+ result = verify(otp)
21
+ raise OtpError, "Received error: #{result.status}" unless result.valid?
22
+ result
23
+ end
24
+
25
+ private
26
+
27
+ def get_response(otp)
28
+ uri = URI.parse(api_url) + "verify"
29
+ uri.query = "id=#{api_id}&otp=#{otp}"
30
+
31
+ http = Net::HTTP.new(uri.host, uri.port)
32
+ http.use_ssl = true
33
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
34
+
35
+ request = Net::HTTP::Get.new(uri.request_uri)
36
+
37
+ response = http.request(request).body
38
+
39
+ response
40
+ end
41
+
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module Yubikey
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,63 @@
1
+ require "omniauth"
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class Yubikey
6
+
7
+ include OmniAuth::Strategy
8
+
9
+ args [:api_id, :api_key]
10
+
11
+ option :api_id, nil
12
+ option :api_key, nil
13
+ option :api_url, "https://api.yubico.com/wsapi/"
14
+
15
+ attr_accessor :otp_id
16
+
17
+ def request_phase
18
+ if env["REQUEST_METHOD"] == "GET"
19
+ get_credentials
20
+ else
21
+ perform
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def get_credentials
28
+ OmniAuth::Form.build(:title => "Yubikey") do
29
+ password_field "One-time password", "otp"
30
+ end.to_response
31
+ end
32
+
33
+ def otp
34
+ request["otp"]
35
+ end
36
+
37
+ def perform
38
+ verifier = OmniAuth::Yubikey::Verifier.new(options.api_id, options.api_key, options.api_url)
39
+ result = verifier.verify!(otp)
40
+
41
+ self.otp_id = result.id
42
+
43
+ env["omniauth.auth"] = auth_hash
44
+ env["omniauth.yubikey"] = result
45
+ env["REQUEST_METHOD"] = "GET"
46
+ env["PATH_INFO"] = "#{OmniAuth.config.path_prefix}/#{name.to_s}/callback"
47
+
48
+ call_app!
49
+ rescue OmniAuth::Yubikey::OtpError => e
50
+ fail!(:invalid_credentials, e)
51
+ end
52
+
53
+ def callback_phase
54
+ fail!(:invalid_credentials)
55
+ end
56
+
57
+ uid do
58
+ otp_id
59
+ end
60
+
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "omniauth-yubikey/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "omniauth-yubikey"
7
+ s.version = OmniAuth::Yubikey::VERSION
8
+ s.authors = ["Steve Hoeksema"]
9
+ s.email = ["steve@seven.net.nz"]
10
+ s.homepage = "https://github.com/steveh/omniauth-yubikey"
11
+ s.summary = "OmniAuth strategy for authenticating against the Yubico API with a Yubikey OTP"
12
+ s.description = "OmniAuth strategy for authenticating against the Yubico API with a Yubikey OTP"
13
+
14
+ s.rubyforge_project = "omniauth-yubikey"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_dependency "omniauth", "~> 1.0"
22
+
23
+ s.add_development_dependency "rspec", "~> 2.7"
24
+ end
@@ -0,0 +1,32 @@
1
+ require "spec_helper"
2
+
3
+ describe OmniAuth::Yubikey::Result do
4
+
5
+ let(:otp) { "ccccccbcifnhfkunerrbtefthtnidhdjfdctblnfihnh" }
6
+ let(:response) { "h=71poL6Z/yjDBF6twhigu777F+7M=\r\nt=2011-09-28T22:05:58Z0964\r\nstatus=OK\r\n\r\n" }
7
+
8
+ before(:all) do
9
+ @result = OmniAuth::Yubikey::Result.new(otp, response)
10
+ end
11
+
12
+ it "should return the OTP" do
13
+ @result.otp.should == "ccccccbcifnhfkunerrbtefthtnidhdjfdctblnfihnh"
14
+ end
15
+
16
+ it "should extract the Yubikey ID from the OTP" do
17
+ @result.id.should == "ccccccbcifnh"
18
+ end
19
+
20
+ it "should extract the Yubikey hash from the response" do
21
+ @result.hash.should == "71poL6Z/yjDBF6twhigu777F+7M="
22
+ end
23
+
24
+ it "should extract the Yubikey timestamp from the response" do
25
+ @result.timestamp.utc.should == Time.utc(2011, 9, 28, 22, 5, 58, 964)
26
+ end
27
+
28
+ it "should extract the Yubikey status from the response" do
29
+ @result.status.should == "OK"
30
+ end
31
+
32
+ end
@@ -0,0 +1 @@
1
+ require "omniauth-yubikey"
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-yubikey
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Steve Hoeksema
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-11-06 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: omniauth
16
+ requirement: &70231725061980 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70231725061980
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &70231725173280 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '2.7'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70231725173280
36
+ description: OmniAuth strategy for authenticating against the Yubico API with a Yubikey
37
+ OTP
38
+ email:
39
+ - steve@seven.net.nz
40
+ executables: []
41
+ extensions: []
42
+ extra_rdoc_files: []
43
+ files:
44
+ - .gitignore
45
+ - Gemfile
46
+ - LICENSE
47
+ - README.md
48
+ - Rakefile
49
+ - examples/sinatra.rb
50
+ - lib/omniauth-yubikey.rb
51
+ - lib/omniauth-yubikey/otp_error.rb
52
+ - lib/omniauth-yubikey/result.rb
53
+ - lib/omniauth-yubikey/verifier.rb
54
+ - lib/omniauth-yubikey/version.rb
55
+ - lib/omniauth/strategies/yubikey.rb
56
+ - omniauth-yubikey.gemspec
57
+ - spec/omniauth/yubikey/result_spec.rb
58
+ - spec/spec_helper.rb
59
+ homepage: https://github.com/steveh/omniauth-yubikey
60
+ licenses: []
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project: omniauth-yubikey
79
+ rubygems_version: 1.8.6
80
+ signing_key:
81
+ specification_version: 3
82
+ summary: OmniAuth strategy for authenticating against the Yubico API with a Yubikey
83
+ OTP
84
+ test_files:
85
+ - spec/omniauth/yubikey/result_spec.rb
86
+ - spec/spec_helper.rb
87
+ has_rdoc: