Class: LetsencryptHttpChallenge::ApplicationController

Inherits:
ActionController::Base
  • Object
show all
Defined in:
app/controllers/letsencrypt_http_challenge/application_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/controllers/letsencrypt_http_challenge/application_controller.rb', line 4

def index
  challenge = params[:challenge].to_s
  response = ENV['LE_HTTP_CHALLENGE_RESPONSE'].to_s
  status = :ok

  # https://letsencrypt.github.io/acme-spec/#rfc.section.7.1

  # token (required, string): This value MUST have at least 128 bits of entropy
  if challenge.length < 16
    response = 'Challenge failed - The token must have at least 128 bits of entropy'
    Rails.logger.error response
    status = :bad_request

  # its “token” field is equal to the “token” field in the challenge;
  elsif response.match(challenge).nil?
    response = 'Challenge failed - The token must match between the challenge and the response'
    Rails.logger.error response
    status = :bad_request
  end

  render plain: response, status: status
end