package mdm import ( "bytes" "crypto" "crypto/aes" "crypto/cipher" "crypto/rand" "crypto/x509" "encoding/base64" "fmt" "io" "github.com/smallstep/pkcs7" ) // MaxProfileRetries is the maximum times an install profile command may be // retried, after which marked as failed and no further attempts will be made // to install the profile. const MaxProfileRetries = 1 // DecryptBase64CMS decrypts a base64 encoded pkcs7-encrypted value using the // provided certificate and private key. func DecryptBase64CMS(p7Base64 string, cert *x509.Certificate, key crypto.PrivateKey) ([]byte, error) { p7Bytes, err := base64.StdEncoding.DecodeString(p7Base64) if err != nil { return nil, err } p7, err := pkcs7.Parse(p7Bytes) if err != nil { return nil, err } return p7.Decrypt(cert, key) } func prefixMatches(val []byte, prefix string) bool { return len(val) >= len(prefix) && bytes.EqualFold([]byte(prefix), val[:len(prefix)]) } // GetRawProfilePlatform identifies the platform type of a profile bytes by // examining its initial content: // // - Returns "darwin" if the profile starts with "