diff --git a/acme/problems.go b/acme/problems.go index 7ac8267f..9234f597 100644 --- a/acme/problems.go +++ b/acme/problems.go @@ -3,6 +3,9 @@ package acme import ( "fmt" "net/http" + "sort" + + jose "github.com/go-jose/go-jose/v4" ) const ( @@ -32,6 +35,7 @@ type ProblemDetails struct { Type string `json:"type,omitempty"` Detail string `json:"detail,omitempty"` HTTPStatus int `json:"status,omitempty"` + Algorithms []string `json:"algorithms,omitempty"` Identifier *Identifier `json:"identifier,omitempty"` Subproblems []ProblemDetails `json:"subproblems,omitempty"` } @@ -192,11 +196,18 @@ func BadPublicKeyProblem(detail string) *ProblemDetails { } } -func BadSignatureAlgorithmProblem(detail string) *ProblemDetails { +func BadSignatureAlgorithmProblem(detail string, algorithms []jose.SignatureAlgorithm) *ProblemDetails { + supportedAlgorithms := make([]string, len(algorithms)) + for i, algorithm := range algorithms { + supportedAlgorithms[i] = string(algorithm) + } + sort.Strings(supportedAlgorithms) + return &ProblemDetails{ Type: badSignatureAlgorithmErr, Detail: detail, HTTPStatus: http.StatusBadRequest, + Algorithms: supportedAlgorithms, } } diff --git a/wfe/wfe.go b/wfe/wfe.go index 3383b70e..2e0ef6eb 100644 --- a/wfe/wfe.go +++ b/wfe/wfe.go @@ -715,7 +715,8 @@ func (wfe *WebFrontEndImpl) parseJWS(body string) (*jose.JSONWebSignature, *acme var unexpectedSignAlgo *jose.ErrUnexpectedSignatureAlgorithm if errors.As(err, &unexpectedSignAlgo) { return nil, acme.BadSignatureAlgorithmProblem(fmt.Sprintf( - "JWS header contained unsupported algorithm, supported algorithms are: %s", goodJWSSignatureAlgorithms)) + "JWS header contained unsupported algorithm, supported algorithms are: %s", + goodJWSSignatureAlgorithms), goodJWSSignatureAlgorithms) } return nil, acme.MalformedProblem(fmt.Sprint("Parse error reading JWS: ", err.Error())) } diff --git a/wfe/wfe_test.go b/wfe/wfe_test.go new file mode 100644 index 00000000..267d49b7 --- /dev/null +++ b/wfe/wfe_test.go @@ -0,0 +1,50 @@ +package wfe + +import ( + "encoding/base64" + "encoding/json" + "io" + "log" + "net/http" + "net/http/httptest" + "reflect" + "strings" + "testing" + + "github.com/letsencrypt/pebble/v2/acme" +) + +func TestNewAccountRejectsUnsupportedSignatureAlgorithm(t *testing.T) { + t.Parallel() + + wfe := &WebFrontEndImpl{ + log: log.New(io.Discard, "", 0), + nonce: newNonceMap(), + } + protected := base64.RawURLEncoding.EncodeToString([]byte(`{"alg":"unsupported"}`)) + body := `{"protected":"` + protected + `","payload":"","signature":"AA"}` + req := httptest.NewRequest(http.MethodPost, newAccountPath, strings.NewReader(body)) + req.Header.Set("Content-Type", expectedJWSContentType) + req.Header.Set("User-Agent", "pebble-test") + recorder := httptest.NewRecorder() + + wfe.Handler().ServeHTTP(recorder, req) + + if recorder.Code != http.StatusBadRequest { + t.Fatalf("response status = %d, want %d", recorder.Code, http.StatusBadRequest) + } + var problem acme.ProblemDetails + if err := json.Unmarshal(recorder.Body.Bytes(), &problem); err != nil { + t.Fatalf("unmarshaling problem response: %v", err) + } + if problem.Type != "urn:ietf:params:acme:error:badSignatureAlgorithm" { + t.Errorf("problem type = %q, want badSignatureAlgorithm (detail: %q)", + problem.Type, problem.Detail) + } + wantAlgorithms := []string{ + "ES256", "ES384", "ES512", "ML-DSA-44", "ML-DSA-65", "ML-DSA-87", "RS256", + } + if !reflect.DeepEqual(problem.Algorithms, wantAlgorithms) { + t.Errorf("algorithms = %q, want %q", problem.Algorithms, wantAlgorithms) + } +}