2023-06-22 20:31:17 +00:00
|
|
|
package microsoft_mdm
|
|
|
|
|
2023-06-27 15:59:33 +00:00
|
|
|
import (
|
2023-10-06 22:04:33 +00:00
|
|
|
"crypto/x509"
|
|
|
|
"encoding/base64"
|
|
|
|
|
2023-06-27 15:59:33 +00:00
|
|
|
"github.com/fleetdm/fleet/v4/server/mdm/internal/commonmdm"
|
2023-10-06 22:04:33 +00:00
|
|
|
"go.mozilla.org/pkcs7"
|
2023-06-27 15:59:33 +00:00
|
|
|
)
|
2023-06-22 20:31:17 +00:00
|
|
|
|
|
|
|
const (
|
2023-06-27 15:59:33 +00:00
|
|
|
// MDMPath is Fleet's HTTP path for the core Windows MDM service.
|
2023-06-22 20:31:17 +00:00
|
|
|
MDMPath = "/api/mdm/microsoft"
|
|
|
|
|
|
|
|
// DiscoveryPath is the HTTP endpoint path that serves the IDiscoveryService functionality.
|
|
|
|
// This is the endpoint that process the Discover and DiscoverResponse messages
|
|
|
|
// See the section 3.1 on the MS-MDE2 specification for more details:
|
|
|
|
// https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-mde2/2681fd76-1997-4557-8963-cf656ab8d887
|
|
|
|
MDE2DiscoveryPath = MDMPath + "/discovery"
|
|
|
|
|
2023-07-19 16:30:24 +00:00
|
|
|
// AuthPath is the HTTP endpoint path that delivers the Security Token Servicefunctionality.
|
|
|
|
// The MS-MDE2 protocol is agnostic to the token format and value returned by this endpoint.
|
|
|
|
// See the section 3.2 on the MS-MDE2 specification for more details:
|
|
|
|
// https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-mde2/27ed8c2c-0140-41ce-b2fa-c3d1a793ab4a
|
|
|
|
MDE2AuthPath = MDMPath + "/auth"
|
|
|
|
|
2023-06-22 20:31:17 +00:00
|
|
|
// MDE2PolicyPath is the HTTP endpoint path that delivers the X.509 Certificate Enrollment Policy (MS-XCEP) functionality.
|
|
|
|
// This is the endpoint that process the GetPolicies and GetPoliciesResponse messages
|
|
|
|
// See the section 3.3 on the MS-MDE2 specification for more details on this endpoint requirements:
|
|
|
|
// https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-mde2/8a5efdf8-64a9-44fd-ab63-071a26c9f2dc
|
|
|
|
// The MS-XCEP specification is available here:
|
|
|
|
// https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-xcep/08ec4475-32c2-457d-8c27-5a176660a210
|
|
|
|
MDE2PolicyPath = MDMPath + "/policy"
|
|
|
|
|
|
|
|
// MDE2EnrollPath is the HTTP endpoint path that delivers WS-Trust X.509v3 Token Enrollment (MS-WSTEP) functionality.
|
|
|
|
// This is the endpoint that process the RequestSecurityToken and RequestSecurityTokenResponseCollection messages
|
|
|
|
// See the section 3.4 on the MS-MDE2 specification for more details on this endpoint requirements:
|
|
|
|
// https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-mde2/5b02c625-ced2-4a01-a8e1-da0ae84f5bb7
|
|
|
|
// The MS-WSTEP specification is available here:
|
|
|
|
// https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-wstep/4766a85d-0d18-4fa1-a51f-e5cb98b752ea
|
|
|
|
MDE2EnrollPath = MDMPath + "/enroll"
|
|
|
|
|
|
|
|
// MDE2ManagementPath is the HTTP endpoint path that delivers WS-Trust X.509v3 Token Enrollment (MS-WSTEP) functionality.
|
|
|
|
// This is the endpoint that process the RequestSecurityToken and RequestSecurityTokenResponseCollection messages
|
|
|
|
// See the section 3.4 on the MS-MDE2 specification for more details:
|
|
|
|
// https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-mde2/5b02c625-ced2-4a01-a8e1-da0ae84f5bb7
|
|
|
|
MDE2ManagementPath = MDMPath + "/management"
|
|
|
|
|
2023-07-21 17:36:26 +00:00
|
|
|
// MDE2TOSPath is the HTTP endpoint path that delivers Terms of Service Content
|
|
|
|
MDE2TOSPath = MDMPath + "/tos"
|
|
|
|
|
2023-06-22 20:31:17 +00:00
|
|
|
// These are the entry points for the Microsoft Device Enrollment (MS-MDE) and Microsoft Device Enrollment v2 (MS-MDE2) protocols.
|
|
|
|
// These are required to be implemented by the MDM server to support user-driven enrollments
|
|
|
|
MSEnrollEntryPoint = "/EnrollmentServer/Discovery.svc"
|
|
|
|
MSManageEntryPoint = "/ManagementServer/MDM.svc"
|
|
|
|
)
|
|
|
|
|
2023-07-05 13:06:37 +00:00
|
|
|
// Device Enrolled States
|
|
|
|
|
|
|
|
const (
|
|
|
|
// Device is not yet MDM enrolled
|
|
|
|
MDMDeviceStateNotEnrolled = "MDMDeviceEnrolledNotEnrolled"
|
|
|
|
|
|
|
|
// Device is MDM enrolled
|
|
|
|
MDMDeviceStateEnrolled = "MDMDeviceEnrolledEnrolled"
|
|
|
|
|
|
|
|
// Device is MDM enrolled and managed
|
2023-09-13 18:59:35 +00:00
|
|
|
/* #nosec G101 -- this constant doesn't contain any credentials */
|
2023-07-05 13:06:37 +00:00
|
|
|
MDMDeviceStateManaged = "MDMDeviceEnrolledManaged"
|
|
|
|
)
|
|
|
|
|
2023-06-27 15:59:33 +00:00
|
|
|
func ResolveWindowsMDMDiscovery(serverURL string) (string, error) {
|
2023-06-22 20:31:17 +00:00
|
|
|
return commonmdm.ResolveURL(serverURL, MDE2DiscoveryPath, false)
|
|
|
|
}
|
|
|
|
|
2023-06-27 15:59:33 +00:00
|
|
|
func ResolveWindowsMDMPolicy(serverURL string) (string, error) {
|
2023-06-22 20:31:17 +00:00
|
|
|
return commonmdm.ResolveURL(serverURL, MDE2PolicyPath, false)
|
|
|
|
}
|
|
|
|
|
2023-06-27 15:59:33 +00:00
|
|
|
func ResolveWindowsMDMEnroll(serverURL string) (string, error) {
|
2023-06-22 20:31:17 +00:00
|
|
|
return commonmdm.ResolveURL(serverURL, MDE2EnrollPath, false)
|
|
|
|
}
|
2023-07-05 13:06:37 +00:00
|
|
|
|
2023-07-19 16:30:24 +00:00
|
|
|
func ResolveWindowsMDMAuth(serverURL string) (string, error) {
|
|
|
|
return commonmdm.ResolveURL(serverURL, MDE2AuthPath, false)
|
|
|
|
}
|
|
|
|
|
2023-07-05 13:06:37 +00:00
|
|
|
func ResolveWindowsMDMManagement(serverURL string) (string, error) {
|
|
|
|
return commonmdm.ResolveURL(serverURL, MDE2ManagementPath, false)
|
|
|
|
}
|
2023-10-06 22:04:33 +00:00
|
|
|
|
|
|
|
// Encrypt uses pkcs7 to encrypt a raw value using the provided certificate.
|
|
|
|
// The returned encrypted value is base64-encoded.
|
|
|
|
func Encrypt(rawValue string, cert *x509.Certificate) (string, error) {
|
|
|
|
encrypted, err := pkcs7.Encrypt([]byte(rawValue), []*x509.Certificate{cert})
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
b64Enc := base64.StdEncoding.EncodeToString(encrypted)
|
|
|
|
return b64Enc, nil
|
|
|
|
}
|