Skip to content

Commit

Permalink
signature verifier location
Browse files Browse the repository at this point in the history
  • Loading branch information
jessepeterson committed Sep 30, 2024
1 parent 6f7a285 commit a3faa70
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion cmd/nanomdm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func main() {
if *flDebug {
opts = append(opts, httpmdm.SigLogWithLogErrors(true))
}
h = httpmdm.CertExtractMdmSignatureMiddleware(h, cryptoutil.MdmSignatureVerifierFunc(cryptoutil.VerifyMdmSignature), opts...)
h = httpmdm.CertExtractMdmSignatureMiddleware(h, httpmdm.MdmSignatureVerifierFunc(cryptoutil.VerifyMdmSignature), opts...)
}
return h
}
Expand Down
8 changes: 0 additions & 8 deletions cryptoutil/cryptoutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,6 @@ func TopicFromPEMCert(pemCert []byte) (string, error) {
return TopicFromCert(cert)
}

// MdmSignatureVerifierFunc is an adapter for verifying Apple MDM "Mdm-Signature" headers.
type MdmSignatureVerifierFunc func(header string, body []byte) (*x509.Certificate, error)

// VerifyMdmSignature calls v with header and body.
func (v MdmSignatureVerifierFunc) VerifyMdmSignature(header string, body []byte) (*x509.Certificate, error) {
return v(header, body)
}

// VerifyMdmSignature verifies an Apple MDM "Mdm-Signature" header and returns the signing certificate.
// See https://developer.apple.com/documentation/devicemanagement/implementing_device_management/managing_certificates_for_mdm_servers_and_devices
// section "Pass an Identity Certificate Through a Proxy."
Expand Down
5 changes: 2 additions & 3 deletions cryptoutil/cryptoutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@ func TestPKCS7ParseTagLengthError(t *testing.T) {
}
}

func TestMdmVerifierFunc(t *testing.T) {
func TestVerifyMdmSignature(t *testing.T) {
body, err := base64.StdEncoding.DecodeString(mdmSignatureBody2)
if err != nil {
t.Error(err)
}
verifier := MdmSignatureVerifierFunc(VerifyMdmSignature)
_, err = verifier.VerifyMdmSignature(mdmSignatureHeader2, body)
_, err = VerifyMdmSignature(mdmSignatureHeader2, body)
if err != nil {
t.Error(err)
}
Expand Down
8 changes: 8 additions & 0 deletions http/mdm/mdm_cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ type MdmSignatureVerifier interface {
VerifyMdmSignature(header string, body []byte) (*x509.Certificate, error)
}

// MdmSignatureVerifierFunc is an adapter for verifying Apple MDM "Mdm-Signature" headers.
type MdmSignatureVerifierFunc func(header string, body []byte) (*x509.Certificate, error)

// VerifyMdmSignature calls v with header and body.
func (v MdmSignatureVerifierFunc) VerifyMdmSignature(header string, body []byte) (*x509.Certificate, error) {
return v(header, body)
}

// CertExtractMdmSignatureMiddleware extracts the MDM enrollment
// identity certificate from the request into the HTTP request context.
// It tries to verify the Mdm-Signature header on the request.
Expand Down

0 comments on commit a3faa70

Please sign in to comment.