Class: CertificateTransparency::LogEntry
- Inherits:
-
Object
- Object
- CertificateTransparency::LogEntry
- Defined in:
- lib/certificate-transparency/log_entry.rb
Overview
This is not the LogEntry type defined in RFC6962 s3.1, because
that type is never actually used anywhere, so I stole its name.
Unlike most other classes, the instance methods on this type are
not a 1:1 mapping to the elements of the source data structure. The
extra_data key in the JSON is a grotty amalgam of several other
things. Those pieces are available via #certificate_chain and
#precertificate.
An element of a CT get-entries array (RFC6962 s4.6).
Instance Attribute Summary collapse
- #certificate_chain ⇒ CT::CertificateChain
- #leaf_input ⇒ CT::MerkleTreeLeaf
-
#precertificate ⇒ OpenSSL::X509::Certificate
The precertificate if this log entry is for a precert, or
nilotherwise.
Class Method Summary collapse
-
.from_json(json) ⇒ Object
Create a new LogEntry instance from a single member of the
"entries"array returned by/ct/v1/get-entries.
Instance Method Summary collapse
-
#to_json ⇒ String
Return a JSON string that represents this log entry, as it would exist in a response from
/get-entries.
Instance Attribute Details
#certificate_chain ⇒ CT::CertificateChain
22 23 24 |
# File 'lib/certificate-transparency/log_entry.rb', line 22 def certificate_chain @certificate_chain end |
#leaf_input ⇒ CT::MerkleTreeLeaf
18 19 20 |
# File 'lib/certificate-transparency/log_entry.rb', line 18 def leaf_input @leaf_input end |
#precertificate ⇒ OpenSSL::X509::Certificate
The precertificate if this log entry is for a precert, or nil
otherwise.
29 30 31 |
# File 'lib/certificate-transparency/log_entry.rb', line 29 def precertificate @precertificate end |
Class Method Details
.from_json(json) ⇒ Object
Create a new LogEntry instance from a single member of the
"entries" array returned by /ct/v1/get-entries.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/certificate-transparency/log_entry.rb', line 34 def self.from_json(json) doc = JSON.parse(json) self.new.tap do |sth| le_blob = doc["leaf_input"].unpack("m").first sth.leaf_input = CT::MerkleTreeLeaf.from_blob(le_blob) ed_blob = doc["extra_data"].unpack("m").first if sth.leaf_input..entry_type == :precert_entry precert_blob, ed_blob = TLS::Opaque.from_blob(ed_blob, 2**24-1) sth.precertificate = OpenSSL::X509::Certificate.new(precert_blob.value) end sth.certificate_chain = CT::CertificateChain.from_blob(ed_blob) end end |
Instance Method Details
#to_json ⇒ String
Return a JSON string that represents this log entry, as it would
exist in a response from /get-entries.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/certificate-transparency/log_entry.rb', line 58 def to_json json = { :leaf_input => [leaf_input.to_blob].pack("m0") } ed_blob = "" if leaf_input..entry_type == :precert_entry ed_blob += TLS::Opaque.new(precertificate.to_der, 2**24-1).to_blob end ed_blob += certificate_chain.to_blob json[:extra_data] = [ed_blob].pack("m0") json.to_json end |