mirror of
https://github.com/micromdm/micromdm/
synced 2026-08-12 04:55:39 +08:00
Parse APNS Topic from push certificate in enroll service constructor.
This commit is contained in:
29
enroll/certificates.go
Normal file
29
enroll/certificates.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package enroll
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"golang.org/x/crypto/pkcs12"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
const PushTopicASN1 string = "0.9.2342.19200300.100.1.1"
|
||||
|
||||
func GetPushTopicFromPKCS12(certPath string, certPass string) (string, error) {
|
||||
certData, err := ioutil.ReadFile(certPath)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
_, cert, err := pkcs12.Decode(certData, certPass)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
for _, v := range cert.Subject.Names {
|
||||
if v.Type.String() == PushTopicASN1 {
|
||||
return v.Value.(string), nil
|
||||
}
|
||||
}
|
||||
|
||||
return "", errors.New("Could not find Push Topic in the provided pkcs12 bundle.")
|
||||
}
|
||||
@@ -4,7 +4,12 @@ type Service interface {
|
||||
Enroll() (Profile, error)
|
||||
}
|
||||
|
||||
func NewService() Service {
|
||||
func NewService(pushCertPath string, pushCertPass string) (Service, error) {
|
||||
pushTopic, err := GetPushTopicFromPKCS12(pushCertPath, pushCertPass)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
scepSubject := [][][]string{
|
||||
[][]string{
|
||||
[]string{"O", "MicroMDM"},
|
||||
@@ -16,9 +21,9 @@ func NewService() Service {
|
||||
Url: "https://micromdm.local:6443",
|
||||
SCEPUrl: "http://micromdm.local:2019/scep",
|
||||
SCEPSubject: scepSubject,
|
||||
Topic: "",
|
||||
Topic: pushTopic,
|
||||
CACert: []byte{},
|
||||
}
|
||||
}, nil
|
||||
}
|
||||
|
||||
type service struct {
|
||||
|
||||
2
main.go
2
main.go
@@ -188,7 +188,7 @@ func main() {
|
||||
commandSvc := command.NewService(commandDB)
|
||||
checkinSvc := checkin.NewService(deviceDB, mgmtSvc, commandSvc, enrollmentProfile)
|
||||
connectSvc := connect.NewService(deviceDB, commandSvc)
|
||||
enrollSvc := enroll.NewService()
|
||||
enrollSvc, _ := enroll.NewService(*flPushCert, *flPushPass)
|
||||
|
||||
httpLogger := log.NewContext(logger).With("component", "http")
|
||||
managementHandler := management.ServiceHandler(ctx, mgmtSvc, httpLogger)
|
||||
|
||||
Reference in New Issue
Block a user