mirror of
https://github.com/micromdm/micromdm/
synced 2026-08-12 04:55:39 +08:00
first try at DEP enrollemnt
This commit is contained in:
committed by
Victor Vrantchan
parent
c14379849d
commit
8c89ba43de
@@ -2,14 +2,21 @@ package enroll
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/go-kit/kit/endpoint"
|
||||
"github.com/micromdm/mdm"
|
||||
)
|
||||
|
||||
type Endpoints struct {
|
||||
GetEnrollEndpoint endpoint.Endpoint
|
||||
}
|
||||
|
||||
type depEnrollmentRequest struct {
|
||||
mdm.DEPEnrollmentRequest
|
||||
}
|
||||
|
||||
type mdmEnrollRequest struct{}
|
||||
|
||||
type mdmEnrollResponse struct {
|
||||
@@ -25,7 +32,16 @@ func MakeServerEndpoints(s Service) Endpoints {
|
||||
|
||||
func MakeGetEnrollEndpoint(s Service) endpoint.Endpoint {
|
||||
return func(ctx context.Context, request interface{}) (interface{}, error) {
|
||||
profile, err := s.Enroll(ctx)
|
||||
return mdmEnrollResponse{profile, err}, nil
|
||||
switch req := request.(type) {
|
||||
case mdmEnrollRequest:
|
||||
profile, err := s.Enroll(ctx)
|
||||
return mdmEnrollResponse{profile, err}, nil
|
||||
case depEnrollmentRequest:
|
||||
fmt.Printf("got DEP enrollment request from %s\n", req.Serial)
|
||||
profile, err := s.Enroll(ctx)
|
||||
return mdmEnrollResponse{profile, err}, nil
|
||||
default:
|
||||
return nil, errors.New("unknown enrollment type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,11 @@ package enroll
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
|
||||
"github.com/fullsailor/pkcs7"
|
||||
"github.com/go-kit/kit/log"
|
||||
httptransport "github.com/go-kit/kit/transport/http"
|
||||
"github.com/gorilla/mux"
|
||||
@@ -17,7 +20,7 @@ func ServiceHandler(ctx context.Context, svc Service, logger log.Logger) http.Ha
|
||||
opts := []httptransport.ServerOption{
|
||||
httptransport.ServerErrorLogger(logger),
|
||||
}
|
||||
r.Methods("GET").Path("/mdm/enroll").Handler(httptransport.NewServer(
|
||||
r.Methods("GET", "POST").Path("/mdm/enroll").Handler(httptransport.NewServer(
|
||||
e.GetEnrollEndpoint,
|
||||
decodeMDMEnrollRequest,
|
||||
encodeResponse,
|
||||
@@ -28,7 +31,28 @@ func ServiceHandler(ctx context.Context, svc Service, logger log.Logger) http.Ha
|
||||
}
|
||||
|
||||
func decodeMDMEnrollRequest(_ context.Context, r *http.Request) (interface{}, error) {
|
||||
return r, nil
|
||||
switch r.Method {
|
||||
case "GET":
|
||||
return mdmEnrollRequest{}, nil
|
||||
case "POST":
|
||||
data, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p7, err := pkcs7.Parse(data)
|
||||
if err != nil {
|
||||
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 {
|
||||
return nil, err
|
||||
}
|
||||
return request, nil
|
||||
default:
|
||||
return nil, errors.New("unknown enrollment method")
|
||||
}
|
||||
}
|
||||
|
||||
func encodeResponse(ctx context.Context, w http.ResponseWriter, response interface{}) error {
|
||||
|
||||
Reference in New Issue
Block a user