mirror of
https://github.com/micromdm/micromdm/
synced 2026-08-08 10:45:34 +08:00
small push service
This commit is contained in:
@@ -60,3 +60,4 @@ data:
|
||||
- /certs.d
|
||||
- /pkgrepo
|
||||
- /profiles
|
||||
- /mdmkeys
|
||||
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -2,3 +2,6 @@ vendor/
|
||||
.docker/data/root/
|
||||
micromdm
|
||||
.k8/
|
||||
*.crt
|
||||
*.key
|
||||
*.p12
|
||||
|
||||
@@ -28,18 +28,23 @@ func decodeMDMCheckinRequest(r *http.Request) (interface{}, error) {
|
||||
func decodeMDMEnrollmentRequest(r *http.Request) (interface{}, error) {
|
||||
data, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return nil, err
|
||||
}
|
||||
fmt.Println(string(data))
|
||||
p7, err := pkcs7.Parse(data)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return nil, err
|
||||
}
|
||||
// TODO: We should verify but not currently possible. Apple
|
||||
// does no provide a cert for the CA.
|
||||
var request depEnrollmentRequest
|
||||
if err := plist.Unmarshal(p7.Content, &request); err != nil {
|
||||
log.Println(err)
|
||||
return nil, err
|
||||
}
|
||||
fmt.Println(request)
|
||||
return request, nil
|
||||
}
|
||||
|
||||
|
||||
68
checkin/push/push.go
Normal file
68
checkin/push/push.go
Normal file
@@ -0,0 +1,68 @@
|
||||
package mdmpush
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/RobotsAndPencils/buford/certificate"
|
||||
"github.com/RobotsAndPencils/buford/payload"
|
||||
"github.com/RobotsAndPencils/buford/push"
|
||||
"github.com/go-kit/kit/log"
|
||||
)
|
||||
|
||||
// Pusher pushes things
|
||||
type Pusher interface {
|
||||
Push(magic, token string)
|
||||
}
|
||||
|
||||
//New returns a Pusher
|
||||
func New(logger log.Logger, certPath, password string) Pusher {
|
||||
filename := certPath
|
||||
cert, key, err := certificate.Load(filename, password)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
logger.Log("err", err)
|
||||
}
|
||||
client, err := push.NewClient(certificate.TLS(cert, key))
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
logger.Log("err", err)
|
||||
}
|
||||
service := &push.Service{
|
||||
Client: client,
|
||||
Host: push.Production,
|
||||
}
|
||||
|
||||
pusher := pushSvc{
|
||||
client: service,
|
||||
logger: logger,
|
||||
}
|
||||
|
||||
return pusher
|
||||
}
|
||||
|
||||
type pushSvc struct {
|
||||
client *push.Service
|
||||
logger log.Logger
|
||||
}
|
||||
|
||||
func (svc pushSvc) Push(magic, token string) {
|
||||
svc.logger.Log("action", "push", "magic", magic, "token", token)
|
||||
enc := token
|
||||
|
||||
p := payload.MDM{Token: magic}
|
||||
json.NewEncoder(os.Stdout).Encode(p)
|
||||
valid := push.IsDeviceTokenValid(enc)
|
||||
if !valid {
|
||||
svc.logger.Log("err", "Invalid Token")
|
||||
return
|
||||
}
|
||||
id, err := svc.client.Push(enc, nil, p)
|
||||
if err != nil {
|
||||
svc.logger.Log("err", err)
|
||||
return
|
||||
}
|
||||
svc.logger.Log("action", "push", "magic", magic, "token", token, "id", id)
|
||||
fmt.Println("success")
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
httptransport "github.com/go-kit/kit/transport/http"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/micromdm/mdm"
|
||||
"github.com/micromdm/micromdm/checkin/push"
|
||||
"github.com/micromdm/micromdm/device"
|
||||
stdprometheus "github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
@@ -40,7 +41,9 @@ func NewCheckinService(options ...func(*config) error) MDMCheckinService {
|
||||
}
|
||||
}
|
||||
var svc MDMCheckinService
|
||||
svc = mdmCheckinService{conf.db}
|
||||
// p := mdmpush.New(conf.logger, conf.pushcert, conf.pushpass)
|
||||
// svc = mdmCheckinServie{pushsvc: p, db: conf.db}
|
||||
svc = mdmCheckinService{db: conf.db}
|
||||
if conf.logger != nil {
|
||||
svc = loggingMiddleware{conf.logger, svc}
|
||||
}
|
||||
@@ -74,13 +77,25 @@ func Datastore(db device.Datastore) func(*config) error {
|
||||
}
|
||||
}
|
||||
|
||||
//Push creates a push client
|
||||
func Push(cert, password string) func(*config) error {
|
||||
return func(c *config) error {
|
||||
c.pushcert = cert
|
||||
c.pushpass = password
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
type config struct {
|
||||
logger log.Logger
|
||||
db device.Datastore
|
||||
pushcert string //path to cert
|
||||
pushpass string //password for cert
|
||||
logger log.Logger
|
||||
db device.Datastore
|
||||
}
|
||||
|
||||
type mdmCheckinService struct {
|
||||
db device.Datastore
|
||||
pushsvc mdmpush.Pusher
|
||||
db device.Datastore
|
||||
}
|
||||
|
||||
func (svc mdmCheckinService) Authenticate(cmd mdm.CheckinCommand) error {
|
||||
@@ -114,6 +129,7 @@ func (svc mdmCheckinService) TokenUpdate(cmd mdm.CheckinCommand) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// svc.pushsvc.Push(cmd.PushMagic, token)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
redis:
|
||||
image: redis
|
||||
restart: always
|
||||
ports:
|
||||
- "6379:6379"
|
||||
|
||||
postgres:
|
||||
image: postgres
|
||||
restart: always
|
||||
|
||||
16
glide.lock
generated
16
glide.lock
generated
@@ -1,5 +1,5 @@
|
||||
hash: 8fe304e9385e4fbe963eba356a9784b3217ae75b65f50178322a7e1e41950e8d
|
||||
updated: 2016-05-03T12:33:50.516339682-04:00
|
||||
updated: 2016-05-05T14:49:55.86880083-04:00
|
||||
imports:
|
||||
- name: github.com/beorn7/perks
|
||||
version: 3ac7bf7a47d159a033b107610db8a1b6575507a4
|
||||
@@ -69,11 +69,25 @@ imports:
|
||||
- model
|
||||
- name: github.com/prometheus/procfs
|
||||
version: abf152e5f3e97f2fafac028d2cc06c1feb87ffa5
|
||||
- name: github.com/RobotsAndPencils/buford
|
||||
version: 2861f2a5612806afe88232539f5e4255d39ae544
|
||||
subpackages:
|
||||
- certificate
|
||||
- payload
|
||||
- push
|
||||
- payload/badge
|
||||
- name: github.com/satori/go.uuid
|
||||
version: f9ab0dce87d815821e221626b772e3475a0d2749
|
||||
- name: golang.org/x/crypto
|
||||
version: 019870fc9d457ee8abd13a2e93e3f2a3b55b7119
|
||||
subpackages:
|
||||
- pkcs12
|
||||
- pkcs12/internal/rc2
|
||||
- name: golang.org/x/net
|
||||
version: b797637b7aeeed133049c7281bfa31dcc9ca42d6
|
||||
subpackages:
|
||||
- context
|
||||
- context/ctxhttp
|
||||
- http2
|
||||
- http2/hpack
|
||||
devImports: []
|
||||
|
||||
3
main.go
3
main.go
@@ -38,6 +38,8 @@ func main() {
|
||||
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")
|
||||
flPushCert = flag.String("push-cert", envString("MICROMDM_PUSH_CERT", ""), "path to push certificate")
|
||||
flPushPass = flag.String("push-pass", envString("MICROMDM_PUSH_PASS", ""), "push certificate password")
|
||||
)
|
||||
|
||||
// set tls to true by default. let user set it to false
|
||||
@@ -104,6 +106,7 @@ func main() {
|
||||
checkinSvc := checkin.NewCheckinService(
|
||||
checkin.Datastore(deviceDB),
|
||||
checkin.Logger(logger),
|
||||
checkin.Push(*flPushCert, *flPushPass),
|
||||
)
|
||||
checkinHandler := checkin.ServiceHandler(ctx, checkinSvc)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user