Class: CertificateTransparency::Client
- Inherits:
-
Object
- Object
- CertificateTransparency::Client
- Defined in:
- lib/certificate-transparency/client.rb
Overview
Interact with a Certificate Transparency server.
Defined Under Namespace
Classes: DataError, Error, HTTPError
Instance Attribute Summary collapse
-
#public_key ⇒ OpenSSL::PKey::PKey
readonly
The public key of the log, as specified in the constructor.
Instance Method Summary collapse
-
#get_entries(first, last = nil) ⇒ Array<CT::LogEntry>
Retrieve one or more entries from the log.
-
#get_roots ⇒ Array<OpenSSL::X509::Certificate>
Retrieve the full set of roots publicised as being supported by this log.
-
#get_sth ⇒ CT::SignedTreeHead
Retrieve the current Signed Tree Head from the log.
-
#initialize(url, opts = {}) ⇒ CT::Client
constructor
Create thyself a new CT::Client.
Constructor Details
#initialize(url, opts = {}) ⇒ CT::Client
Create thyself a new CT::Client.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/certificate-transparency/client.rb', line 39 def initialize(url, opts = {}) unless opts.is_a? Hash raise ArgumentError, "Must pass a hash of options as second argument" end if opts[:public_key] pkdata = if opts[:public_key].valid_encoding? && opts[:public_key] =~ /^[A-Za-z0-9+\/]+=*$/ opts[:public_key].unpack("m").first else opts[:public_key] end @public_key = begin OpenSSL::PKey::EC.new(pkdata) rescue ArgumentError begin OpenSSL::PKey::RSA.new(pkdata) rescue StandardError => ex raise "Invalid public key: #{ex.message} (#{ex.class})" end rescue StandardError => ex raise ArgumentError, "Invalid public key: #{ex.message} (#{ex.class})" end end @url = URI(url) end |
Instance Attribute Details
#public_key ⇒ OpenSSL::PKey::PKey (readonly)
The public key of the log, as specified in the constructor.
25 26 27 |
# File 'lib/certificate-transparency/client.rb', line 25 def public_key @public_key end |
Instance Method Details
#get_entries(first, last = nil) ⇒ Array<CT::LogEntry>
Retrieve one or more entries from the log.
98 99 100 101 102 103 104 105 |
# File 'lib/certificate-transparency/client.rb', line 98 def get_entries(first, last = nil) last ||= get_sth.tree_size - 1 entries_json = make_request("get-entries", :start => first, :end => last) JSON.parse(entries_json)["entries"].map do |entry| CT::LogEntry.from_json(entry.to_json) end end |
#get_roots ⇒ Array<OpenSSL::X509::Certificate>
Retrieve the full set of roots publicised as being supported by this log.
115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/certificate-transparency/client.rb', line 115 def get_roots json = make_request("get-roots") begin JSON.parse(json)["certificates"].map do |c| OpenSSL::X509::Certificate.new(c.unpack("m").first) end rescue StandardError => ex raise CT::Client::DataError, "Failed to parse get-roots response: #{ex.message} (#{ex.class})" end end |
#get_sth ⇒ CT::SignedTreeHead
Retrieve the current Signed Tree Head from the log.
76 77 78 |
# File 'lib/certificate-transparency/client.rb', line 76 def get_sth CT::SignedTreeHead.from_json(make_request("get-sth")) end |