Class: Billy::Certificate
- Inherits:
-
Object
- Object
- Billy::Certificate
- Includes:
- CertificateHelpers
- Defined in:
- lib/billy/ssl/certificate.rb
Overview
This class is dedicated to the generation of a request certifcate for a given domain name. We have to generate for each handled connection a new request certifcate, due to the fact that each request has probably a different domain name which will be proxied. So we can’t know of future domain name we could include in the list of subject alternative names which is required by modern browsers. (Chrome 58+)
We use our generated certifcate authority to sign any request certifcate, so a client can be prepared to trust us before a possible test scenario starts.
This behaviour and functionality mimics the mighty mitmproxy and it will enable the usage of Chrome Headless at a time where no ssl issue ignoring works. And its even secure at testing level.
Instance Attribute Summary collapse
-
#cert ⇒ Object
readonly
Returns the value of attribute cert.
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
-
#cert_file ⇒ Object
Write out the certifcate to file (PEM format) and give back the file path.
-
#initialize(domain) ⇒ Certificate
constructor
To generate a new request certifcate just pass the domain in and you are ready to go.
-
#key_file ⇒ Object
Write out the private key to file (PEM format) and give back the file path.
Methods included from CertificateHelpers
#days_ago, #days_from_now, #serial, #write_file
Constructor Details
#initialize(domain) ⇒ Certificate
To generate a new request certifcate just pass the domain in and you are ready to go.
Example:
cert = Billy::Certificate.new('localhost')
[cert.cert_file, cert.key_file]
34 35 36 37 38 |
# File 'lib/billy/ssl/certificate.rb', line 34 def initialize(domain) @domain = domain @key = OpenSSL::PKey::RSA.new(2048) @cert = generate end |
Instance Attribute Details
#cert ⇒ Object (readonly)
Returns the value of attribute cert.
25 26 27 |
# File 'lib/billy/ssl/certificate.rb', line 25 def cert @cert end |
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
25 26 27 |
# File 'lib/billy/ssl/certificate.rb', line 25 def domain @domain end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
25 26 27 |
# File 'lib/billy/ssl/certificate.rb', line 25 def key @key end |
Instance Method Details
#cert_file ⇒ Object
Write out the certifcate to file (PEM format) and give back the file path.
48 49 50 |
# File 'lib/billy/ssl/certificate.rb', line 48 def cert_file write_file("request-#{domain}.crt", cert.to_pem) end |
#key_file ⇒ Object
Write out the private key to file (PEM format) and give back the file path.
42 43 44 |
# File 'lib/billy/ssl/certificate.rb', line 42 def key_file write_file("request-#{domain}.key", key.to_pem) end |