Class: Varanus::SSL
- Inherits:
-
Object
- Object
- Varanus::SSL
- Defined in:
- lib/varanus/ssl.rb
Overview
An connection to the SSL/TSL API. This should not be initialized directly. Instead, use Varanus#ssl
Defined Under Namespace
Classes: CSR
Instance Method Summary collapse
-
#certificate_type_from_csr(csr) ⇒ Hash
Returns the option from #certificate_types that best matches the csr.
-
#certificate_types ⇒ Array<Hash>
Certificate types that can be used to sign a cert.
-
#collect(id, type = 'x509') ⇒ String
Retrieves the cert.
-
#initialize(varanus) ⇒ SSL
constructor
A new instance of SSL.
-
#revoke(id, reason) ⇒ Object
Revoke an ssl cert.
-
#sign(csr, org_id, opts = {}) ⇒ Integer
Sign an SSL cert.
Constructor Details
#initialize(varanus) ⇒ SSL
Note:
Do not call this directly. Use Varanus#ssl to initialize
Returns a new instance of SSL.
7 8 9 |
# File 'lib/varanus/ssl.rb', line 7 def initialize varanus @varanus = varanus end |
Instance Method Details
#certificate_type_from_csr(csr) ⇒ Hash
Returns the option from #certificate_types that best matches the csr.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/varanus/ssl.rb', line 14 def certificate_type_from_csr csr # first exclude certificate types we don't want types = certificate_types.reject do |ct| ct['name'] =~ /\b(?:EV|ECC|AMT|Elite)\b/ end if csr.all_names.any? { |n| n.start_with?('*.') } types.find { |ct| ct['name'] =~ /Wildcard.+SSL/i } elsif csr.subject_alt_names.any? types.find { |ct| ct['name'] =~ /Multi.?Domain.+SSL/i } else types.find do |ct| ct['name'] =~ /\bSSL\b/ && ct['name'] !~ /(?:Multi.?Domain|Wildcard)/i end end end |
#certificate_types ⇒ Array<Hash>
Certificate types that can be used to sign a cert
32 33 34 |
# File 'lib/varanus/ssl.rb', line 32 def certificate_types @certificate_types ||= get('types') end |
#collect(id, type = 'x509') ⇒ String
Retrieves the cert. type can be one of:
'x509' - X509 format - cert and chain (default)
'x509CO' - X509 format - cert only
'x509IO' - X509 format - intermediates/root only
'x590IOR' - X509 format - intermediates/root only reversed
'base64' - PKCS#7 base64 encoded
'bin' - PKCS#7 bin encoded
50 51 52 |
# File 'lib/varanus/ssl.rb', line 50 def collect id, type = 'x509' get("collect/#{id}/#{type}") end |
#revoke(id, reason) ⇒ Object
Revoke an ssl cert
58 59 60 61 |
# File 'lib/varanus/ssl.rb', line 58 def revoke id, reason post("revoke/#{id}", reason: reason) nil end |
#sign(csr, org_id, opts = {}) ⇒ Integer
Sign an SSL cert. Returns the id of the SSL cert
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/varanus/ssl.rb', line 77 def sign csr, org_id, opts = {} csr = Varanus::SSL::CSR.new(csr) unless csr.is_a?(Varanus::SSL::CSR) cert_type_id = opts_to_cert_type_id opts, csr args = { orgId: org_id, csr: csr.to_s, subjAltNames: csr.subject_alt_names.join(','), certType: cert_type_id, term: opts_to_term(opts, cert_type_id), serverType: -1, comments: opts[:comments].to_s[0, 1024], externalRequester: opts[:external_requester].to_s[0, 512] } post('enroll', args)['sslId'] end |