devise_pkcs12_authenticatable 0.0.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 39f4ea9093428f249714901f66cfe03c24095307
4
+ data.tar.gz: 080c9912059e55f269faf3996aa72cbf3f0a20dd
5
+ SHA512:
6
+ metadata.gz: bfcd00a1814e20030ffa49a41c7a4b2176aeb7f7a4efb9bb8bbd8d5a6658dfe0757e445fbaf80f16773d52de69883547eb0bafa4946d0827b697e1d37f625e75
7
+ data.tar.gz: 6736276dfec95f164e0bf7170c6b07d2989f6bf354842f63ba649068199b90f7084265fcf05d464a58f4e71b68b432ac241b637ff88cb76e6a29f2d637ae2111
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ ## RVM
12
+ .rvmrc
13
+ .ruby-version
14
+ .ruby-gemset
15
+
16
+ ## Mac
17
+ .DS_Store
18
+
19
+ ## Vim
20
+ *.swp
21
+ *.swo
22
+ *~
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in devise_pkcs12_authenticatable.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Alexander Grigoriev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # DevisePkcs12Authenticatable
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/devise_pkcs12_authenticatable`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'devise_pkcs12_authenticatable'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install devise_pkcs12_authenticatable
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it ( https://github.com/[my-github-username]/devise_pkcs12_authenticatable/fork )
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'devise_pkcs12_authenticatable/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'devise_pkcs12_authenticatable'
8
+ spec.version = DevisePKCS12Authenticatable::VERSION.dup
9
+ spec.author = 'Alexander Grigoriev'
10
+ spec.email = 'a.grigorev007@gmail.com'
11
+
12
+ spec.summary = 'PKCS #12 authentication for Devise.'
13
+ spec.description = 'PKCS #12 authentication for Devise.'
14
+ spec.homepage = 'https://github.com/vill/devise_pkcs12_authenticatable'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.required_ruby_version = '>= 1.9.3'
22
+ spec.required_rubygems_version = '>= 2.2.0'
23
+
24
+ spec.add_dependency 'devise', '~> 3.4.1'
25
+ spec.add_dependency 'activesupport', '~> 4.1.8'
26
+ spec.add_dependency 'railties', '~> 4.1.8'
27
+
28
+ spec.add_development_dependency 'bundler', '~> 1.9'
29
+ spec.add_development_dependency 'rake', '~> 10.0'
30
+ end
@@ -0,0 +1,22 @@
1
+ require 'devise'
2
+ require 'active_support'
3
+ require 'active_support/inflector'
4
+ require 'active_support/concern'
5
+
6
+ require 'devise_pkcs12_authenticatable/engine'
7
+
8
+ module DevisePKCS12Authenticatable
9
+ end
10
+
11
+ module Devise
12
+ # Name of the field for 'commonName'
13
+ mattr_accessor :pkcs12_common_name_field
14
+ @@pkcs12_common_name_field = :cn
15
+ end
16
+
17
+ Devise.add_module(:pkcs12_authenticatable,
18
+ route: :session,
19
+ controller: :sessions,
20
+ strategy: true,
21
+ model: 'devise_pkcs12_authenticatable/model'
22
+ )
@@ -0,0 +1,7 @@
1
+ module PKCS12Authenticatable
2
+ class Engine < ::Rails::Engine
3
+ ActiveSupport::Inflector.inflections(:en) do |inflect|
4
+ inflect.acronym 'PKCS12'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,23 @@
1
+ require 'devise_pkcs12_authenticatable/strategy'
2
+
3
+ module Devise
4
+ module Models
5
+ module PKCS12Authenticatable
6
+ extend ActiveSupport::Concern
7
+ include Devise::Models::DatabaseAuthenticatable
8
+
9
+ def valid_common_name?(common_name)
10
+ return false if self[::Devise.pkcs12_common_name_field].blank?
11
+ self[::Devise.pkcs12_common_name_field] == common_name
12
+ end
13
+
14
+ protected
15
+
16
+ module ClassMethods
17
+ def find_for_pkcs12_authentication(conditions)
18
+ find_for_authentication(conditions)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,43 @@
1
+ require 'devise/strategies/database_authenticatable'
2
+
3
+ module Devise
4
+ module Strategies
5
+ class PKCS12Authenticatable < DatabaseAuthenticatable
6
+ def authenticate!
7
+ opts = authentication_hash.merge(Hash[::Devise.pkcs12_common_name_field, common_name])
8
+ resource = password.present? && mapping.to.find_for_pkcs12_authentication(opts)
9
+ encrypted = false
10
+
11
+ if validate(resource){ encrypted = true; resource.valid_password?(password) } && resource.valid_common_name?(common_name)
12
+ remember_me(resource)
13
+ resource.after_database_authentication
14
+ success!(resource)
15
+ end
16
+
17
+ mapping.to.new.password = password if !encrypted && Devise.paranoid
18
+ fail!(:not_found_in_database) unless resource
19
+ end
20
+
21
+ def valid?
22
+ super && client_verify?
23
+ end
24
+
25
+ protected
26
+
27
+ def common_name
28
+ request.headers['X-SSL-CLIENT-S-DN'].split('/').last.split('=').last.strip
29
+ end
30
+
31
+ def client_verify?
32
+ case request.headers['X-CLIENT-VERIFY'].upcase
33
+ when 'SUCCESS'
34
+ true
35
+ else
36
+ false
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ Warden::Strategies.add(:pkcs12_authenticatable, Devise::Strategies::PKCS12Authenticatable)
@@ -0,0 +1,3 @@
1
+ module DevisePKCS12Authenticatable
2
+ VERSION = '0.0.1'.freeze
3
+ end
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: devise_pkcs12_authenticatable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Alexander Grigoriev
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-17 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: 3.4.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 3.4.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 4.1.8
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 4.1.8
41
+ - !ruby/object:Gem::Dependency
42
+ name: railties
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 4.1.8
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 4.1.8
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.9'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '1.9'
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: 'PKCS #12 authentication for Devise.'
84
+ email: a.grigorev007@gmail.com
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - .gitignore
90
+ - Gemfile
91
+ - LICENSE.txt
92
+ - README.md
93
+ - Rakefile
94
+ - devise_pkcs12_authenticatable.gemspec
95
+ - lib/devise_pkcs12_authenticatable.rb
96
+ - lib/devise_pkcs12_authenticatable/engine.rb
97
+ - lib/devise_pkcs12_authenticatable/model.rb
98
+ - lib/devise_pkcs12_authenticatable/strategy.rb
99
+ - lib/devise_pkcs12_authenticatable/version.rb
100
+ homepage: https://github.com/vill/devise_pkcs12_authenticatable
101
+ licenses:
102
+ - MIT
103
+ metadata: {}
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - '>='
111
+ - !ruby/object:Gem::Version
112
+ version: 1.9.3
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: 2.2.0
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 2.2.2
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: 'PKCS #12 authentication for Devise.'
124
+ test_files: []