varanus 0.2.1 → 0.3.0

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
  SHA256:
3
- metadata.gz: 21d141fb4a79d1be189992feb7ef7aec763e488024e516736dc2e9e9398bbb57
4
- data.tar.gz: 2eee7f27b14b98d0d1fcd061b16943be273c0f219a54440fbbab8fca601aebb7
3
+ metadata.gz: 230026bcb2def2b083ca884cd2302daf51407b6d57aa212c66d208d29a335b11
4
+ data.tar.gz: 69728f0eb64f2735e32bfa4b1d77e8bd4fde87b47f3f6e029a7ccbe441d85f3f
5
5
  SHA512:
6
- metadata.gz: 376cb245e647b3efc042495142c80c72e90d2fe4155d214560ca6788d3d2e0a619c4a91d37e304cf79d914e24bf79117256243f9023a206d4b93ff9439700248
7
- data.tar.gz: b83f3beb482ab7660d9fa0ffb4a8ee0593113823746f07a7aeb617c8900cbb27a773d9a7109917efc852d2de92a8f898f3a80d8af740ee29cc84c4b217b564da
6
+ metadata.gz: 6708842c8291bedf4b3d71d29b7437aba40ea1d1148e090f023eff5ba130abe8e74f278c95a67d39ca8346e37574a576f693e9caee946b02a68f58e4811ac636
7
+ data.tar.gz: 6db3621c1415feafb91eb3eb46407a240942f142d5b5aea3024bd44c644bf2232d73155c5908da51f7e85f6affc23533626e281d12848c8cd9293b4265517695
@@ -1,9 +1,15 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.3
2
+ NewCops: disable
3
+ TargetRubyVersion: 2.5
3
4
 
4
5
  Bundler/OrderedGems:
5
6
  AutoCorrect: false
6
7
 
8
+ Layout/LineLength:
9
+ Max: 90
10
+ Exclude:
11
+ - 'test/**/*'
12
+
7
13
  Metrics/AbcSize:
8
14
  Max: 25
9
15
  Exclude:
@@ -14,11 +20,6 @@ Metrics/ClassLength:
14
20
  Exclude:
15
21
  - 'test/**/*'
16
22
 
17
- Metrics/LineLength:
18
- Max: 90
19
- Exclude:
20
- - 'test/**/*'
21
-
22
23
  Metrics/MethodLength:
23
24
  Max: 20
24
25
  Exclude:
@@ -1,4 +1,7 @@
1
- ### 0.2.1 (2018-22-13)
1
+ ### 0.3.0 (2020-08-24)
2
+ * Add support for new 'Short Life' certs
3
+
4
+ ### 0.2.1 (2018-11-13)
2
5
  * Increase timeout value for SSL requests
3
6
 
4
7
  ### 0.2.0 (2018-11-09)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- varanus (0.2.0)
4
+ varanus (0.3.0)
5
5
  faraday
6
6
  faraday_middleware
7
7
  savon (~> 2.0)
@@ -14,7 +14,7 @@ GEM
14
14
  akami (1.3.1)
15
15
  gyoku (>= 0.4.0)
16
16
  nokogiri
17
- ast (2.4.0)
17
+ ast (2.4.1)
18
18
  builder (3.2.3)
19
19
  crack (0.4.3)
20
20
  safe_yaml (~> 1.0.0)
@@ -29,7 +29,6 @@ GEM
29
29
  httpi (2.4.4)
30
30
  rack
31
31
  socksify
32
- jaro_winkler (1.5.1)
33
32
  json (2.1.0)
34
33
  metaclass (0.0.4)
35
34
  mini_portile2 (2.3.0)
@@ -42,23 +41,27 @@ GEM
42
41
  nokogiri (1.8.5)
43
42
  mini_portile2 (~> 2.3.0)
44
43
  nori (2.6.0)
45
- parallel (1.12.1)
46
- parser (2.5.3.0)
47
- ast (~> 2.4.0)
48
- powerpack (0.1.2)
44
+ parallel (1.19.2)
45
+ parser (2.7.1.4)
46
+ ast (~> 2.4.1)
49
47
  public_suffix (3.0.3)
50
48
  rack (2.0.6)
51
49
  rainbow (3.0.0)
52
50
  rake (10.5.0)
53
- rubocop (0.60.0)
54
- jaro_winkler (~> 1.5.1)
51
+ regexp_parser (1.7.1)
52
+ rexml (3.2.4)
53
+ rubocop (0.89.1)
55
54
  parallel (~> 1.10)
56
- parser (>= 2.5, != 2.5.1.1)
57
- powerpack (~> 0.1)
55
+ parser (>= 2.7.1.1)
58
56
  rainbow (>= 2.2.2, < 4.0)
57
+ regexp_parser (>= 1.7)
58
+ rexml
59
+ rubocop-ast (>= 0.3.0, < 1.0)
59
60
  ruby-progressbar (~> 1.7)
60
- unicode-display_width (~> 1.4.0)
61
- ruby-progressbar (1.10.0)
61
+ unicode-display_width (>= 1.4.0, < 2.0)
62
+ rubocop-ast (0.3.0)
63
+ parser (>= 2.7.1.4)
64
+ ruby-progressbar (1.10.1)
62
65
  safe_yaml (1.0.4)
63
66
  savon (2.12.0)
64
67
  akami (~> 1.2)
@@ -74,7 +77,7 @@ GEM
74
77
  simplecov-html (~> 0.10.0)
75
78
  simplecov-html (0.10.2)
76
79
  socksify (1.7.1)
77
- unicode-display_width (1.4.0)
80
+ unicode-display_width (1.7.0)
78
81
  wasabi (3.5.0)
79
82
  httpi (~> 2.0)
80
83
  nokogiri (>= 1.4.2)
@@ -100,4 +103,4 @@ DEPENDENCIES
100
103
  yard
101
104
 
102
105
  BUNDLED WITH
103
- 1.17.1
106
+ 1.17.3
@@ -1,7 +1,7 @@
1
1
  version: '3'
2
2
  services:
3
3
  console:
4
- image: ruby:2.3
4
+ image: ruby:2.5
5
5
  volumes:
6
6
  - .:/app:z
7
7
  hostname: varanus-dev
@@ -11,19 +11,15 @@ class Varanus::SSL
11
11
  # Returns the option from #certificate_types that best matches the csr.
12
12
  # @param csr [Varanus::SSL::CSR]
13
13
  # @return [Hash] The option from {#certificate_types} that best matches the csr
14
- def certificate_type_from_csr csr
15
- # first exclude certificate types we don't want
16
- types = certificate_types.reject do |ct|
17
- ct['name'] =~ /\b(?:EV|ECC|AMT|Elite)\b/
18
- end
19
- if csr.all_names.any? { |n| n.start_with?('*.') }
20
- types.find { |ct| ct['name'] =~ /Wildcard.+SSL/i }
21
- elsif csr.subject_alt_names.any?
22
- types.find { |ct| ct['name'] =~ /Multi.?Domain.+SSL/i }
23
- else
24
- types.find do |ct|
25
- ct['name'] =~ /\bSSL\b/ && ct['name'] !~ /(?:Multi.?Domain|Wildcard)/i
26
- end
14
+ def certificate_type_from_csr csr, days = nil
15
+ types = certificate_types_standard(days)
16
+ return types.first if types.length <= 1
17
+
18
+ regexp = cert_type_regexp(csr)
19
+ return types.find { |ct| ct['name'] =~ regexp } if regexp
20
+
21
+ types.find do |ct|
22
+ ct['name'] =~ /\bSSL\b/ && ct['name'] !~ /(?:Multi.?Domain|Wildcard)/i
27
23
  end
28
24
  end
29
25
 
@@ -33,6 +29,18 @@ class Varanus::SSL
33
29
  @certificate_types ||= get('types')
34
30
  end
35
31
 
32
+ # Return Array of certificate types based on standard sorting.
33
+ # @param days [Integer] if present, only include types that support the given day count
34
+ # @return [Array<Hash>]
35
+ def certificate_types_standard days = nil
36
+ types = certificate_types.reject do |ct|
37
+ ct['name'] =~ /\b(?:EV|ECC|AMT|Elite)\b/
38
+ end
39
+ types = types.select! { |t| t['terms'].include? days } unless days.nil?
40
+
41
+ types
42
+ end
43
+
36
44
  # Retrieves the cert.
37
45
  # @param id [Integer] As returned by {#sign}
38
46
  # @param type [String]
@@ -75,6 +83,7 @@ class Varanus::SSL
75
83
  # specified, lowest allowed for the cert type will be used)
76
84
  # @return [Integer] Id of SSL cert.
77
85
  def sign csr, org_id, opts = {}
86
+ opts[:days] ||= opts[:years] * 365 unless opts[:years].nil?
78
87
  csr = Varanus::SSL::CSR.new(csr) unless csr.is_a?(Varanus::SSL::CSR)
79
88
  cert_type_id = opts_to_cert_type_id opts, csr
80
89
  args = {
@@ -92,6 +101,14 @@ class Varanus::SSL
92
101
 
93
102
  private
94
103
 
104
+ def cert_type_regexp csr
105
+ return /Wildcard.+SSL/i if csr.all_names.any? { |n| n.start_with?('*.') }
106
+
107
+ return /Multi.?Domain.+SSL/i if csr.subject_alt_names.any?
108
+
109
+ nil
110
+ end
111
+
95
112
  def check_result result
96
113
  body = result.body
97
114
  return unless body.is_a?(Hash)
@@ -132,7 +149,7 @@ class Varanus::SSL
132
149
  when String
133
150
  certificate_types.find { |ct| ct['name'] == opts[:cert_type] }['id']
134
151
  else
135
- certificate_type_from_csr(csr)['id']
152
+ certificate_type_from_csr(csr, opts[:days])['id']
136
153
  end
137
154
  end
138
155
 
@@ -144,7 +161,6 @@ class Varanus::SSL
144
161
 
145
162
  def opts_to_term opts, cert_type_id
146
163
  term = opts[:days]
147
- term ||= opts[:years] * 365 unless opts[:years].nil?
148
164
  term ||= certificate_types.find { |ct| ct['id'] == cert_type_id }['terms'].min
149
165
  term
150
166
  end
@@ -25,18 +25,23 @@ class Varanus::SSL::CSR
25
25
  request = OpenSSL::X509::Request.new
26
26
  request.version = 0
27
27
  request.subject = OpenSSL::X509::Name.parse subject.map { |k, v| "/#{k}=#{v}" }.join
28
+ request.add_attribute names_to_san_attribute(names)
29
+ request.public_key = key.public_key
30
+
31
+ request.sign(key, OpenSSL::Digest::SHA256.new)
32
+
33
+ [key, Varanus::SSL::CSR.new(request)]
34
+ end
28
35
 
29
- # Set Subject Alternate Names
36
+ # :nodoc:
37
+ # Create a Subject Alternate Names attribute from an Array of dns names
38
+ def self.names_to_san_attribute names
30
39
  ef = OpenSSL::X509::ExtensionFactory.new
31
40
  name_str = names.map { |n| "DNS:#{n}" }.join(', ')
32
41
  ext = ef.create_extension('subjectAltName', name_str, false)
33
42
  seq = OpenSSL::ASN1::Sequence([ext])
34
43
  ext_req = OpenSSL::ASN1::Set([seq])
35
- request.add_attribute OpenSSL::X509::Attribute.new('extReq', ext_req)
36
-
37
- request.public_key = key.public_key
38
- request.sign(key, OpenSSL::Digest::SHA256.new)
39
- [key, Varanus::SSL::CSR.new(request)]
44
+ OpenSSL::X509::Attribute.new('extReq', ext_req)
40
45
  end
41
46
 
42
47
  # Common Name (CN) for cert.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Varanus
4
- VERSION = '0.2.1'
4
+ VERSION = '0.3.0'
5
5
  end
@@ -4,7 +4,6 @@ lib = File.expand_path('lib', __dir__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
  require 'varanus/version'
6
6
 
7
- # rubocop:disable Metrics/BlockLength
8
7
  Gem::Specification.new do |spec|
9
8
  spec.name = 'varanus'
10
9
  spec.version = Varanus::VERSION
@@ -28,7 +27,7 @@ Gem::Specification.new do |spec|
28
27
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
29
28
  end
30
29
  spec.require_paths = ['lib']
31
- spec.required_ruby_version = '>= 2.3.0'
30
+ spec.required_ruby_version = '>= 2.5.0'
32
31
 
33
32
  spec.add_development_dependency 'bundler', '~> 1.16'
34
33
  spec.add_development_dependency 'minitest', '~> 5.0'
@@ -44,4 +43,3 @@ Gem::Specification.new do |spec|
44
43
  spec.add_runtime_dependency 'faraday_middleware'
45
44
  spec.add_runtime_dependency 'savon', '~> 2.0'
46
45
  end
47
- # rubocop:enable Metrics/BlockLength
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: varanus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Dilda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-13 00:00:00.000000000 Z
11
+ date: 2020-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -222,15 +222,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
222
222
  requirements:
223
223
  - - ">="
224
224
  - !ruby/object:Gem::Version
225
- version: 2.3.0
225
+ version: 2.5.0
226
226
  required_rubygems_version: !ruby/object:Gem::Requirement
227
227
  requirements:
228
228
  - - ">="
229
229
  - !ruby/object:Gem::Version
230
230
  version: '0'
231
231
  requirements: []
232
- rubyforge_project:
233
- rubygems_version: 2.7.8
232
+ rubygems_version: 3.0.3
234
233
  signing_key:
235
234
  specification_version: 4
236
235
  summary: Interface for Sectigo's (formerly Comodo CA) API.