fleet/server/contexts/certserial/certserial.go
Carlo 715d963f82
My device page (self-service) for iOS/iPadOS (#35238)
Implements #32247. This is the complete feature branch, consolidating:

- https://github.com/fleetdm/fleet/pull/35018
- https://github.com/fleetdm/fleet/pull/34758
- https://github.com/fleetdm/fleet/pull/35009
- https://github.com/fleetdm/fleet/pull/35181
- https://github.com/fleetdm/fleet/pull/35342

---------

Co-authored-by: Jonathan Katz <44128041+jkatz01@users.noreply.github.com>
Co-authored-by: RachelElysia <71795832+RachelElysia@users.noreply.github.com>
Co-authored-by: Martin Angers <martin.n.angers@gmail.com>
Co-authored-by: jkatz01 <yehonatankatz@gmail.com>
2025-11-07 17:30:51 -05:00

21 lines
748 B
Go

// Package certserial provides a context key for storing client certificate serial numbers
// extracted from HTTP headers during mTLS authentication for device endpoints.
package certserial
import "context"
type key int
const certSerialKey key = 0
// NewContext returns a new context.Context with the provided certificate serial number.
func NewContext(ctx context.Context, serial uint64) context.Context {
return context.WithValue(ctx, certSerialKey, serial)
}
// FromContext returns the certificate serial number from the context, if present.
// The second return value indicates whether a serial number was found.
func FromContext(ctx context.Context) (uint64, bool) {
serial, ok := ctx.Value(certSerialKey).(uint64)
return serial, ok
}