Skip to content

Commit

Permalink
Revert URL encoding OCSP GET fix #18938 (#19037)
Browse files Browse the repository at this point in the history
- This fix was incorrect as now the tests and program are double
   URL encoding the OCSP GET requests, so the base64 + characters
   when using Vault proper are becoming space characters.
  • Loading branch information
stevendpclark authored Feb 8, 2023
1 parent 7058107 commit 05e742b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
8 changes: 1 addition & 7 deletions builtin/logical/pki/path_ocsp.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"io"
"math/big"
"net/http"
"net/url"
"strings"
"time"

Expand Down Expand Up @@ -249,12 +248,7 @@ func fetchDerEncodedRequest(request *logical.Request, data *framework.FieldData)
return nil, errors.New("request is too large")
}

unescapedBase64, err := url.QueryUnescape(base64Req)
if err != nil {
return nil, fmt.Errorf("failed to unescape base64 string: %w", err)
}

return base64.StdEncoding.DecodeString(unescapedBase64)
return base64.StdEncoding.DecodeString(base64Req)
case logical.UpdateOperation:
// POST bodies should contain the binary form of the DER request.
// NOTE: Writing an empty update request to Vault causes a nil request.HTTPRequest, and that object
Expand Down
5 changes: 2 additions & 3 deletions builtin/logical/pki/path_ocsp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"fmt"
"io"
"net/http"
"net/url"
"strconv"
"strings"
"testing"
Expand Down Expand Up @@ -441,7 +440,7 @@ func TestOcsp_HigherLevel(t *testing.T) {
require.Equal(t, certToRevoke.SerialNumber, ocspResp.SerialNumber)

// Test OCSP Get request for ocsp
urlEncoded := url.QueryEscape(base64.StdEncoding.EncodeToString(ocspReq))
urlEncoded := base64.StdEncoding.EncodeToString(ocspReq)
ocspGetReq := client.NewRequest(http.MethodGet, "/v1/pki/ocsp/"+urlEncoded)
ocspGetReq.Headers.Set("Content-Type", "application/ocsp-request")
rawResp, err = client.RawRequest(ocspGetReq)
Expand Down Expand Up @@ -688,7 +687,7 @@ func SendOcspRequest(t *testing.T, b *backend, s logical.Storage, getOrPost stri
}

func sendOcspGetRequest(b *backend, s logical.Storage, ocspRequest []byte) (*logical.Response, error) {
urlEncoded := url.QueryEscape(base64.StdEncoding.EncodeToString(ocspRequest))
urlEncoded := base64.StdEncoding.EncodeToString(ocspRequest)
return CBRead(b, s, "ocsp/"+urlEncoded)
}

Expand Down

0 comments on commit 05e742b

Please sign in to comment.