Skip to content

Commit e381191

Browse files
authored
Merge pull request #31 from 61131/master
Deprecate Content-Transfer-Encoding per RFC 8951
2 parents 75756af + 2094627 commit e381191

File tree

5 files changed

+0
-127
lines changed

5 files changed

+0
-127
lines changed

client.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -256,14 +256,6 @@ func (c *Client) ServerKeyGen(ctx context.Context, r *x509.CertificateRequest) (
256256
return nil, nil, fmt.Errorf("more than %d parts in HTTP response", numParts)
257257
}
258258

259-
// Check content-transfer-encoding is as expected, and read the part
260-
// body.
261-
if ce := part.Header.Get(transferEncodingHeader); ce == "" {
262-
return nil, nil, fmt.Errorf("missing %s header", transferEncodingHeader)
263-
} else if strings.ToUpper(ce) != strings.ToUpper(encodingTypeBase64) {
264-
return nil, nil, fmt.Errorf("unexpected %s: %s", transferEncodingHeader, ce)
265-
}
266-
267259
// Process based on the part's content-type. Per RFC7030 4.4.2, if
268260
// additional encryption is not being employed, the private key data
269261
// must be placed in an application/pkcs8 part. Otherwise, it must

est_test.go

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -727,31 +727,6 @@ func TestServerErrors(t *testing.T) {
727727
status: http.StatusUnsupportedMediaType,
728728
errText: "415 malformed or missing Content-Type header\n",
729729
},
730-
{
731-
name: "Enroll/BadContentTransferEncoding",
732-
path: enrollEndpoint,
733-
method: http.MethodPost,
734-
headers: http.Header{
735-
typeHeader: []string{mimeTypePKCS10},
736-
encodingHeader: []string{encodingBinary},
737-
authorizationHeader: []string{authorizationValue},
738-
hostHeader: []string{testDomain},
739-
},
740-
status: http.StatusUnsupportedMediaType,
741-
errText: "415 Content-Transfer-Encoding must be base64\n",
742-
},
743-
{
744-
name: "Enroll/MissingContentTransferEncoding",
745-
path: enrollEndpoint,
746-
method: http.MethodPost,
747-
headers: http.Header{
748-
typeHeader: []string{mimeTypePKCS10},
749-
authorizationHeader: []string{authorizationValue},
750-
hostHeader: []string{testDomain},
751-
},
752-
status: http.StatusUnsupportedMediaType,
753-
errText: "415 missing Content-Transfer-Encoding header\n",
754-
},
755730
{
756731
name: "Enroll/BadBase64",
757732
path: enrollEndpoint,

http.go

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -245,17 +245,6 @@ func verifyResponseType(r *http.Response, t, e string) error {
245245
return fmt.Errorf("unexpected %s: %s", contentTypeHeader, ctype)
246246
}
247247

248-
cenc := r.Header.Get(transferEncodingHeader)
249-
if cenc == "" {
250-
return fmt.Errorf("missing %s header", transferEncodingHeader)
251-
}
252-
253-
// Content-Transfer-Encoding values are not case sensitive per RFC 2045
254-
// section 6.
255-
if strings.ToUpper(cenc) != strings.ToUpper(e) {
256-
return fmt.Errorf("unexpected %s: %s", transferEncodingHeader, cenc)
257-
}
258-
259248
return nil
260249
}
261250

@@ -272,17 +261,6 @@ func verifyPartTypeResponse(part *multipart.Part, t, e string) error {
272261
return fmt.Errorf("unexpected %s: %s", contentTypeHeader, ctype)
273262
}
274263

275-
cenc := part.Header.Get(transferEncodingHeader)
276-
if cenc == "" {
277-
return fmt.Errorf("missing %s header", transferEncodingHeader)
278-
}
279-
280-
// Content-Transfer-Encoding values are not case sensitive per RFC 2045
281-
// section 6.
282-
if strings.ToUpper(cenc) != strings.ToUpper(e) {
283-
return fmt.Errorf("unexpected %s: %s", transferEncodingHeader, cenc)
284-
}
285-
286264
return nil
287265
}
288266

@@ -307,29 +285,6 @@ func verifyRequestType(have, want string) error {
307285
return nil
308286
}
309287

310-
// verifyRequestEncoding verifies if the content-transfer-encoding of an HTTP
311-
// request is as expected. It returns an error implementing Error and is
312-
// intended to be used by server code.
313-
func verifyRequestEncoding(have, want string) error {
314-
if have == "" {
315-
return &estError{
316-
status: http.StatusUnsupportedMediaType,
317-
desc: fmt.Sprintf("missing %s header", transferEncodingHeader),
318-
}
319-
}
320-
321-
// Content-Transfer-Encoding values are not case sensitive per RFC 2045
322-
// section 6.
323-
if strings.ToUpper(have) != strings.ToUpper(want) {
324-
return &estError{
325-
status: http.StatusUnsupportedMediaType,
326-
desc: fmt.Sprintf("%s must be %s", transferEncodingHeader, want),
327-
}
328-
}
329-
330-
return nil
331-
}
332-
333288
// writeResponse writes headers, a status code, and an object containing the
334289
// body to an HTTP response. If encode is true, the object is base64-encoded.
335290
// The appropriate encoding is chosen according to the object's type.

http_test.go

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -66,29 +66,6 @@ func TestVerifyResponseType(t *testing.T) {
6666
e: "base64",
6767
err: errors.New("missing or malformed Content-Type header: mime: no media type"),
6868
},
69-
{
70-
name: "WrongEncoding",
71-
r: &http.Response{
72-
Header: http.Header{
73-
"Content-Type": []string{"application/pkcs7; smime-type=certs-only"},
74-
"Content-Transfer-Encoding": []string{"base64"},
75-
},
76-
},
77-
t: "application/pkcs7",
78-
e: "binary",
79-
err: errors.New("unexpected Content-Transfer-Encoding: base64"),
80-
},
81-
{
82-
name: "MissingEncoding",
83-
r: &http.Response{
84-
Header: http.Header{
85-
"Content-Type": []string{"application/pkcs7; smime-type=certs-only"},
86-
},
87-
},
88-
t: "application/pkcs7",
89-
e: "base64",
90-
err: errors.New("missing Content-Transfer-Encoding header"),
91-
},
9269
{
9370
name: "BadTypeParameter",
9471
r: &http.Response{

server.go

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -170,16 +170,12 @@ func NewRouter(cfg *ServerConfig) (http.Handler, error) {
170170

171171
r.With(
172172
requireContentType(mimeTypePKCS10),
173-
).With(
174-
requireTransferEncoding(encodingTypeBase64),
175173
).With(
176174
requireBasicAuth(cfg.CheckBasicAuth, true),
177175
).Post(enrollEndpoint, enroll)
178176

179177
r.With(
180178
requireContentType(mimeTypePKCS10),
181-
).With(
182-
requireTransferEncoding(encodingTypeBase64),
183179
).With(
184180
requireBasicAuth(cfg.CheckBasicAuth, true),
185181
).With(
@@ -188,8 +184,6 @@ func NewRouter(cfg *ServerConfig) (http.Handler, error) {
188184

189185
r.With(
190186
requireContentType(mimeTypePKCS10),
191-
).With(
192-
requireTransferEncoding(encodingTypeBase64),
193187
).With(
194188
requireBasicAuth(cfg.CheckBasicAuth, true),
195189
).Post(serverkeygenEndpoint, serverkeygen)
@@ -207,16 +201,12 @@ func NewRouter(cfg *ServerConfig) (http.Handler, error) {
207201

208202
r.With(
209203
requireContentType(mimeTypePKCS10),
210-
).With(
211-
requireTransferEncoding(encodingTypeBase64),
212204
).With(
213205
requireBasicAuth(cfg.CheckBasicAuth, true),
214206
).Post(enrollEndpoint, enroll)
215207

216208
r.With(
217209
requireContentType(mimeTypePKCS10),
218-
).With(
219-
requireTransferEncoding(encodingTypeBase64),
220210
).With(
221211
requireBasicAuth(cfg.CheckBasicAuth, true),
222212
).With(
@@ -225,8 +215,6 @@ func NewRouter(cfg *ServerConfig) (http.Handler, error) {
225215

226216
r.With(
227217
requireContentType(mimeTypePKCS10),
228-
).With(
229-
requireTransferEncoding(encodingTypeBase64),
230218
).With(
231219
requireBasicAuth(cfg.CheckBasicAuth, true),
232220
).Post(serverkeygenEndpoint, serverkeygen)
@@ -615,20 +603,6 @@ func requireContentType(t string) func(next http.Handler) http.Handler {
615603
}
616604
}
617605

618-
// requireTransferEncoding is middleware which rejects a request if the content
619-
// transfer encoding is not as stated.
620-
func requireTransferEncoding(e string) func(next http.Handler) http.Handler {
621-
return func(next http.Handler) http.Handler {
622-
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
623-
if err := verifyRequestEncoding(r.Header.Get(transferEncodingHeader), e); err != nil {
624-
writeOnError(r.Context(), w, logMsgTransferEncodingInvalid, err)
625-
return
626-
}
627-
next.ServeHTTP(w, r)
628-
})
629-
}
630-
}
631-
632606
// addServerHeader is middleware which writes to an HTTP response a Server HTTP
633607
// header. Including too much detail (such as an operating system version) in
634608
// this header can be a security risk, but including enough detail can sometimes

0 commit comments

Comments
 (0)