Fix panic when ACME server returns a genuine error

This commit is contained in:
James Munnelly 2018-01-08 19:58:44 +00:00 committed by James Munnelly
parent db2bc98821
commit ea1dc8f58f

View File

@ -87,13 +87,19 @@ func (a *Acme) registerAccount(ctx context.Context, cl *acme.Client) (*acme.Acco
if !ok {
return nil, err
}
if typedErr.StatusCode == http.StatusConflict {
accountUri := typedErr.Header.Get("Location")
if accountUri == "" {
return nil, fmt.Errorf("unexpected error - 409 Conflict error returned, but no Location header set: %s", typedErr.Error())
}
return a.verifyAccount(ctx, cl, accountUri)
// StatusConflict means an account with the users private key already exists.
// If the response code was *not* StatusConflict, we should return the error
// here as we are not able to handle it.
if typedErr.StatusCode != http.StatusConflict {
return nil, err
}
// If StatusConflict was the returned error, we can attempt to look up the existing
// registration URI in the response headers.
accountUri := typedErr.Header.Get("Location")
if accountUri == "" {
return nil, fmt.Errorf("unexpected error - 409 Conflict error returned, but no Location header set: %s", typedErr.Error())
}
return a.verifyAccount(ctx, cl, accountUri)
}
return acc, nil
}