devise_ssl_authenticatable 0.1.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +2 -0
- data/devise_ssl_authenticatable.gemspec +27 -0
- data/lib/devise/models/ssl_authenticatable.rb +22 -0
- data/lib/devise/ssl_authenticatable.rb +13 -0
- data/lib/devise/ssl_authenticatable/version.rb +5 -0
- data/lib/devise/strategies/ssl_authenticatable.rb +64 -0
- data/lib/devise_ssl_authenticatable.rb +7 -0
- metadata +125 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d9aabe09042c17ab46f34ca84410ca34bd1aca31
|
4
|
+
data.tar.gz: 34478d97131ce969cf17a69cfeb0cece04b53754
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 31dc97125d2be30722f55687046fba201ac00654859ef0e8e27883c94650324b937522cfc71816e9cd430197d756813d55e1fa72f3afa6091ff122e378198b58
|
7
|
+
data.tar.gz: b00dd8a3f688c921be74c2bbc8252295d4590c90fed41fbd1ffc5990db981243a7a8c8adb52f3b0a86000a3882bc4d7b90bfbb625e51bed3471f57b385acffd5
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Brilligent Solutions, Inc.
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Devise SSL Authenticatable
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'devise_ssl_authenticatable'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install devise_ssl_authenticatable
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it ( https://github.com/szechyjs/devise_ssl_authenticatable/fork )
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'devise/ssl_authenticatable/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "devise_ssl_authenticatable"
|
8
|
+
spec.version = Devise::SslAuthenticatable::VERSION
|
9
|
+
spec.platform = Gem::Platform::RUBY
|
10
|
+
spec.authors = ["Jared Szechy"]
|
11
|
+
spec.email = ["jared.szechy@gmail.com"]
|
12
|
+
spec.summary = %q{Implements SSL client authentication for Devise.}
|
13
|
+
spec.description = %q{Reads the SSL client authentication headers from your webserver.}
|
14
|
+
spec.homepage = "http://github.com/szechyjs/devise_ssl_authenticatable"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0")
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency 'devise', '~> 4'
|
22
|
+
|
23
|
+
spec.add_development_dependency "rails", "~> 5"
|
24
|
+
spec.add_development_dependency "rspec-rails", "~> 3.7"
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Devise
|
2
|
+
module Models
|
3
|
+
module SslAuthenticatable
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
# Hook called after ssl authentication
|
7
|
+
def after_ssl_authentication
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
def find_for_ssl_authentication(authentication_hash)
|
12
|
+
dn_field = ssl_client_dn_field.to_sym
|
13
|
+
dn = authentication_hash[dn_field]
|
14
|
+
resource = find_for_authentication(dn_field: dn) || new(dn_field: dn, email: authentication_hash[:email])
|
15
|
+
resource
|
16
|
+
end
|
17
|
+
|
18
|
+
Devise::Models.config(self, :ssl_client_dn_field)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'devise'
|
2
|
+
|
3
|
+
require 'devise/strategies/ssl_authenticatable'
|
4
|
+
|
5
|
+
module Devise
|
6
|
+
# The database column that holds the DN of the user
|
7
|
+
mattr_accessor :ssl_client_dn_field
|
8
|
+
@@ssl_client_dn_field = :ssl_client_dn
|
9
|
+
|
10
|
+
end
|
11
|
+
|
12
|
+
Devise.add_module(:ssl_authenticatable, strategy: true,
|
13
|
+
model: true, no_input: true)
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'devise/strategies/authenticatable'
|
2
|
+
|
3
|
+
module Devise
|
4
|
+
module Strategies
|
5
|
+
#
|
6
|
+
# Strategy for signing in a user, based on a SSL certificate.
|
7
|
+
#
|
8
|
+
class SslAuthenticatable < Authenticatable
|
9
|
+
def authenticate!
|
10
|
+
resource = mapping.to.find_for_ssl_authentication(authentication_hash)
|
11
|
+
return fail(:invalid_ssl) unless resource
|
12
|
+
|
13
|
+
if validate(resource)
|
14
|
+
resource.after_ssl_authentication
|
15
|
+
success!(resource)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def store?
|
20
|
+
false
|
21
|
+
end
|
22
|
+
|
23
|
+
def valid?
|
24
|
+
super || valid_for_ssl_auth?
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
# Check if this strategy is valid for ssl authentication by:
|
30
|
+
#
|
31
|
+
# * If the request contians valid SSL headers
|
32
|
+
# * If all authentication keys are present
|
33
|
+
#
|
34
|
+
def valid_for_ssl_auth?
|
35
|
+
client_verify? && with_authentication_hash(:ssl_auth, ssl_auth_hash)
|
36
|
+
end
|
37
|
+
|
38
|
+
def ssl_auth_hash
|
39
|
+
{ authentication_keys.first => client_dn, email: client_email }
|
40
|
+
end
|
41
|
+
|
42
|
+
# Does the request contain a valid SSL cert?
|
43
|
+
def client_verify?
|
44
|
+
request.headers['puma.peercert'] || request.headers['X-SSL-Client-Verify'] == 'SUCCESS'
|
45
|
+
end
|
46
|
+
|
47
|
+
# The DN of the client certificate
|
48
|
+
def client_dn
|
49
|
+
request.headers['puma.peercert'].subject.to_s
|
50
|
+
end
|
51
|
+
|
52
|
+
def client_email
|
53
|
+
request.headers['puma.peercert'].subject.to_s.match(/emailAddress=([^\/]*)/)[0]
|
54
|
+
end
|
55
|
+
|
56
|
+
# Overwrite authentication keys to use ssl_client_dn_field.
|
57
|
+
def authentication_keys
|
58
|
+
@authentication_keys ||= [Devise::ssl_client_dn_field]
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
Warden::Strategies.add(:ssl_authenticatable, Devise::Strategies::SslAuthenticatable)
|
metadata
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: devise_ssl_authenticatable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0.pre
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jared Szechy
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-05-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: devise
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec-rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.7'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.7'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.7'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.7'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
description: Reads the SSL client authentication headers from your webserver.
|
84
|
+
email:
|
85
|
+
- jared.szechy@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- Gemfile
|
92
|
+
- LICENSE.txt
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- devise_ssl_authenticatable.gemspec
|
96
|
+
- lib/devise/models/ssl_authenticatable.rb
|
97
|
+
- lib/devise/ssl_authenticatable.rb
|
98
|
+
- lib/devise/ssl_authenticatable/version.rb
|
99
|
+
- lib/devise/strategies/ssl_authenticatable.rb
|
100
|
+
- lib/devise_ssl_authenticatable.rb
|
101
|
+
homepage: http://github.com/szechyjs/devise_ssl_authenticatable
|
102
|
+
licenses:
|
103
|
+
- MIT
|
104
|
+
metadata: {}
|
105
|
+
post_install_message:
|
106
|
+
rdoc_options: []
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">"
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: 1.3.1
|
119
|
+
requirements: []
|
120
|
+
rubyforge_project:
|
121
|
+
rubygems_version: 2.6.14
|
122
|
+
signing_key:
|
123
|
+
specification_version: 4
|
124
|
+
summary: Implements SSL client authentication for Devise.
|
125
|
+
test_files: []
|