class Ronin::Support::Crypto::CertChain
Represents a X509 or TLS certificate chain.
@api public
@since 1.0.0
Attributes
The certificates in the certificate chain.
@return [Array<Cert>]
Public Class Methods
Alias for {parse}.
@param [String] string
The string to parse.
@return [CertChain]
The parsed certificate chain.
@see parse
# File lib/ronin/support/crypto/cert_chain.rb, line 87 def self.load(string) parse(string) end
Reads and parses the certificate chain from a file.
@param [String] path
The path to the file to parse.
@return [CertChain]
The parsed certificate chain.
# File lib/ronin/support/crypto/cert_chain.rb, line 100 def self.load_file(path) parse(File.read(path)) end
The certificates in the certificate chain.
@param [Array<Cert>] certs
The certificates that make up the certificate chain.
# File lib/ronin/support/crypto/cert_chain.rb, line 47 def initialize(certs) @certs = certs end
Parses a certificate chain.
@param [String] string
The string to parse.
@return [CertChain]
The parsed certificate chain.
# 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
Public Instance Methods
Accesses one or more certificates at the index or range/length.
@param [Integer, Range<Integer,Integer>] index_or_range
The index or range of indices.
@param [Integer, nil] length
Optional length.
@return [Cert, Array
<Cert>, nil]
The certificate(s) at the index or range of indices.
# File lib/ronin/support/crypto/cert_chain.rb, line 133 def [](index_or_range,length=nil) @certs[index_or_range,*length] end
Enumerates over the certificates in the certificate chain.
@yield [cert]
If a block is given, it will be passed each certificate in the certificate chain.
@yieldparam [Cert] cert
A parsed certificate object in the certificate chain.
@return [Enumerator]
If no block is given an Enumerator object will be returned.
# File lib/ronin/support/crypto/cert_chain.rb, line 117 def each(&block) @certs.each(&block) end
The intermediary certificates.
@return [Array<Cert>]
The certificates between the {#root} and {#leaf} certificates.
# File lib/ronin/support/crypto/cert_chain.rb, line 167 def intermediates @certs[1..-2] end
The issuer certificate.
@return [Cert]
The second-to-last certificate in the certificate chain.
# File lib/ronin/support/crypto/cert_chain.rb, line 153 def issuer if @certs.length == 1 @certs[0] else @certs[1] end end
The leaf certificate.
@return [Cert]
The last certificate in the certiificate chain.
# File lib/ronin/support/crypto/cert_chain.rb, line 143 def leaf @certs.first end
The number of certificates in the certificate chain.
@return [Integer]
# File lib/ronin/support/crypto/cert_chain.rb, line 186 def length @certs.length end
The root certificate.
@return [Cert]
The first certificate in the certificate chain.
# File lib/ronin/support/crypto/cert_chain.rb, line 177 def root @certs.last end
Converts the certificate chain to a PEM encoded certificate chain.
@return [String]
# File lib/ronin/support/crypto/cert_chain.rb, line 195 def to_pem @certs.map(&:to_pem).join end