rails-letsencrypt 0.5.5 → 0.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a5aeeebd0dd776f4fcc05752ea8b438878398d79
4
- data.tar.gz: fdff5b40a3526cbff50a83c7811b5a9970ccdf19
3
+ metadata.gz: 5be585e8379ddfbc487d70af910c3cf3302fb69b
4
+ data.tar.gz: 492664cf69aaf349837c0ae4f776ebb5fd6d913f
5
5
  SHA512:
6
- metadata.gz: d8759789aae5935de7951c65bb1281de060485ed0ff0d5532f825cd1bb6a0087a2fab3e659c94d42dc76a81f5bf3da7a974eda33e8214d6d94d8f8666a86903f
7
- data.tar.gz: d092e84fd25d14dd4e22546f922d9e74cce4a9357f5f0d1948f43c444fa1c8453170fbf313d51817648fcabefccf75e9c6b7ca9529a9bf3a45ef1d7d8d88f2d9
6
+ metadata.gz: 02564ed000fac27c0c623da185ffb58d0e37665fc979bf565d7e69a64743b88990991fd82962cc97aa23fd0e18ad6ace0d527561bc9c2addaff3fc494dd61cc3
7
+ data.tar.gz: b90615e07e0d1eeea7cb9deccc5b71926bd195d56d4e25ec304d2ce2f9c04a181db28599acb8a4c7123313115087404943d9f621638cbcc09a104db34df9bfed
@@ -18,21 +18,22 @@ module LetsEncrypt
18
18
  private
19
19
 
20
20
  def csr
21
- csr = OpenSSL::X509::Request.new
22
- csr.subject = OpenSSL::X509::Name.new(
23
- [['CN', domain, OpenSSL::ASN1::UTF8STRING]]
21
+ Acme::Client::CertificateRequest.new(
22
+ private_key: OpenSSL::PKey::RSA.new(key),
23
+ subject: {
24
+ common_name: domain
25
+ }
24
26
  )
25
- private_key = OpenSSL::PKey::RSA.new(key)
26
- csr.public_key = private_key.public_key
27
- csr.sign(private_key, OpenSSL::Digest::SHA256.new)
28
- csr
29
27
  end
30
28
 
31
29
  def create_certificate
32
- https_cert = LetsEncrypt.client.new_certificate(csr)
33
- self.certificate = https_cert.to_pem
34
- self.intermediaries = https_cert.chain_to_pem
35
- self.expires_at = https_cert.x509.not_after
30
+ order.finalize(csr: csr)
31
+ sleep 1 while order.status == 'processing'
32
+ fullchain = order.certificate.split("\n\n")
33
+ cert = OpenSSL::X509::Certificate.new(fullchain.shift)
34
+ self.certificate = cert.to_pem
35
+ self.intermediaries = fullchain.join("\n\n")
36
+ self.expires_at = cert.not_after
36
37
  self.renew_after = (expires_at - 1.month) + rand(10).days
37
38
  save!
38
39
  end
@@ -7,7 +7,7 @@ module LetsEncrypt
7
7
 
8
8
  # Returns true if verify domain is succeed.
9
9
  def verify
10
- start_authorize
10
+ create_order
11
11
  start_challenge
12
12
  wait_verify_status
13
13
  check_verify_status
@@ -17,9 +17,9 @@ module LetsEncrypt
17
17
 
18
18
  private
19
19
 
20
- def start_authorize
21
- authorization = LetsEncrypt.client.authorize(domain: domain)
22
- @challenge = authorization.http01
20
+ def create_order
21
+ # TODO: Support multiple domain
22
+ @challenge = order.authorizations.first.http
23
23
  self.verification_path = @challenge.filename
24
24
  self.verification_string = @challenge.file_content
25
25
  save!
@@ -27,24 +27,25 @@ module LetsEncrypt
27
27
 
28
28
  def start_challenge
29
29
  logger.info "Attempting verification of #{domain}"
30
- @challenge.request_verification
30
+ @challenge.request_validation
31
31
  end
32
32
 
33
33
  def wait_verify_status
34
34
  checks = 0
35
- until @challenge.verify_status != 'pending'
35
+ until @challenge.status != 'pending'
36
36
  checks += 1
37
37
  if checks > 30
38
38
  logger.info 'Status remained at pending for 30 checks'
39
39
  return false
40
40
  end
41
41
  sleep 1
42
+ @challenge.reload
42
43
  end
43
44
  end
44
45
 
45
46
  def check_verify_status
46
- unless @challenge.verify_status == 'valid'
47
- logger.info "Status was not valid (was: #{@challenge.verify_status})"
47
+ unless @challenge.status == 'valid'
48
+ logger.info "Status was not valid (was: #{@challenge.status})"
48
49
  return false
49
50
  end
50
51
 
@@ -78,5 +78,9 @@ module LetsEncrypt
78
78
  def logger
79
79
  LetsEncrypt.logger
80
80
  end
81
+
82
+ def order
83
+ @order ||= LetsEncrypt.client.new_order(identifiers: [domain])
84
+ end
81
85
  end
82
86
  end
data/lib/letsencrypt.rb CHANGED
@@ -12,18 +12,18 @@ require 'letsencrypt/redis'
12
12
  # :nodoc:
13
13
  module LetsEncrypt
14
14
  # Production mode API Endpoint
15
- ENDPOINT = 'https://acme-v01.api.letsencrypt.org/'
15
+ ENDPOINT = 'https://acme-v02.api.letsencrypt.org/directory'
16
16
 
17
17
  # Staging mode API Endpoint, the rate limit is higher
18
18
  # but got invalid certificate for testing
19
- ENDPOINT_STAGING = 'https://acme-staging.api.letsencrypt.org'
19
+ ENDPOINT_STAGING = 'https://acme-staging-v02.api.letsencrypt.org/directory'
20
20
 
21
21
  class << self
22
22
  # Create the ACME Client to Let's Encrypt
23
23
  def client
24
24
  @client ||= ::Acme::Client.new(
25
25
  private_key: private_key,
26
- endpoint: endpoint
26
+ directory: directory
27
27
  )
28
28
  end
29
29
 
@@ -38,7 +38,7 @@ module LetsEncrypt
38
38
  end
39
39
 
40
40
  # Get current using Let's Encrypt endpoint
41
- def endpoint
41
+ def directory
42
42
  @endpoint ||= config.use_staging? ? ENDPOINT_STAGING : ENDPOINT
43
43
  end
44
44
 
@@ -49,10 +49,9 @@ module LetsEncrypt
49
49
  # connect with domain and assign the owner who can
50
50
  # renew and revoked.
51
51
  def register(email)
52
- registration = client.register(contact: "mailto:#{email}")
52
+ account = client.new_account(contact: "mailto:#{email}", terms_of_service_agreed: true)
53
53
  logger.info "Successfully registered private key with address #{email}"
54
- registration.agree_terms
55
- logger.info 'Terms have been accepted'
54
+ account.kid # TODO: Save KID
56
55
  true
57
56
  end
58
57
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LetsEncrypt
4
- VERSION = '0.5.5'
4
+ VERSION = '0.6.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-letsencrypt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.5
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - 蒼時弦也
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-20 00:00:00.000000000 Z
11
+ date: 2018-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.0'
33
+ version: 2.0.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.0'
40
+ version: 2.0.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: redis
43
43
  requirement: !ruby/object:Gem::Requirement