Porting fix from micromdm/scep (#38638)

<!-- Add the related story/sub-task/bug number, like Resolves #123, or
remove if NA -->
**Related issue:** Resolves #38579

Porting this fix from upstream:
https://github.com/micromdm/scep/commit/a8623d6b71c383ed448ededb834401a014961e61

# Checklist for submitter

If some of the following don't apply, delete the relevant line.

- [x] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.

## Testing

- [x] Added/updated automated tests
- [x] QA'd all new/changed functionality manually
  - QA'd the change manually using micromdm/scep
This commit is contained in:
Victor Lyuboslavsky
2026-01-22 13:34:53 -06:00
committed by GitHub
parent e0631aff76
commit 774595f32e
3 changed files with 23 additions and 1 deletions
+1
View File
@@ -0,0 +1 @@
Fixed SCEP proxy to use standard base64 encoding for PKIOperation GET requests, ensuring compatibility with standard SCEP servers.
+3 -1
View File
@@ -87,7 +87,9 @@ func EncodeSCEPRequest(ctx context.Context, r *http.Request, request interface{}
if len(req.Message) > 0 {
var msg string
if req.Operation == "PKIOperation" {
msg = base64.URLEncoding.EncodeToString(req.Message)
// Use standard base64 encoding (with + and /) as expected by SCEP servers.
// The subsequent params.Encode() call will URL-encode the + and / characters.
msg = base64.StdEncoding.EncodeToString(req.Message)
} else {
msg = string(req.Message)
}
+19
View File
@@ -86,6 +86,25 @@ func TestGetCACertMessage(t *testing.T) {
}
}
func TestEncodeSCEPRequest_PKIOperation_UsesStdBase64(t *testing.T) {
// Data that encodes to "++++////" in standard base64
testData := []byte{0xfb, 0xef, 0xbe, 0xff, 0xff, 0xff}
req, _ := http.NewRequest("GET", "http://example.com/scep", nil)
if err := scepserver.EncodeSCEPRequest(t.Context(), req, scepserver.SCEPRequest{
Operation: "PKIOperation",
Message: testData,
}); err != nil {
t.Fatal(err)
}
// Verify message decodes correctly with StdEncoding (not URLEncoding)
msg := req.URL.Query().Get("message")
if _, err := base64.StdEncoding.DecodeString(msg); err != nil {
t.Fatalf("message should be valid standard base64: %v", err)
}
}
func TestPKIOperation(t *testing.T) {
server, _, teardown := newServer(t)
defer teardown()