From 5cd40a374b80f104c75043e6a04071d3a743ffd9 Mon Sep 17 00:00:00 2001 From: Filippo Valsorda Date: Thu, 14 Jun 2018 16:23:13 -0400 Subject: [PATCH] acme/autocert: surface details of acme.AuthorizationError Fixes golang/go#19800 Change-Id: If915a70f4dee78e71dcfc487726cdf83d45b4d50 Reviewed-on: https://go-review.googlesource.com/115938 Reviewed-by: Alex Vaghin Reviewed-by: Brad Fitzpatrick --- acme/autocert/autocert.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/acme/autocert/autocert.go b/acme/autocert/autocert.go index cd61353..c8fa4e6 100644 --- a/acme/autocert/autocert.go +++ b/acme/autocert/autocert.go @@ -658,6 +658,8 @@ func (m *Manager) verify(ctx context.Context, client *acme.Client, domain string } }() + // errs accumulates challenge failure errors, printed if all fail + errs := make(map[*acme.Challenge]error) var nextTyp int // challengeType index of the next challenge type to try for { // Start domain authorization and get the challenge. @@ -683,22 +685,30 @@ func (m *Manager) verify(ctx context.Context, client *acme.Client, domain string nextTyp++ } if chal == nil { - return fmt.Errorf("acme/autocert: unable to authorize %q; tried %q", domain, challengeTypes) + errorMsg := fmt.Sprintf("acme/autocert: unable to authorize %q", domain) + for chal, err := range errs { + errorMsg += fmt.Sprintf("; challenge %q failed with error: %v", chal.Type, err) + } + return errors.New(errorMsg) } cleanup, err := m.fulfill(ctx, client, chal) if err != nil { + errs[chal] = err continue } defer cleanup() if _, err := client.Accept(ctx, chal); err != nil { + errs[chal] = err continue } // A challenge is fulfilled and accepted: wait for the CA to validate. - if _, err := client.WaitAuthorization(ctx, authz.URI); err == nil { - delete(pendingAuthzs, authz.URI) - return nil + if _, err := client.WaitAuthorization(ctx, authz.URI); err != nil { + errs[chal] = err + continue } + delete(pendingAuthzs, authz.URI) + return nil } }