tinycert 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: bdaf3ad85df64ecd2e36e07e59ca9368649dc6dc
4
+ data.tar.gz: 25b28c91c45eb8c3e962f25fdeb4ac5a2d7214c3
5
+ SHA512:
6
+ metadata.gz: 76604bfe635c3d2e3c62d2e599b746715b5db83f4dfdc3bb47fdf0fc81e9c7f20ced0739fceb8a9be801064f69f30d0789c0a32b70e64fc3a9ed7a265863e93c
7
+ data.tar.gz: 60be954b121b5c7746c5f386cc95f44a53015537d9f3a88a7e72f20a0a5b1614dc299a30b3865b71a8b8b2e7c4227e961b227be23a7a23dd04b5d338169728ac
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.16.1
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in tinycert.gemspec
6
+ gemspec
@@ -0,0 +1,41 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ tinycert (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ coderay (1.1.2)
10
+ diff-lcs (1.3)
11
+ method_source (0.9.0)
12
+ pry (0.11.3)
13
+ coderay (~> 1.1.0)
14
+ method_source (~> 0.9.0)
15
+ rake (10.5.0)
16
+ rspec (3.7.0)
17
+ rspec-core (~> 3.7.0)
18
+ rspec-expectations (~> 3.7.0)
19
+ rspec-mocks (~> 3.7.0)
20
+ rspec-core (3.7.1)
21
+ rspec-support (~> 3.7.0)
22
+ rspec-expectations (3.7.0)
23
+ diff-lcs (>= 1.2.0, < 2.0)
24
+ rspec-support (~> 3.7.0)
25
+ rspec-mocks (3.7.0)
26
+ diff-lcs (>= 1.2.0, < 2.0)
27
+ rspec-support (~> 3.7.0)
28
+ rspec-support (3.7.1)
29
+
30
+ PLATFORMS
31
+ ruby
32
+
33
+ DEPENDENCIES
34
+ bundler (~> 1.16)
35
+ pry
36
+ rake (~> 10.0)
37
+ rspec (~> 3.0)
38
+ tinycert!
39
+
40
+ BUNDLED WITH
41
+ 1.16.1
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Jamie Lawrence
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,79 @@
1
+ # Tinycert
2
+
3
+ A small client for the Tinycert.org api
4
+
5
+ ![Build status](https://travis-ci.org/ideasasylum/tinycert.svg?branch=master)
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'tinycert'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install tinycert
22
+
23
+ ## Usage
24
+
25
+ ```ruby
26
+ require 'tinycert'
27
+ tinycert = TinyCert::Client.new '<your@email.address>', '<your passphrase>', '<your api key>'
28
+ ```
29
+
30
+ Note, your API key can be found [in the API documentation](https://www.tinycert.org/docs/api/v1/intro)
31
+
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
+
34
+ ### List all CAs
35
+
36
+ ```ruby
37
+ cas = tinycert.authorities.list
38
+ ```
39
+
40
+ ### Fetch a CA
41
+
42
+ ```ruby
43
+ ca = tinycert.authorities[1111]
44
+ => #<Tinycert::CertAuthority:0x007f83423cd710 @id=1111, @name="Ideas Asylum">
45
+ ```
46
+
47
+ ### Create a cert
48
+
49
+ ```ruby
50
+ ca.certs.create 'example.com', names: ['example.com', 'www.example.com', '*.example.com']
51
+ ```
52
+
53
+ ### Find all the valid certs
54
+
55
+ ```ruby
56
+ certs = ca.certs.good
57
+ [#<Tinycert::Cert:0x007f97d84043c8 @id=11111, @status="good", @cn=nil, @names=[]>]
58
+ ```
59
+
60
+ ### Get more details
61
+
62
+ ```
63
+ certs.first.details
64
+ => #<Tinycert::Cert:0x007ff34bb0fce8 @id=14236, @status="good", @cn="lvh.me", @names=["lvh.me", "*.lvh.me"]>
65
+ ```
66
+
67
+ ## Development
68
+
69
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
70
+
71
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
72
+
73
+ ## Contributing
74
+
75
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ideasasylum/tinycert.
76
+
77
+ ## License
78
+
79
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "tinycert"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,7 @@
1
+ require 'tinycert/client'
2
+ require 'tinycert/request'
3
+ require 'tinycert/cert_authorities'
4
+ require 'tinycert/cert_authority'
5
+ require 'tinycert/certs'
6
+ require 'tinycert/cert'
7
+ require 'tinycert/error'
@@ -0,0 +1,72 @@
1
+ module Tinycert
2
+ class Cert
3
+ attr_reader :id, :status, :names, :cn
4
+
5
+ def initialize tinycert, results
6
+ @tinycert = tinycert
7
+ parse_results results
8
+ end
9
+
10
+ CERT = "cert"
11
+ CHAIN = "chain"
12
+ CSR = "csr"
13
+ KEY_DEC = "key.dec"
14
+ KEY_ENC = "key.enc"
15
+ PKCS12 = "pkcs12"
16
+
17
+ def cert
18
+ get CERT
19
+ end
20
+
21
+ def chain
22
+ get CHAIN
23
+ end
24
+
25
+ def csr
26
+ get CSR
27
+ end
28
+
29
+ def key_dec
30
+ get KEY_DEC
31
+ end
32
+
33
+ def key_enc
34
+ get KEY_ENC
35
+ end
36
+
37
+ def pkcs12
38
+ get PKCS12
39
+ end
40
+
41
+ def get what
42
+ request = @tinycert.session_request 'https://www.tinycert.org/api/v1/cert/get', { cert_id: id, what: what }
43
+ request.results
44
+ end
45
+
46
+ def details
47
+ request = @tinycert.session_request 'https://www.tinycert.org/api/v1/cert/details', { cert_id: id }
48
+ parse_results request.results
49
+ self
50
+ end
51
+
52
+ def revoke
53
+ change_status 'revoked'
54
+ end
55
+
56
+ def change_status new_status
57
+ request = @tinycert.session_request 'https://www.tinycert.org/api/v1/cert/status', {
58
+ cert_id: id,
59
+ status: new_status
60
+ }
61
+ request.results
62
+ end
63
+
64
+ def parse_results results
65
+ @id = results['id']
66
+ @status = results['status']
67
+ @cn = results['CN']
68
+ @name = results['name']
69
+ @names = results.fetch('Alt', []).collect { |name| name['DNS'] }
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,19 @@
1
+ module Tinycert
2
+ class CertAuthorities
3
+ def initialize tinycert
4
+ @tinycert = tinycert
5
+ end
6
+
7
+ def create
8
+ end
9
+
10
+ def list
11
+ request = @tinycert.session_request 'https://www.tinycert.org/api/v1/ca/list', { token: @tinycert.token }
12
+ request.results.collect { |a| Tinycert::CertAuthority.new @tinycert, a }
13
+ end
14
+
15
+ def [](ca_id)
16
+ list.find { |ca| ca.id == ca_id }
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,25 @@
1
+ module Tinycert
2
+ class CertAuthority
3
+ attr_reader :id, :name
4
+
5
+ def initialize tinycert, results
6
+ @tinycert = tinycert
7
+ parse_results results
8
+ end
9
+
10
+ def parse_results results
11
+ @id = results['id']
12
+ @name = results['name']
13
+ end
14
+
15
+ def certs
16
+ Tinycert::Certs.new(@tinycert, self)
17
+ end
18
+
19
+ def details
20
+ end
21
+
22
+ def delete
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,62 @@
1
+ module Tinycert
2
+ class Certs
3
+ attr_reader :ca
4
+
5
+ EXPIRED = 1
6
+ GOOD = 2
7
+ REVOKED = 4
8
+ HOLD = 8
9
+
10
+ def initialize tinycert, ca
11
+ @tinycert = tinycert
12
+ @ca = ca
13
+ end
14
+
15
+ def expired
16
+ list EXPIRED
17
+ end
18
+
19
+ def good
20
+ list GOOD
21
+ end
22
+
23
+ def revoked
24
+ list REVOKED
25
+ end
26
+
27
+ def hold
28
+ list HOLD
29
+ end
30
+
31
+ def list what
32
+ request = @tinycert.session_request 'https://www.tinycert.org/api/v1/cert/list', { ca_id: ca.id, what: what, token: @tinycert.token }
33
+ request.results.collect { |c| Tinycert::Cert.new @tinycert, c }
34
+ end
35
+
36
+ def [](cert_id)
37
+ request = @tinycert.session_request 'https://www.tinycert.org/api/v1/cert/details', { cert_id: cert_id, token: @tinycert.token }
38
+ Tinycert::Cert.new @tinycert, results
39
+ end
40
+
41
+ def create name, c:'US', l:'', o:'', ou:'', st: '', names:[]
42
+ # Include the common name in the SANs too
43
+ all_names = names << name
44
+
45
+ indexed_names = all_names.uniq.each_with_index.inject({}) { |names, (name, index)|
46
+ names["SANs[#{index}][DNS]"] = name
47
+ names
48
+ }
49
+
50
+ request = @tinycert.session_request 'https://www.tinycert.org/api/v1/cert/new', {
51
+ token: @tinycert.token,
52
+ CN: name,
53
+ C: c,
54
+ O: o,
55
+ OU: ou,
56
+ ST: st,
57
+ ca_id: ca.id
58
+ }.merge(indexed_names)
59
+ Tinycert::Cert.new @tinycert, request.results
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,33 @@
1
+ module Tinycert
2
+ class Client
3
+ attr_reader :api_key, :email, :passphrase, :token
4
+
5
+ def initialize email, passphrase, api_key
6
+ @email = email
7
+ @passphrase = passphrase
8
+ @api_key = api_key
9
+ @token = nil
10
+ end
11
+
12
+ def connect
13
+ request = request 'https://www.tinycert.org/api/v1/connect', { email: email, passphrase: passphrase }
14
+ @token = request.results['token']
15
+ end
16
+
17
+ def request url, params
18
+ Tinycert::Request.new api_key, url, params
19
+ end
20
+
21
+ def session_request url, params
22
+ connect unless token
23
+ Tinycert::Request.new api_key, url, params.merge({token: token})
24
+ end
25
+
26
+ def authorities
27
+ Tinycert::CertAuthorities.new(self)
28
+ end
29
+
30
+ def disconnect
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,18 @@
1
+ module Tinycert
2
+ class Error < StandardError
3
+ attr_reader :response
4
+ def initialize response
5
+ error = JSON.parse response.body
6
+ name = error['code']
7
+ description = error['text']
8
+
9
+ super "#{name} - #{description}"
10
+
11
+ @response = response
12
+ end
13
+
14
+ def message
15
+ "#{@response.code}: #{super}"
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,63 @@
1
+ require 'uri'
2
+ require 'net/http'
3
+ require 'openssl'
4
+ require 'json'
5
+
6
+ module Tinycert
7
+ class Request
8
+ attr_reader :params
9
+
10
+ def initialize api_key, url, params
11
+ @api_key = api_key
12
+ @uri = URI(url)
13
+ @params = prepare_params(params)
14
+
15
+ # Create client
16
+ @client = Net::HTTP.new(@uri.host, @uri.port)
17
+ @client.use_ssl = true
18
+ @client.verify_mode = OpenSSL::SSL::VERIFY_PEER
19
+ end
20
+
21
+ # Sort the params consistently
22
+ def prepare_params params
23
+ # Sort nested structures
24
+ # params.sort_by { |k,v| k.to_s }.to_h.each { |k, v| params[k] = v.sort.to_h if v.respond_to?(:sort) }
25
+ params.sort.to_h
26
+ end
27
+
28
+ def digest
29
+ sorted_params = @params
30
+ sorted_params_string = URI.encode_www_form(sorted_params)
31
+ OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), @api_key, sorted_params_string)
32
+ end
33
+
34
+ # Create Request
35
+ def build_request
36
+ req = Net::HTTP::Post.new(@uri)
37
+ req.add_field "Content-Type", "application/x-www-form-urlencoded; charset=utf-8"
38
+ req.body = URI.encode_www_form(params_with_digest)
39
+ # puts @uri
40
+ # puts req.body
41
+ req
42
+ end
43
+
44
+ def params_with_digest
45
+ params = @params.dup
46
+ params['digest'] = digest
47
+ params
48
+ end
49
+
50
+ # Fetch Request
51
+ def response
52
+ res = @client.request(build_request)
53
+ raise Tinycert::Error.new(res) if res.code != '200'
54
+ res
55
+ end
56
+
57
+ def results
58
+ results = JSON.parse(response.body)
59
+ puts results
60
+ results
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,3 @@
1
+ module Tinycert
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,28 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "tinycert/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "tinycert"
8
+ spec.version = Tinycert::VERSION
9
+ spec.authors = ["Jamie Lawrence"]
10
+ spec.email = ["jamie@ideasasylum.com"]
11
+
12
+ spec.summary = %q{Tinycert api client}
13
+ spec.description = %q{A small gem for interacting with the Tinycert.org API}
14
+ spec.homepage = "http://github.com/ideasasylum/tinycert"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.16"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+ spec.add_development_dependency "pry"
28
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tinycert
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jamie Lawrence
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-02-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
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: A small gem for interacting with the Tinycert.org API
70
+ email:
71
+ - jamie@ideasasylum.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - Gemfile.lock
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/setup
86
+ - lib/tinycert.rb
87
+ - lib/tinycert/cert.rb
88
+ - lib/tinycert/cert_authorities.rb
89
+ - lib/tinycert/cert_authority.rb
90
+ - lib/tinycert/certs.rb
91
+ - lib/tinycert/client.rb
92
+ - lib/tinycert/error.rb
93
+ - lib/tinycert/request.rb
94
+ - lib/tinycert/version.rb
95
+ - tinycert.gemspec
96
+ homepage: http://github.com/ideasasylum/tinycert
97
+ licenses:
98
+ - MIT
99
+ metadata: {}
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 2.6.13
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: Tinycert api client
120
+ test_files: []