Class: Ronin::Support::Crypto::CertChain
- Inherits:
-
Object
- Object
- Ronin::Support::Crypto::CertChain
- Includes:
- Enumerable
- Defined in:
- lib/ronin/support/crypto/cert_chain.rb
Overview
Represents a X509 or TLS certificate chain.
Instance Attribute Summary collapse
-
#certs ⇒ Array<Cert>
readonly
The certificates in the certificate chain.
Class Method Summary collapse
-
.load(string) ⇒ CertChain
Alias for CertChain.parse.
-
.load_file(path) ⇒ CertChain
Reads and parses the certificate chain from a file.
-
.parse(string) ⇒ CertChain
Parses a certificate chain.
Instance Method Summary collapse
-
#[](index_or_range, length = nil) ⇒ Cert, ...
Accesses one or more certificates at the index or range/length.
-
#each {|cert| ... } ⇒ Enumerator
Enumerates over the certificates in the certificate chain.
-
#initialize(certs) ⇒ CertChain
constructor
The certificates in the certificate chain.
-
#intermediates ⇒ Array<Cert>
The intermediary certificates.
-
#issuer ⇒ Cert
The issuer certificate.
-
#leaf ⇒ Cert
The leaf certificate.
-
#length ⇒ Integer
The number of certificates in the certificate chain.
-
#root ⇒ Cert
The root certificate.
-
#to_pem ⇒ String
(also: #to_s)
Converts the certificate chain to a PEM encoded certificate chain.
Methods included from Enumerable
Constructor Details
#initialize(certs) ⇒ CertChain
The certificates in the certificate chain.
47 48 49 |
# File 'lib/ronin/support/crypto/cert_chain.rb', line 47 def initialize(certs) @certs = certs end |
Instance Attribute Details
Class Method Details
.load(string) ⇒ CertChain
Alias for parse.
87 88 89 |
# File 'lib/ronin/support/crypto/cert_chain.rb', line 87 def self.load(string) parse(string) end |
.load_file(path) ⇒ CertChain
Reads and parses the certificate chain from a file.
100 101 102 |
# File 'lib/ronin/support/crypto/cert_chain.rb', line 100 def self.load_file(path) parse(File.read(path)) end |
.parse(string) ⇒ CertChain
Parses a certificate chain.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/ronin/support/crypto/cert_chain.rb', line 60 def self.parse(string) cert_buffer = String.new certs = [] string.each_line do |line| cert_buffer << line if line.chomp == '-----END CERTIFICATE-----' certs << Cert.parse(cert_buffer) cert_buffer.clear end end return new(certs) end |
Instance Method Details
#[](index_or_range, length = nil) ⇒ Cert, ...
Accesses one or more certificates at the index or range/length.
133 134 135 |
# File 'lib/ronin/support/crypto/cert_chain.rb', line 133 def [](index_or_range,length=nil) @certs[index_or_range,*length] end |
#each {|cert| ... } ⇒ Enumerator
Enumerates over the certificates in the certificate chain.
117 118 119 |
# File 'lib/ronin/support/crypto/cert_chain.rb', line 117 def each(&block) @certs.each(&block) end |
#intermediates ⇒ Array<Cert>
The intermediary certificates.
167 168 169 |
# File 'lib/ronin/support/crypto/cert_chain.rb', line 167 def intermediates @certs[1..-2] end |
#issuer ⇒ Cert
The issuer certificate.
153 154 155 156 157 158 159 |
# File 'lib/ronin/support/crypto/cert_chain.rb', line 153 def issuer if @certs.length == 1 @certs[0] else @certs[1] end end |
#leaf ⇒ Cert
The leaf certificate.
143 144 145 |
# File 'lib/ronin/support/crypto/cert_chain.rb', line 143 def leaf @certs.first end |
#length ⇒ Integer
The number of certificates in the certificate chain.
186 187 188 |
# File 'lib/ronin/support/crypto/cert_chain.rb', line 186 def length @certs.length end |
#root ⇒ Cert
The root certificate.
177 178 179 |
# File 'lib/ronin/support/crypto/cert_chain.rb', line 177 def root @certs.last end |
#to_pem ⇒ String Also known as: to_s
Converts the certificate chain to a PEM encoded certificate chain.
195 196 197 |
# File 'lib/ronin/support/crypto/cert_chain.rb', line 195 def to_pem @certs.map(&:to_pem).join end |