handshakejs 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +19 -0
- data/.rspec +2 -0
- data/.travis.yml +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +25 -0
- data/Rakefile +1 -0
- data/handshakejs.gemspec +26 -0
- data/lib/handshakejs.rb +56 -0
- data/lib/handshakejs/version.rb +3 -0
- data/spec/handshakejs_spec.rb +61 -0
- data/spec/spec_helper.rb +13 -0
- metadata +139 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
script: "bundle exec rspec"
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Scott Motte
|
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,25 @@
|
|
1
|
+
# handshakejs rubygem
|
2
|
+
|
3
|
+
Makes interacting with handshakejs easier in ruby.
|
4
|
+
|
5
|
+
```ruby
|
6
|
+
Handshakejs.salt = "your_long_secret_salt"
|
7
|
+
Handshakejs.valid?({email: email, hash: hash})
|
8
|
+
```
|
9
|
+
|
10
|
+
## Running Specs
|
11
|
+
|
12
|
+
```
|
13
|
+
bundle exec rspec
|
14
|
+
```
|
15
|
+
|
16
|
+
## Publish to RubyGems.org
|
17
|
+
|
18
|
+
You first need to request access from [scottmotte](http://github.com/scottmotte).
|
19
|
+
|
20
|
+
```
|
21
|
+
gem build handshakejs.gemspec
|
22
|
+
gem push handshakejs-0.0.1.gem
|
23
|
+
```
|
24
|
+
|
25
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/handshakejs.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'handshakejs/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "handshakejs"
|
8
|
+
gem.version = Handshakejs::VERSION
|
9
|
+
gem.authors = ["scottmotte"]
|
10
|
+
gem.email = ["scott@scottmotte.com"]
|
11
|
+
gem.description = %q{Rubygem for Handshakejs session check.}
|
12
|
+
gem.summary = %q{Rubygem for Handshakejs session check.}
|
13
|
+
gem.homepage = "http://github.com/scottmotte/handshakejs-ruby"
|
14
|
+
|
15
|
+
gem.add_dependency "pbkdf2", "0.1.0"
|
16
|
+
|
17
|
+
gem.add_development_dependency "foreman"
|
18
|
+
gem.add_development_dependency "pry"
|
19
|
+
gem.add_development_dependency "rake"
|
20
|
+
gem.add_development_dependency "rspec"
|
21
|
+
|
22
|
+
gem.files = `git ls-files`.split($/)
|
23
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
24
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
25
|
+
gem.require_paths = ["lib"]
|
26
|
+
end
|
data/lib/handshakejs.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require "pbkdf2"
|
2
|
+
require "handshakejs/version"
|
3
|
+
|
4
|
+
module Handshakejs
|
5
|
+
extend self
|
6
|
+
|
7
|
+
def salt=(salt)
|
8
|
+
@salt = salt
|
9
|
+
|
10
|
+
@salt
|
11
|
+
end
|
12
|
+
|
13
|
+
def salt
|
14
|
+
return @salt if @salt
|
15
|
+
"salt_required"
|
16
|
+
end
|
17
|
+
|
18
|
+
def iterations=(iterations)
|
19
|
+
@iterations = iterations
|
20
|
+
|
21
|
+
@iterations
|
22
|
+
end
|
23
|
+
|
24
|
+
def iterations
|
25
|
+
return @iterations if @iterations
|
26
|
+
1000
|
27
|
+
end
|
28
|
+
|
29
|
+
def key_length=(key_length)
|
30
|
+
@key_length = key_length
|
31
|
+
|
32
|
+
@key_length
|
33
|
+
end
|
34
|
+
|
35
|
+
def key_length
|
36
|
+
return @key_length if @key_length
|
37
|
+
16
|
38
|
+
end
|
39
|
+
|
40
|
+
def validate(params={})
|
41
|
+
pbkdf2 = PBKDF2.new do |p|
|
42
|
+
p.password = params[:email]
|
43
|
+
p.salt = Handshakejs.salt
|
44
|
+
p.iterations = Handshakejs.iterations
|
45
|
+
p.key_length = Handshakejs.key_length
|
46
|
+
p.hash_function = "sha1"
|
47
|
+
end
|
48
|
+
|
49
|
+
puts pbkdf2.hex_string
|
50
|
+
|
51
|
+
params[:hash] == pbkdf2.hex_string
|
52
|
+
|
53
|
+
#pbkdf2 = PBKDF2.new(:password=>params[:email], :salt=>Hanshakejs.salt, :iterations=>1000, :key_length => 16, :hash_function => "sha1")
|
54
|
+
#session[:user] = params[:email] if pbkdf2.hex_string == params[:hash]
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Handshakejs do
|
4
|
+
describe "defaults" do
|
5
|
+
before do
|
6
|
+
Handshakejs.salt = nil
|
7
|
+
end
|
8
|
+
|
9
|
+
it { Handshakejs.salt.should eq "salt_required" }
|
10
|
+
it { Handshakejs::VERSION.should eq "0.0.1" }
|
11
|
+
it { Handshakejs.iterations.should eq 1000 }
|
12
|
+
it { Handshakejs.key_length.should eq 16 }
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "setting values" do
|
16
|
+
let(:salt) { "adf3434938492fjkdfj" }
|
17
|
+
|
18
|
+
before do
|
19
|
+
Handshakejs.salt = salt
|
20
|
+
end
|
21
|
+
|
22
|
+
it { Handshakejs.salt.should eq salt }
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#validate" do
|
26
|
+
let(:salt) { "1234" }
|
27
|
+
let(:email) { "scott@mailinator.com" }
|
28
|
+
let(:hash) { "852874208fc66f6c404b6150e2bf3fba" }
|
29
|
+
|
30
|
+
before do
|
31
|
+
Handshakejs.salt = salt
|
32
|
+
end
|
33
|
+
|
34
|
+
it "is valid against against a correct email, hash combination" do
|
35
|
+
result = Handshakejs.validate({email: email, hash: hash})
|
36
|
+
|
37
|
+
result.should be_true
|
38
|
+
end
|
39
|
+
|
40
|
+
it "is invalid against against an incorrect email" do
|
41
|
+
email = "different@email.com"
|
42
|
+
result = Handshakejs.validate({email: email, hash: hash})
|
43
|
+
|
44
|
+
result.should be_false
|
45
|
+
end
|
46
|
+
|
47
|
+
it "is invalid against against an incorrect hash" do
|
48
|
+
hash = "differenthash"
|
49
|
+
result = Handshakejs.validate({email: email, hash: hash})
|
50
|
+
|
51
|
+
result.should be_false
|
52
|
+
end
|
53
|
+
|
54
|
+
it "is invalid against against a different salt" do
|
55
|
+
Handshakejs.salt = "different"
|
56
|
+
result = Handshakejs.validate({email: email, hash: hash})
|
57
|
+
|
58
|
+
result.should be_false
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
require 'pry'
|
4
|
+
require 'handshakejs'
|
5
|
+
require 'securerandom'
|
6
|
+
|
7
|
+
Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f}
|
8
|
+
|
9
|
+
RSpec.configure do |config|
|
10
|
+
config.before(:suite) do
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
metadata
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: handshakejs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- scottmotte
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-02-16 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: pbkdf2
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - '='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.1.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - '='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.1.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: foreman
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: pry
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rake
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: rspec
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
description: Rubygem for Handshakejs session check.
|
95
|
+
email:
|
96
|
+
- scott@scottmotte.com
|
97
|
+
executables: []
|
98
|
+
extensions: []
|
99
|
+
extra_rdoc_files: []
|
100
|
+
files:
|
101
|
+
- .gitignore
|
102
|
+
- .rspec
|
103
|
+
- .travis.yml
|
104
|
+
- Gemfile
|
105
|
+
- LICENSE.txt
|
106
|
+
- README.md
|
107
|
+
- Rakefile
|
108
|
+
- handshakejs.gemspec
|
109
|
+
- lib/handshakejs.rb
|
110
|
+
- lib/handshakejs/version.rb
|
111
|
+
- spec/handshakejs_spec.rb
|
112
|
+
- spec/spec_helper.rb
|
113
|
+
homepage: http://github.com/scottmotte/handshakejs-ruby
|
114
|
+
licenses: []
|
115
|
+
post_install_message:
|
116
|
+
rdoc_options: []
|
117
|
+
require_paths:
|
118
|
+
- lib
|
119
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
120
|
+
none: false
|
121
|
+
requirements:
|
122
|
+
- - ! '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
|
+
none: false
|
127
|
+
requirements:
|
128
|
+
- - ! '>='
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
requirements: []
|
132
|
+
rubyforge_project:
|
133
|
+
rubygems_version: 1.8.23
|
134
|
+
signing_key:
|
135
|
+
specification_version: 3
|
136
|
+
summary: Rubygem for Handshakejs session check.
|
137
|
+
test_files:
|
138
|
+
- spec/handshakejs_spec.rb
|
139
|
+
- spec/spec_helper.rb
|