acme-authorizer 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 977529790f213295b6f3c79975b6513cd944ff46
4
+ data.tar.gz: c111c0e8486f8dab57bea8263b7c89272828abf1
5
+ SHA512:
6
+ metadata.gz: 73af8b62cee96aa35a9fc0fc1332213822bd6ba058f872d2a376dd52b72c49547be4a3eb6d32dd9955307fdf9a3430ec77b2d753d46f009bc56fb0d66a058284
7
+ data.tar.gz: 2f142ca3a679b917f5a49c08b0ab62dde93d4595fe37cb063a4e908cbd6d4ee0b72c4fc0a6359f13b701360f4c3410a712a5aae63ad904be1649c4cbfdf46eed
@@ -0,0 +1,20 @@
1
+ Copyright 2016 BetterUp, Inc.
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.
@@ -0,0 +1,39 @@
1
+ ## Overview
2
+ This gem is an implementation of the [ACME http-01
3
+ challenge](https://tools.ietf.org/html/draft-ietf-acme-acme-01#page-38)
4
+ for use in Rails applications.
5
+
6
+ ## Installation
7
+
8
+ ```ruby
9
+ # Gemfile
10
+ gem 'acme-authorizer'
11
+ ```
12
+
13
+ NOTE: the ACME http-01 challenge/response *must* be served over HTTP without
14
+ SSL. This means that your Rails application can not have the `force_ssl` flag
15
+ set in your `config/application.rb`.
16
+
17
+ In order to enable application wide SSL, use this alternative method:
18
+ http://guides.rubyonrails.org/action_controller_overview.html#force-https-protocol
19
+
20
+ ## Configuration
21
+
22
+ By default, this library is configured via pairs of ENV variables with the same format used by [sabayon](https://github.com/dmathieu/sabayon):
23
+ ```
24
+ /ACME_TOKEN_[0-9]+/
25
+ /ACME_KEY_[0-9]+/
26
+ ```
27
+
28
+ for example:
29
+ ```
30
+ ACME_TOKEN_0=123123
31
+ ACME_KEY_0=123123
32
+ ```
33
+
34
+ The challenge and token can also be configured via Ruby API.
35
+ ```ruby
36
+ Acme::Authorizer.configure do |config|
37
+ config.add_token('my_challenge_token', 'my_key_authorization')
38
+ end
39
+ ```
@@ -0,0 +1,29 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'acme-authorizer'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+ load 'rails/tasks/statistics.rake'
21
+
22
+ Bundler::GemHelper.install_tasks
23
+
24
+ begin
25
+ require 'rspec/core/rake_task'
26
+ RSpec::Core::RakeTask.new(:spec)
27
+ rescue LoadError
28
+ end
29
+ task default: :spec
@@ -0,0 +1,7 @@
1
+ module Acme
2
+ module Authorizer
3
+ class ApplicationController < ActionController::Base
4
+ protect_from_forgery with: :exception
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,20 @@
1
+ module Acme
2
+ module Authorizer
3
+ class TokensController < ApplicationController
4
+ def show
5
+ token = params[:token]
6
+ if acme_authorizer_config.valid_token?(token)
7
+ render text: acme_authorizer_config.key_authorization_for_token(token)
8
+ else
9
+ render nothing: true, status: 404
10
+ end
11
+ end
12
+
13
+ private
14
+
15
+ def acme_authorizer_config
16
+ Acme::Authorizer.configuration
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ Rails.application.routes.draw do
2
+ get '/.well-known/acme-challenge/:token' => 'acme/authorizer/tokens#show', constraints: { protocol: 'http://' }
3
+ end
@@ -0,0 +1,16 @@
1
+ require 'acme/authorizer/engine' if defined?(Rails)
2
+ require 'acme/authorizer/configuration'
3
+
4
+ module Acme
5
+ module Authorizer
6
+ class << self
7
+ def configure
8
+ yield configuration
9
+ end
10
+
11
+ def configuration
12
+ @configuration ||= Acme::Authorizer::Configuration.new
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,36 @@
1
+ module Acme
2
+ module Authorizer
3
+ class Configuration
4
+ def initialize
5
+ @tokens = {}
6
+ add_tokens_from_env
7
+ end
8
+
9
+ def add_token(token, key_authorization)
10
+ @tokens[token] = key_authorization
11
+ end
12
+
13
+ def valid_token?(token)
14
+ @tokens.key?(token)
15
+ end
16
+
17
+ def key_authorization_for_token(token)
18
+ @tokens[token]
19
+ end
20
+
21
+ private
22
+
23
+ # TODO: raise error if missing matching authorization for token index
24
+ def add_tokens_from_env
25
+ ENV.each do |key, value|
26
+ match = key.match(/\A^ACME_TOKEN_([0-9]+)\Z/)
27
+ next unless match
28
+ index = match[1]
29
+ token = value
30
+ key_authorization = ENV["ACME_KEY_#{index}"]
31
+ add_token(token, key_authorization)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,12 @@
1
+ module Acme
2
+ module Authorizer
3
+ class Engine < ::Rails::Engine
4
+ InvalidConfigurationError = Class.new(StandardError)
5
+
6
+ isolate_namespace Acme::Authorizer
7
+ initializer 'acme-authorizer.config.force_ssl_assertion' do |app|
8
+ raise InvalidConfigurationError, 'force_ssl can not be enabled globally. see http://guides.rubyonrails.org/action_controller_overview.html#force-https-protocol' if app.config.force_ssl
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ module Acme
2
+ module Authorizer
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: acme-authorizer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - BetterUp Developers
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-06-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 4.2.6
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 4.2.6
27
+ - !ruby/object:Gem::Dependency
28
+ name: sqlite3
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
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: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: shoulda-matchers
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Rails engine for generating SSL certificates using the ACME challenge
70
+ and response method
71
+ email:
72
+ - developers@betterup.co
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - MIT-LICENSE
78
+ - README.md
79
+ - Rakefile
80
+ - app/controllers/acme/authorizer/application_controller.rb
81
+ - app/controllers/acme/authorizer/tokens_controller.rb
82
+ - config/routes.rb
83
+ - lib/acme-authorizer.rb
84
+ - lib/acme/authorizer/configuration.rb
85
+ - lib/acme/authorizer/engine.rb
86
+ - lib/acme/authorizer/version.rb
87
+ homepage: http://github.com/betterup/acme-authorizer
88
+ licenses:
89
+ - MIT
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.6.4
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: Rails engine for generating SSL certificates with ACME challenges
111
+ test_files: []