globessl 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,121 @@
1
+ module GlobeSSL
2
+ class DomainControlValidation < Base
3
+ METHODS = ["email", "http", "https"].freeze
4
+
5
+ attribute :certificate, SSLCertificate
6
+ attribute :dcv_method, String
7
+ attribute :approver_email, String
8
+ attribute :approver_emails, String
9
+
10
+ def change!
11
+ @errors.clear
12
+
13
+ return false unless valid?
14
+
15
+ params = {
16
+ "id" => @certificate.id,
17
+ "dcv_method" => @dcv_method
18
+ }
19
+
20
+ if @dcv_method == "email" && @certificate.product.validation == "dv"
21
+ email_params = {
22
+ "approver_email" => @approver_email
23
+ }
24
+ params.merge!(email_params)
25
+
26
+ if @certificate.product.multi_domain
27
+ multi_domain_params = {
28
+ "approver_emails" => @approver_emails
29
+ }
30
+ params.merge!(multi_domain_params)
31
+ end
32
+ end
33
+
34
+ request = Client.post('/dcv/change', params)
35
+
36
+ case response.code
37
+ when '200'
38
+ return true
39
+ when '400', '401', '403'
40
+ set_errors(response)
41
+ return false
42
+ else
43
+ return false
44
+ end
45
+ end
46
+
47
+ def resend!
48
+ @errors.clear
49
+
50
+ unless @certificate
51
+ @errors << "certificate is required"
52
+ return false
53
+ end
54
+
55
+ params = {
56
+ "id" => @certificate.id
57
+ }
58
+
59
+ request = Client.post('/dcv/resend', params)
60
+
61
+ case response.code
62
+ when '200'
63
+ return true
64
+ when '400', '401', '403'
65
+ set_errors(response)
66
+ return false
67
+ else
68
+ return false
69
+ end
70
+ end
71
+
72
+ def set_errors(response)
73
+ json = response.body
74
+ hash = JSON.parse(json)
75
+ @errors << hash["message"]
76
+ end
77
+
78
+ def valid?
79
+ validate
80
+ end
81
+
82
+ def validate
83
+ unless @certificate
84
+ @errors << "certificate is required"
85
+ end
86
+
87
+ unless @dcv_method
88
+ @errors << "dcv_method is required"
89
+ else
90
+ unless METHODS.include?(@dcv_method)
91
+ @errors << "dcv_method must be one of 'email', 'http' or 'https'"
92
+ end
93
+ end
94
+
95
+ if @dcv_method == "email"
96
+ unless @approver_email
97
+ @errors << "approver_email is required"
98
+ end
99
+
100
+ if @certificate.product.multi_domain
101
+ unless @approver_emails
102
+ @errors << "approver_emails are required"
103
+ end
104
+ end
105
+ end
106
+
107
+ if @errors.any?
108
+ return false
109
+ else
110
+ return true
111
+ end
112
+ end
113
+
114
+ def self.write_file(sha1, md5, location)
115
+ File.open(File.join(location, "#{md5}.txt"), 'w') do |file|
116
+ file.puts sha1
117
+ file.puts "comodoca.com"
118
+ end
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,38 @@
1
+ module GlobeSSL
2
+ class DomainEmails < Base
3
+ attribute :domain, String
4
+ attribute :list, Array[String]
5
+ attribute :errors, Array[String]
6
+
7
+ def fetch
8
+ @errors.clear
9
+ @list.clear
10
+
11
+ unless @domain
12
+ @errors << "domain is required"
13
+ return false
14
+ end
15
+
16
+ response = Client.get('/tools/domainemails', { 'domain' => @domain })
17
+
18
+ case response.code
19
+ when '200'
20
+ json = response.body
21
+ hash = JSON.parse(json)
22
+ hash.each { |email| @list << email }
23
+ return true
24
+ when '400', '401', '403'
25
+ set_errors(response)
26
+ return false
27
+ else
28
+ return false
29
+ end
30
+ end
31
+
32
+ def set_errors(response)
33
+ json = response.body
34
+ hash = JSON.parse(json)
35
+ @errors << hash["message"]
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,298 @@
1
+ require_relative 'country_codes'
2
+
3
+ module GlobeSSL
4
+ class OrderSSLCertificate < Base
5
+ EXPIRY_PERIODS = [0, 1, 2, 3].freeze
6
+
7
+ attribute :admin_firstname, String
8
+ attribute :admin_lastname, String
9
+ attribute :admin_email, String
10
+ attribute :admin_org, String # [optional] Required for OV and EV SSL
11
+ attribute :admin_jobtitle, String
12
+ attribute :admin_address, String # [optional] Required for OV and EV SSL
13
+ attribute :admin_city, String # [optional] Required for OV and EV SSL
14
+ attribute :admin_country, String # [optional] Required for OV and EV SSL, must be one in COUNTRY_CODES
15
+ attribute :admin_phone, String
16
+ attribute :amount, Float
17
+ attribute :approver_email, String # [optional] Required when dcv_method = email
18
+ attribute :approver_emails, String # [optional] Required for SAN/UCC/Multi-Domain SSL, required only if dcv_method = email
19
+ attribute :certificate_id, Integer
20
+ attribute :currency, String
21
+ attribute :dcv_method, String # one of DomainControlValidation::METHODS
22
+ attribute :dcv_file_path, String # The path to write the domain validation text file is it is used
23
+ attribute :dns_names, String # [optional] Required for SAN/UCC/Multi-Domain SSL
24
+ attribute :errors, Array[String]
25
+ attribute :csr, CertificateSigningRequest
26
+ attribute :optional_admin_params, Boolean, :default => false
27
+ attribute :optional_org_params, Boolean, :default => false
28
+ attribute :order_id, Integer
29
+ attribute :org_name, String # [optional] Required for OV and EV SSL
30
+ attribute :org_division, String # [optional] Required for OV and EV SSL
31
+ attribute :org_address, String # [optional] Required for OV and EV SSL
32
+ attribute :org_city, String # [optional] Required for OV and EV SSL
33
+ attribute :org_state, String # [optional] Required for OV and EV SSL
34
+ attribute :org_country, String # [optional] Required for OV and EV SSL, must be one in COUNTRY_CODES
35
+ attribute :org_postalcode, String # [optional] Required for OV and EV SSL
36
+ attribute :org_phone, String # [optional] Required for OV and EV SSL
37
+ attribute :period, Integer # must be one of 1, 2 or 3 years (see EXPIRY_PERIODS); pass 0 for free product
38
+ attribute :product, Product # should be retrieved using Product#fetch
39
+ attribute :webserver_type, Integer # can be retrieved using WebServers#fetch
40
+
41
+ def dcv_method=(value)
42
+ @dcv_method = value.downcase
43
+ end
44
+
45
+ def purchase!
46
+ @errors.clear
47
+ return false unless valid?
48
+
49
+ # If the dcv_method is 'http' or 'https', prepare the validation text file.
50
+ # Use MD5 for .txt file name.
51
+ # Write SHA1 to first line and comodoca.com to 2nd line.
52
+ # Save to web app root (@txt_file_path).
53
+ unless @dcv_method == "email"
54
+ DomainControlValidation.write_file(@csr.fingerprint_sha1, @csr.fingerprint_md5, @dcv_file_path)
55
+ end
56
+
57
+ params = {
58
+ "admin_firstname" => @admin_firstname,
59
+ "admin_lastname" => @admin_lastname,
60
+ "admin_email" => @admin_email,
61
+ "admin_phone" => @admin_phone,
62
+ "csr" => @csr.csr_code,
63
+ "dcv_method" => @dcv_method,
64
+ "period" => @period,
65
+ "product_id" => @product.id,
66
+ "webserver_type" => @webserver_type
67
+ }
68
+
69
+ admin_params = {
70
+ "admin_org" => @admin_org,
71
+ "admin_jobtitle" => @admin_jobtitle,
72
+ "admin_address" => @admin_address,
73
+ "admin_city" => @admin_city,
74
+ "admin_country" => @admin_country
75
+ }
76
+
77
+ email_params = {
78
+ "approver_email" => @approver_email
79
+ }
80
+
81
+ multiple_emails_params = {
82
+ "approver_emails" => @approver_emails
83
+ }
84
+
85
+ org_params = {
86
+ "org_name" => @org_name,
87
+ "org_division" => @org_division,
88
+ "org_address" => @org_address,
89
+ "org_city" => @org_city,
90
+ "org_state" => @org_state,
91
+ "org_country" => @org_country,
92
+ "org_postalcode" => @org_postalcode,
93
+ "org_phone" => @org_phone
94
+ }
95
+
96
+ multi_domain_params = {
97
+ "dns_names" => @dns_names
98
+ }
99
+
100
+ if @product.validation == "dv"
101
+ if @dcv_method == "email"
102
+ params.merge!(email_params)
103
+ end
104
+
105
+ if @product.multi_domain
106
+ params.merge!(multi_domain_params)
107
+ end
108
+
109
+ if @dcv_method == "email" && @product.multi_domain
110
+ params.merge!(multiple_emails_params)
111
+ end
112
+
113
+ if @optional_admin_params
114
+ params.merge!(admin_params)
115
+ end
116
+
117
+ if @optional_org_params
118
+ params.merge!(org_params)
119
+ end
120
+ else
121
+ params.merge!(admin_params)
122
+ params.merge!(org_params)
123
+ end
124
+
125
+ response = Client.post('/order/ssl', params)
126
+
127
+ case response.code
128
+ when '200'
129
+ json = response.body
130
+ hash = JSON.parse(json)
131
+
132
+ @order_id = hash["order_id"]
133
+ @certificate_id = hash["certificate_id"]
134
+ @amount = hash["amount"]
135
+ @currency = hash["currency"]
136
+
137
+ return true
138
+ when '400', '401', '403'
139
+ set_errors(response)
140
+ return false
141
+ else
142
+ return false
143
+ end
144
+ end
145
+
146
+ def set_errors(response)
147
+ json = response.body
148
+ hash = JSON.parse(json)
149
+ @errors << hash["message"]
150
+ end
151
+
152
+ def valid?
153
+ validate
154
+ end
155
+
156
+ def validate
157
+ unless @dcv_method
158
+ @errors << "dcv_method is required"
159
+ else
160
+ unless DomainControlValidation::METHODS.include?(@dcv_method)
161
+ @errors << "dcv_method must be one of 'email', 'http' or 'https'"
162
+ end
163
+
164
+ unless @dcv_method == "email"
165
+ unless @dcv_file_path
166
+ @errors << "dcv_file_path is required"
167
+ end
168
+ end
169
+ end
170
+
171
+ if @product.multi_domain
172
+ unless @dns_names.size > (@product.min_domains - 1)
173
+ @errors << "dns_names are required"
174
+ end
175
+ end
176
+
177
+ if @dcv_method == "email"
178
+ unless @approver_email
179
+ @errors << "approver_email is required"
180
+ end
181
+
182
+ if @product.multi_domain
183
+ unless @approver_emails.size == @dns_names.size
184
+ @errors << "approver_emails are required"
185
+ end
186
+ end
187
+ end
188
+
189
+ unless @product.validation == "dv" # if not domain validation
190
+ unless @admin_org
191
+ @errors << "admin_org is required"
192
+ end
193
+
194
+ unless @admin_address
195
+ @errors << "admin_address is required"
196
+ end
197
+
198
+ unless @admin_city
199
+ @errors << "admin_city is required"
200
+ end
201
+
202
+ unless @admin_country
203
+ @errors << "admin_country is required"
204
+ else
205
+ unless COUNTRY_CODES.has_key?(@admin_country)
206
+ @errors << "admin_country must be one in COUNTRY_CODES"
207
+ end
208
+ end
209
+
210
+ unless @org_name
211
+ @errors << "org_name is required"
212
+ end
213
+
214
+ unless @org_division
215
+ @errors << "org_division is required"
216
+ end
217
+
218
+ unless @org_address
219
+ @errors << "org_address is required"
220
+ end
221
+
222
+ unless @org_city
223
+ @errors << "org_city is required"
224
+ end
225
+
226
+ unless @org_state
227
+ @errors << "org_state is required"
228
+ end
229
+
230
+ unless @org_country
231
+ @errors << "org_country is required"
232
+ else
233
+ unless COUNTRY_CODES.has_key?(@org_country)
234
+ @errors << "org_country must be one in COUNTRY_CODES"
235
+ end
236
+ end
237
+
238
+ unless @org_postalcode
239
+ @errors << "org_postalcode is required"
240
+ end
241
+
242
+ unless @org_phone
243
+ @errors << "org_phone is required"
244
+ end
245
+ end
246
+
247
+ unless @admin_firstname
248
+ @errors << "admin_firstname is required"
249
+ end
250
+
251
+ unless @admin_lastname
252
+ @errors << "admin_lastname is required"
253
+ end
254
+
255
+ unless @admin_email
256
+ @errors << "admin_email is required"
257
+ end
258
+
259
+ unless @admin_jobtitle
260
+ @errors << "admin_jobtitle is required"
261
+ end
262
+
263
+ unless @admin_phone
264
+ @errors << "admin_phone is required"
265
+ end
266
+
267
+ unless @admin_phone
268
+ @errors << "admin_phone is required"
269
+ end
270
+
271
+ unless @csr
272
+ @errors << "certificate signing request (csr) is required"
273
+ end
274
+
275
+ unless @period
276
+ @errors << "period is required"
277
+ else
278
+ unless EXPIRY_PERIODS.include?(@period)
279
+ @errors << "period must be 1, 2 or 3 years or 0 if product is free"
280
+ end
281
+ end
282
+
283
+ unless @webserver_type
284
+ @errors << "webserver_type is required"
285
+ end
286
+
287
+ unless @product
288
+ @errors << "product is required"
289
+ end
290
+
291
+ if @errors.any?
292
+ return false
293
+ else
294
+ return true
295
+ end
296
+ end
297
+ end
298
+ end