// Root performs the root request to the CA with the given SHA256 and returns
// the api.RootResponse struct. It uses an insecure client, but it checks the
// resulting root certificate with the given SHA256, returning an error if they
// do not match.
Root performs the root request to the CA with the given SHA256 and returns
the api.RootResponse struct. It uses an insecure client, but it checks the
resulting root certificate with the given SHA256, returning an error if they
do not match.
// Root performs the root request to the CA with the given SHA256 and returns // the api . RootResponse struct . It uses an insecure client but it checks the // resulting root certificate with the given SHA256 returning an error if they // do not match .
func (c *Client) Root(sha256Sum string) (*api.RootResponse, error) {
	var retried bool
	sha256Sum = strings.ToLower(strings.Replace(sha256Sum, "-", "", -1))
	u := c.endpoint.ResolveReference(&url.URL{Path: "/root/" + sha256Sum})
retry:
	resp, err := newInsecureClient().Get(u.String())
	if err != nil {
		return nil, errs.Wrapf(http.StatusInternalServerError, err, "client.Root; client GET %s failed", u)
	}
	if resp.StatusCode >= 400 {
		if !retried && c.retryOnError(resp) {
			retried = true
			goto retry
		}
		return nil, readError(resp.Body)
	}
	var root api.RootResponse
	if err := readJSON(resp.Body, &root); err != nil {
		return nil, errs.Wrapf(http.StatusInternalServerError, err, "client.Root; error reading %s", u)
	}
	sum := sha256.Sum256(root.RootPEM.Raw)
	if sha256Sum != strings.ToLower(hex.EncodeToString(sum[:])) {
		return nil, errs.BadRequest("client.Root; root certificate SHA256 fingerprint do not match")
	}
	return &root, nil
}
func ( c * Client ) Root ( sha256Sum string ) ( * api . RootResponse , error ) { var retried bool sha256Sum = strings . ToLower ( strings . Replace ( sha256Sum , " " , " " , - 1 ) ) u := c . endpoint . ResolveReference ( & url . URL { Path : " " + sha256Sum } ) retry : resp , err := newInsecureClient ( ) . Get ( u . String ( ) ) if err != nil { return nil , errs . Wrapf ( http . StatusInternalServerError , err , " " , u ) } if resp . StatusCode >= 400 { if ! retried && c . retryOnError ( resp ) { retried = true goto retry } return nil , readError ( resp . Body ) } var root api . RootResponse if err := readJSON ( resp . Body , & root ) ; err != nil { return nil , errs . Wrapf ( http . StatusInternalServerError , err , " " , u ) } sum := sha256 . Sum256 ( root . RootPEM . Raw ) if sha256Sum != strings . ToLower ( hex . EncodeToString ( sum [ : ] ) ) { return nil , errs . BadRequest ( " " ) } return & root , nil }
Root performs the root request to the CA with the given SHA256 and returns
the api.RootResponse struct.
Root performs the root request to the CA with the given SHA256 and returns the api . RootResponse struct .
// verify the sha256