Allow passing in PEM MDM cert and key (#60)

closes #55
This commit is contained in:
Jesse Peterson
2016-11-16 15:38:45 -08:00
committed by Victor Vrantchan
parent 08528c207e
commit 0dc1a18eea
2 changed files with 2 additions and 35 deletions

View File

@@ -1,29 +0,0 @@
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

@@ -10,13 +10,9 @@ type Service interface {
Enroll(ctx context.Context) (Profile, error)
}
func NewService(pushCertPath, pushCertPass, caCertPath, scepURL, scepChallenge, url, tlsCertPath, scepSubject string) (Service, error) {
pushTopic, err := GetPushTopicFromPKCS12(pushCertPath, pushCertPass)
if err != nil {
return nil, err
}
func NewService(pushTopic, caCertPath, scepURL, scepChallenge, url, tlsCertPath, scepSubject string) (Service, error) {
var caCert, tlsCert []byte
var err error
if caCertPath != "" {
caCert, err = ioutil.ReadFile(caCertPath)