Fix error with plist encoding by dereferencing nested payloads.

Add correct header for enrollment profile.
Enrollment works with micromdm/scep server!
This commit is contained in:
Mosen
2016-06-28 22:03:45 +10:00
committed by Victor Vrantchan
parent 2cac88f6e4
commit 82f657ef6a
4 changed files with 35 additions and 30 deletions

View File

@@ -8,7 +8,7 @@ import (
type mdmEnrollRequest struct{} type mdmEnrollRequest struct{}
type mdmEnrollResponse struct { type mdmEnrollResponse struct {
*Profile Profile
} }
func makeEnrollEndpoint(svc Service) endpoint.Endpoint { func makeEnrollEndpoint(svc Service) endpoint.Endpoint {

View File

@@ -13,7 +13,7 @@ type Payload struct {
PayloadDisplayName string `json:"displayname" db:"displayname"` PayloadDisplayName string `json:"displayname" db:"displayname"`
PayloadDescription string `json:"description,omitempty" db:"description"` PayloadDescription string `json:"description,omitempty" db:"description"`
PayloadOrganization string `json:"organization,omitempty" db:"organization"` PayloadOrganization string `json:"organization,omitempty" db:"organization"`
PayloadContent interface{} `json:"content,omitempty"` PayloadContent interface{} `json:"content,omitempty" plist:"PayloadContent,omitempty"`
} }
type Profile struct { type Profile struct {
@@ -43,35 +43,35 @@ func NewProfile() *Profile {
} }
} }
func NewPayload(identifier string) *Payload { func NewPayload(payloadType string) *Payload {
payloadUuid := uuid.NewV4() payloadUuid := uuid.NewV4()
return &Payload{ return &Payload{
PayloadVersion: 1, PayloadVersion: 1,
PayloadIdentifier: identifier, PayloadType: payloadType,
PayloadUUID: payloadUuid.String(), PayloadUUID: payloadUuid.String(),
} }
} }
type SCEPPayloadContent struct { type SCEPPayloadContent struct {
CAFingerprint []byte `plist:"omitempty"` // NSData CAFingerprint []byte `plist:"CAFingerprint,omitempty"` // NSData
Challenge string `plist:"omitempty"` Challenge string `plist:"Challenge,omitempty"`
Keysize int Keysize int
KeyType string `plist:"Key Type"` KeyType string `plist:"Key Type"`
KeyUsage int `plist:"Key Usage"` KeyUsage int `plist:"Key Usage"`
Name string Name string
Subject [][][]string `plist:"omitempty"` Subject [][][]string `plist:"Subject,omitempty"`
URL string URL string
} }
// TODO: Actually this is one of those non-nested payloads that doesnt respect the PayloadContent key. // TODO: Actually this is one of those non-nested payloads that doesnt respect the PayloadContent key.
type MDMPayloadContent struct { type MDMPayloadContent struct {
Payload Payload Payload
AccessRights int AccessRights int
CheckInURL string CheckInURL string
CheckOutWhenRemoved bool CheckOutWhenRemoved bool
IdentityCertificateUUID string IdentityCertificateUUID string
ServerCapabilities []string `plist:"omitempty"` ServerCapabilities []string `plist:"ServerCapabilities,omitempty"`
ServerURL string ServerURL string
Topic string Topic string
} }

View File

@@ -1,7 +1,7 @@
package enroll package enroll
type Service interface { type Service interface {
Enroll() (*Profile, error) Enroll() (Profile, error)
} }
func NewService() Service { func NewService() Service {
@@ -13,7 +13,11 @@ func NewService() Service {
} }
return &service{ return &service{
Url: "https://micromdm.local:6443",
SCEPUrl: "http://micromdm.local:2019/scep",
SCEPSubject: scepSubject, SCEPSubject: scepSubject,
Topic: "",
CACert: []byte{},
} }
} }
@@ -23,9 +27,10 @@ type service struct {
SCEPChallenge string SCEPChallenge string
SCEPSubject [][][]string SCEPSubject [][][]string
Topic string // APNS Topic for MDM notifications Topic string // APNS Topic for MDM notifications
CACert []byte
} }
func (svc service) Enroll() (*Profile, error) { func (svc service) Enroll() (Profile, error) {
profile := NewProfile() profile := NewProfile()
profile.PayloadIdentifier = "com.github.micromdm.micromdm.mdm" profile.PayloadIdentifier = "com.github.micromdm.micromdm.mdm"
profile.PayloadOrganization = "MicroMDM" profile.PayloadOrganization = "MicroMDM"
@@ -45,15 +50,16 @@ func (svc service) Enroll() (*Profile, error) {
scepPayload := NewPayload("com.apple.security.scep") scepPayload := NewPayload("com.apple.security.scep")
scepPayload.PayloadDescription = "Configures SCEP" scepPayload.PayloadDescription = "Configures SCEP"
scepPayload.PayloadDisplayName = "SCEP" scepPayload.PayloadDisplayName = "SCEP"
scepPayload.PayloadIdentifier = "com.github.micromdm.scep"
scepPayload.PayloadContent = scepContent scepPayload.PayloadContent = scepContent
mdmPayload := MDMPayloadContent{ mdmPayload := NewPayload("com.apple.mdm")
Payload: Payload{ mdmPayload.PayloadDescription = "Enrolls with the MDM server"
PayloadVersion: 1, mdmPayload.PayloadOrganization = "MicroMDM"
PayloadType: "com.apple.mdm", mdmPayload.PayloadIdentifier = "com.github.micromdm.mdm"
PayloadDescription: "Enrolls with the MDM server",
PayloadOrganization: "MicroMDM", mdmPayloadContent := MDMPayloadContent{
}, Payload: *mdmPayload,
AccessRights: 8191, AccessRights: 8191,
CheckInURL: svc.Url + "/mdm/checkin", CheckInURL: svc.Url + "/mdm/checkin",
CheckOutWhenRemoved: true, CheckOutWhenRemoved: true,
@@ -62,11 +68,12 @@ func (svc service) Enroll() (*Profile, error) {
Topic: svc.Topic, Topic: svc.Topic,
} }
caPayload := NewPayload("com.apple.ssl.certificate") //caPayload := NewPayload("com.apple.ssl.certificate")
caPayload.PayloadDisplayName = "Root certificate for MicroMDM" //caPayload.PayloadDisplayName = "Root certificate for MicroMDM"
caPayload.PayloadDescription = "Installs the root CA certificate for MicroMDM" //caPayload.PayloadDescription = "Installs the root CA certificate for MicroMDM"
//caPayload.PayloadContent = []byte{}
profile.PayloadContent = []interface{}{scepPayload, mdmPayload, caPayload} profile.PayloadContent = []interface{}{*scepPayload, mdmPayloadContent}
return profile, nil return *profile, nil
} }

View File

@@ -37,13 +37,11 @@ func decodeMDMEnrollRequest(_ context.Context, r *http.Request) (interface{}, er
func encodeResponse(ctx context.Context, w http.ResponseWriter, response interface{}) error { func encodeResponse(ctx context.Context, w http.ResponseWriter, response interface{}) error {
resp := response.(mdmEnrollResponse) resp := response.(mdmEnrollResponse)
plistData, err := plist.Marshal(resp.Profile) w.Header().Set("Content-Type", "application/x-apple-aspen-config")
if err != nil {
if err := plist.NewEncoder(w).Encode(resp); err != nil {
return err return err
} }
if len(plistData) != 0 {
w.Write(plistData)
}
return nil return nil
} }