Class: CertificateTransparency::LogEntry

Inherits:
Object
  • Object
show all
Defined in:
lib/certificate-transparency/log_entry.rb

Overview

Note:

This is not the LogEntry type defined in RFC6962 s3.1, because that type is never actually used anywhere, so I stole its name.

Note:

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

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#certificate_chainCT::CertificateChain



22
23
24
# File 'lib/certificate-transparency/log_entry.rb', line 22

def certificate_chain
  @certificate_chain
end

#leaf_inputCT::MerkleTreeLeaf

Returns:



18
19
20
# File 'lib/certificate-transparency/log_entry.rb', line 18

def leaf_input
  @leaf_input
end

#precertificateOpenSSL::X509::Certificate

The precertificate if this log entry is for a precert, or nil otherwise.

Returns:

  • (OpenSSL::X509::Certificate)


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.timestamped_entry.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_jsonString

Return a JSON string that represents this log entry, as it would exist in a response from /get-entries.

Returns:



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.timestamped_entry.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