omniauth-trezor 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8ba29e12a780fb3e7cec9fb2a9f5265ab790711c
4
+ data.tar.gz: 9b10852f47f24c9f9ffcaab04942f862bf7b31f0
5
+ SHA512:
6
+ metadata.gz: fdc05db2a77528bcc0d65070f5e3ade1771745ca56b4d2e9698e21779bbc09f1737dc4fe07b3b88927dae07229daa0e1ee4178b221e30b4b7da6a2b942e8b8cd
7
+ data.tar.gz: f3924ad94fc450545eb98864725585aa95353c3134ac46cffced1c48d70798dfa29ac98fe6a4e27692c9185428a2d32076021c1b6eae38a7cd62a28121ae9f05
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in omniauth-trezor.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Jiri Kubicek
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,70 @@
1
+ # omniauth-trezor
2
+
3
+ `omniauth-trezor` provides an [OmniAuth][omniauth] strategy for [Trezor Connect][trezor_connect].
4
+
5
+ With this strategy your users can use popular [Bitcoin Trezor][trezor] to login to your website.
6
+
7
+ [omniauth]: https://github.com/intridea/omniauth
8
+ [trezor_connect]: https://github.com/trezor/connect
9
+ [trezor]: https://www.bitcointrezor.com
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'omniauth-trezor'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install omniauth-trezor
26
+
27
+ ## Usage
28
+
29
+ In Rails app, add config/initializers/omniauth.rb:
30
+
31
+ ```ruby
32
+ Rails.application.config.middleware.use OmniAuth::Builder do
33
+ provider :trezor, hosticon: "https://image.url"
34
+ end
35
+ ```
36
+
37
+ Or, in a Sinatra app:
38
+
39
+ ```ruby
40
+ use OmniAuth::Builder do
41
+ provider :trezor, hosticon: 'https://example.com/icon.png'
42
+ end
43
+
44
+ post '/auth/trezor/callback' do
45
+ auth = request.env['omniauth.auth]
46
+ # Use the auth info
47
+ end
48
+ ```
49
+
50
+ ### Options
51
+
52
+ These are the options you can specify that are relevant to Omniauth Trezor:
53
+
54
+ Challenge-response authentication via TREZOR. To protect against replay attacks, you must use a server-side generated and randomized challenge_hidden for every attempt. You can also provide a visual challenge that will be shown on the device.
55
+
56
+ * `:visual_challenge` - Text that will be shown on the device (defaults to `Time.now.strftime("%Y-%m-%d %H:%M:%S")`)
57
+ * `:hidden_challenge` - Hidden randomized hex string used to protect agains replay attacks (defaults to `SecureRandom.hex(32)`)
58
+ * `:hosticon` - Optional site icon https url. Should be at least 48x48px.
59
+
60
+ ### Callback phase
61
+
62
+ After successful authentication `request.env['omniauth.auth'].extra` contains all data that was used to verify the signature: `visual_challenge`, `hidden_challenge`, `signature` and `public_key` for your additional needs (ie. audit log).
63
+
64
+ ## Contributing
65
+
66
+ Bug reports and pull requests are welcome on GitHub at https://github.com/kraxnet/omniauth-trezor.
67
+
68
+ ## License
69
+
70
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,26 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ Bundler.setup :default, :development, :example
5
+ require 'sinatra'
6
+ require 'omniauth'
7
+ require 'omniauth-trezor'
8
+
9
+ use Rack::Session::Cookie
10
+
11
+ use OmniAuth::Builder do
12
+ provider :trezor, hosticon: 'https://example.com/icon.png'
13
+ end
14
+
15
+ get '/' do
16
+ <<-HTML
17
+ <ul>
18
+ <li><a href='/auth/trezor'>Sign in with Trezor</a></li>
19
+ </ul>
20
+ HTML
21
+ end
22
+
23
+ post '/auth/:provider/callback' do
24
+ content_type 'text/plain'
25
+ request.env['omniauth.auth'].inspect
26
+ end
@@ -0,0 +1,8 @@
1
+ require "omniauth-trezor/version"
2
+ require "omniauth"
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ autoload :Trezor, 'omniauth/strategies/trezor'
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module Trezor
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,95 @@
1
+ require 'omniauth'
2
+ require 'bitcoin'
3
+ require 'securerandom'
4
+
5
+ module OmniAuth
6
+ module Strategies
7
+ class Trezor
8
+ include OmniAuth::Strategy
9
+
10
+ option :visual_challenge, Time.now.strftime("%Y-%m-%d %H:%M:%S")
11
+ option :hidden_challenge, SecureRandom.hex(32)
12
+ option :hosticon
13
+ option :fields, [:public_key, :signature]
14
+ option :uid_field, :public_key
15
+
16
+ def request_phase
17
+ session['omniauth.trezor_visual_challenge'] = options[:visual_challenge]
18
+ session['omniauth.trezor_hidden_challenge'] = options[:hidden_challenge]
19
+
20
+ OmniAuth::Form.build(
21
+ title: "Trezor Login",
22
+ url: callback_path,
23
+ header_info: <<-HTML
24
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js" type="text/javascript"></script>
25
+ <script src="https://trezor.github.io/connect/login.js"></script>
26
+ <script type='text/javascript'>
27
+ function trezorLogin() {
28
+ TrezorConnect.requestLogin('#{options[:hosticon]}', '#{options[:hidden_challenge]}', '#{options[:visual_challenge]}', function (result) {
29
+ if (result.success) {
30
+ $('input[name=public_key]').val(result.public_key);
31
+ $('input[name=signature]').val(result.signature);
32
+ $('form').submit();
33
+ } else {
34
+ console.log('Error:', result.error);
35
+ }
36
+ });
37
+
38
+ }
39
+ $(function() {
40
+ $('button').click(function() {
41
+ trezorLogin();
42
+ return false;
43
+ });
44
+ });
45
+ </script>
46
+ HTML
47
+ ) do |f|
48
+ f.input_field('hidden', 'public_key')
49
+ f.input_field('hidden', 'signature')
50
+ f.html "<p>Logging in at: #{options[:visual_challenge]}</p>"
51
+ end.to_response
52
+ end
53
+
54
+ def callback_phase
55
+ verified = verify_signature(
56
+ extra[:public_key],
57
+ extra[:signature],
58
+ extra[:hidden_challenge],
59
+ extra[:visual_challenge]
60
+ )
61
+ if verified
62
+ super
63
+ else
64
+ fail!(:invalid_credentials)
65
+ end
66
+ end
67
+
68
+ uid do
69
+ request.params[options.uid_field.to_s]
70
+ end
71
+
72
+ extra do
73
+ {
74
+ hidden_challenge: session['omniauth.trezor_hidden_challenge'],
75
+ visual_challenge: session['omniauth.trezor_visual_challenge'],
76
+ public_key: request.params['public_key'],
77
+ signature: request.params['signature']
78
+ }
79
+ end
80
+
81
+ def skip_info?
82
+ true
83
+ end
84
+
85
+ private
86
+ def verify_signature(pubkey, signature, challenge_hidden='', challenge_visual='')
87
+ address = Bitcoin.pubkey_to_address(pubkey)
88
+ sha256 = Digest::SHA256.new
89
+ signature = [signature.htb].pack('m0')
90
+ message = sha256.digest(challenge_hidden.htb) + sha256.digest(challenge_visual)
91
+ Bitcoin.verify_message(address, signature, message)
92
+ end
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'omniauth-trezor/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "omniauth-trezor"
8
+ spec.version = OmniAuth::Trezor::VERSION
9
+ spec.authors = ["Jiri Kubicek"]
10
+ spec.email = ["jiri@kubicek.cz"]
11
+
12
+ spec.summary = "OmniAuth strategy for authenticating against the Trezor Connect"
13
+ spec.description = "OmniAuth strategy for authenticating against the Trezor Connect"
14
+ spec.homepage = "https://github.com/kraxnet/omniauth-trezor"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "omniauth", "~> 1.0"
23
+ spec.add_dependency "bitcoin", "~> 0.2"
24
+ spec.add_dependency "ffi", "~> 1.9"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.10"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "sinatra"
29
+ end
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-trezor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jiri Kubicek
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-01-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: omniauth
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bitcoin
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: ffi
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.9'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.9'
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: sinatra
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: OmniAuth strategy for authenticating against the Trezor Connect
98
+ email:
99
+ - jiri@kubicek.cz
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - Gemfile
106
+ - LICENSE.txt
107
+ - README.md
108
+ - Rakefile
109
+ - examples/sinatra.rb
110
+ - lib/omniauth-trezor.rb
111
+ - lib/omniauth-trezor/version.rb
112
+ - lib/omniauth/strategies/trezor.rb
113
+ - omniauth-trezor.gemspec
114
+ homepage: https://github.com/kraxnet/omniauth-trezor
115
+ licenses:
116
+ - MIT
117
+ metadata: {}
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ requirements: []
133
+ rubyforge_project:
134
+ rubygems_version: 2.4.5.1
135
+ signing_key:
136
+ specification_version: 4
137
+ summary: OmniAuth strategy for authenticating against the Trezor Connect
138
+ test_files: []
139
+ has_rdoc: