mirror of
https://github.com/micromdm/micromdm/
synced 2026-08-12 04:55:39 +08:00
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:
@@ -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
|
||||
}
|
||||
|
||||
3
main.go
3
main.go
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user