func FetchAuthorizations(authorizationsURL string) ([]string, error) {
	if 0 == len(authorizationsURL) {
		return []string{}, nil
	}

	req := utils.HttpRequest{
		Method: "GET",
		URL:    authorizationsURL,
	}

	resp, err := req.Run()
	if nil != err {
		return nil, fmt.Errorf("Retrieving authorizations list from %s failed: %s", authorizationsURL, err)
	}

	if resp.StatusCode < 200 || resp.StatusCode >= 300 {
		return nil, fmt.Errorf("GET %s failed: %s", authorizationsURL, resp.Status)
	}

	response := authorizationsJSON{
		Authorizations: []string{},
	}
	err = json.Unmarshal(resp.Body, &response)
	if nil != err {
		return nil, fmt.Errorf("Failed decoding response from GET %s: %s", authorizationsURL, err)
	}

	return response.Authorizations, nil
}
示例#2
0
func FetchCertificates(certificatesURL string) ([]string, error) {
	if 0 == len(certificatesURL) {
		return []string{}, nil
	}

	req := utils.HttpRequest{
		Method: "GET",
		URL:    certificatesURL,
	}

	resp, err := req.Run()
	if nil != err {
		return nil, fmt.Errorf("Retrieving certificates list from %s failed: %s", certificatesURL, err)
	}

	if resp.StatusCode < 200 || resp.StatusCode >= 300 {
		return nil, fmt.Errorf("GET %s failed: %s", certificatesURL, resp.Status)
	}

	response := certificatesJSON{
		Certificates: []string{},
	}
	err = json.Unmarshal(resp.Body, &response)
	if nil != err {
		return nil, fmt.Errorf("Failed decoding response from GET %s: %s", certificatesURL, err)
	}

	return response.Certificates, nil
}
func FetchAuthorization(authURL string) (*types.AuthorizationResource, error) {
	req := utils.HttpRequest{
		Method: "GET",
		URL:    authURL,
	}

	resp, err := req.Run()
	if nil != err {
		return nil, fmt.Errorf("Refreshing authorization %s failed: %s", authURL, err)
	}

	if resp.StatusCode < 200 || resp.StatusCode >= 300 {
		return nil, fmt.Errorf("GET %s failed: %s", authURL, resp.Status)
	}

	var response types.AuthorizationResource
	err = json.Unmarshal(resp.Body, &response)
	if nil != err {
		return nil, fmt.Errorf("Failed decoding response from GET %s: %s", authURL, err)
	}

	return &response, nil
}
示例#4
0
func RunSignedRequest(signingKey types.SigningKey, req *utils.HttpRequest, payloadJson []byte) (*utils.HttpResponse, error) {
	var nonce string
	{
		nonceResp, err := http.Head(req.URL)
		if nil != err {
			return nil, err
		}
		defer nonceResp.Body.Close()

		nonce = nonceResp.Header.Get("Replay-Nonce")
	}
	if 0 == len(nonce) {
		return nil, fmt.Errorf("Didn't get a Replay-Nonce header")
	}

	sig, err := signingKey.Sign(payloadJson, nonce)
	if nil != err {
		return nil, err
	}
	utils.Debugf("sending to %s signed payload: %s\n", req.URL, string(payloadJson))
	req.Body = []byte(sig.FullSerialize())

	return req.Run()
}