profile

package
v0.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 10, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package profile composes, signs and parses Apple configuration profiles.

Design

The package supplies the top-level envelope and common payload keys around generated schema/profiles values. Callers choose stable PayloadIdentifier and PayloadUUID values; a Resolver selects typed payloads during parsing. Attached CMS signing and signature-required parsing use mdmprotocol/cms.

Payload selection for MDM enrollment and OTA delivery belong to mdmprotocol/enroll. Preserving identifiers across updates is the caller's responsibility.

References

Index

Constants

View Source
const (
	ScopeSystem = "System"
	ScopeUser   = "User"
)

Scope values for PayloadScope.

View Source
const PayloadTypeConfiguration = "Configuration"

PayloadTypeConfiguration is the top-level PayloadType of every profile.

Variables

View Source
var (
	ErrInvalid = errors.New("profile: invalid")
	ErrParse   = errors.New("profile: parse")
)

Errors returned by this package.

Functions

func DefaultResolver

func DefaultResolver(payloadType string, _ map[string]any) profiles.Payload

DefaultResolver resolves a payload type through schema/profiles.

func Find

func Find[T profiles.Payload](p *Profile) (T, bool)

Find returns the first payload whose content has the type T.

func NewUUID

func NewUUID() string

NewUUID returns a fresh upper-case UUID (version 7) for PayloadUUID values. Callers keep it with the profile so updates stay in place.

Types

type ParseOptions

type ParseOptions struct {
	// Verify is applied when the data is CMS-signed. Roots nil means any
	// embedded chain is accepted; see cms.VerifyOptions.
	Verify cms.VerifyOptions
	// RequireSignature rejects unsigned input.
	RequireSignature bool
	// Resolve overrides the registry lookup. The default resolves payload
	// types with exactly one generated type and keeps the rest raw.
	Resolve Resolver
	// MaxBytes bounds the plist (default plist.Decoder default).
	MaxBytes int
}

ParseOptions configure Parse.

type Parsed

type Parsed struct {
	Profile *Profile
	// Signer is the certificate that signed the profile, nil when unsigned.
	Signer *x509.Certificate
	// Plist is the decoded (unsigned) plist bytes.
	Plist []byte
}

Parsed is the result of Parse.

func Parse

func Parse(data []byte, o ParseOptions) (*Parsed, error)

Parse reads a signed or unsigned profile back into typed payloads.

type Payload

type Payload struct {
	Identifier   string
	UUID         string
	Version      int64 // default 1
	DisplayName  string
	Description  string
	Organization string
	// Content is the payload body, a type from schema/profiles or a Raw.
	Content profiles.Payload
}

Payload is one entry in PayloadContent: the common keys plus a typed body.

func (*Payload) Map

func (pl *Payload) Map() (map[string]any, error)

Map renders one payload with its common keys.

type Profile

type Profile struct {
	Identifier        string
	UUID              string
	Version           int64 // default 1
	DisplayName       string
	Description       string
	Organization      string
	Scope             string
	RemovalDisallowed bool
	Payloads          []Payload
	// Extra top-level keys emitted verbatim (ConsentText, RemovalDate...).
	// Reserved keys set by the builder are ignored here.
	Extra map[string]any
}

Profile is a configuration profile.

func (*Profile) FindUUID

func (p *Profile) FindUUID(u string) (*Payload, bool)

FindUUID returns the payload with the PayloadUUID.

func (*Profile) Map

func (p *Profile) Map() (map[string]any, error)

Map renders the profile as plist-ready keys.

func (*Profile) Marshal

func (p *Profile) Marshal() ([]byte, error)

Marshal renders the profile as an XML plist.

func (*Profile) Sign

func (p *Profile) Sign(cert *x509.Certificate, key crypto.Signer) ([]byte, error)

Sign renders and signs the profile with an attached CMS signature, the form devices show as "Verified".

func (*Profile) Validate

func (p *Profile) Validate(t support.Target) error

Validate checks the envelope and every payload against the schema for the target. Errors are collected, not first-fail.

type Raw

type Raw struct {
	Type string
	Keys map[string]any
}

Raw is a payload whose body is kept as plist keys, for payload types with no generated type or where the registry cannot pick one.

func (*Raw) PayloadTypeName

func (r *Raw) PayloadTypeName() string

PayloadTypeName implements profiles.Payload.

func (*Raw) SchemaPath

func (*Raw) SchemaPath() string

SchemaPath implements profiles.Payload.

func (*Raw) Validate

func (*Raw) Validate(support.Target) error

Validate implements profiles.Payload; raw payloads are not validated.

type Resolver

type Resolver func(payloadType string, keys map[string]any) profiles.Payload

Resolver picks the Go type for a payload. It returns nil to keep the payload as Raw.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL