Skip to content

Commit c8dbbf0

Browse files
jshaDaniel McCarney
authored andcommitted
Handle unprintable characters in HTTP responses. (letsencrypt#4312)
Fixes letsencrypt#4244.
1 parent c734417 commit c8dbbf0

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

va/http.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ func (va *ValidationAuthorityImpl) validateHTTP01(ctx context.Context, ident ide
634634
payload := strings.TrimRight(string(body), whitespaceCutset)
635635

636636
if payload != challenge.ProvidedKeyAuthorization {
637-
problem := probs.Unauthorized("The key authorization file from the server did not match this challenge [%v] != [%v]",
637+
problem := probs.Unauthorized("The key authorization file from the server did not match this challenge %q != %q",
638638
challenge.ProvidedKeyAuthorization, payload)
639639
va.log.Infof("%s for %s", problem.Detail, ident)
640640
return validationRecords, problem

va/http_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,29 @@ func TestHTTPBadPort(t *testing.T) {
10021002
}
10031003
}
10041004

1005+
func TestHTTPKeyAuthorizationFileMismatch(t *testing.T) {
1006+
chall := core.HTTPChallenge01("")
1007+
setChallengeToken(&chall, expectedToken)
1008+
1009+
m := http.NewServeMux()
1010+
hs := httptest.NewUnstartedServer(m)
1011+
m.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
1012+
w.Write([]byte("\xef\xffAABBCC"))
1013+
})
1014+
hs.Start()
1015+
1016+
va, _ := setup(hs, 0, "", nil)
1017+
_, prob := va.validateHTTP01(ctx, dnsi("localhost.com"), chall)
1018+
1019+
if prob == nil {
1020+
t.Fatalf("Expected validation to fail when file mismatched.")
1021+
}
1022+
expected := `The key authorization file from the server did not match this challenge "LoqXcYV8q5ONbJQxbmR7SCTNo3tiAXDfowyjxAjEuX0.9jg46WB3rR_AHD-EBXdN7cBkH1WOu0tA3M9fm21mqTI" != "\xef\xffAABBCC"`
1023+
if prob.Detail != expected {
1024+
t.Errorf("validation failed with %s, expected %s", prob.Detail, expected)
1025+
}
1026+
}
1027+
10051028
func TestHTTP(t *testing.T) {
10061029
chall := core.HTTPChallenge01("")
10071030
setChallengeToken(&chall, expectedToken)

va/va_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ func TestMultiVA(t *testing.T) {
325325
}
326326

327327
unauthorized := probs.Unauthorized(
328-
"The key authorization file from the server did not match this challenge [%s] != [???]",
328+
`The key authorization file from the server did not match this challenge %q != "???"`,
329329
expectedKeyAuthorization)
330330

331331
internalErr := probs.ServerInternal("Remote PerformValidation RPC failed")

0 commit comments

Comments
 (0)