http

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 25, 2021 License: MIT Imports: 18 Imported by: 1

Documentation

Overview

Package http includes handlers and utilties

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CertExtractMdmSignatureMiddleware

func CertExtractMdmSignatureMiddleware(next http.Handler, logger log.Logger) http.HandlerFunc

CertExtractMdmSignatureMiddleware extracts the MDM enrollment identity certificate from the request into the HTTP request context. It tries to verify the Mdm-Signature header on the request.

This middleware does not error if a certificate is not found. It will, however, error with an HTTP 400 status if the signature verification fails.

func CertExtractPEMHeaderMiddleware

func CertExtractPEMHeaderMiddleware(next http.Handler, header string, logger log.Logger) http.HandlerFunc

CertExtractPEMHeaderMiddleware extracts the MDM enrollment identity certificate from the request into the HTTP request context. It looks at the request header which should be a URL-encoded PEM certificate.

This is ostensibly to support Nginx' $ssl_client_escaped_cert in a proxy_set_header directive. Though any reverse proxy setting a similar header could be used, of course.

func CertExtractTLSMiddleware

func CertExtractTLSMiddleware(next http.Handler, logger log.Logger) http.HandlerFunc

CertExtractTLSMiddleware extracts the MDM enrollment identity certificate from the request into the HTTP request context. It looks at the TLS peer certificate in the request.

func CertVerifyMiddleware

func CertVerifyMiddleware(next http.Handler, verifier CertVerifier, logger log.Logger) http.HandlerFunc

CertVerifyMiddleware checks the MDM certificate against verifier and returns an error if it fails.

We deliberately do not reply with 401 as this may cause unintentional MDM unenrollments in the case of bugs or something going wrong.

func CheckinAndCommandHandlerFunc

func CheckinAndCommandHandlerFunc(service service.CheckinAndCommandService, logger log.Logger) http.HandlerFunc

CheckinAndCommandHandlerFunc handles both check-in and command requests.

func CheckinHandlerFunc

func CheckinHandlerFunc(svc service.Checkin, logger log.Logger) http.HandlerFunc

CheckinHandlerFunc decodes an MDM check-in request and adapts it to service.

func CommandAndReportResultsHandlerFunc

func CommandAndReportResultsHandlerFunc(svc service.CommandAndReportResults, logger log.Logger) http.HandlerFunc

CommandAndReportResultsHandlerFunc decodes an MDM command request and adapts it to service.

func GetCert

func GetCert(ctx context.Context) *x509.Certificate

GetCert retrieves the MDM enrollment identity certificate from the HTTP request context.

func PushHandlerFunc

func PushHandlerFunc(pusher push.Pusher, logger log.Logger) http.HandlerFunc

PushHandlerFunc sends APNs push notifications to MDM enrollments.

Note the whole URL path is used as the identifier to push to. This probably necessitates stripping the URL prefix before using. Also note we expose Go errors to the output as this is meant for "API" users.

func RawCommandEnqueueHandler

func RawCommandEnqueueHandler(enqueuer storage.CommandEnqueuer, pusher push.Pusher, logger log.Logger) http.HandlerFunc

RawCommandEnqueueHandler enqueues a raw MDM command plist and sends push notifications to MDM enrollments.

Note the whole URL path is used as the identifier to enqueue (and push to. This probably necessitates stripping the URL prefix before using. Also note we expose Go errors to the output as this is meant for "API" users.

func ReadAllAndReplaceBody

func ReadAllAndReplaceBody(r *http.Request) ([]byte, error)

ReadAllAndReplaceBody reads all of r.Body and replaces it with a new byte buffer.

func StorePushCertHandlerFunc

func StorePushCertHandlerFunc(storage storage.PushCertStore, logger log.Logger) http.HandlerFunc

StorePushCertHandlerFunc reads a PEM-encoded certificate and private key from the HTTP body and saves it to storage. This effectively enables us to do something like: "% cat push.pem push.key | curl -T - http://api.example.com/" to upload our push certs.

Types

type CertVerifier

type CertVerifier interface {
	Verify(*x509.Certificate) error
}

CertVerifier is a simple interface for verifying a certificate.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL