Skip to content

Commit

Permalink
wfe: Use RawURLEncoding for authz2 challenge IDs (letsencrypt#4280)
Browse files Browse the repository at this point in the history
  • Loading branch information
rolandshoemaker authored and Daniel McCarney committed Jun 21, 2019
1 parent f4b9235 commit 0591126
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion core/objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ func (ch Challenge) StringID() string {
h := fnv.New128a()
h.Write([]byte(ch.Token))
h.Write([]byte(ch.Type))
return base64.URLEncoding.EncodeToString(h.Sum(nil)[0:4])
return base64.RawURLEncoding.EncodeToString(h.Sum(nil)[0:4])
}

// Authorization represents the authorization of an account key holder
Expand Down
4 changes: 2 additions & 2 deletions core/objects_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@ func TestChallengeStringID(t *testing.T) {
Token: "asd",
Type: ChallengeTypeDNS01,
}
test.AssertEquals(t, ch.StringID(), "iFVMwA==")
test.AssertEquals(t, ch.StringID(), "iFVMwA")
ch.Type = ChallengeTypeHTTP01
test.AssertEquals(t, ch.StringID(), "0Gexug==")
test.AssertEquals(t, ch.StringID(), "0Gexug")
}

func TestFindChallengeByType(t *testing.T) {
Expand Down
20 changes: 10 additions & 10 deletions wfe/wfe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1118,11 +1118,11 @@ func TestGetChallengeV2UpRel(t *testing.T) {
wfe, _ := setupWFE(t)
_ = features.Set(map[string]bool{"NewAuthorizationSchema": true})

challengeURL := "http://localhost/acme/challenge/v2/1/-ZfxEw=="
challengeURL := "http://localhost/acme/challenge/v2/1/-ZfxEw"
resp := httptest.NewRecorder()

req, err := http.NewRequest("GET", challengeURL, nil)
req.URL.Path = "v2/1/-ZfxEw=="
req.URL.Path = "v2/1/-ZfxEw"
test.AssertNotError(t, err, "Could not make NewRequest")

wfe.Challenge(ctx, newRequestEvent(), resp, req)
Expand Down Expand Up @@ -1886,7 +1886,7 @@ func TestAuthorization(t *testing.T) {
{
"type": "dns",
"token":"token",
"uri": "http://localhost/acme/challenge/v2/1/-ZfxEw=="
"uri": "http://localhost/acme/challenge/v2/1/-ZfxEw"
}
]
}`)
Expand Down Expand Up @@ -2588,7 +2588,7 @@ func TestPrepChallengeForDisplay(t *testing.T) {
_ = features.Set(map[string]bool{"NewAuthorizationSchema": true})
authz.V2 = true
wfe.prepChallengeForDisplay(req, authz, chall)
test.AssertEquals(t, chall.URI, "http://example.com/acme/challenge/v2/eyup/iFVMwA==")
test.AssertEquals(t, chall.URI, "http://example.com/acme/challenge/v2/eyup/iFVMwA")
}

// noSCTMockRA is a mock RA that always returns a `berrors.MissingSCTsError` from `NewCertificate`
Expand Down Expand Up @@ -2671,9 +2671,9 @@ func TestChallengeNewIDScheme(t *testing.T) {
expected: `{"type":"dns","token":"token","uri":"http://localhost/acme/challenge/valid/23"}`,
},
{
path: "v2/1/-ZfxEw==",
location: "http://localhost/acme/challenge/v2/1/-ZfxEw==",
expected: `{"type":"dns","token":"token","uri":"http://localhost/acme/challenge/v2/1/-ZfxEw=="}`,
path: "v2/1/-ZfxEw",
location: "http://localhost/acme/challenge/v2/1/-ZfxEw",
expected: `{"type":"dns","token":"token","uri":"http://localhost/acme/challenge/v2/1/-ZfxEw"}`,
},
} {
resp := httptest.NewRecorder()
Expand Down Expand Up @@ -2703,9 +2703,9 @@ func TestChallengeNewIDScheme(t *testing.T) {
expected: `{"type":"dns","token":"token","uri":"http://localhost/acme/challenge/valid/23"}`,
},
{
path: "v2/1/-ZfxEw==",
location: "http://localhost/acme/challenge/v2/1/-ZfxEw==",
expected: `{"type":"dns","token":"token","uri":"http://localhost/acme/challenge/v2/1/-ZfxEw=="}`,
path: "v2/1/-ZfxEw",
location: "http://localhost/acme/challenge/v2/1/-ZfxEw",
expected: `{"type":"dns","token":"token","uri":"http://localhost/acme/challenge/v2/1/-ZfxEw"}`,
},
} {
resp := httptest.NewRecorder()
Expand Down
22 changes: 11 additions & 11 deletions wfe2/wfe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1557,7 +1557,7 @@ func TestGetAuthorization(t *testing.T) {
{
"type": "dns",
"token":"token",
"url": "http://localhost/acme/challenge/v2/1/-ZfxEw=="
"url": "http://localhost/acme/challenge/v2/1/-ZfxEw"
}
]
}`)
Expand All @@ -1580,7 +1580,7 @@ func TestGetAuthorization(t *testing.T) {
{
"type": "dns",
"token":"token",
"url": "http://localhost/acme/challenge/v2/1/-ZfxEw=="
"url": "http://localhost/acme/challenge/v2/1/-ZfxEw"
}
]
}`)
Expand Down Expand Up @@ -2920,7 +2920,7 @@ func TestPrepAuthzForDisplay(t *testing.T) {
authz.V2 = true
wfe.prepAuthorizationForDisplay(&http.Request{Host: "localhost"}, authz)
chal = authz.Challenges[0]
test.AssertEquals(t, chal.URL, "http://localhost/acme/challenge/v2/12345/po1V2w==")
test.AssertEquals(t, chal.URL, "http://localhost/acme/challenge/v2/12345/po1V2w")
test.AssertEquals(t, chal.URI, "")
}

Expand Down Expand Up @@ -2978,9 +2978,9 @@ func TestChallengeNewIDScheme(t *testing.T) {
expected: `{"type":"dns","token":"token","url":"http://localhost/acme/challenge/valid/23"}`,
},
{
path: "v2/1/-ZfxEw==",
location: "http://localhost/acme/challenge/v2/1/-ZfxEw==",
expected: `{"type":"dns","token":"token","url":"http://localhost/acme/challenge/v2/1/-ZfxEw=="}`,
path: "v2/1/-ZfxEw",
location: "http://localhost/acme/challenge/v2/1/-ZfxEw",
expected: `{"type":"dns","token":"token","url":"http://localhost/acme/challenge/v2/1/-ZfxEw"}`,
},
} {
resp := httptest.NewRecorder()
Expand Down Expand Up @@ -3010,9 +3010,9 @@ func TestChallengeNewIDScheme(t *testing.T) {
expected: `{"type":"dns","token":"token","url":"http://localhost/acme/challenge/valid/23"}`,
},
{
path: "v2/1/-ZfxEw==",
location: "http://localhost/acme/challenge/v2/1/-ZfxEw==",
expected: `{"type":"dns","token":"token","url":"http://localhost/acme/challenge/v2/1/-ZfxEw=="}`,
path: "v2/1/-ZfxEw",
location: "http://localhost/acme/challenge/v2/1/-ZfxEw",
expected: `{"type":"dns","token":"token","url":"http://localhost/acme/challenge/v2/1/-ZfxEw"}`,
},
} {
resp := httptest.NewRecorder()
Expand Down Expand Up @@ -3123,11 +3123,11 @@ func TestGetChallengeV2UpRel(t *testing.T) {
wfe, _ := setupWFE(t)
_ = features.Set(map[string]bool{"NewAuthorizationSchema": true})

challengeURL := "http://localhost/acme/challenge/v2/1/-ZfxEw=="
challengeURL := "http://localhost/acme/challenge/v2/1/-ZfxEw"
resp := httptest.NewRecorder()

req, err := http.NewRequest("GET", challengeURL, nil)
req.URL.Path = "v2/1/-ZfxEw=="
req.URL.Path = "v2/1/-ZfxEw"
test.AssertNotError(t, err, "Could not make NewRequest")

wfe.Challenge(ctx, newRequestEvent(), resp, req)
Expand Down

0 comments on commit 0591126

Please sign in to comment.