Class: Billy::CertificateChain

Inherits:
Object
  • Object
show all
Includes:
CertificateHelpers
Defined in:
lib/billy/ssl/certificate_chain.rb

Overview

This class is dedicated to the generation of a certificate chain in the PEM format. Fortunately we just have to concatenate the given certificates in the given order and write them to temporary file which will last until the current process terminates.

We do not have to generate a certificate chain to make puffing billy work on modern browser like Chrome 59+ or Firefox 55+, but its good to ship it anyways. This mimics the behaviour of the mighty mitmproxy.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CertificateHelpers

#days_ago, #days_from_now, #serial, #write_file

Constructor Details

#initialize(domain, *certs) ⇒ CertificateChain

Just pass all certificates into the new instance. We use the variadic argument feature here to ease the usage and improve the readability.

Example:

certs_chain_file = Billy::CertificateChain.new('localhost',
                                               cert1,
                                               cert2, ..).file


28
29
30
31
# File 'lib/billy/ssl/certificate_chain.rb', line 28

def initialize(domain, *certs)
  @domain = domain
  @certificates = [certs].flatten
end

Instance Attribute Details

#certificatesObject (readonly)

Returns the value of attribute certificates.



18
19
20
# File 'lib/billy/ssl/certificate_chain.rb', line 18

def certificates
  @certificates
end

#domainObject (readonly)

Returns the value of attribute domain.



18
19
20
# File 'lib/billy/ssl/certificate_chain.rb', line 18

def domain
  @domain
end

Instance Method Details

#fileObject

Write out the certificates chain file and pass the path back. This will produce a temporary file which will be remove after the current process terminates.



36
37
38
39
# File 'lib/billy/ssl/certificate_chain.rb', line 36

def file
  contents = certificates.map { |cert| cert.to_pem }.join
  write_file("chain-#{domain}.pem", contents)
end