mirror of
https://github.com/micromdm/micromdm/
synced 2026-08-12 04:55:39 +08:00
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:
38
profile.go
38
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
|
||||
}
|
||||
|
||||
50
service.go
50
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"
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user