Class: Billy::Authority

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

Overview

This class is dedicated to the generation of a brand new certificate authority which can be picked up by a browser to verify and secure any communication with puffing billy. This authority certificate will be generated once on runtime and will sign each request certificate. So we do not have to deal with outdated certificates or stuff like that.

The resulting certificate authority is at its bare minimum to keep things simple and snappy. We do not handle a certificate revoke list (CRL) nor any other special key handling, even if we enable these extensions. It’s just a mimic of the mighty mitmproxy certificate authority file.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CertificateHelpers

#days_ago, #days_from_now, #serial, #write_file

Constructor Details

#initializeAuthority

The authority generation does not require any arguments from outside of this class definition. We just generate the certificate and thats it.

Example:

ca = Billy::Authority.new
[ca.cert_file, ca.key_file]


32
33
34
35
# File 'lib/billy/ssl/authority.rb', line 32

def initialize
  @key = OpenSSL::PKey::RSA.new(2048)
  @cert = generate
end

Instance Attribute Details

#certObject (readonly)

Returns the value of attribute cert.



22
23
24
# File 'lib/billy/ssl/authority.rb', line 22

def cert
  @cert
end

#keyObject (readonly)

Returns the value of attribute key.



22
23
24
# File 'lib/billy/ssl/authority.rb', line 22

def key
  @key
end

Instance Method Details

#cert_fileObject

Write out the certifcate to file (PEM format) and give back the file path.



45
46
47
# File 'lib/billy/ssl/authority.rb', line 45

def cert_file
  write_file('ca.crt', cert.to_pem)
end

#key_fileObject

Write out the private key to file (PEM format) and give back the file path.



39
40
41
# File 'lib/billy/ssl/authority.rb', line 39

def key_file
  write_file('ca.key', key.to_pem)
end