Class: CertificateTransparency::SignedTreeHead

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

Overview

A CT SignedTreeHead (RFC6962 s3.5, s4.3).

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#root_hashObject

Returns the value of attribute root_hash.



9
10
11
# File 'lib/certificate-transparency/signed_tree_head.rb', line 9

def root_hash
  @root_hash
end

#signatureObject

Returns the value of attribute signature.



10
11
12
# File 'lib/certificate-transparency/signed_tree_head.rb', line 10

def signature
  @signature
end

#timestampObject

Returns the value of attribute timestamp.



8
9
10
# File 'lib/certificate-transparency/signed_tree_head.rb', line 8

def timestamp
  @timestamp
end

#tree_sizeObject

Returns the value of attribute tree_size.



7
8
9
# File 'lib/certificate-transparency/signed_tree_head.rb', line 7

def tree_size
  @tree_size
end

Class Method Details

.from_json(json) ⇒ Object

Create a new SignedTreeHead instance from the JSON returned by /ct/v1/get-sth.



15
16
17
18
19
20
21
22
23
24
# File 'lib/certificate-transparency/signed_tree_head.rb', line 15

def self.from_json(json)
	doc = JSON.parse(json)

	self.new.tap do |sth|
		sth.tree_size = doc['tree_size']
		sth.timestamp = Time.at(doc['timestamp'].to_f / 1000)
		sth.root_hash = doc['sha256_root_hash'].unpack("m").first
		sth.signature = doc['tree_head_signature'].unpack("m").first
	end
end

Instance Method Details

#valid?(pk) ⇒ Boolean

Determine whether or not the signature that was provided in the signed tree head is a valid one, based on the provided key.

Parameters:

  • pk (String, OpenSSL::PKey::PKey)

    either the raw binary form of the public key of the log, or an existing OpenSSL public key object.

Returns:

  • (Boolean)

    Boolean



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/certificate-transparency/signed_tree_head.rb', line 34

def valid?(pk)
	key = if pk.is_a?(OpenSSL::PKey::PKey)
		pk
	else
		begin
			OpenSSL::PKey::EC.new(pk)
		rescue ArgumentError
			OpenSSL::PKey::RSA.new(pk)
		end
	end

	blob = [
		CT::Version[:v1],
		CT::SignatureType[:tree_hash],
	   timestamp.ms,
	   tree_size,
	   root_hash
	].pack("ccQ>Q>a32")

	ds = TLS::DigitallySigned.from_blob(signature)
	ds.content = blob
	ds.key = key

	ds.valid?
end