Class: Diamant::CertGenerator
- Inherits:
-
Object
- Object
- Diamant::CertGenerator
- Defined in:
- lib/diamant/cert_generator.rb
Overview
Creates a new self-signed certificate and its related RSA private key, suitable to be used as certificate for the Gemini network protocol.
This Generator is not intended to advance use as it offers no configuration at all. It use the following options:
-
4096 bits RSA key
-
1 year validity
-
self signed certificate
Instance Method Summary collapse
-
#initialize(subject = 'localhost') ⇒ CertGenerator
constructor
A new instance of CertGenerator.
- #write ⇒ Object
Constructor Details
#initialize(subject = 'localhost') ⇒ CertGenerator
Returns a new instance of CertGenerator.
17 18 19 20 21 22 23 |
# File 'lib/diamant/cert_generator.rb', line 17 def initialize(subject = 'localhost') @subject = OpenSSL::X509::Name.parse "/CN=#{subject}" @key = OpenSSL::PKey::RSA.new 4096 init_cert add_extensions @cert.sign @key, OpenSSL::Digest.new('SHA256') end |
Instance Method Details
#write ⇒ Object
25 26 27 28 29 30 |
# File 'lib/diamant/cert_generator.rb', line 25 def write IO.write('key.rsa', @key.to_pem) File.chmod(0o400, 'key.rsa') IO.write('cert.pem', @cert.to_pem) File.chmod(0o644, 'cert.pem') end |