seraph 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 87a649e9b8023837802c9437c543efaa7f469015
4
+ data.tar.gz: d45906cdf355f54da00e42b219c1f9757c560819
5
+ SHA512:
6
+ metadata.gz: 3194065256e655a84637ea53b122184ad8777f6909bf850ccc44ab6deba25aa471aa582706b70a473897be039ae880d18360393443626582aff4876ddf682323
7
+ data.tar.gz: b4b5eb110e7a57a951e575288791aba5014194eb085e275a1543c4786fa4fc092ac8e0a04e02a13247b96bc4a9b30d1c3187313ba4bdab7ac8a1842e23259ab0
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ /.bundle
2
+ /Gemfile.lock
3
+ /html/
4
+ /pkg/
5
+ /vendor/cache/*.gem
data/.pryrc ADDED
@@ -0,0 +1 @@
1
+ require 'seraph'
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --format Fuubar
data/.rubocop.yml ADDED
@@ -0,0 +1,27 @@
1
+ AllCops:
2
+ Exclude:
3
+ - 'script/**/*'
4
+ - 'Guardfile'
5
+ - 'Rakefile'
6
+ - 'seraph.gemspec'
7
+ Documentation:
8
+ Enabled: false
9
+ Metrics/ClassLength:
10
+ Max: 150
11
+ Metrics/LineLength:
12
+ Enabled: true
13
+ Max: 100
14
+ Rails/ActionFilter:
15
+ Enabled: false
16
+ SignalException:
17
+ Enabled: false
18
+ Style/StringLiterals:
19
+ EnforcedStyle: single_quotes
20
+ Style/TrailingCommaInLiteral:
21
+ EnforcedStyleForMultiline: comma
22
+ Enabled: true
23
+ TrailingCommaInArguments:
24
+ Enabled: false
25
+ Style/DotPosition:
26
+ EnforcedStyle: leading
27
+ Enabled: true
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.3.0
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ ---
2
+ language: ruby
3
+ rvm:
4
+ - 2.0
5
+ - 2.1
6
+ - 2.2
7
+ - 2.3
8
+ - 2.3.1
data/ChangeLog.md ADDED
@@ -0,0 +1,4 @@
1
+ ### 0.1.0 / 2016-06-14
2
+
3
+ * Initial release:
4
+
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2016 Szymon Szeliga
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,70 @@
1
+ # seraph
2
+ [![Build Status](https://secure.travis-ci.org//seraph.svg?branch=master)](https://travis-ci.org//seraph)
3
+
4
+ * [Homepage](https://rubygems.org/gems/seraph)
5
+ * [Documentation](http://rubydoc.info/gems/seraph/frames)
6
+ * [Email](mailto:szymon.szeliga at netguru.co)
7
+
8
+ ## Installation
9
+
10
+ Type
11
+ ```
12
+ gem install seraph
13
+ ```
14
+ or put
15
+ ```
16
+ gem 'seraph'
17
+ ```
18
+ inside your Gemfile
19
+
20
+ ## Description
21
+
22
+ A simple framework-agnostic library for authentication. seraph provides an API for implementing User authentication inside your app. It doesn't make any assumptions about your setup, so you do not have to have a `User` class that inherits from `ActiveRecord::Base`.
23
+
24
+ ### What do you get?
25
+
26
+ seraph offers two basic functionalities:
27
+
28
+ * encrypting the password (registration)
29
+ * checking if provided password matches the encrypted password (authentication)
30
+
31
+ #### Encrypting the password
32
+
33
+ seraph uses [BCrypt](https://github.com/codahale/bcrypt-ruby) to hash the password. Additionally a pepper can be provided:
34
+
35
+ To get a random, high-entropy pepper, you can use `/dev/urandom`:
36
+
37
+ ```
38
+ ⇒ xxd -l 32 -p /dev/urandom
39
+ 435a501746f35834862e49fd6654680803bc37a2a83bc67318342603b7176aaa
40
+ ```
41
+
42
+ Save this value as a constant in you application code, so even if you have an SQL Injection vulnerability in your code, the attacker won't be able to get the passwords, because the pepper will be added to each password without encryption. This is of course true only if the attacker doesn't have access to your application code!
43
+
44
+ So with that out of the way, to encrypt a password, run the following code:
45
+
46
+ ``` ruby
47
+ PEPPER = '435a501746f35834862e49fd6654680803bc37a2a83bc67318342603b7176aaa'
48
+ seraph::PasswordEncryptor.call('foobar12')
49
+ # => "$2a$10$MvzzJOcgCbxmVAUqwq7Zye.3Hn9L0ahB4M8riQTK6cPUfJCR6x3ZW"
50
+ ```
51
+
52
+ As a result you get the encrypted password, which you can persist in the database alongside other user data (e-mail, login, etc.)
53
+
54
+ #### Comparing a provided password with the encrypted one
55
+
56
+ Comparison is done using a constant-time secure comparison method, from the gem (fast_secure_compare)[https://github.com/daxtens/fast_secure_compare]
57
+
58
+ To do it simply run:
59
+
60
+ ``` ruby
61
+ PEPPER = '435a501746f35834862e49fd6654680803bc37a2a83bc67318342603b7176aaa'
62
+ seraph::Authenticator.call(encrypted_password, plaintext_password)
63
+ # => true or false
64
+ ```
65
+
66
+ ## Copyright
67
+
68
+ Copyright (c) 2016 Szymon Szeliga
69
+
70
+ See LICENSE.txt for details.
data/Rakefile ADDED
@@ -0,0 +1,25 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+
5
+ begin
6
+ require 'bundler/setup'
7
+ rescue LoadError => e
8
+ abort e.message
9
+ end
10
+
11
+ require 'rake'
12
+
13
+
14
+ require 'rubygems/tasks'
15
+ Gem::Tasks.new
16
+
17
+ require 'rdoc/task'
18
+ RDoc::Task.new
19
+ task :doc => :rdoc
20
+
21
+ require 'rspec/core/rake_task'
22
+ RSpec::Core::RakeTask.new
23
+
24
+ task :test => :spec
25
+ task :default => :spec
@@ -0,0 +1,11 @@
1
+ module Seraph
2
+ module Extensions
3
+ module NilClassBlank
4
+ refine NilClass do
5
+ def blank?
6
+ true
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,14 @@
1
+ require 'bcrypt'
2
+ require 'fast_blank'
3
+ require 'seraph/extensions/nil_class_blank'
4
+
5
+ module Seraph
6
+ class PasswordEncryptor
7
+ using Extensions::NilClassBlank
8
+
9
+ def self.call(password)
10
+ return false if String(password).blank?
11
+ BCrypt::Password.create(password)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ module Seraph
2
+ VERSION = '0.0.1'.freeze
3
+ end
data/lib/seraph.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'seraph/version'
2
+ require 'seraph/password_encryptor'
data/seraph.gemspec ADDED
@@ -0,0 +1,42 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'seraph/version'
6
+ require 'English'
7
+
8
+ Gem::Specification.new do |gem|
9
+ gem.name = 'seraph'
10
+ gem.version = Seraph::VERSION
11
+ gem.summary = 'A simple framework-agnostic library for authentication'
12
+ gem.description = "Looking for an authentication gem that doesn't make any assumptions about your setup? You've came to the right place."
13
+ gem.license = 'MIT'
14
+ gem.authors = ['Szymon Szeliga']
15
+ gem.email = 'szeliga.szymon@gmail.com'
16
+ gem.homepage = 'https://rubygems.org/gems/seraph'
17
+
18
+ gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
19
+
20
+ `git submodule --quiet foreach --recursive pwd`.split($INPUT_RECORD_SEPARATOR).each do |submodule|
21
+ submodule.sub!("#{Dir.pwd}/", '')
22
+
23
+ Dir.chdir(submodule) do
24
+ `git ls-files`.split($INPUT_RECORD_SEPARATOR).map do |subpath|
25
+ gem.files << File.join(submodule, subpath)
26
+ end
27
+ end
28
+ end
29
+ gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
30
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
31
+ gem.require_paths = ['lib']
32
+
33
+ gem.add_dependency 'bcrypt', '~> 3.1'
34
+ gem.add_dependency 'fast_secure_compare', '~> 1.0'
35
+ gem.add_dependency 'fast_blank', '~> 1.0'
36
+ gem.add_development_dependency 'bundler', '~> 1.10'
37
+ gem.add_development_dependency 'rake', '~> 10.0'
38
+ gem.add_development_dependency 'rspec', '~> 3.0'
39
+ gem.add_development_dependency 'rubygems-tasks', '~> 0.2'
40
+ gem.add_development_dependency 'fuubar'
41
+ gem.add_development_dependency 'pry'
42
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+ require 'seraph/password_encryptor'
3
+
4
+ RSpec.describe Seraph::PasswordEncryptor do
5
+ describe '.call' do
6
+ let(:password) { 'foobar12' }
7
+ subject { described_class.call(password) }
8
+
9
+ it 'encrypts the password using BCrypt' do
10
+ encrypted = subject
11
+ expect(encrypted.to_s).to eq BCrypt::Engine.hash_secret(password, encrypted.salt)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+ require 'seraph'
3
+
4
+ describe Seraph do
5
+ it "should have a VERSION constant" do
6
+ expect(subject.const_get('VERSION')).to_not be_empty
7
+ end
8
+ end
@@ -0,0 +1,15 @@
1
+ require 'rspec'
2
+ require 'seraph/version'
3
+
4
+ RSpec.configure do |config|
5
+ config.expect_with :rspec do |expectations|
6
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
7
+ end
8
+
9
+ config.mock_with :rspec do |mocks|
10
+ mocks.verify_partial_doubles = true
11
+ end
12
+
13
+ config.order = :random
14
+ Kernel.srand config.seed
15
+ end
metadata ADDED
@@ -0,0 +1,192 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: seraph
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Szymon Szeliga
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-06-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bcrypt
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.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.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: fast_secure_compare
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: fast_blank
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
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.10'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.10'
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
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubygems-tasks
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.2'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.2'
111
+ - !ruby/object:Gem::Dependency
112
+ name: fuubar
113
+ requirement: !ruby/object:Gem::Requirement
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
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: pry
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: Looking for an authentication gem that doesn't make any assumptions about
140
+ your setup? You've came to the right place.
141
+ email: szeliga.szymon@gmail.com
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - ".gitignore"
147
+ - ".pryrc"
148
+ - ".rspec"
149
+ - ".rubocop.yml"
150
+ - ".ruby-version"
151
+ - ".travis.yml"
152
+ - ChangeLog.md
153
+ - Gemfile
154
+ - LICENSE.txt
155
+ - README.md
156
+ - Rakefile
157
+ - lib/seraph.rb
158
+ - lib/seraph/extensions/nil_class_blank.rb
159
+ - lib/seraph/password_encryptor.rb
160
+ - lib/seraph/version.rb
161
+ - seraph.gemspec
162
+ - spec/password_encryptor_spec.rb
163
+ - spec/serafin_spec.rb
164
+ - spec/spec_helper.rb
165
+ homepage: https://rubygems.org/gems/seraph
166
+ licenses:
167
+ - MIT
168
+ metadata: {}
169
+ post_install_message:
170
+ rdoc_options: []
171
+ require_paths:
172
+ - lib
173
+ required_ruby_version: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - ">="
176
+ - !ruby/object:Gem::Version
177
+ version: '0'
178
+ required_rubygems_version: !ruby/object:Gem::Requirement
179
+ requirements:
180
+ - - ">="
181
+ - !ruby/object:Gem::Version
182
+ version: '0'
183
+ requirements: []
184
+ rubyforge_project:
185
+ rubygems_version: 2.5.1
186
+ signing_key:
187
+ specification_version: 4
188
+ summary: A simple framework-agnostic library for authentication
189
+ test_files:
190
+ - spec/password_encryptor_spec.rb
191
+ - spec/serafin_spec.rb
192
+ - spec/spec_helper.rb