From 31cb8f47cf33ff22d2b6807377e48c4d1ef94e77 Mon Sep 17 00:00:00 2001 From: Mosen Date: Sun, 26 Jun 2016 23:44:06 +1000 Subject: [PATCH] Add MDM payload Add NewPayload method Profiles and payloads created by their factory methods automatically generate a UUID Add go-kit service for enroll. --- profile.go | 38 +++++++++++++++++++++++++++++++++----- service.go | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 5 deletions(-) diff --git a/profile.go b/profile.go index 1473ef04..dd878062 100644 --- a/profile.go +++ b/profile.go @@ -1,6 +1,9 @@ package enroll -import "time" +import ( + "github.com/satori/go.uuid" + "time" +) type Payload struct { PayloadType string `json:"type" db:"type"` @@ -34,11 +37,36 @@ func NewProfile() Profile { return &Profile{ PayloadVersion: 1, PayloadType: "Configuration", + PayloadUUID: uuid.NewV4(), } } -type ProfileServicePayload struct { - URL string - DeviceAttributes []string - Challenge string +func NewPayload(identifier string) Payload { + return &Payload{ + PayloadVersion: 1, + PayloadIdentifier: identifier, + PayloadUUID: uuid.NewV4(), + } +} + +type SCEPPayload struct { + CAFingerprint []byte `plist:"omitempty"` // NSData + Challenge string `plist:"omitempty"` + Keysize int + KeyType string `plist:"Key Type"` + KeyUsage int `plist:"Key Usage"` + Name string + Subject [][][]string `plist:"omitempty"` + URL string +} + +// TODO: Actually this is one of those non-nested payloads that doesnt respect the PayloadContent key. +type MDMPayload struct { + AccessRights int + CheckInURL string + CheckOutWhenRemoved bool + IdentityCertificateUUID string + ServerCapabilities []string `plist:"omitempty"` + ServerURL string + Topic string } diff --git a/service.go b/service.go index 4b183cfe..fbb5dcb0 100644 --- a/service.go +++ b/service.go @@ -3,3 +3,53 @@ package enroll type Service interface { Enroll() } + +type service struct { + Url string + SCEPUrl string + SCEPChallenge string + Topic string // APNS Topic for MDM notifications +} + +func (svc service) Enroll() { + profile := NewProfile() + profile.PayloadIdentifier = "com.github.micromdm.micromdm.mdm" + profile.PayloadOrganization = "MicroMDM" + profile.PayloadDisplayName = "Enrollment Profile" + profile.PayloadDescription = "The server may alter your settings" + + scepSubject := []string{ + []string{ + []string{"O", "MicroMDM"}, + []string{"CN", "MDM Identity Certificate:UDID"}, + }, + } + + scepContent := SCEPPayload{ + Challenge: svc.SCEPChallenge, + URL: svc.SCEPUrl, + Keysize: 1024, + KeyType: "RSA", + KeyUsage: 0, + Name: "Device Management Identity Certificate", + Subject: scepSubject, + } + + scepPayload := NewPayload("com.apple.security.scep") + scepPayload.PayloadDescription = "Configures SCEP" + scepPayload.PayloadDisplayName = "SCEP" + scepPayload.PayloadContent = scepContent + + mdmContent := MDMPayload{ + AccessRights: 8191, + CheckInURL: svc.Url + "/mdm/checkin", + CheckOutWhenRemoved: true, + ServerURL: svc.Url + "/mdm/connect", + IdentityCertificateUUID: scepPayload.PayloadUUID, + Topic: svc.Topic, + } + + mdmPayload := NewPayload("com.apple.mdm") + mdmPayload.PayloadDescription = "Enrolls with the MDM server" + +}