mirror of
https://github.com/micromdm/micromdm/
synced 2026-08-09 02:55:59 +08:00
In iOS 10.13/macOS 10.15 a new, BYOD specific enrollment type was added, called User Enrollment. This enrollment type replaces the typical UDID field in checkin and acknowledge requests with a EnrollmentID field which is unique per each enrollment. One important aspect of this enrollment type is that no personally identifiable information is available to the MDM (UDID, SerialNumber). The implementation implemented here adds the new EnrollmentID field where appropriate, and ensures that the device tables do not store the enrollment ID. I will follow up this change set with one that allows listing/removing current enrollment IDs in a similar way that mdmctl get devices and mdmctl get users does.
81 lines
1.9 KiB
Go
81 lines
1.9 KiB
Go
package apns
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/go-kit/kit/log"
|
|
"github.com/go-kit/kit/log/level"
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/micromdm/micromdm/mdm"
|
|
"github.com/micromdm/micromdm/platform/pubsub"
|
|
)
|
|
|
|
type WorkerStore interface {
|
|
Save(context.Context, *PushInfo) error
|
|
}
|
|
|
|
type Worker struct {
|
|
db WorkerStore
|
|
sub pubsub.Subscriber
|
|
logger log.Logger
|
|
}
|
|
|
|
func NewWorker(db WorkerStore, subscriber pubsub.Subscriber, logger log.Logger) *Worker {
|
|
return &Worker{
|
|
db: db,
|
|
sub: subscriber,
|
|
logger: logger,
|
|
}
|
|
}
|
|
|
|
func (w *Worker) Run(ctx context.Context) error {
|
|
const subscription = "pushinfo_worker"
|
|
tokenUpdateEvents, err := w.sub.Subscribe(ctx, subscription, mdm.TokenUpdateTopic)
|
|
if err != nil {
|
|
return errors.Wrapf(err,
|
|
"subscribing %s to %s topic", subscription, mdm.TokenUpdateTopic)
|
|
}
|
|
|
|
for {
|
|
var err error
|
|
select {
|
|
case <-ctx.Done():
|
|
return ctx.Err()
|
|
case event := <-tokenUpdateEvents:
|
|
err = w.updatePushInfoFromTokenUpdate(ctx, event.Message)
|
|
}
|
|
if err != nil {
|
|
level.Info(w.logger).Log(
|
|
"msg", "update pushinfo from event",
|
|
"err", err,
|
|
)
|
|
continue
|
|
}
|
|
}
|
|
}
|
|
|
|
func (w *Worker) updatePushInfoFromTokenUpdate(ctx context.Context, message []byte) error {
|
|
var ev mdm.CheckinEvent
|
|
if err := mdm.UnmarshalCheckinEvent(message, &ev); err != nil {
|
|
return errors.Wrap(err, "unmarshal pushinfo event")
|
|
}
|
|
info := PushInfo{
|
|
UDID: ev.Command.UDID,
|
|
Token: ev.Command.Token.String(),
|
|
PushMagic: ev.Command.PushMagic,
|
|
MDMTopic: ev.Command.Topic,
|
|
}
|
|
// UDID is the primary key for storing the APNS values.
|
|
// For MDM managed users, use the UserID instead,
|
|
// and for BYOD User Enrollment, use the EnrollmentID.
|
|
if ev.Command.UserID != "" {
|
|
info.UDID = ev.Command.UserID
|
|
}
|
|
if ev.Command.EnrollmentID != "" {
|
|
info.UDID = ev.Command.EnrollmentID
|
|
}
|
|
err := w.db.Save(ctx, &info)
|
|
return errors.Wrapf(err, "saving pushinfo for udid=%s", info.UDID)
|
|
}
|