digicert 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -0
  3. data/.hound.yml +3 -0
  4. data/.rspec +0 -1
  5. data/.rubocop.yml +629 -0
  6. data/.sample.env +4 -0
  7. data/.sample.pryrc +3 -0
  8. data/.travis.yml +5 -2
  9. data/LICENSE.txt +21 -0
  10. data/README.md +812 -9
  11. data/bin/console +2 -5
  12. data/bin/rspec +17 -0
  13. data/digicert.gemspec +7 -14
  14. data/lib/digicert.rb +40 -2
  15. data/lib/digicert/actions.rb +9 -0
  16. data/lib/digicert/actions/all.rb +27 -0
  17. data/lib/digicert/actions/base.rb +11 -0
  18. data/lib/digicert/actions/create.rb +25 -0
  19. data/lib/digicert/actions/fetch.rb +21 -0
  20. data/lib/digicert/actions/update.rb +25 -0
  21. data/lib/digicert/base.rb +35 -0
  22. data/lib/digicert/base_order.rb +39 -0
  23. data/lib/digicert/certificate.rb +43 -0
  24. data/lib/digicert/certificate_downloader.rb +137 -0
  25. data/lib/digicert/certificate_request.rb +19 -0
  26. data/lib/digicert/client_certificate/base.rb +17 -0
  27. data/lib/digicert/client_certificate/digital_signature_plus.rb +13 -0
  28. data/lib/digicert/client_certificate/email_security_plus.rb +13 -0
  29. data/lib/digicert/client_certificate/premium.rb +17 -0
  30. data/lib/digicert/config.rb +21 -0
  31. data/lib/digicert/configuration.rb +26 -0
  32. data/lib/digicert/container.rb +35 -0
  33. data/lib/digicert/container_template.rb +32 -0
  34. data/lib/digicert/csr_generator.rb +43 -0
  35. data/lib/digicert/debugger.rb +34 -0
  36. data/lib/digicert/domain.rb +59 -0
  37. data/lib/digicert/duplicate_certificate.rb +21 -0
  38. data/lib/digicert/duplicate_certificate_finder.rb +42 -0
  39. data/lib/digicert/email_validation.rb +35 -0
  40. data/lib/digicert/errors.rb +30 -0
  41. data/lib/digicert/errors/forbidden.rb +9 -0
  42. data/lib/digicert/errors/request_error.rb +37 -0
  43. data/lib/digicert/errors/server_error.rb +9 -0
  44. data/lib/digicert/errors/unauthorized.rb +9 -0
  45. data/lib/digicert/expiring_order.rb +21 -0
  46. data/lib/digicert/findable.rb +33 -0
  47. data/lib/digicert/order.rb +81 -0
  48. data/lib/digicert/order_cancellation.rb +25 -0
  49. data/lib/digicert/order_duplicator.rb +11 -0
  50. data/lib/digicert/order_manager.rb +39 -0
  51. data/lib/digicert/order_reissuer.rb +11 -0
  52. data/lib/digicert/organization.rb +43 -0
  53. data/lib/digicert/product.rb +14 -0
  54. data/lib/digicert/request.rb +123 -0
  55. data/lib/digicert/response.rb +30 -0
  56. data/lib/digicert/ssl_certificate/base.rb +9 -0
  57. data/lib/digicert/ssl_certificate/ssl_ev_plus.rb +13 -0
  58. data/lib/digicert/ssl_certificate/ssl_plus.rb +13 -0
  59. data/lib/digicert/ssl_certificate/ssl_wildcard.rb +13 -0
  60. data/lib/digicert/version.rb +23 -1
  61. data/spec/acceptance/certificate_download_spec.rb +68 -0
  62. data/spec/acceptance/duplicating_certificate_spec.rb +86 -0
  63. data/spec/acceptance/reissuing_certificate_spec.rb +104 -0
  64. data/spec/digicert/actions/all_spec.rb +26 -0
  65. data/spec/digicert/actions/create_spec.rb +47 -0
  66. data/spec/digicert/actions/fetch_spec.rb +28 -0
  67. data/spec/digicert/actions/update_spec.rb +39 -0
  68. data/spec/digicert/certificate_downloader_spec.rb +89 -0
  69. data/spec/digicert/certificate_request_spec.rb +49 -0
  70. data/spec/digicert/certificate_spec.rb +93 -0
  71. data/spec/digicert/client_certificate/digital_signature_plus_spec.rb +32 -0
  72. data/spec/digicert/client_certificate/email_security_plus_spec.rb +36 -0
  73. data/spec/digicert/client_certificate/premium_spec.rb +34 -0
  74. data/spec/digicert/config_spec.rb +39 -0
  75. data/spec/digicert/container_spec.rb +44 -0
  76. data/spec/digicert/container_template_spec.rb +32 -0
  77. data/spec/digicert/csr_generator_spec.rb +31 -0
  78. data/spec/digicert/domain_spec.rb +89 -0
  79. data/spec/digicert/duplicate_certificate_finder_spec.rb +27 -0
  80. data/spec/digicert/duplicate_certificate_spec.rb +15 -0
  81. data/spec/digicert/email_validation_spec.rb +26 -0
  82. data/spec/digicert/expiring_order_spec.rb +16 -0
  83. data/spec/digicert/findable_spec.rb +19 -0
  84. data/spec/digicert/order_cancellation_spec.rb +24 -0
  85. data/spec/digicert/order_duplicator_spec.rb +35 -0
  86. data/spec/digicert/order_reissuer_spec.rb +35 -0
  87. data/spec/digicert/order_spec.rb +134 -0
  88. data/spec/digicert/organization_spec.rb +61 -0
  89. data/spec/digicert/product_spec.rb +28 -0
  90. data/spec/digicert/request_spec.rb +47 -0
  91. data/spec/digicert/ssl_certificate/ssl_ev_plus_spec.rb +35 -0
  92. data/spec/digicert/ssl_certificate/ssl_plus_spec.rb +36 -0
  93. data/spec/digicert/ssl_certificate/ssl_wildcard_spec.rb +35 -0
  94. data/spec/fixtures/certificate.pem +79 -0
  95. data/spec/fixtures/certificate.zip +0 -0
  96. data/spec/fixtures/certificate_request.json +116 -0
  97. data/spec/fixtures/certificate_requests.json +59 -0
  98. data/spec/fixtures/certificate_revoked.json +13 -0
  99. data/spec/fixtures/container.json +15 -0
  100. data/spec/fixtures/container_created.json +3 -0
  101. data/spec/fixtures/container_template.json +15 -0
  102. data/spec/fixtures/container_templates.json +14 -0
  103. data/spec/fixtures/containers.json +14 -0
  104. data/spec/fixtures/domain.json +71 -0
  105. data/spec/fixtures/domain_created.json +3 -0
  106. data/spec/fixtures/domains.json +49 -0
  107. data/spec/fixtures/email_validations.json +17 -0
  108. data/spec/fixtures/empty.json +0 -0
  109. data/spec/fixtures/errors.json +6 -0
  110. data/spec/fixtures/expiring_orders.json +20 -0
  111. data/spec/fixtures/order.json +107 -0
  112. data/spec/fixtures/order_created.json +9 -0
  113. data/spec/fixtures/order_duplicated.json +8 -0
  114. data/spec/fixtures/order_duplications.json +57 -0
  115. data/spec/fixtures/order_reissued.json +8 -0
  116. data/spec/fixtures/orders.json +93 -0
  117. data/spec/fixtures/organization.json +35 -0
  118. data/spec/fixtures/organization_created.json +3 -0
  119. data/spec/fixtures/organizations.json +84 -0
  120. data/spec/fixtures/ping.json +3 -0
  121. data/spec/fixtures/product.json +71 -0
  122. data/spec/fixtures/products.json +100 -0
  123. data/spec/fixtures/rsa4096.key +51 -0
  124. data/spec/requests/certificate_duplication_spec.rb +41 -0
  125. data/spec/requests/certificate_generation_spec.rb +93 -0
  126. data/spec/requests/certificate_reissuing_spec.rb +38 -0
  127. data/spec/requests/container_management_spec.rb +36 -0
  128. data/spec/requests/domain_management_spec.rb +64 -0
  129. data/spec/requests/order_client_email_security_plus_spec.rb +38 -0
  130. data/spec/requests/order_management_spec.rb +24 -0
  131. data/spec/requests/order_ssl_ev_plus_spec.rb +57 -0
  132. data/spec/requests/order_ssl_wildcard_spec.rb +57 -0
  133. data/spec/requests/organization_management_spec.rb +22 -0
  134. data/spec/requests/product_management_spec.rb +24 -0
  135. data/spec/requests/request_management_spec.rb +24 -0
  136. data/spec/spec_helper.rb +35 -0
  137. data/spec/support/fake_digicert_api.rb +324 -0
  138. metadata +162 -5
@@ -0,0 +1,19 @@
1
+ require "digicert/base"
2
+
3
+ module Digicert
4
+ class CertificateRequest < Digicert::Base
5
+ include Digicert::Actions::All
6
+ include Digicert::Actions::Fetch
7
+ include Digicert::Actions::Update
8
+
9
+ private
10
+
11
+ def resource_path
12
+ "request"
13
+ end
14
+
15
+ def resource_update_path
16
+ [resource_path, resource_id, "status"].join("/")
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,17 @@
1
+ require "digicert/base_order"
2
+
3
+ module Digicert
4
+ module ClientCertificate
5
+ class Base < Digicert::BaseOrder
6
+ private
7
+
8
+ def validate_certificate(common_name:, signature_hash:, emails:, **attrs)
9
+ attrs.merge(
10
+ emails: emails,
11
+ common_name: common_name,
12
+ signature_hash: signature_hash,
13
+ )
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,13 @@
1
+ require "digicert/client_certificate/base"
2
+
3
+ module Digicert
4
+ module ClientCertificate
5
+ class DigitalSignaturePlus < Digicert::ClientCertificate::Base
6
+ private
7
+
8
+ def certificate_type
9
+ "client_digital_signature_plus"
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ require "digicert/client_certificate/base"
2
+
3
+ module Digicert
4
+ module ClientCertificate
5
+ class EmailSecurityPlus < Digicert::ClientCertificate::Base
6
+ private
7
+
8
+ def certificate_type
9
+ "client_email_security_plus"
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,17 @@
1
+ require "digicert/client_certificate/base"
2
+
3
+ module Digicert
4
+ module ClientCertificate
5
+ class Premium < Digicert::ClientCertificate::Base
6
+ private
7
+
8
+ def certificate_type
9
+ "client_premium_sha2"
10
+ end
11
+
12
+ def validate_certificate(csr:, **attributes)
13
+ super(attributes.merge(csr: csr))
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,21 @@
1
+ require "digicert/configuration"
2
+
3
+ module Digicert
4
+ module Config
5
+ def configure
6
+ if block_given?
7
+ yield configuration
8
+ end
9
+ end
10
+
11
+ def configuration
12
+ @configuration ||= Configuration.new
13
+ end
14
+ end
15
+
16
+ # Expose config module methods as class level method,
17
+ # so we can use those method whenever necessary, specially
18
+ # the `configuration` throughout the gem
19
+ #
20
+ extend Config
21
+ end
@@ -0,0 +1,26 @@
1
+ module Digicert
2
+ class Configuration
3
+ attr_accessor :api_key, :api_host, :base_path, :response_type, :debug_mode
4
+
5
+ def initialize
6
+ @api_host = "www.digicert.com"
7
+ @base_path = "services/v2"
8
+ @response_type = :object
9
+ @debug_mode = false
10
+ end
11
+
12
+ def response_klass
13
+ response_klasses[response_type.to_sym] || ResponseObject
14
+ end
15
+
16
+ def debug_mode?
17
+ debug_mode == true
18
+ end
19
+
20
+ private
21
+
22
+ def response_klasses
23
+ { hash: Hash, object: ResponseObject }
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,35 @@
1
+ require "digicert/base"
2
+
3
+ module Digicert
4
+ class Container < Digicert::Base
5
+ include Digicert::Actions::All
6
+ include Digicert::Actions::Fetch
7
+ include Digicert::Actions::Create
8
+
9
+ def self.create(container_id:, **attributes)
10
+ new(attributes.merge(container_id: container_id)).create
11
+ end
12
+
13
+ private
14
+
15
+ def extract_local_attribute_ids
16
+ @container_id = attributes.delete(:container_id)
17
+ end
18
+
19
+ def validate(name:, template_id:, **attributes)
20
+ required_attributes = {
21
+ name: name, template_id: template_id
22
+ }
23
+
24
+ required_attributes.merge(attributes)
25
+ end
26
+
27
+ def resource_path
28
+ "container"
29
+ end
30
+
31
+ def resource_creation_path
32
+ [resource_path, @container_id, "children"].join("/")
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,32 @@
1
+ require "digicert/base"
2
+
3
+ module Digicert
4
+ class ContainerTemplate < Digicert::Base
5
+ include Digicert::Actions::All
6
+ include Digicert::Actions::Fetch
7
+
8
+ def self.all(container_id)
9
+ new(container_id: container_id).all
10
+ end
11
+
12
+ def self.fetch(template_id:, container_id:)
13
+ new(resource_id: template_id, container_id: container_id).fetch
14
+ end
15
+
16
+ private
17
+
18
+ attr_reader :container_id
19
+
20
+ def extract_local_attribute_ids
21
+ @container_id = attributes.delete(:container_id)
22
+ end
23
+
24
+ def resources_key
25
+ "container_templates"
26
+ end
27
+
28
+ def resource_path
29
+ ["container", container_id, "template"].join("/")
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,43 @@
1
+ require "r509"
2
+
3
+ module Digicert
4
+ class CSRGenerator
5
+ def initialize(common_name:, organization:, san_names: [], rsa_key: nil)
6
+ @rsa_key = rsa_key
7
+ @common_name = common_name
8
+ @san_names = san_names
9
+ @organization = organization
10
+ end
11
+
12
+ def generate
13
+ create_r509_csr.to_s
14
+ end
15
+
16
+ def self.generate(attributes)
17
+ new(attributes).generate
18
+ end
19
+
20
+ private
21
+
22
+ attr_reader :organization, :common_name, :san_names, :rsa_key
23
+
24
+ def create_r509_csr
25
+ R509::CSR.new(r509_attributes_hash)
26
+ end
27
+
28
+ def r509_attributes_hash
29
+ { key: rsa_key, subject: subject_items, san_names: san_names }.
30
+ reject { |key, value| value.nil? || value.empty? }
31
+ end
32
+
33
+ def subject_items
34
+ [
35
+ ["CN", common_name],
36
+ ["C", organization.country],
37
+ ["ST", organization.state],
38
+ ["L", organization.city],
39
+ ["O", organization.name],
40
+ ]
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,34 @@
1
+ module Digicert
2
+ class Debugger
3
+ def initialize(request:, response:)
4
+ @request = request
5
+ @response = response
6
+ end
7
+
8
+ def debug
9
+ puts "[API Reqeust Begin]".center(50, "=")
10
+ puts api_request_details
11
+ puts api_response_details
12
+ puts "[API Reqeust End]".center(50, "=")
13
+ end
14
+
15
+ private
16
+
17
+ attr_reader :request, :response
18
+
19
+ def api_request_details
20
+ uri = ["[URI]", request.method, request.uri].join(" ")
21
+ headers = "[Headers] " + request.to_hash.to_s
22
+ body = "[Request Body] " + request.body.to_json if request.body
23
+
24
+ [uri, headers, body].join("\n")
25
+ end
26
+
27
+ def api_response_details
28
+ response_object = "[Response] " + response.inspect
29
+ body = "[Response Body] " + response.body if response.body
30
+
31
+ [response_object, body].join("\n")
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,59 @@
1
+ require "digicert/base"
2
+ require "digicert/findable"
3
+
4
+ module Digicert
5
+ class Domain < Digicert::Base
6
+ extend Digicert::Findable
7
+
8
+ include Digicert::Actions::All
9
+ include Digicert::Actions::Fetch
10
+ include Digicert::Actions::Create
11
+
12
+ def activate
13
+ request_klass.new(
14
+ :put, [resource_path, resource_id, "activate"].join("/"),
15
+ ).parse
16
+ end
17
+
18
+ def deactivate
19
+ request_klass.new(
20
+ :put, [resource_path, resource_id, "deactivate"].join("/"),
21
+ ).parse
22
+ end
23
+
24
+ private
25
+
26
+ def resource_path
27
+ "domain"
28
+ end
29
+
30
+ def validate_validations(attributes)
31
+ attributes.map do |attribute|
32
+ validate_validation(attribute)
33
+ end
34
+ end
35
+
36
+ # Validate validation
37
+ #
38
+ # We need to provide a valid type of valitations when creating a new domain,
39
+ # but the most important thing about the types are it has to be in lowercase
40
+ # format, otherwise Digicert won't accept it a valid type. So let's ensure
41
+ # we are always providig the type in correct format.
42
+ #
43
+ # Ref: https://www.digicert.com/services/v2/documentation/appendix-validation-types
44
+ #
45
+ def validate_validation(type:, **attributes)
46
+ { type: type.downcase }.merge(attributes)
47
+ end
48
+
49
+ def validate(name:, organization:, validations:, **attributes)
50
+ required_attributes = {
51
+ name: name,
52
+ organization: organization,
53
+ validations: validate_validations(validations)
54
+ }
55
+
56
+ required_attributes.merge(attributes)
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,21 @@
1
+ require "digicert/base"
2
+
3
+ module Digicert
4
+ class DuplicateCertificate < Digicert::Base
5
+ include Digicert::Actions::All
6
+
7
+ def self.all(order_id:, **attributes)
8
+ new(resource_id: order_id, **attributes).all
9
+ end
10
+
11
+ private
12
+
13
+ def resources_key
14
+ "certificates"
15
+ end
16
+
17
+ def resource_path
18
+ ["order", "certificate", resource_id, "duplicate"].join("/")
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,42 @@
1
+ module Digicert
2
+ class DuplicateCertificateFinder
3
+ def initialize(request_id:)
4
+ @request_id = request_id
5
+ end
6
+
7
+ def find
8
+ certificate_by_date_created
9
+ end
10
+
11
+ def self.find_by(request_id:)
12
+ new(request_id: request_id).find
13
+ end
14
+
15
+ private
16
+
17
+ attr_reader :request_id
18
+
19
+ def certificate_by_date_created
20
+ certificates_by_date_created.first
21
+ end
22
+
23
+ def certificates_by_date_created
24
+ duplicate_certificates.select do |certificate|
25
+ certificate.date_created == request_created_at
26
+ end
27
+ end
28
+
29
+ def duplicate_certificates
30
+ @duplicate_certificates ||=
31
+ Digicert::DuplicateCertificate.all(order_id: request.order.id)
32
+ end
33
+
34
+ def request_created_at
35
+ request.order.certificate.date_created
36
+ end
37
+
38
+ def request
39
+ @request ||= Digicert::CertificateRequest.fetch(request_id)
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,35 @@
1
+ require "digicert/base"
2
+
3
+ module Digicert
4
+ class EmailValidation < Digicert::Base
5
+ include Digicert::Actions::All
6
+
7
+ def self.all(order_id:, **filter_params)
8
+ new(order_id: order_id, params: filter_params).all
9
+ end
10
+
11
+ def self.valid?(token:, email:)
12
+ response = Digicert::Request.new(
13
+ :put, ["email-validation", token].join("/"), params: {email: email }
14
+ ).run
15
+
16
+ response.code.to_i == 204
17
+ end
18
+
19
+ private
20
+
21
+ attr_reader :order_id
22
+
23
+ def extract_local_attribute_ids
24
+ @order_id = attributes.delete(:order_id)
25
+ end
26
+
27
+ def resources_key
28
+ "emails"
29
+ end
30
+
31
+ def resource_path
32
+ ["order", "certificate", order_id, "email-validation"].join("/")
33
+ end
34
+ end
35
+ end