Class: Certificate

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/letsencrypt/cli/support/certificate.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fullchain_certificate) ⇒ Certificate

Returns a new instance of Certificate.



8
9
10
11
12
# File 'lib/letsencrypt/cli/support/certificate.rb', line 8

def initialize(fullchain_certificate)
  fullchain_array = fullchain_certificate.strip.split("\n\n")
  @x509 = OpenSSL::X509::Certificate.new(fullchain_array.first)
  @x509_chain = fullchain_array[1..-1].map { |cert| OpenSSL::X509::Certificate.new(cert) }
end

Instance Attribute Details

#x509Object (readonly)

Returns the value of attribute x509.



4
5
6
# File 'lib/letsencrypt/cli/support/certificate.rb', line 4

def x509
  @x509
end

#x509_chainObject (readonly)

Returns the value of attribute x509_chain.



4
5
6
# File 'lib/letsencrypt/cli/support/certificate.rb', line 4

def x509_chain
  @x509_chain
end

Instance Method Details

#chain_to_pemObject



14
15
16
# File 'lib/letsencrypt/cli/support/certificate.rb', line 14

def chain_to_pem
  x509_chain.map(&:to_pem).join("\n")
end

#common_nameObject



26
27
28
# File 'lib/letsencrypt/cli/support/certificate.rb', line 26

def common_name
  x509.subject.to_a.find { |name, _, _| name == 'CN' }[1]
end

#fullchain_to_pemObject



22
23
24
# File 'lib/letsencrypt/cli/support/certificate.rb', line 22

def fullchain_to_pem
  x509_fullchain.map(&:to_pem).join("\n")
end

#x509_fullchainObject



18
19
20
# File 'lib/letsencrypt/cli/support/certificate.rb', line 18

def x509_fullchain
  [x509, *x509_chain]
end