acme-client 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c389451aba873b133d61324af15bb4c4d8fd7ac0
4
- data.tar.gz: 803eb577b2e2d4ede9d7c5f1ccabf89a6b9c36b7
3
+ metadata.gz: db4de0115967af2794cdf73fbc564ba3207d07bb
4
+ data.tar.gz: a6e4dbafa02042fa3ebdf0c171a5f700770d000c
5
5
  SHA512:
6
- metadata.gz: dd04dd1c2bcebb94d8fd336d151797ba7262c41faef0b521cb92c9b00122a29ef6f68639c532951c40474347ca49faff0d92c9678e42dda89ca0adbb2ae877c4
7
- data.tar.gz: 15d1539125077753c8a8e68e7bd380daa0bcfb616d91424ba2ac640f4737b679b9aaae6585aeaf40c622cb6c0b9a2cf697fac2eddebcff35af0743cd75d360aa
6
+ metadata.gz: e54827c5a1b93c079476b4ee7061d42d8a69c668063afd571887a040b063c362fc68f279fff2ebc9260b0bde0dd3d4af6b86b8f950385419f715bb6bb5f74f42
7
+ data.tar.gz: 368afee114cd978a13f764869f84c74fbd7df1177bed9ed8a25c3e675b2bb8e4f0de80c97bc3f3f6d061e4bd9c6d0c4a938f78cd1f16789e48907f721499a0a7
data/bin/console CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "bundler/setup"
4
- require "acme/client"
4
+ require "acme-client"
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
data/lib/acme/client.rb CHANGED
@@ -17,7 +17,7 @@ class Acme::Client
17
17
 
18
18
  def register(contact:)
19
19
  payload = {
20
- resource: 'new-reg', contact: Array.wrap(contact)
20
+ resource: 'new-reg', contact: Array(contact)
21
21
  }
22
22
 
23
23
  response = connection.post(@operation_endpoints.fetch('new-reg'), payload)
data/lib/acme/crypto.rb CHANGED
@@ -30,7 +30,11 @@ class Acme::Crypto
30
30
  end
31
31
 
32
32
  def jwk
33
- JSON::JWK.new(public_key).to_hash
33
+ JSON::JWK.new(public_key)
34
+ end
35
+
36
+ def thumbprint
37
+ jwk.thumbprint
34
38
  end
35
39
 
36
40
  def public_key
@@ -1,7 +1,7 @@
1
1
  class Acme::Resources::Authorization
2
- SimpleHttp = Acme::Resources::Challenges::SimpleHttp
2
+ HTTP01 = Acme::Resources::Challenges::HTTP01
3
3
 
4
- attr_reader :domain, :status, :simple_http
4
+ attr_reader :domain, :status, :http01
5
5
 
6
6
  def initialize(client, response)
7
7
  @client = client
@@ -14,7 +14,7 @@ class Acme::Resources::Authorization
14
14
  def assign_challenges(challenges)
15
15
  challenges.each do |attributes|
16
16
  case attributes.fetch('type')
17
- when 'simpleHttp' then @simple_http = SimpleHttp.new(@client, attributes)
17
+ when 'http-01' then @http01 = HTTP01.new(@client, attributes)
18
18
  else
19
19
  # no supported
20
20
  end
@@ -1,2 +1,3 @@
1
1
  module Acme::Resources::Challenges; end
2
- require 'acme/resources/challenges/simple_http'
2
+ require 'acme/resources/challenges/base'
3
+ require 'acme/resources/challenges/http01'
@@ -0,0 +1,33 @@
1
+ class Acme::Resources::Challenges::Base
2
+
3
+ attr_reader :client, :status, :uri, :token, :error
4
+
5
+ def initialize(client, attributes)
6
+ @client = client
7
+ assign_attributes(attributes)
8
+ end
9
+
10
+ def verify_status
11
+ response = @client.connection.get(@uri)
12
+
13
+ assign_attributes(response.body)
14
+ @error = response.body['error']
15
+ status
16
+ end
17
+
18
+ private
19
+
20
+ def authorization_key
21
+ "#{token}.#{crypto.thumbprint}"
22
+ end
23
+
24
+ def assign_attributes(attributes)
25
+ @status = attributes.fetch('status', 'pending')
26
+ @uri = attributes.fetch('uri')
27
+ @token = attributes.fetch('token')
28
+ end
29
+
30
+ def crypto
31
+ @crypto ||= Acme::Crypto.new(@client.private_key)
32
+ end
33
+ end
@@ -0,0 +1,20 @@
1
+ class Acme::Resources::Challenges::HTTP01 < Acme::Resources::Challenges::Base
2
+ CONTENT_TYPE = 'text/plain'
3
+
4
+ def content_type
5
+ CONTENT_TYPE
6
+ end
7
+
8
+ def file_content
9
+ authorization_key
10
+ end
11
+
12
+ def filename
13
+ ".well-known/acme-challenge/#{token}"
14
+ end
15
+
16
+ def request_verification
17
+ response = client.connection.post(@uri, { resource: 'challenge', type: 'http-01', keyAuthorization: authorization_key })
18
+ response.success?
19
+ end
20
+ end
data/lib/acme/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Acme
2
2
  class Client
3
- VERSION = '0.1.2'
3
+ VERSION = '0.1.3'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acme-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Charles Barbier
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-21 00:00:00.000000000 Z
11
+ date: 2015-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -183,7 +183,8 @@ files:
183
183
  - lib/acme/resources.rb
184
184
  - lib/acme/resources/authorization.rb
185
185
  - lib/acme/resources/challenges.rb
186
- - lib/acme/resources/challenges/simple_http.rb
186
+ - lib/acme/resources/challenges/base.rb
187
+ - lib/acme/resources/challenges/http01.rb
187
188
  - lib/acme/resources/registration.rb
188
189
  - lib/acme/version.rb
189
190
  homepage: http://github.com/unixcharles/acme-client
@@ -1,50 +0,0 @@
1
- class Acme::Resources::Challenges::SimpleHttp
2
- CONTENT_TYPE = 'application/jose+json'
3
-
4
- attr_reader :status, :uri, :token, :error
5
- attr_accessor :tls
6
-
7
- def initialize(client, attributes)
8
- @client = client
9
- assign_attributes(attributes)
10
- end
11
-
12
- def content_type
13
- CONTENT_TYPE
14
- end
15
-
16
- def file_content
17
- message = { 'type' => 'simpleHttp', 'token' => token, 'tls' => tls }
18
- crypto.generate_signed_jws(header: {}, payload: message)
19
- end
20
-
21
- def filename
22
- ".well-known/acme-challenge/#{token}"
23
- end
24
-
25
- def request_verification
26
- response = @client.connection.post(@uri, { resource: 'challenge', type: 'simpleHttp', tls: tls })
27
- response.success?
28
- end
29
-
30
- def verify_status
31
- response = @client.connection.get(@uri)
32
-
33
- assign_attributes(response.body)
34
- @error = response.body['error']
35
- status
36
- end
37
-
38
- private
39
-
40
- def assign_attributes(attributes)
41
- @status = attributes.fetch('status', 'pending')
42
- @uri = attributes.fetch('uri')
43
- @token = attributes.fetch('token')
44
- @tls = attributes.fetch('tls')
45
- end
46
-
47
- def crypto
48
- @crypto ||= Acme::Crypto.new(@client.private_key)
49
- end
50
- end