vcert 0.1.0 → 0.1.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.
- checksums.yaml +4 -4
- data/lib/utils/utils.rb +98 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a2cf972208fd705b59387e15029d570634fc0c31417c8e675fe876b8cbd4f158
|
4
|
+
data.tar.gz: 65dc71e3ccc17f3bd5dc210198dcf7e0f7d6b8ab3c7e5e65f6545d3fe66da4bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee6b93da05a44810c9034ad1aa85a5122bcf8d520d98c2055acbb2185c4a53460a7399e89d51fa9977cb91fb3dfa36ff2f3db7dafd45d46665ca1bc7345f39bc
|
7
|
+
data.tar.gz: 83b5964f8300fb15704dc9bf06ebf5afbe95a287f7671fd4f128843a5280a6b9a19680f70479207fc87bc6b5e7b19d626aa491da5b68756c4a3b612885bb134b
|
data/lib/utils/utils.rb
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
def parse_pem_list(multiline)
|
2
|
+
pems = []
|
3
|
+
buf = ""
|
4
|
+
current_string_is_pem = false
|
5
|
+
multiline.each_line do |line|
|
6
|
+
if line.match(/-----BEGIN [A-Z\ ]+-----/)
|
7
|
+
current_string_is_pem = true
|
8
|
+
end
|
9
|
+
if current_string_is_pem
|
10
|
+
buf = buf + line
|
11
|
+
end
|
12
|
+
if line.match(/-----END [A-Z\ ]+-----/)
|
13
|
+
current_string_is_pem = false
|
14
|
+
pems.push(buf)
|
15
|
+
buf = ""
|
16
|
+
end
|
17
|
+
end
|
18
|
+
pems
|
19
|
+
end
|
20
|
+
|
21
|
+
def parse_csr_fields(csr)
|
22
|
+
LOG.info("Trying to parse CSR:\n#{csr}")
|
23
|
+
csr_obj = OpenSSL::X509::Request.new(csr)
|
24
|
+
result = Hash.new
|
25
|
+
|
26
|
+
subject_array = csr_obj.subject.to_a
|
27
|
+
subject_array.map { |x|
|
28
|
+
if x[1] != ""
|
29
|
+
result[x[0].to_sym] = x[1]
|
30
|
+
end
|
31
|
+
}
|
32
|
+
|
33
|
+
attributes = csr_obj.attributes
|
34
|
+
|
35
|
+
seq = nil
|
36
|
+
values = nil
|
37
|
+
|
38
|
+
if attributes
|
39
|
+
attributes.each do |a|
|
40
|
+
if a.oid == 'extReq'
|
41
|
+
seq = a.value
|
42
|
+
break
|
43
|
+
end
|
44
|
+
end
|
45
|
+
# return nil if not seq
|
46
|
+
end
|
47
|
+
|
48
|
+
if seq
|
49
|
+
seq.value.each do |v|
|
50
|
+
v.each do |v|
|
51
|
+
if v.value[0].value == 'subjectAltName'
|
52
|
+
values = v.value[1].value
|
53
|
+
break
|
54
|
+
end
|
55
|
+
break if values
|
56
|
+
end
|
57
|
+
end
|
58
|
+
# return nil if not values
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
if values
|
63
|
+
values = OpenSSL::ASN1.decode(values).value
|
64
|
+
|
65
|
+
values.each do |v|
|
66
|
+
case v.tag
|
67
|
+
when 2
|
68
|
+
result[:DNS] = v.value
|
69
|
+
when 7
|
70
|
+
case v.value.size
|
71
|
+
when 4
|
72
|
+
ip = v.value.unpack('C*').join('.')
|
73
|
+
when 16
|
74
|
+
ip = v.value.unpack('n*').map { |o| sprintf("%X", o) }.join(':')
|
75
|
+
else
|
76
|
+
STDERR.print "The encountered IP-address is neither IPv4 nor IPv6\n"
|
77
|
+
next
|
78
|
+
end
|
79
|
+
result[:IP] = ip
|
80
|
+
else
|
81
|
+
STDERR.print "Uknown tag #{v.tag} -- I only know 2 (DNS) and 7 (IP)\n"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
if csr_obj.public_key.instance_of? OpenSSL::PKey::RSA
|
87
|
+
result[:key_type] = Vcert::KeyType.new "rsa", csr_obj.public_key.n.num_bits
|
88
|
+
elsif csr_obj.public_key.instance_of? OpenSSL::PKey::EC
|
89
|
+
# todo: implement
|
90
|
+
raise "not implemented"
|
91
|
+
else
|
92
|
+
raise Vcert::VcertError
|
93
|
+
end
|
94
|
+
|
95
|
+
|
96
|
+
LOG.info("Parsed CSR fields:\n #{result.inspect}")
|
97
|
+
return result
|
98
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vcert
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Denis Subbotin
|
@@ -21,6 +21,7 @@ files:
|
|
21
21
|
- lib/fake/fake.rb
|
22
22
|
- lib/objects/objects.rb
|
23
23
|
- lib/tpp/tpp.rb
|
24
|
+
- lib/utils/utils.rb
|
24
25
|
- lib/vcert.rb
|
25
26
|
homepage: https://rubygems.org/gems/vcert
|
26
27
|
licenses:
|