ssltool 0.0.5 → 0.0.6

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.
@@ -13,7 +13,7 @@ end
13
13
 
14
14
  begin
15
15
  store = SSLTool::CertificateStore.new("file://#{File.dirname(__FILE__)}/../var/pools")
16
- chain = store.resolve_chain_from_pem_string(ARGF.read)
16
+ chain = store.resolve_chain(ARGF.read)
17
17
  rescue SSLTool::ChainResolution::ZeroCertsChainResolutionError ; die("No certificate given.", 1)
18
18
  rescue SSLTool::ChainResolution::ZeroHeadsChainResolutionError ; die("No certificate given covers a domain name.", 2)
19
19
  rescue SSLTool::ChainResolution::TooManyHeadsChainResolutionError; die("More than one domain name certificate given.", 3)
@@ -6,7 +6,7 @@
6
6
 
7
7
  require_relative "../lib/ssltool/certificate"
8
8
 
9
- certs = SSLTool::PEMScanner.new(ARGF.read).certs.map(&:strip).uniq.map do |s|
9
+ certs = SSLTool::PEMScanner.new(ARGF.read).cert_strings.uniq.map do |s|
10
10
  begin
11
11
  SSLTool::Certificate.new(s)
12
12
  rescue => e
@@ -22,7 +22,7 @@ module SSLTool
22
22
 
23
23
  # returns an array of Certificate objects created from cert strings found in s
24
24
  def self.scan(s)
25
- PEMScanner.new(s).certs.map { |s| new(s) }.uniq
25
+ PEMScanner.new(s).certificates.uniq
26
26
  end
27
27
 
28
28
  ### signing
@@ -79,13 +79,10 @@ module SSLTool
79
79
  ### chains
80
80
 
81
81
  def resolve_chain(certs)
82
+ certs = Certificate.scan(certs) if certs.is_a?(String)
82
83
  detect_and_merge_intermediates!(certs)
83
84
  ChainResolution.new(certs, self)
84
85
  end
85
86
 
86
- def resolve_chain_from_pem_string(s)
87
- resolve_chain(Certificate.scan(s))
88
- end
89
-
90
87
  end
91
88
  end
@@ -7,7 +7,7 @@ module SSLTool
7
7
  extend self
8
8
 
9
9
  def scan(s)
10
- keys SSLTool::PEMScanner.new(s).keys
10
+ SSLTool::PEMScanner.new(s).keys
11
11
  end
12
12
 
13
13
  def keys(*pems)
@@ -1,8 +1,9 @@
1
1
  # encoding: UTF-8
2
+ require_relative 'certificate'
2
3
 
3
4
  module SSLTool
4
5
  class PEMScanner
5
- attr_reader :pems, :certs, :keys, :garbage
6
+ attr_reader :pem_strings, :cert_strings, :key_strings, :garbage_strings
6
7
  RX_PEM_BLOCK = /(-----BEGIN.*?-----\n
7
8
  (?:[A-Za-z0-9\+\/]+\n)*
8
9
  [A-Za-z0-9\+\/]*={0,2}\n
@@ -10,11 +11,20 @@ module SSLTool
10
11
  )/x
11
12
 
12
13
  def initialize(s)
13
- s = s.dup.force_encoding('BINARY').gsub(/\r\n?/, "\n").gsub(/\s+\n/, "\n")
14
- @pems, @garbage = s.split(RX_PEM_BLOCK).map(&:strip).reject(&:empty?).partition { |s| s =~ RX_PEM_BLOCK }
15
- @certs = @pems.select { |s| s =~ /-----BEGIN CERTIFICATE-----/ }
16
- @keys = @pems.select { |s| s =~ /-----BEGIN (RSA )?PRIVATE KEY-----/ }
17
- @garbage += @pems - @certs - @keys
14
+ s = s.dup.force_encoding('BINARY').gsub(/\r\n?/, "\n").gsub(/\s+\n/, "\n")
15
+ @pem_strings, @garbage_strings = s.split(RX_PEM_BLOCK).map(&:strip).reject(&:empty?).partition { |s| s =~ RX_PEM_BLOCK }
16
+ @cert_strings = @pem_strings.select { |s| s =~ /-----BEGIN CERTIFICATE-----/ }
17
+ @key_strings = @pem_strings.select { |s| s =~ /-----BEGIN (RSA )?PRIVATE KEY-----/ }
18
+ @garbage_strings += @pem_strings - @cert_strings - @key_strings
19
+ end
20
+
21
+ def certificates
22
+ cert_strings.map { |s| Certificate.new(s) }
23
+ end
24
+ alias_method :certs, :certificates
25
+
26
+ def keys
27
+ key_strings.map { |s| OpenSSL::PKey::RSA.new(s, '') }
18
28
  end
19
29
 
20
30
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ssltool
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-13 00:00:00.000000000 Z
12
+ date: 2012-09-14 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Orders and completes SSL certificate trust chains, maintains an up-to-date
15
15
  pool of viable intermediates and trusted roots, and provides other tooling for dealing