openssl-extensions 0.0.1
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.
- data/lib/openssl-extensions.rb +12 -0
- data/lib/openssl-extensions/all.rb +5 -0
- data/lib/openssl-extensions/version.rb +3 -0
- data/lib/openssl-extensions/x509.rb +2 -0
- data/lib/openssl-extensions/x509/authority_key_identifier.rb +36 -0
- data/lib/openssl-extensions/x509/certificate.rb +26 -0
- data/lib/openssl-extensions/x509/name.rb +38 -0
- metadata +86 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
require 'openssl-extensions/x509'
|
|
2
|
+
|
|
3
|
+
class OpenSSLExtensions::X509::AuthorityKeyIdentifier
|
|
4
|
+
|
|
5
|
+
attr_reader :issuer_name, :serial_number, :key_id
|
|
6
|
+
alias :serial :serial_number
|
|
7
|
+
|
|
8
|
+
def initialize(extension_string)
|
|
9
|
+
parse(extension_string.dup)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def parse(string)
|
|
13
|
+
Hash[string.scan(%r{(\w+):([^,\n]+)})].tap do |h|
|
|
14
|
+
@issuer_name = common_name(strip(h['DirName']))
|
|
15
|
+
@serial_number = strip(h['serial'])
|
|
16
|
+
@key_id = strip(h['keyid'])
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
private :parse
|
|
20
|
+
|
|
21
|
+
def strip(input)
|
|
22
|
+
input ? input.to_s.strip : nil
|
|
23
|
+
end
|
|
24
|
+
private :strip
|
|
25
|
+
|
|
26
|
+
def common_name(input)
|
|
27
|
+
if input
|
|
28
|
+
name = input.split('/').
|
|
29
|
+
collect { |v| v.split('=') }.
|
|
30
|
+
detect { |id, val| id == 'CN' }
|
|
31
|
+
name[1] if name
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
private :common_name
|
|
35
|
+
|
|
36
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
require 'openssl-extensions/x509'
|
|
2
|
+
require 'openssl-extensions/x509/authority_key_identifier'
|
|
3
|
+
|
|
4
|
+
module OpenSSLExtensions::X509::Certificate
|
|
5
|
+
|
|
6
|
+
def subject_alternative_names
|
|
7
|
+
names_string = read_extension_by_oid('subjectAltName')
|
|
8
|
+
names_string ? names_string.scan(%r{DNS:([^,]+)}).flatten : []
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def subject_key_identifier
|
|
12
|
+
read_extension_by_oid('subjectKeyIdentifier')
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def authority_key_identifier
|
|
16
|
+
OpenSSLExtensions::X509::AuthorityKeyIdentifier.new(read_extension_by_oid('authorityKeyIdentifier'))
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def read_extension_by_oid(oid)
|
|
20
|
+
(extensions.detect { |e| e.to_a.first == oid } || []).to_a[1]
|
|
21
|
+
end
|
|
22
|
+
protected :read_extension_by_oid
|
|
23
|
+
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
OpenSSL::X509::Certificate.send(:include, OpenSSLExtensions::X509::Certificate)
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
require 'openssl-extensions/x509'
|
|
2
|
+
|
|
3
|
+
module OpenSSLExtensions::X509::Name
|
|
4
|
+
def organization
|
|
5
|
+
read_entry_by_oid('O')
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def organizational_unit
|
|
9
|
+
read_entry_by_oid('OU')
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def common_name
|
|
13
|
+
read_entry_by_oid('CN')
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def country
|
|
17
|
+
read_entry_by_oid('C')
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def locality
|
|
21
|
+
read_entry_by_oid('L')
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def state
|
|
25
|
+
read_entry_by_oid('ST')
|
|
26
|
+
end
|
|
27
|
+
alias :region :state
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
protected
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def read_entry_by_oid(oid)
|
|
34
|
+
(to_a.detect { |e| e.first == oid } || [])[1]
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
OpenSSL::X509::Name.send(:include, OpenSSLExtensions::X509::Name)
|
metadata
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: openssl-extensions
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
prerelease: false
|
|
5
|
+
segments:
|
|
6
|
+
- 0
|
|
7
|
+
- 0
|
|
8
|
+
- 1
|
|
9
|
+
version: 0.0.1
|
|
10
|
+
platform: ruby
|
|
11
|
+
authors:
|
|
12
|
+
- Nathaniel Bibler
|
|
13
|
+
autorequire:
|
|
14
|
+
bindir: bin
|
|
15
|
+
cert_chain: []
|
|
16
|
+
|
|
17
|
+
date: 2010-10-01 00:00:00 -04:00
|
|
18
|
+
default_executable:
|
|
19
|
+
dependencies:
|
|
20
|
+
- !ruby/object:Gem::Dependency
|
|
21
|
+
name: rspec
|
|
22
|
+
prerelease: false
|
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
|
24
|
+
requirements:
|
|
25
|
+
- - ">="
|
|
26
|
+
- !ruby/object:Gem::Version
|
|
27
|
+
segments:
|
|
28
|
+
- 2
|
|
29
|
+
- 0
|
|
30
|
+
- 0
|
|
31
|
+
- beta
|
|
32
|
+
- 19
|
|
33
|
+
version: 2.0.0.beta.19
|
|
34
|
+
type: :development
|
|
35
|
+
version_requirements: *id001
|
|
36
|
+
description: This library patches OpenSSL to add helper methods and extensions to OpenSSL objects with the intention of making the interface more intuitive.
|
|
37
|
+
email:
|
|
38
|
+
- nate@envylabs.com
|
|
39
|
+
executables: []
|
|
40
|
+
|
|
41
|
+
extensions: []
|
|
42
|
+
|
|
43
|
+
extra_rdoc_files: []
|
|
44
|
+
|
|
45
|
+
files:
|
|
46
|
+
- lib/openssl-extensions/all.rb
|
|
47
|
+
- lib/openssl-extensions/version.rb
|
|
48
|
+
- lib/openssl-extensions/x509/authority_key_identifier.rb
|
|
49
|
+
- lib/openssl-extensions/x509/certificate.rb
|
|
50
|
+
- lib/openssl-extensions/x509/name.rb
|
|
51
|
+
- lib/openssl-extensions/x509.rb
|
|
52
|
+
- lib/openssl-extensions.rb
|
|
53
|
+
has_rdoc: true
|
|
54
|
+
homepage: http://github.com/envylabs/openssl-extensions
|
|
55
|
+
licenses: []
|
|
56
|
+
|
|
57
|
+
post_install_message:
|
|
58
|
+
rdoc_options: []
|
|
59
|
+
|
|
60
|
+
require_paths:
|
|
61
|
+
- lib
|
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
63
|
+
requirements:
|
|
64
|
+
- - ">="
|
|
65
|
+
- !ruby/object:Gem::Version
|
|
66
|
+
segments:
|
|
67
|
+
- 0
|
|
68
|
+
version: "0"
|
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
70
|
+
requirements:
|
|
71
|
+
- - ">="
|
|
72
|
+
- !ruby/object:Gem::Version
|
|
73
|
+
segments:
|
|
74
|
+
- 1
|
|
75
|
+
- 3
|
|
76
|
+
- 6
|
|
77
|
+
version: 1.3.6
|
|
78
|
+
requirements: []
|
|
79
|
+
|
|
80
|
+
rubyforge_project:
|
|
81
|
+
rubygems_version: 1.3.6
|
|
82
|
+
signing_key:
|
|
83
|
+
specification_version: 3
|
|
84
|
+
summary: Helper methods and extensions for OpenSSL to make the interface more intuitive.
|
|
85
|
+
test_files: []
|
|
86
|
+
|