Add cli flag tls-ca-cert and environment var MICROMDM_TLS_CA_CERT to specify a CA certificate which will be included in the enrollment profile. This is handy if you are using self signed certificates and you need to establish a CA trust.

This commit is contained in:
Mosen
2016-06-29 16:29:19 +10:00
committed by Victor Vrantchan
parent 3ca4e954e8
commit 49fa779d1c
2 changed files with 25 additions and 8 deletions

View File

@@ -1,15 +1,27 @@
package enroll
import "io/ioutil"
type Service interface {
Enroll() (Profile, error)
}
func NewService(pushCertPath string, pushCertPass string) (Service, error) {
func NewService(pushCertPath string, pushCertPass string, caCertPath string) (Service, error) {
pushTopic, err := GetPushTopicFromPKCS12(pushCertPath, pushCertPass)
if err != nil {
return nil, err
}
var caCert []byte
if caCertPath != "" {
caCert, err = ioutil.ReadFile(caCertPath)
if err != nil {
return nil, err
}
}
scepSubject := [][][]string{
[][]string{
[]string{"O", "MicroMDM"},
@@ -22,7 +34,7 @@ func NewService(pushCertPath string, pushCertPass string) (Service, error) {
SCEPUrl: "http://micromdm.local:2019/scep",
SCEPSubject: scepSubject,
Topic: pushTopic,
CACert: []byte{},
CACert: caCert,
}, nil
}
@@ -73,12 +85,16 @@ func (svc service) Enroll() (Profile, error) {
Topic: svc.Topic,
}
//caPayload := NewPayload("com.apple.ssl.certificate")
//caPayload.PayloadDisplayName = "Root certificate for MicroMDM"
//caPayload.PayloadDescription = "Installs the root CA certificate for MicroMDM"
//caPayload.PayloadContent = []byte{}
if len(svc.CACert) > 0 {
caPayload := NewPayload("com.apple.ssl.certificate")
caPayload.PayloadDisplayName = "Root certificate for MicroMDM"
caPayload.PayloadDescription = "Installs the root CA certificate for MicroMDM"
caPayload.PayloadContent = svc.CACert
profile.PayloadContent = []interface{}{*scepPayload, mdmPayloadContent}
profile.PayloadContent = []interface{}{*scepPayload, mdmPayloadContent, *caPayload}
} else {
profile.PayloadContent = []interface{}{*scepPayload, mdmPayloadContent}
}
return *profile, nil
}

View File

@@ -43,6 +43,7 @@ func main() {
flTLS = flag.Bool("tls", envBool("MICROMDM_USE_TLS"), "use https")
flTLSCert = flag.String("tls-cert", envString("MICROMDM_TLS_CERT", ""), "path to TLS certificate")
flTLSKey = flag.String("tls-key", envString("MICROMDM_TLS_KEY", ""), "path to TLS private key")
flTLSCACert = flag.String("tls-ca-cert", envString("MICROMDM_TLS_CA_CERT", ""), "path to CA certificate")
flPGconn = flag.String("postgres", envString("MICROMDM_POSTGRES_CONN_URL", ""), "postgres connection url")
flRedisconn = flag.String("redis", envString("MICROMDM_REDIS_CONN_URL", ""), "redis connection url")
flVersion = flag.Bool("version", false, "print version information")
@@ -188,7 +189,7 @@ func main() {
commandSvc := command.NewService(commandDB)
checkinSvc := checkin.NewService(deviceDB, mgmtSvc, commandSvc, enrollmentProfile)
connectSvc := connect.NewService(deviceDB, commandSvc)
enrollSvc, _ := enroll.NewService(*flPushCert, *flPushPass)
enrollSvc, _ := enroll.NewService(*flPushCert, *flPushPass, *flTLSCACert)
httpLogger := log.NewContext(logger).With("component", "http")
managementHandler := management.ServiceHandler(ctx, mgmtSvc, httpLogger)