Add MDM payload

Add NewPayload method
Profiles and payloads created by their factory methods automatically generate a UUID
Add go-kit service for enroll.
This commit is contained in:
Mosen
2016-06-26 23:44:06 +10:00
committed by Victor Vrantchan
parent a745a7596f
commit 31cb8f47cf
2 changed files with 83 additions and 5 deletions

View File

@@ -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
}

View File

@@ -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"
}