global_sign 2.0.0 → 2.1.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
  SHA1:
3
- metadata.gz: c5a54622924310a43ab46e3a6973962ad4bf45be
4
- data.tar.gz: f887d279c8a4f186bcdb521b750e88bc608a0b00
3
+ metadata.gz: 916c05af61f1d1c2044bf3470e77bd4a47e120fe
4
+ data.tar.gz: 3d6bae04c691a34ab72f7d69fb658e4e8d018fd2
5
5
  SHA512:
6
- metadata.gz: 33bb4c0ff984aaafd1c157701d7297fec8291a3f3187d2c99d5b24f5aebed49b28ea5fd0c9c3fee7c057c1f4b32e7a29b801096e95e5f878375b394d681e0e37
7
- data.tar.gz: 42d3222a900e70362a42a2d22995343ac37c072d648050ec674d67fcee38ba96e229e9c8b72321dcf6fa0d6c618a023780b167464e613527678a08a61603ee11
6
+ metadata.gz: 11f5cdc7182ab5affc64af5d05327b56551bb2152742d783230506267be3e5405271331bbc68dabf577dc6594347a6ba9ca0bcecd8c4fc8fbeb9ede0395ee0db
7
+ data.tar.gz: 52d4a09e9fb441cd04974b2b6687abb35306581743cea59bc01ba3817ae7d7d6a35cf77378325fc9d85f3d8e021207e5f3f16a93e9cb75d75e0b8bdb2c1568ce
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 2.1.0
2
+
3
+ - Support GlobalSign API: DecodeCSR
4
+ - Support GlobalSign API: DVDNSOrder & DVDNSVerificationForIssue
5
+ - Added `options` optional keyword argument to `GlobalSign::OrderGetterByOrderId::Request` for getting certificate info and fulfillment
6
+
1
7
  ## 2.0.0
2
8
 
3
9
  - Added `product_code` required keyword argument to `GlobalSign::UrlVerification::Request` for selecting SSL certificate type
data/README.md CHANGED
@@ -113,6 +113,31 @@ request = GlobalSign::UrlVerification::Request.new(
113
113
  )
114
114
  ```
115
115
 
116
+ ### DNS Verification
117
+
118
+ Verification flow is the same as URL Verification. Request class use the following:
119
+
120
+ ```ruby
121
+ client = GlobalSign::Client.new
122
+
123
+ request = GlobalSign::DnsVerification::Request.new(
124
+ product_code: 'DV_LOW_DNS',
125
+ order_kind: 'new',
126
+ validity_period_months: 6,
127
+ csr: csr,
128
+ contract_info: contract,
129
+ )
130
+
131
+ response = client.process(request)
132
+
133
+ if response.success?
134
+ puts "Successfully DNS Verification"
135
+ puts response.params # => { dns_txt: "xxxxx", verification_fqdn_list: ['example.com', 'www.example.com'], ... }
136
+ else
137
+ raise StandardError, "#{response.error_code}: #{response.error_message}"
138
+ end
139
+ ```
140
+
116
141
  ### URL Verification for Issue
117
142
 
118
143
  ```ruby
@@ -139,10 +164,36 @@ else
139
164
  end
140
165
  ```
141
166
 
167
+ ### DNS Verification for Issue
168
+
169
+ ```ruby
170
+ client = GlobalSign::Client.new
171
+
172
+ # You can use ApproverFQDN value such as:
173
+ # - www.example.com
174
+ # - example.com
175
+
176
+ request = GlobalSign::UrlVerificationForIssue::Request.new(
177
+ order_id: 'xxxx123456789',
178
+ approver_fqdn: 'www.example.com',
179
+ )
180
+
181
+ response = client.process(request)
182
+
183
+ if response.success?
184
+ puts "Successfully DNS Verification for Issue"
185
+ puts response.params # => { fulfillment: { ca_certificates: [{ ca_cert: "xxxxx" }, ...]}, ... }
186
+ else
187
+ raise StandardError, "#{response.error_code}: #{response.error_message}"
188
+ end
189
+ ```
190
+
142
191
  ### Get Order by OrderID
143
192
 
144
193
  ```ruby
145
- request = GlobalSign::OrderGetterByOrderId::Request.new(order_id: 'xxxx123456789')
194
+ request = GlobalSign::OrderGetterByOrderId::Request.new(
195
+ order_id: 'xxxx123456789'
196
+ )
146
197
  response = client.process(request)
147
198
 
148
199
  puts response.params # => { order_id: "xxxx123456789", order_status: "2", ... }
@@ -151,6 +202,40 @@ puts response.params # => { order_id: "xxxx123456789", order_status: "2", ... }
151
202
  puts response.order_status_text # => "phishing_checking"
152
203
  ```
153
204
 
205
+ You can specify request options.
206
+
207
+ ```ruby
208
+ # certificate_info option
209
+ request = GlobalSign::OrderGetterByOrderId::Request.new(
210
+ order_id: 'xxxx123456789',
211
+ options: { certificate_info: true }
212
+ )
213
+ response = client.process(request)
214
+
215
+ puts response.params[:certificate_info] # => { certificate_status: '4', start_date: '2016-10-06T14:53:23.000+09:00', ... }
216
+
217
+ # fulfillment option
218
+ request = GlobalSign::OrderGetterByOrderId::Request.new(
219
+ order_id: 'xxxx123456789',
220
+ options: { fulfillment: true }
221
+ )
222
+ response = client.process(request)
223
+
224
+ puts response.params[:fulfillment] # => { ca_certificates: [{ ca_cert: "xxxxx" }, ...]}
225
+ ```
226
+
227
+ ### Decode CSR
228
+
229
+ ```ruby
230
+ request = GlobalSign::CsrDecoder::Request.new(
231
+ product_type: 'DV_LOW',
232
+ csr: csr
233
+ )
234
+ response = client.process(request)
235
+
236
+ puts response.params # => { common_name: "www.example.com", ... }
237
+ ```
238
+
154
239
  ## Contributing
155
240
 
156
241
  1. Create your feature branch (git checkout -b my-new-feature)
@@ -25,6 +25,12 @@ module GlobalSign
25
25
 
26
26
  def find_response_class_for(request)
27
27
  case request
28
+ when GlobalSign::CsrDecoder::Request
29
+ GlobalSign::CsrDecoder::Response
30
+ when GlobalSign::DnsVerification::Request
31
+ GlobalSign::DnsVerification::Response
32
+ when GlobalSign::DnsVerificationForIssue::Request
33
+ GlobalSign::DnsVerificationForIssue::Response
28
34
  when GlobalSign::UrlVerification::Request
29
35
  GlobalSign::UrlVerification::Response
30
36
  when GlobalSign::UrlVerificationForIssue::Request
@@ -0,0 +1,29 @@
1
+ module GlobalSign
2
+ module CsrDecoder
3
+ class Request < GlobalSign::Request
4
+ def initialize(csr:, product_type:)
5
+ @csr = csr
6
+ @product_type = product_type
7
+ end
8
+
9
+ def path
10
+ 'GASService'
11
+ end
12
+
13
+ def action
14
+ 'DecodeCSR'
15
+ end
16
+
17
+ def request_header
18
+ :QueryRequestHeader
19
+ end
20
+
21
+ def params
22
+ {
23
+ CSR: @csr,
24
+ ProductType: @product_type
25
+ }
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,36 @@
1
+ module GlobalSign
2
+ module CsrDecoder
3
+ class Response < GlobalSign::Response
4
+ module XPath
5
+ CSRData = '//Response/CSRData'
6
+ CertificatePreview = '//Response/CertificatePreview'
7
+ end
8
+
9
+ def response_header
10
+ :QueryResponseHeader
11
+ end
12
+
13
+ def params
14
+ @params ||= {
15
+ csr_data: detail(@xml.xpath(XPath::CSRData)),
16
+ certificate_preview: detail(@xml.xpath(XPath::CertificatePreview))
17
+ }
18
+ end
19
+
20
+ private
21
+
22
+ def detail(data)
23
+ {
24
+ common_name: data.at('CommonName').try(:text) || '',
25
+ organization: data.at('Organization').try(:text) || '',
26
+ organization_unit: data.at('Organization').try(:text) || '',
27
+ locality: data.at('Locality').try(:text) || '',
28
+ state: data.at('State').try(:text) || '',
29
+ country: data.at('Country').try(:text) || '',
30
+ email_address: data.at('EmailAddress').try(:text) || '',
31
+ key_length: data.at('KeyLength').try(:text) || ''
32
+ }
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,2 @@
1
+ require 'global_sign/csr_decoder/request'
2
+ require 'global_sign/csr_decoder/response'
@@ -0,0 +1,55 @@
1
+ module GlobalSign
2
+ module DnsVerification
3
+ class Request < GlobalSign::UrlVerification::Request
4
+ def initialize(product_code:, order_kind:, validity_period_months:, csr:, renewal_target_order_id: nil, contract_info: nil)
5
+ @product_code = product_code
6
+ @order_kind = order_kind
7
+ @validity_period_months = validity_period_months
8
+ @csr = csr
9
+ @renewal_target_order_id = renewal_target_order_id
10
+ @contract_info = contract_info || GlobalSign.contract
11
+ end
12
+
13
+ def path
14
+ 'ServerSSLService'
15
+ end
16
+
17
+ def action
18
+ 'DVDNSOrder'
19
+ end
20
+
21
+ def request_header
22
+ :OrderRequestHeader
23
+ end
24
+
25
+ def params
26
+ _params = {
27
+ OrderRequestParameter: {
28
+ ProductCode: @product_code,
29
+ OrderKind: @order_kind,
30
+ Licenses: 1,
31
+ ValidityPeriod: {
32
+ Months: @validity_period_months
33
+ },
34
+ CSR: @csr,
35
+ },
36
+ ContactInfo: {
37
+ FirstName: @contract_info.first_name,
38
+ LastName: @contract_info.last_name,
39
+ Phone: @contract_info.phone_number,
40
+ Email: @contract_info.email
41
+ }
42
+ }
43
+
44
+ # require `RenewalTargetOrderID` to request a renewal certificate
45
+ if @order_kind == 'renewal'
46
+ _params[:OrderRequestParameter].merge!(
47
+ { RenewalTargetOrderID: @renewal_target_order_id }
48
+ )
49
+ end
50
+
51
+ _params
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,29 @@
1
+ module GlobalSign
2
+ module DnsVerification
3
+ class Response < GlobalSign::Response
4
+ module XPath
5
+ ORDER_ID = '//Response/OrderID'
6
+ DNS_TXT = '//Response/DNSTXT'
7
+ VERIFICATION_FQDN_LIST = '//Response/VerificationFQDNList'
8
+ end
9
+
10
+ def response_header
11
+ :OrderResponseHeader
12
+ end
13
+
14
+ def params
15
+ @params ||= {
16
+ order_id: @xml.xpath(XPath::ORDER_ID).text,
17
+ dns_txt: @xml.xpath(XPath::DNS_TXT).text,
18
+ verification_fqdn_list: verification_fqdn_list,
19
+ }
20
+ end
21
+
22
+ private
23
+
24
+ def verification_fqdn_list
25
+ @xml.xpath(XPath::VERIFICATION_FQDN_LIST).children.map(&:text)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,2 @@
1
+ require 'global_sign/dns_verification/request'
2
+ require 'global_sign/dns_verification/response'
@@ -0,0 +1,29 @@
1
+ module GlobalSign
2
+ module DnsVerificationForIssue
3
+ class Request < GlobalSign::Request
4
+ def initialize(order_id:, approver_fqdn:)
5
+ @order_id = order_id
6
+ @approver_fqdn = approver_fqdn
7
+ end
8
+
9
+ def path
10
+ 'ServerSSLService'
11
+ end
12
+
13
+ def action
14
+ 'DVDNSVerificationForIssue'
15
+ end
16
+
17
+ def request_header
18
+ :OrderRequestHeader
19
+ end
20
+
21
+ def params
22
+ {
23
+ OrderID: @order_id,
24
+ ApproverFQDN: @approver_fqdn,
25
+ }
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,53 @@
1
+ module GlobalSign
2
+ module DnsVerificationForIssue
3
+ class Response < GlobalSign::Response
4
+ module XPath
5
+ Certificate_Info = '//Response/URLVerificationForIssue/CertificateInfo'
6
+ CA_Certificates = '//Response/URLVerificationForIssue/Fulfillment/CACertificates'
7
+ Server_Certificate = '//Response/URLVerificationForIssue/Fulfillment/ServerCertificate'
8
+ end
9
+
10
+ def response_header
11
+ :OrderResponseHeader
12
+ end
13
+
14
+ def params
15
+ @params ||= {
16
+ certificate_info: {
17
+ certificate_status: certificate_info.at('CertificateStatus').text,
18
+ start_date: certificate_info.at('StartDate').text,
19
+ end_date: certificate_info.at('EndDate').text,
20
+ common_name: certificate_info.at('CommonName').text,
21
+ subject_name: certificate_info.at('SubjectName').text,
22
+ },
23
+ fulfillment: {
24
+ ca_certificates: ca_certificates_list,
25
+ server_certificate: {
26
+ x509_cert: server_certificate.at('X509Cert').text,
27
+ pkcs7_cert: server_certificate.at('PKCS7Cert').text,
28
+ }
29
+ }
30
+ }
31
+ end
32
+
33
+ private
34
+
35
+ def certificate_info
36
+ @xml.xpath(XPath::Certificate_Info)
37
+ end
38
+
39
+ def ca_certificates_list
40
+ @xml.xpath(XPath::CA_Certificates).children.map do |c|
41
+ {
42
+ ca_cert_type: c.at('CACertType').text,
43
+ ca_cert: c.at('CACert').text,
44
+ }
45
+ end
46
+ end
47
+
48
+ def server_certificate
49
+ @xml.xpath(XPath::Server_Certificate)
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,2 @@
1
+ require 'global_sign/dns_verification_for_issue/request'
2
+ require 'global_sign/dns_verification_for_issue/response'
@@ -1,8 +1,9 @@
1
1
  module GlobalSign
2
2
  module OrderGetterByOrderId
3
3
  class Request < GlobalSign::Request
4
- def initialize(order_id:)
4
+ def initialize(order_id:, options: {})
5
5
  @order_id = order_id
6
+ @options = options
6
7
  end
7
8
 
8
9
  def path
@@ -18,7 +19,15 @@ module GlobalSign
18
19
  end
19
20
 
20
21
  def params
21
- { OrderID: @order_id }
22
+ _params = { OrderID: @order_id }
23
+
24
+ # options
25
+ option_params = {}
26
+ option_params[:ReturnCertificateInfo] = true if @options[:certificate_info]
27
+ option_params[:ReturnFulfillment] = true if @options[:fulfillment]
28
+ _params[:OrderQueryOption] = option_params if option_params.present?
29
+
30
+ _params
22
31
  end
23
32
  end
24
33
  end
@@ -5,14 +5,44 @@ module GlobalSign
5
5
  ORDER_ID = '//Response/OrderID'
6
6
  ORDER_STATUS = '//Response/OrderDetail/OrderInfo/OrderStatus'
7
7
  MODIFICATION_EVENTS = '//Response/OrderDetail/ModificationEvents'
8
+
9
+ # options
10
+ CERTIFICATE_INFO = '//Response/OrderDetail/CertificateInfo'
11
+ FULFILLMENT = '//Response/OrderDetail/Fulfillment'
12
+ CA_CERTIFICATES = '//Response/OrderDetail/Fulfillment/CACertificates'
13
+ SERVER_CERTIFICATE = '//Response/OrderDetail/Fulfillment/ServerCertificate'
14
+ end
15
+
16
+ def response_header
17
+ :OrderResponseHeader
8
18
  end
9
19
 
10
20
  def params
11
- @params ||= {
21
+ return @params if @params
22
+ _params = {
12
23
  order_id: @xml.xpath(XPath::ORDER_ID).text,
13
24
  order_status: @xml.xpath(XPath::ORDER_STATUS).text,
14
25
  modification_events: modification_events_list
15
26
  }
27
+
28
+ # options
29
+ _params[:certificate_info] = {
30
+ certificate_status: certificate_info.at('CertificateStatus').text,
31
+ start_date: certificate_info.at('StartDate').text,
32
+ end_date: certificate_info.at('EndDate').text,
33
+ common_name: certificate_info.at('CommonName').text,
34
+ subject_name: certificate_info.at('SubjectName').text,
35
+ } if certificate_info.text.present?
36
+
37
+ _params[:fulfillment] = {
38
+ ca_certificates: ca_certificates_list,
39
+ server_certificate: {
40
+ x509_cert: server_certificate.at('X509Cert').text,
41
+ pkcs7_cert: server_certificate.at('PKCS7Cert').text,
42
+ }
43
+ } if fulfillment.text.present?
44
+
45
+ @params = _params
16
46
  end
17
47
 
18
48
  def order_status_text
@@ -29,6 +59,27 @@ module GlobalSign
29
59
  }
30
60
  end
31
61
  end
62
+
63
+ def certificate_info
64
+ @xml.xpath(XPath::CERTIFICATE_INFO)
65
+ end
66
+
67
+ def fulfillment
68
+ @xml.xpath(XPath::FULFILLMENT)
69
+ end
70
+
71
+ def ca_certificates_list
72
+ @xml.xpath(XPath::CA_CERTIFICATES).children.map do |c|
73
+ {
74
+ ca_cert_type: c.at('CACertType').text,
75
+ ca_cert: c.at('CACert').text,
76
+ }
77
+ end
78
+ end
79
+
80
+ def server_certificate
81
+ @xml.xpath(XPath::SERVER_CERTIFICATE)
82
+ end
32
83
  end
33
84
  end
34
85
  end
@@ -5,21 +5,24 @@ module GlobalSign
5
5
  SUCCESS_CODE = '0'.freeze
6
6
  WARNING_CODE = '1'.freeze
7
7
 
8
- module XPath
9
- RESULT = '//Response/OrderResponseHeader/SuccessCode'
10
- ERRORS = '//Response/OrderResponseHeader/Errors'
11
- end
12
-
13
8
  def initialize(body)
14
9
  @xml = Nokogiri::XML(body)
15
10
  end
16
11
 
12
+ def xpath_result
13
+ "//Response/#{response_header}/SuccessCode"
14
+ end
15
+
16
+ def xpath_errors
17
+ "//Response/#{response_header}/Errors"
18
+ end
19
+
17
20
  def success?
18
- @xml.xpath(XPath::RESULT).text == SUCCESS_CODE
21
+ @xml.xpath(xpath_result).text == SUCCESS_CODE
19
22
  end
20
23
 
21
24
  def warning?
22
- @xml.xpath(XPath::RESULT).text == WARNING_CODE
25
+ @xml.xpath(xpath_result).text == WARNING_CODE
23
26
  end
24
27
 
25
28
  def error?
@@ -41,7 +44,7 @@ module GlobalSign
41
44
  private
42
45
 
43
46
  def errors
44
- @xml.xpath(XPath::ERRORS)
47
+ @xml.xpath(xpath_errors)
45
48
  end
46
49
  end
47
50
  end
@@ -7,6 +7,10 @@ module GlobalSign
7
7
  VERIFICATION_URL_LIST = '//Response/VerificationURLList'
8
8
  end
9
9
 
10
+ def response_header
11
+ :OrderResponseHeader
12
+ end
13
+
10
14
  def params
11
15
  @params ||= {
12
16
  order_id: @xml.xpath(XPath::ORDER_ID).text,
@@ -7,6 +7,10 @@ module GlobalSign
7
7
  Server_Certificate = '//Response/URLVerificationForIssue/Fulfillment/ServerCertificate'
8
8
  end
9
9
 
10
+ def response_header
11
+ :OrderResponseHeader
12
+ end
13
+
10
14
  def params
11
15
  @params ||= {
12
16
  certificate_info: {
@@ -1,3 +1,3 @@
1
1
  module GlobalSign
2
- VERSION = "2.0.0"
2
+ VERSION = "2.1.0"
3
3
  end
data/lib/global_sign.rb CHANGED
@@ -11,6 +11,9 @@ require 'global_sign/order_status'
11
11
  require 'global_sign/url_verification'
12
12
  require 'global_sign/url_verification_for_issue'
13
13
  require 'global_sign/order_getter_by_order_id'
14
+ require 'global_sign/csr_decoder'
15
+ require 'global_sign/dns_verification'
16
+ require 'global_sign/dns_verification_for_issue'
14
17
 
15
18
  module GlobalSign
16
19
  class << self
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: global_sign
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ku00
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-11-21 00:00:00.000000000 Z
11
+ date: 2016-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -185,6 +185,15 @@ files:
185
185
  - lib/global_sign.rb
186
186
  - lib/global_sign/client.rb
187
187
  - lib/global_sign/contract.rb
188
+ - lib/global_sign/csr_decoder.rb
189
+ - lib/global_sign/csr_decoder/request.rb
190
+ - lib/global_sign/csr_decoder/response.rb
191
+ - lib/global_sign/dns_verification.rb
192
+ - lib/global_sign/dns_verification/request.rb
193
+ - lib/global_sign/dns_verification/response.rb
194
+ - lib/global_sign/dns_verification_for_issue.rb
195
+ - lib/global_sign/dns_verification_for_issue/request.rb
196
+ - lib/global_sign/dns_verification_for_issue/response.rb
188
197
  - lib/global_sign/order_getter_by_order_id.rb
189
198
  - lib/global_sign/order_getter_by_order_id/request.rb
190
199
  - lib/global_sign/order_getter_by_order_id/response.rb