vcert 0.2.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 64e42e07f9d888bfb7ce44fb88012806021ddc027d153f85c8d525862f974b30
4
- data.tar.gz: '08cce53508dac0bd413f4b5d9ce5279995cdf9c4f09f85be1936e9f6255ab529'
3
+ metadata.gz: 4bcc98fd562fcb5c015d138eb9728a53f6c0c2a7009680e4f2df3765c6e2a6a9
4
+ data.tar.gz: e123df63ec44aae86e435830692463f75c0363697556f701b027da87f73a0b74
5
5
  SHA512:
6
- metadata.gz: 11ac60359d93852be73e6d55440f9453525258f9ee88727fbdf98e8bc899e01264b385589a6b0f77979af8af497689ba152bc94fdc66589a7d12190659c1644c
7
- data.tar.gz: 02e16121c702f97653271b3e8b1c172ec1cce57b8e3fbfec2b011a3c87cb5a87f7583b3c6ffdbb8ffb6b162e8379acc1cb2afa94d888da8e9ca9578554e29f98
6
+ metadata.gz: d1a9b791f98b2e4c33ba0f8ff09226ece7944d70dc8a6030cc8f944f26f33117c1d5a42e7c210c29f796105aa32e8f2fb54371b7b8075e8f70858a9c06d0379f
7
+ data.tar.gz: b5a01c97e9242a0dabd5b0e670d23e22ce10010bcb38cd6bc126e106c4a9395cce956b35b61e3fab74d531ac277b4ba71167c3e473384f167374ec9559d84f22
data/lib/cloud/cloud.rb CHANGED
@@ -1,12 +1,13 @@
1
1
  require 'json'
2
2
  require 'utils/utils'
3
+ require 'addressable/uri'
3
4
 
4
5
  class Vcert::CloudConnection
5
6
  CLOUD_PREFIX = '<Cloud>'.freeze
6
7
 
7
8
  def initialize(url, apikey)
8
9
  @url = if url.nil?
9
- 'https://api.venafi.cloud/v1'.freeze
10
+ 'https://api.venafi.cloud'.freeze
10
11
  else
11
12
  url
12
13
  end
@@ -15,8 +16,12 @@ class Vcert::CloudConnection
15
16
 
16
17
 
17
18
  def request(zone_tag, request)
18
- zone_id = get_zoneId_by_tag(zone_tag)
19
- _, data = post(URL_CERTIFICATE_REQUESTS, {:zoneId => zone_id, :certificateSigningRequest => request.csr})
19
+ zone_config = zone_configuration(zone_tag)
20
+ _, data = post(URL_CERTIFICATE_REQUESTS, {:applicationId => zone_config.app_id,
21
+ :certificateIssuingTemplateId=>zone_config.cit_id,
22
+ :certificateSigningRequest => request.csr,
23
+ :apiClientInformation => getApiClientInformation
24
+ })
20
25
  LOG.debug("Raw response to certificate request:")
21
26
  LOG.debug(JSON.pretty_generate(data))
22
27
  request.id = data['certificateRequests'][0]["id"]
@@ -34,7 +39,8 @@ class Vcert::CloudConnection
34
39
  when CERT_STATUS_FAILED
35
40
  raise Vcert::ServerUnexpectedBehaviorError, "Certificate issue status is FAILED"
36
41
  when CERT_STATUS_ISSUED
37
- status, full_chain = get(URL_CERTIFICATE_RETRIEVE % request.id + "?chainOrder=#{CHAIN_OPTION_ROOT_LAST}&format=PEM")
42
+ cert_arr = data["certificateIds"]
43
+ status, full_chain = get(URL_CERTIFICATE_RETRIEVE % cert_arr[0] + "?chainOrder=#{CHAIN_OPTION_ROOT_LAST}&format=PEM")
38
44
  if status == 200
39
45
  cert = parse_full_chain full_chain
40
46
  if cert.private_key == nil
@@ -57,30 +63,38 @@ class Vcert::CloudConnection
57
63
  raise Vcert::ClientBadDataError, "Either request ID or certificate thumbprint is required to renew the certificate"
58
64
  end
59
65
  if request.thumbprint != nil
60
- manage_id = search_by_thumbprint(request.thumbprint)
66
+ cert_id, request_id = search_by_thumbprint(request.thumbprint)
61
67
  end
62
68
  if request.id != nil
63
69
  prev_request = get_cert_status(request)
64
- manage_id = prev_request[:manage_id]
70
+ request_id = request.id
65
71
  zone = prev_request[:zoneId]
66
72
  end
67
- if manage_id == nil
68
- raise Vcert::VcertError, "Can't find the existing certificate"
73
+ if request_id == nil
74
+ raise Vcert::VcertError, "Can't find the existing certificate request id"
69
75
  end
70
76
 
71
- status, data = get(URL_MANAGED_CERTIFICATE_BY_ID % manage_id)
77
+ status, data = get(URL_CERTIFICATE_STATUS % request_id)
78
+
72
79
  if status == 200
73
- request.id = data['latestCertificateRequestId']
80
+ request.id = data['id']
81
+ cert_id = data['certificateIds'][0]
74
82
  else
75
83
  raise Vcert::ServerUnexpectedBehaviorError, "Status #{status}"
76
84
  end
77
85
 
78
- if zone == nil
86
+
87
+ if prev_request == nil
79
88
  prev_request = get_cert_status(request)
80
- zone = prev_request[:zoneId]
81
89
  end
82
90
 
83
- d = {existingManagedCertificateId: manage_id, zoneId: zone}
91
+
92
+ d = {existingCertificateId: cert_id,
93
+ applicationId: data["applicationId"],
94
+ certificateIssuingTemplateId: data["certificateIssuingTemplateId"],
95
+ apiClientInformation: getApiClientInformation
96
+
97
+ }
84
98
  if request.csr?
85
99
  d.merge!(certificateSigningRequest: request.csr)
86
100
  d.merge!(reuseCSR: false)
@@ -96,7 +110,8 @@ class Vcert::CloudConnection
96
110
  organizational_unit: parsed_csr[:OU])
97
111
  d.merge!(certificateSigningRequest: renew_request.csr)
98
112
  else
99
- d.merge!(reuseCSR: true)
113
+ raise Vcert::VcertError, "This operation is not yet supported"
114
+ #d.merge!(reuseCSR: true)
100
115
  end
101
116
 
102
117
  status, data = post(URL_CERTIFICATE_REQUESTS, data = d)
@@ -118,9 +133,23 @@ class Vcert::CloudConnection
118
133
  raise Vcert::ClientBadDataError, "Zone should not be empty"
119
134
  end
120
135
  LOG.info("Getting configuration for zone #{tag}")
121
- _, data = get(URL_ZONE_BY_TAG % tag)
122
- template_id = data['certificateIssuingTemplateId']
123
- _, data = get(URL_TEMPLATE_BY_ID % template_id)
136
+ arr = tag.split("\\", 2)
137
+
138
+ app_name = arr[0]
139
+ cit_alias = arr[1]
140
+
141
+ if app_name.to_s.strip.empty? || cit_alias.to_s.strip.empty?
142
+ raise Vcert::ClientBadDataError, "The parameters: app_name, cit_alias or both are empty"
143
+ end
144
+ app_name = Addressable::URI.encode_component(app_name, Addressable::URI::CharacterClasses::QUERY)
145
+ cit_alias = Addressable::URI.encode_component(cit_alias, Addressable::URI::CharacterClasses::QUERY)
146
+
147
+ #get cit
148
+ _, data = get(URL_CIT_BY_APP_NAME_CIT_ALIAS % [app_name, cit_alias])
149
+
150
+ #get app info
151
+ _, app = get(URL_APPLICATION_BY_NAME % app_name)
152
+
124
153
  kt = Vcert::KeyType.new data['keyTypes'][0]["keyType"], data['keyTypes'][0]["keyLengths"][0].to_i
125
154
  z = Vcert::ZoneConfiguration.new(
126
155
  country: Vcert::CertField.new(""),
@@ -130,6 +159,9 @@ class Vcert::CloudConnection
130
159
  organizational_unit: Vcert::CertField.new(""),
131
160
  key_type: Vcert::CertField.new(kt, locked: true),
132
161
  )
162
+ z.app_id = app["id"]
163
+ z.cit_id = data["id"]
164
+
133
165
  return z
134
166
  end
135
167
 
@@ -137,14 +169,21 @@ class Vcert::CloudConnection
137
169
  unless zone_id
138
170
  raise Vcert::ClientBadDataError, "Zone should be not nil"
139
171
  end
140
- status, data = get(URL_PROJECT_ZONE_DETAILS % zone_id)
141
- if status != 200
142
- raise Vcert::ServerUnexpectedBehaviorError, "Invalid status getting issuing template: %s for zone %s" % status, zone_id
172
+ arr = zone_id.split("\\", 2)
173
+
174
+ app_name = arr[0]
175
+ cit_alias = arr[1]
176
+
177
+ if app_name.to_s.strip.empty? || cit_alias.to_s.strip.empty?
178
+ raise Vcert::ClientBadDataError, "The parameters: app_name, cit_alias or both are empty"
143
179
  end
144
- template_id = data['certificateIssuingTemplateId']
145
- status, data = get(URL_TEMPLATE_BY_ID % template_id)
180
+
181
+ app_name = Addressable::URI.encode_component(app_name, Addressable::URI::CharacterClasses::QUERY)
182
+ cit_alias = Addressable::URI.encode_component(cit_alias, Addressable::URI::CharacterClasses::QUERY)
183
+ status, data = get(URL_CIT_BY_APP_NAME_CIT_ALIAS % [app_name, cit_alias])
184
+ puts data
146
185
  if status != 200
147
- raise Vcert::ServerUnexpectedBehaviorError, "Invalid status getting policy: %s for issuing template %s" % status, template_id
186
+ raise Vcert::ServerUnexpectedBehaviorError, "Invalid status getting issuing template: %s for zone %s" % status, zone_id
148
187
  end
149
188
  parse_policy_responce_to_object(data)
150
189
  end
@@ -158,20 +197,13 @@ class Vcert::CloudConnection
158
197
  CERT_STATUS_PENDING = 'PENDING'
159
198
  CERT_STATUS_FAILED = 'FAILED'
160
199
  CERT_STATUS_ISSUED = 'ISSUED'
161
- URL_ZONE_BY_TAG = "zones/tag/%s"
162
- URL_PROJECT_ZONE_DETAILS = "projectzones/%s"
163
- URL_TEMPLATE_BY_ID = "certificateissuingtemplates/%s"
164
- URL_CERTIFICATE_REQUESTS = "certificaterequests"
200
+ URL_CIT_BY_APP_NAME_CIT_ALIAS = "outagedetection/v1/applications/%s/certificateissuingtemplates/%s"
201
+ URL_APPLICATION_BY_NAME = "outagedetection/v1/applications/name/%s"
202
+ URL_CERTIFICATE_REQUESTS = "outagedetection/v1/certificaterequests"
165
203
  URL_CERTIFICATE_STATUS = URL_CERTIFICATE_REQUESTS + "/%s"
166
- URL_CERTIFICATE_RETRIEVE = URL_CERTIFICATE_REQUESTS + "/%s/certificate"
167
- URL_CERTIFICATE_SEARCH = "certificatesearch"
168
- URL_MANAGED_CERTIFICATES = "managedcertificates"
169
- URL_MANAGED_CERTIFICATE_BY_ID = URL_MANAGED_CERTIFICATES + "/%s"
170
-
171
- def get_zoneId_by_tag(tag)
172
- _, data = get(URL_ZONE_BY_TAG % tag)
173
- data['id']
174
- end
204
+ URL_CERTIFICATE_RETRIEVE = "outagedetection/v1/certificates/%s/contents"
205
+ URL_CERTIFICATE_SEARCH = "outagedetection/v1/certificatesearch"
206
+
175
207
 
176
208
  def get(url)
177
209
  uri = URI.parse(@url)
@@ -262,9 +294,10 @@ class Vcert::CloudConnection
262
294
  raise Vcert::ServerUnexpectedBehaviorError, "Status: #{status}. Message: #{data.body.to_s}"
263
295
  end
264
296
  # TODO: check data
265
- manageId = data['certificates'][0]['managedCertificateId']
266
- LOG.info("Found existing certificate with ID #{manageId}")
267
- return manageId
297
+ certId = data['certificates'][0]['id']
298
+ certReqId = data['certificates'][0]['certificateRequestId']
299
+ LOG.info("Found existing certificate with ID #{certId}")
300
+ return certId, certReqId
268
301
  end
269
302
 
270
303
  def get_cert_status(request)
@@ -300,7 +300,8 @@ module Vcert
300
300
  end
301
301
 
302
302
  class ZoneConfiguration
303
- attr_reader :country, :province, :locality, :organization, :organizational_unit, :key_type
303
+ attr_reader :country, :province, :locality, :organization, :organizational_unit, :key_type, :app_id, :cit_id;
304
+ attr_accessor :app_id, :cit_id
304
305
 
305
306
  # @param [CertField] country
306
307
  # @param [CertField] province
data/lib/utils/utils.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'socket'
2
+
1
3
  def parse_pem_list(multiline)
2
4
  pems = []
3
5
  buf = ""
@@ -144,3 +146,12 @@ module Vcert
144
146
  end
145
147
  end
146
148
 
149
+ def getApiClientInformation()
150
+ ip = Socket.ip_address_list.detect{|intf| intf.ipv4_private?}
151
+ ip_addres = ip.ip_address
152
+ data = {
153
+ type: CLIENT_ID,
154
+ identifier: ip_addres
155
+ }
156
+ return data
157
+ end
metadata CHANGED
@@ -1,17 +1,38 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vcert
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Denis Subbotin
8
8
  - Alexander Rykalin
9
9
  - Russel Vela
10
+ - Angel Moo
10
11
  autorequire:
11
12
  bindir: bin
12
13
  cert_chain: []
13
- date: 2021-01-05 00:00:00.000000000 Z
14
- dependencies: []
14
+ date: 2021-02-03 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: addressable
18
+ requirement: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 2.7.0
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '2.7'
26
+ type: :runtime
27
+ prerelease: false
28
+ version_requirements: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 2.7.0
33
+ - - "~>"
34
+ - !ruby/object:Gem::Version
35
+ version: '2.7'
15
36
  description: Ruby client for Venafi Cloud and Trust Protection Platform
16
37
  email: opensource@venafi.com
17
38
  executables: []