Class: Lyrebird::Certificate
- Inherits:
-
Object
- Object
- Lyrebird::Certificate
- Defined in:
- lib/lyrebird/certificate.rb
Constant Summary collapse
- LOCK =
Mutex.new
- EXTENSIONS =
{ "basicConstraints" => "CA:FALSE", "keyUsage" => "digitalSignature,keyEncipherment" }.freeze
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#x509 ⇒ Object
readonly
Returns the value of attribute x509.
Class Method Summary collapse
Instance Method Summary collapse
- #base64 ⇒ Object
- #fingerprint(algorithm = :sha256) ⇒ Object
-
#initialize(bits: 2048, cn: "lyrebird", o: nil, valid_for: 365, valid_until: nil, key: nil, x509: nil) ⇒ Certificate
constructor
A new instance of Certificate.
- #key_pem ⇒ Object
- #x509_pem ⇒ Object
Constructor Details
#initialize(bits: 2048, cn: "lyrebird", o: nil, valid_for: 365, valid_until: nil, key: nil, x509: nil) ⇒ Certificate
Returns a new instance of Certificate.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/lyrebird/certificate.rb', line 30 def initialize( bits: 2048, cn: "lyrebird", o: nil, valid_for: 365, valid_until: nil, key: nil, x509: nil ) @common_name = cn @organization = o @valid_for = valid_for @valid_until = valid_until @key = key || OpenSSL::PKey::RSA.new(bits) @x509 = x509 || build_x509 end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
12 13 14 |
# File 'lib/lyrebird/certificate.rb', line 12 def key @key end |
#x509 ⇒ Object (readonly)
Returns the value of attribute x509.
12 13 14 |
# File 'lib/lyrebird/certificate.rb', line 12 def x509 @x509 end |
Class Method Details
.build(**kwargs) {|config| ... } ⇒ Object
18 19 20 21 22 |
# File 'lib/lyrebird/certificate.rb', line 18 def self.build(**kwargs) config = OpenStruct.new(kwargs) yield config if block_given? new(**config.to_h) end |
.default ⇒ Object
14 15 16 |
# File 'lib/lyrebird/certificate.rb', line 14 def self.default LOCK.synchronize { @default ||= build } end |
.load(key_pem:, x509_pem:) ⇒ Object
24 25 26 27 28 |
# File 'lib/lyrebird/certificate.rb', line 24 def self.load(key_pem:, x509_pem:) key = OpenSSL::PKey::RSA.new(key_pem) x509 = OpenSSL::X509::Certificate.new(x509_pem) new(key: key, x509: x509) end |
Instance Method Details
#base64 ⇒ Object
60 61 62 |
# File 'lib/lyrebird/certificate.rb', line 60 def base64 Base64.strict_encode64(@x509.to_der) end |
#fingerprint(algorithm = :sha256) ⇒ Object
55 56 57 58 |
# File 'lib/lyrebird/certificate.rb', line 55 def fingerprint(algorithm = :sha256) digest = OpenSSL::Digest.new(algorithm.to_s) digest.hexdigest(@x509.to_der).upcase.scan(/../).join(":") end |
#key_pem ⇒ Object
47 48 49 |
# File 'lib/lyrebird/certificate.rb', line 47 def key_pem @key.to_pem end |
#x509_pem ⇒ Object
51 52 53 |
# File 'lib/lyrebird/certificate.rb', line 51 def x509_pem @x509.to_pem end |