@@ -100,14 +100,22 @@ func SigLogWithLogErrors(errors bool) SigLogOption {
100
100
}
101
101
}
102
102
103
+ // MdmSignatureVerifier verifies Apple Mdm-Signature headers and extracts certificates.
104
+ type MdmSignatureVerifier interface {
105
+ // VerifyMdmSignature verifies an Apple MDM "Mdm-Signature" header and returns the signing certificate.
106
+ // See https://developer.apple.com/documentation/devicemanagement/implementing_device_management/managing_certificates_for_mdm_servers_and_devices
107
+ // section "Pass an Identity Certificate Through a Proxy."
108
+ VerifyMdmSignature (header string , body []byte ) (* x509.Certificate , error )
109
+ }
110
+
103
111
// CertExtractMdmSignatureMiddleware extracts the MDM enrollment
104
112
// identity certificate from the request into the HTTP request context.
105
113
// It tries to verify the Mdm-Signature header on the request.
106
114
//
107
115
// This middleware does not error if a certificate is not found. It
108
116
// will, however, error with an HTTP 400 status if the signature
109
117
// verification fails.
110
- func CertExtractMdmSignatureMiddleware (next http.Handler , opts ... SigLogOption ) http.HandlerFunc {
118
+ func CertExtractMdmSignatureMiddleware (next http.Handler , verifier MdmSignatureVerifier , opts ... SigLogOption ) http.HandlerFunc {
111
119
config := & sigLogConfig {logger : log .NopLogger }
112
120
for _ , opt := range opts {
113
121
opt (config )
@@ -129,7 +137,7 @@ func CertExtractMdmSignatureMiddleware(next http.Handler, opts ...SigLogOption)
129
137
http .Error (w , http .StatusText (http .StatusInternalServerError ), http .StatusInternalServerError )
130
138
return
131
139
}
132
- cert , err := cryptoutil .VerifyMdmSignature (mdmSig , b )
140
+ cert , err := verifier .VerifyMdmSignature (mdmSig , b )
133
141
if err != nil {
134
142
logger .Info ("msg" , "verifying Mdm-Signature header" , "err" , err )
135
143
http .Error (w , http .StatusText (http .StatusBadRequest ), http .StatusBadRequest )
0 commit comments