Parse APNS Topic from push certificate in enroll service constructor.

This commit is contained in:
Mosen
2016-06-28 22:41:00 +10:00
committed by Victor Vrantchan
parent 82f657ef6a
commit e2492daddc
3 changed files with 38 additions and 4 deletions

29
enroll/certificates.go Normal file
View 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.")
}

View File

@@ -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 {

View File

@@ -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)