Allow signed profiles to be uploaded by checking for PKCS7 (#218)

* Allow signed profiles to be uploaded by checking for PKCS7

* Remove comment
This commit is contained in:
Jesse Peterson
2017-06-25 20:17:44 -07:00
committed by GitHub
parent 20689679ae
commit db014d3a0e

View File

@@ -1,8 +1,9 @@
package profile
import (
"errors"
"github.com/pkg/errors"
"github.com/fullsailor/pkcs7"
"github.com/gogo/protobuf/proto"
"github.com/groob/plist"
"github.com/micromdm/micromdm/profile/internal/profileproto"
@@ -16,9 +17,20 @@ type payloadIdentifier struct {
}
func (mc *Mobileconfig) GetPayloadIdentifier() (string, error) {
// TODO: support CMS signed profiles
mcBytes := *mc
if len(mcBytes) > 5 && string(mcBytes[0:5]) != "<?xml" {
p7, err := pkcs7.Parse(mcBytes)
if err != nil {
return "", errors.Wrapf(err, "Mobileconfig is not XML nor PKCS7 parseable")
}
err = p7.Verify()
if err != nil {
return "", err
}
mcBytes = Mobileconfig(p7.Content)
}
var pId payloadIdentifier
err := plist.Unmarshal(*mc, &pId)
err := plist.Unmarshal(mcBytes, &pId)
if err != nil {
return "", err
}