tinycert 0.1.3 → 0.1.4

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: 69c0bb347db168ce7091c9cbdb6774f2b9c521dc
4
- data.tar.gz: 47a6253aa174fb8cb030d06e62e9676e46b0aafd
3
+ metadata.gz: b36e0b5cca75f3a5db731ccad59d81fe3e92add1
4
+ data.tar.gz: ac1e66823bc92e5f381789e15e5e39e0fa924e2c
5
5
  SHA512:
6
- metadata.gz: 565080a0835817068cc69cec2922c43ccb16453681193babf4c7e54300982f07f7ab224ffd0284271ae39297a703149fb462b746a3667133c5a5b357936f2006
7
- data.tar.gz: 26bf62cf7926f9c677267117f2f7d3bc3d20771f8f66770de570ed84bf2237f009aaefc0a29b45ed0180355a599792514778302fa15aaa33332752f0bad78146
6
+ metadata.gz: 487d3c600a1a6f73a22b912cf92d1d5aaf84316c152cce7eb0333576c215cf4db142c3644d61e69881a38381739ba610afe47dab01a2c01fe53fc51a63e5c4aa
7
+ data.tar.gz: e7ffe3e3785c236a25fc1e07b6615c3d714c5b231e5e063eb01b34b2668a91916fc78f97f7629c98bbdc288bafc2beeb974c4921a45a4454148215a43542aecb
data/README.md CHANGED
@@ -31,6 +31,18 @@ Note, your API key can be found [in the API documentation](https://www.tinycert.
31
31
 
32
32
  **Your passphrase is _not_ the same as your password**. You should have your passphrase stored in your browser or securely elsewhere. You can set your password on the [Tinycert profile page](https://www.tinycert.org/profile)
33
33
 
34
+ ### Connect with a block
35
+
36
+ This will also call disconnect after the block
37
+
38
+ ```ruby
39
+ t = TinyCert::Client.new '<your@email.address>', '<your passphrase>', '<your api key>'
40
+ t.connect do |t|
41
+ a = t.authorities[5358]
42
+ cert = a.certs.create 'example.com', names: ['www.example.com', '*.example.com'], o: 'Development'
43
+ end
44
+ ```
45
+
34
46
  ### List all CAs
35
47
 
36
48
  ```ruby
@@ -63,6 +63,7 @@ module Tinycert
63
63
 
64
64
  def parse_results results
65
65
  @id = results['id']
66
+ @id ||= results['cert_id']
66
67
  @status = results['status']
67
68
  @cn = results['CN']
68
69
  @cn ||= results['name']
@@ -38,23 +38,23 @@ module Tinycert
38
38
  Tinycert::Cert.new @tinycert, results
39
39
  end
40
40
 
41
- def create name, c:'US', l:'', o:'', ou:'', st: '', names:[]
41
+ def create name, c:'US', l:nil, o:nil, ou:nil, st: nil, names:[]
42
42
  # Include the common name in the SANs too
43
43
  all_names = names << name
44
44
 
45
- indexed_names = all_names.uniq.each_with_index.inject({}) { |names, (name, index)|
46
- names["SANs[#{index}][DNS]"] = name
47
- names
45
+ indexed_names = all_names.uniq.each_with_index.inject({}) { |all, (n, index)|
46
+ all["SANs[#{index}][DNS]"] = n
47
+ all
48
48
  }
49
-
50
- request = @tinycert.session_request 'https://www.tinycert.org/api/v1/cert/new', {
49
+ request_params = {
51
50
  CN: name,
52
51
  C: c,
53
52
  O: o,
54
53
  OU: ou,
55
54
  ST: st,
56
55
  ca_id: ca.id
57
- }.merge(indexed_names)
56
+ }.merge(indexed_names).reject { |k,v| v.nil? }
57
+ request = @tinycert.session_request 'https://www.tinycert.org/api/v1/cert/new', request_params
58
58
  Tinycert::Cert.new @tinycert, request.results
59
59
  end
60
60
  end
@@ -9,16 +9,22 @@ module Tinycert
9
9
  @token = nil
10
10
  end
11
11
 
12
- def connect
12
+ def connect &block
13
13
  request = request 'https://www.tinycert.org/api/v1/connect', { email: email, passphrase: passphrase }
14
14
  @token = request.results['token']
15
+ if block_given?
16
+ result = yield self
17
+ disconnect
18
+ return result
19
+ end
20
+ return self
15
21
  end
16
22
 
17
23
  def request url, params
18
24
  Tinycert::Request.new api_key, url, params
19
25
  end
20
26
 
21
- def session_request url, params
27
+ def session_request url, params={}
22
28
  connect unless token
23
29
  Tinycert::Request.new api_key, url, params.merge({token: token})
24
30
  end
@@ -28,6 +34,9 @@ module Tinycert
28
34
  end
29
35
 
30
36
  def disconnect
37
+ request = session_request 'https://www.tinycert.org/api/v1/disconnect'
38
+ @token = nil
39
+ request.results
31
40
  end
32
41
  end
33
42
  end
@@ -19,40 +19,42 @@ module Tinycert
19
19
  end
20
20
 
21
21
  # Sort the params consistently
22
- def prepare_params params
22
+ def prepare_params p
23
23
  results = {}
24
24
  # Build a new hash with string keys
25
- params.each { |k, v| results[k.to_s] = v }
25
+ p.each { |k, v| results[k.to_s] = v }
26
26
  # Sort nested structures
27
27
  results.sort.to_h
28
28
  end
29
29
 
30
30
  def digest
31
- sorted_params = @params
32
- sorted_params_string = URI.encode_www_form(sorted_params)
33
- OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), @api_key, sorted_params_string)
31
+ OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), @api_key, params_string)
32
+ end
33
+
34
+ def params_string
35
+ # Replace * with %2A
36
+ URI.encode_www_form(@params).gsub(/\*/, '%2A')
34
37
  end
35
38
 
36
39
  # Create Request
37
40
  def build_request
38
41
  req = Net::HTTP::Post.new(@uri)
39
42
  req.add_field "Content-Type", "application/x-www-form-urlencoded; charset=utf-8"
40
- req.body = URI.encode_www_form(params_with_digest)
43
+ req.body = params_string_with_digest
41
44
  # puts @uri
42
45
  # puts req.body
43
46
  req
44
47
  end
45
48
 
46
- def params_with_digest
47
- params = @params.dup
48
- params['digest'] = digest
49
- params
49
+ def params_string_with_digest
50
+ params_string << "&digest=#{digest}"
50
51
  end
51
52
 
52
53
  # Fetch Request
53
54
  def response
54
55
  res = @client.request(build_request)
55
56
  raise Tinycert::Error.new(res) if res.code != '200'
57
+ puts res.body
56
58
  res
57
59
  end
58
60
 
@@ -1,3 +1,3 @@
1
1
  module Tinycert
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tinycert
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jamie Lawrence
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-02-21 00:00:00.000000000 Z
11
+ date: 2018-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler