Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion acme/problems.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package acme
import (
"fmt"
"net/http"
"sort"

jose "github.com/go-jose/go-jose/v4"
)

const (
Expand Down Expand Up @@ -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"`
}
Expand Down Expand Up @@ -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,
}
}

Expand Down
3 changes: 2 additions & 1 deletion wfe/wfe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
}
Expand Down
50 changes: 50 additions & 0 deletions wfe/wfe_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
Loading