Feature/add lom commands (#839)

This commit is contained in:
hrgbcxd
2022-07-20 17:27:24 +02:00
committed by GitHub
parent d556eb9880
commit 1e49dc2585
25 changed files with 1200 additions and 804 deletions

2
go.mod
View File

@@ -22,7 +22,7 @@ require (
go.mozilla.org/pkcs7 v0.0.0-20210826202110-33d05740a352
golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110
google.golang.org/protobuf v1.27.1
google.golang.org/protobuf v1.28.0
gopkg.in/Masterminds/squirrel.v1 v1.0.0-20170825200431-a6b93000bd21
)

4
go.sum
View File

@@ -104,7 +104,7 @@ golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8T
google.golang.org/appengine v1.2.0 h1:S0iUepdCWODXRvtE+gcRDd15L+k+k1AiHlMiMjefH24=
google.golang.org/appengine v1.2.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ=
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw=
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/Masterminds/squirrel.v1 v1.0.0-20170825200431-a6b93000bd21 h1:GmGVIcDxdecAcVjcTp4IpK4VmCMxXhyZKwN2eIzsZ4Y=
gopkg.in/Masterminds/squirrel.v1 v1.0.0-20170825200431-a6b93000bd21/go.mod h1:8PH4rQjb7OdPC6OWDDuY6J/PT8iSNTiff3jmccc2m10=

View File

@@ -1,7 +1,7 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.26.0
// protoc v3.18.1
// protoc-gen-go v1.28.0
// protoc v3.21.2
// source: checkin.proto
package checkinproto

View File

@@ -1,7 +1,7 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.26.0
// protoc v3.18.1
// protoc-gen-go v1.28.0
// protoc v3.21.2
// source: connect.proto
package connectproto

View File

@@ -69,6 +69,8 @@ type Command struct {
ActiveNSExtensions *ActiveNSExtensions
RotateFileVaultKey *RotateFileVaultKey
RefreshCellularPlans *RefreshCellularPlans
LOMDeviceRequest *LOMDeviceRequest
LOMSetupRequestCommand *LOMSetupRequestCommand
}
// InstallProfile is an InstallProfile MDM Command
@@ -236,6 +238,23 @@ type Setting struct {
ConfigurationData []byte `plist:"-" json:"configuration"` // used to build the dictionary
}
type LOMDeviceRequest struct {
RequestList []LOMDeviceRequestCommand `plist:",omitempty" json:"request_list,omitempty"`
}
type LOMDeviceRequestCommand struct {
DeviceDNSName string `json:"device_dns_name"`
DeviceRequestType string `json:"device_request_type"`
DeviceRequestUUID string `json:"device_request_uuid"`
LOMProtocolVersion int `json:"lom_protocol_version"`
PrimaryIPv6AddressList []string `json:"primary_ip_v6_address_list"`
SecondaryIPv6AddressList []string `json:"secondary_ip_v6_address_list"`
}
type LOMSetupRequestCommand struct {
RequestRequiresNetworkTether *bool `plist:",omitempty" json:"request_requires_network_tether,omitempty"`
}
type ManagedApplicationConfiguration struct {
Identifiers []string `plist:",omitempty" json:"identifiers,omitempty"`
}

File diff suppressed because it is too large Load Diff

View File

@@ -18,6 +18,7 @@ message Command {
- CertificateList",
- SecurityInfo
- RestartDevice
- LOMSetupRequest
- ShutDownDevice
- StopMirroring
- ClearRestrictionsPassword
@@ -74,6 +75,7 @@ message Command {
SetRecoveryLock set_recovery_lock = 38;
VerifyRecoveryLock verify_recovery_lock = 39;
RefreshCellularPlans refresh_cellular_plans = 40;
LOMDeviceRequest lomDeviceRequestCommand = 41;
}
}
@@ -256,6 +258,19 @@ message RemoveMedia {
string persistent_id = 3;
}
message LOMDeviceRequest {
repeated LOMDeviceRequestCommand requestList = 1;
}
message LOMDeviceRequestCommand {
string deviceDNSName = 1;
string deviceRequestType = 2;
string deviceRequestUUID = 3;
int64 lomProtocolVersion = 4;
repeated string primaryIPv6AddressList = 5;
repeated string secondaryIPv6AddressList = 6;
}
message Settings {
repeated Setting settings = 1;
}

View File

@@ -12,6 +12,7 @@ func (c *Command) MarshalJSON() ([]byte, error) {
"CertificateList",
"SecurityInfo",
"RestartDevice",
"LOMSetupRequest",
"ShutDownDevice",
"StopMirroring",
"ClearRestrictionsPassword",
@@ -250,6 +251,15 @@ func (c *Command) MarshalJSON() ([]byte, error) {
RemoveMedia: c.RemoveMedia,
}
return json.Marshal(&x)
case "LOMDeviceRequest":
var x = struct {
RequestType string `json:"request_type"`
*LOMDeviceRequest
}{
RequestType: c.RequestType,
LOMDeviceRequest: c.LOMDeviceRequest,
}
return json.Marshal(&x)
case "Settings":
var x = struct {
RequestType string `json:"request_type"`

View File

@@ -14,6 +14,7 @@ func (c *Command) MarshalPlist() (interface{}, error) {
"CertificateList",
"SecurityInfo",
"RestartDevice",
"LOMSetupRequest",
"ShutDownDevice",
"StopMirroring",
"ClearRestrictionsPassword",
@@ -228,6 +229,14 @@ func (c *Command) MarshalPlist() (interface{}, error) {
RequestType: c.RequestType,
RemoveMedia: c.RemoveMedia,
}, nil
case "LOMDeviceRequest":
return &struct {
RequestType string
*LOMDeviceRequest
}{
RequestType: c.RequestType,
LOMDeviceRequest: c.LOMDeviceRequest,
}, nil
case "Settings":
// convert all the data plists into the dictionary inside settings before serialization.
for i, set := range c.Settings.Settings {

View File

@@ -31,6 +31,7 @@ func commandToProto(cmd *Command) (*mdmproto.Command, error) {
"CertificateList",
"SecurityInfo",
"RestartDevice",
"LOMSetupRequest",
"ShutDownDevice",
"StopMirroring",
"ClearRestrictionsPassword",
@@ -297,6 +298,24 @@ func commandToProto(cmd *Command) (*mdmproto.Command, error) {
PersistentId: cmd.RemoveMedia.PersistentID,
},
}
case "LOMDeviceRequest":
var requestList []*mdmproto.LOMDeviceRequestCommand
for _, r := range cmd.LOMDeviceRequest.RequestList {
requestList = append(requestList, &mdmproto.LOMDeviceRequestCommand{
DeviceDNSName: r.DeviceDNSName,
DeviceRequestType: r.DeviceRequestType,
DeviceRequestUUID: r.DeviceRequestUUID,
LomProtocolVersion: int64(r.LOMProtocolVersion),
PrimaryIPv6AddressList: r.PrimaryIPv6AddressList,
SecondaryIPv6AddressList: r.SecondaryIPv6AddressList,
})
}
cmdproto.Request = &mdmproto.Command_LomDeviceRequestCommand{
LomDeviceRequestCommand: &mdmproto.LOMDeviceRequest{
RequestList: requestList,
},
}
case "Settings":
var settings []*mdmproto.Setting
for _, s := range cmd.Settings.Settings {

View File

@@ -146,6 +146,27 @@ func TestMarshalCommand(t *testing.T) {
},
},
},
{
Command: Command{
RequestType: "LOMDeviceRequest",
LOMDeviceRequest: &LOMDeviceRequest{
RequestList: []LOMDeviceRequestCommand{
{
DeviceDNSName: "dns.name",
DeviceRequestType: "request.type",
DeviceRequestUUID: "uuid",
LOMProtocolVersion: 1356382,
PrimaryIPv6AddressList: []string{
"2fb2:244a:d925:ddf6:8a28:1a52:b0e2:ea62",
},
SecondaryIPv6AddressList: []string{
"2fb2:244a:d925:ddf6:8a28:1a52:b0e2:ea63",
},
},
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.Command.RequestType+"_json", func(t *testing.T) {
@@ -525,6 +546,33 @@ func TestEndToEnd(t *testing.T) {
}
},
},
{
name: "LOMDeviceRequest",
requestBytes: []byte(
`{"udid":"controllerUid","request_type":"LOMDeviceRequest","request_list":[{"device_dns_name":"deviceDnsName","device_request_type":"Reset","device_request_uuid":"B97F3491-E5E9-40D4-B163-36C41648CB46","lom_protocol_version":254,"primary_ip_v6_address_list":["primaryIpV6"],"secondary_ip_v6_address_list":["secondaryIpV6"]}]}`,
),
testFn: func(t *testing.T, parts endToEndParts) {
needToSee := [][]byte{
[]byte(`LOMDeviceRequest`),
[]byte(`deviceDnsName`),
[]byte(`Reset`),
[]byte(`B97F3491-E5E9-40D4-B163-36C41648CB46`),
[]byte(`254`),
[]byte(`primaryIpV6`),
[]byte(`secondaryIpV6`),
}
for _, b := range needToSee {
if !bytes.Contains(parts.plistData, b) {
t.Error(fmt.Sprintf("marshaled plist does not contain required bytes: '%s'", string(b)))
}
}
if parts.req.UDID != "controllerUid" {
t.Error("UDID should be set to request udid")
}
},
},
}
for _, tt := range tests {

View File

@@ -37,6 +37,7 @@ func (c *Command) UnmarshalJSON(data []byte) error {
"CertificateList",
"SecurityInfo",
"RestartDevice",
"LOMSetupRequest",
"ShutDownDevice",
"StopMirroring",
"ClearRestrictionsPassword",
@@ -222,6 +223,13 @@ func (c *Command) UnmarshalJSON(data []byte) error {
}
c.RemoveMedia = &payload
return nil
case "LOMDeviceRequest":
var payload LOMDeviceRequest
if err := json.Unmarshal(data, &payload); err != nil {
return errors.Wrapf(err, "mdm: unmarshal %s command json", c.RequestType)
}
c.LOMDeviceRequest = &payload
return nil
case "Settings":
var payload Settings
if err := json.Unmarshal(data, &payload); err != nil {

View File

@@ -21,6 +21,7 @@ func (c *Command) UnmarshalPlist(unmarshal func(i interface{}) error) error {
"CertificateList",
"SecurityInfo",
"RestartDevice",
"LOMSetupRequest",
"ShutDownDevice",
"StopMirroring",
"ClearRestrictionsPassword",
@@ -206,6 +207,13 @@ func (c *Command) UnmarshalPlist(unmarshal func(i interface{}) error) error {
}
c.RemoveMedia = &payload
return nil
case "LOMDeviceRequest":
var payload LOMDeviceRequest
if err := unmarshal(&payload); err != nil {
return errors.Wrapf(err, "mdm: unmarshal %s command plist", requestType.RequestType)
}
c.LOMDeviceRequest = &payload
return nil
case "Settings":
var payload Settings
if err := unmarshal(&payload); err != nil {

View File

@@ -17,6 +17,7 @@ func protoToCommand(pb *mdmproto.Command) *Command {
"CertificateList",
"SecurityInfo",
"RestartDevice",
"LOMSetupRequest",
"ShutDownDevice",
"StopMirroring",
"ClearRestrictionsPassword",
@@ -269,6 +270,22 @@ func protoToCommand(pb *mdmproto.Command) *Command {
MediaType: pbc.GetMediaType(),
PersistentID: pbc.GetPersistentId(),
}
case "LOMDeviceRequest":
pbc := pb.GetLomDeviceRequestCommand()
var requestList []LOMDeviceRequestCommand
for _, r := range pbc.GetRequestList() {
requestList = append(requestList, LOMDeviceRequestCommand{
DeviceDNSName: r.GetDeviceDNSName(),
DeviceRequestType: r.GetDeviceRequestType(),
DeviceRequestUUID: r.GetDeviceRequestUUID(),
LOMProtocolVersion: int(r.GetLomProtocolVersion()),
PrimaryIPv6AddressList: r.GetPrimaryIPv6AddressList(),
SecondaryIPv6AddressList: r.GetSecondaryIPv6AddressList(),
})
}
cmd.LOMDeviceRequest = &LOMDeviceRequest{
RequestList: requestList,
}
case "Settings":
pbc := pb.GetSettings()
var settings []Setting

View File

@@ -1,7 +1,7 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.26.0
// protoc v3.18.1
// protoc-gen-go v1.28.0
// protoc v3.21.2
// source: push.proto
package pushproto

View File

@@ -1,7 +1,7 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.26.0
// protoc v3.18.1
// protoc-gen-go v1.28.0
// protoc v3.21.2
// source: blueprint.proto
package blueprintproto

View File

@@ -1,7 +1,7 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.26.0
// protoc v3.18.1
// protoc-gen-go v1.28.0
// protoc v3.21.2
// source: command.proto
package commandproto

View File

@@ -1,7 +1,7 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.26.0
// protoc v3.18.1
// protoc-gen-go v1.28.0
// protoc v3.21.2
// source: config.proto
package configproto

View File

@@ -1,7 +1,7 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.26.0
// protoc v3.18.1
// protoc-gen-go v1.28.0
// protoc v3.21.2
// source: depsync.proto
package depsyncproto

View File

@@ -1,7 +1,7 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.26.0
// protoc v3.18.1
// protoc-gen-go v1.28.0
// protoc v3.21.2
// source: device.proto
package deviceproto

View File

@@ -1,7 +1,7 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.26.0
// protoc v3.18.1
// protoc-gen-go v1.28.0
// protoc v3.21.2
// source: profile.proto
package profileproto

View File

@@ -1,7 +1,7 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.26.0
// protoc v3.18.1
// protoc-gen-go v1.28.0
// protoc v3.21.2
// source: device_command.proto
package devicecommandproto

View File

@@ -1,7 +1,7 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.26.0
// protoc v3.18.1
// protoc-gen-go v1.28.0
// protoc v3.21.2
// source: remove.proto
package removeproto

View File

@@ -1,7 +1,7 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.26.0
// protoc v3.18.1
// protoc-gen-go v1.28.0
// protoc v3.21.2
// source: user.proto
package userproto

View File

@@ -0,0 +1,33 @@
#!/bin/bash
source $MICROMDM_ENV_PATH
endpoint="v1/commands"
# apple documentation https://developer.apple.com/documentation/devicemanagement/lomdevicerequestcommand/command/requestlistitem
requestUuid=$(cat /proc/sys/kernel/random/uuid)
requestUuid=${requestUuid^^}
jq -n \
--arg request_type "LOMDeviceRequest" \
--arg udid "$1" \
--arg requestUuid "$requestUuid" \
--arg deviceDnsName "$2" \
--arg deviceIpV6 "$3" \
'.udid = $udid
|.request_type = $request_type
|.request_list = [
{
"device_dns_name": $deviceDnsName,
"device_request_type": "Reset",
"device_request_uuid": $requestUuid,
"lom_protocol_version": 1,
"primary_ip_v6_address_list": [
$deviceIpV6
],
"secondary_ip_v6_address_list": [
]
}
]
'| \
curl $CURL_OPTS -K <(cat <<< "-u micromdm:$API_TOKEN") "$SERVER_URL/$endpoint" -d@-