client

package
v0.0.0-...-1dc6284 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 15, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package client provides a Certificate Transparency (CT) Log Client that prioritizes preserving and returning as much information about each http request that is made, and detailed descriptions of any errors that occur along the way.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BodyReadError

type BodyReadError struct {
	URL string
	Err error
}

BodyReadError for if reading the body of an http.Response fails.

func (*BodyReadError) Error

func (e *BodyReadError) Error() string

type GetError

type GetError struct {
	URL string
	Err error
}

GetError for if http.Client.Get() fails.

func (*GetError) Error

func (e *GetError) Error() string

type HTTPData

type HTTPData struct {
	Timing   Timing
	Response *http.Response
	Body     []byte
}

HTTPData contains information about an HTTP request that was made.

type HTTPStatusError

type HTTPStatusError struct {
	StatusCode int
}

HTTPStatusError for if the status code of an HTTP response is not 200.

func (*HTTPStatusError) Error

func (e *HTTPStatusError) Error() string

type JSONParseError

type JSONParseError struct {
	Data []byte
	Err  error
}

JSONParseError for if JSON fails to parse.

func (*JSONParseError) Error

func (e *JSONParseError) Error() string

type LogClient

type LogClient struct {
	// contains filtered or unexported fields
}

LogClient is a client for a specific CT Log.

Most of the LogClient methods return HTTPData structs and errors.

A returned HTTPData struct contains:

  • Timing: The time it took for the LogClient's HTTP client to send the request and receive a response.
  • Response: The http.Response returned by the LogClient's HTTP client, with http.Response.Body already read and closed.
  • Body: The body of the response received, read from the Body field in the http.Response returned by the LogClient's HTTP client.

This HTTPData struct will always be returned containing at least the timing of the request, even in the case where an error is returned too.

If an error is returned it could be any of the following types, in addition to any error types specified in the documentation specific to that method. The type of error that is returned influences what the HTTPData struct returned will contain:

  • GetError
  • HTTPData will contain only the timing of the request.
  • PostError
  • HTTPData will contain only the timing of the request.
  • NilResponseError
  • HTTPData will contain only the timing of the request.
  • BodyReadError
  • HTTPData will contain the timing of the request and the received response.
  • HTTPStatusError
  • HTTPData will contain the timing of the request, the received response, and the body of the response.
  • JSONParseError
  • HTTPData will contain the timing of the request, the received response, and the body of the response.

func New

func New(logURL string, hc *http.Client) *LogClient

New creates a new LogClient for monitoring the CT Log served at logURL.

func (*LogClient) AddChain

func (lc *LogClient) AddChain(chain []*x509.Certificate) (*ct.SignedCertificateTimestamp, *HTTPData, error)

AddChain performs an add-chain request, posting the provided certificate chain to the CT Log hosted at LogClient.url. The first certificate in the chain must be the end-entity certificate, with the second chaining to the first and so on to the last, which should either be the root certificate or a certificate that chains to a root certificate that is accepted by the Log. Returned is:

  • a populated ct.SignedCertificateTimestamp, if no error is returned.
  • an HTTPData struct (may be non-nil even when err != nil, see above).
  • an error, which could be an error from the Go standard library, any of the error types listed in the LogClient documentation (see above), or a ResponseToStructError.

func (*LogClient) AddPreChain

func (lc *LogClient) AddPreChain(chain []*x509.Certificate) (*ct.SignedCertificateTimestamp, *HTTPData, error)

AddPreChain performs an add-pre-chain request, posting the provided certificate chain to the CT Log hosted at LogClient.url. The first certificate in the chain must be the end-entity pre-certificate, with the second chaining to the first and so on to the last, which should either be the root certificate or a certificate that chains to a root certificate that is accepted by the Log. Returned is:

  • a populated ct.SignedCertificateTimestamp, if no error is returned.
  • an HTTPData struct (may be non-nil even when err != nil, see above).
  • an error, which could be an error from the Go standard library, any of the error types listed in the LogClient documentation (see above), or a ResponseToStructError.

func (*LogClient) GetProofByHash

func (lc *LogClient) GetProofByHash(hash []byte, treeSize uint64) (*ct.GetProofByHashResponse, *HTTPData, error)

GetProofByHash performs a get-proof-by-hash request, with parameters hash and treeSize. Returned is:

  • a GetProofByHashResponse struct, if no error is returned.
  • the HTTPData struct returned by GetAndParse() (see above).
  • an error, which could be any of the error types returned by GetAndParse().

func (*LogClient) GetRoots

func (lc *LogClient) GetRoots() ([]*x509.Certificate, *HTTPData, error)

GetRoots performs a get-roots request. Returned is:

  • a list of certificates, if no error is returned.
  • the HTTPData struct returned by GetAndParse() (see above).
  • an error, which could be any of the error types returned by GetAndParse(), or a ResponseToStructError.

func (*LogClient) GetSTH

func (lc *LogClient) GetSTH() (*ct.SignedTreeHead, *HTTPData, error)

GetSTH performs a get-sth request. Returned is:

  • a populated ct.SignedTreeHead, if no error is returned.
  • an HTTPData struct (see above).
  • an error, which could be any of the error types listed in the LogClient documentation (see above), or a ResponseToStructError.

type NilResponseError

type NilResponseError struct {
	URL string
}

NilResponseError for if http.Client.Get() returns a nil response, but no error.

func (*NilResponseError) Error

func (e *NilResponseError) Error() string

type PostError

type PostError struct {
	URL         string
	ContentType string
	Body        []byte
	Err         error
}

PostError for if http.Client.Post() fails.

func (*PostError) Error

func (e *PostError) Error() string

func (*PostError) VerboseError

func (e *PostError) VerboseError() string

type ResponseToStructError

type ResponseToStructError struct {
	From reflect.Type
	To   reflect.Type
	Err  error
}

ResponseToStructError for if conversion from response type to ct type fails.

func (*ResponseToStructError) Error

func (e *ResponseToStructError) Error() string

type Timing

type Timing struct {
	Start time.Time
	End   time.Time
}

Timing represents an interval of time. It can be used to represent when an event started and ended.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL