| 1 |
// Package state serializes, protects, and restores the OAuth2 state parameter |
| 2 |
// used during OpenVPN web authentication. |
| 3 |
// |
| 4 |
// The state value is sent to the VPN client as part of the authentication URL |
| 5 |
// and returns later through the browser callback. The client can see and modify |
| 6 |
// that value, so it must be treated as attacker-controlled input. Decrypt |
| 7 |
// accepts a state value only after the cryptographic layer has authenticated it, |
| 8 |
// which protects the OpenVPN client identifiers, client address, and session |
| 9 |
// state from undetected manipulation. |
| 10 |
// |
| 11 |
// The representation is intentionally compact. OpenVPN accepts at most 1023 |
| 12 |
// bytes for the complete client-pending-auth management command. The encrypted |
| 13 |
// state shares that budget with command metadata, the configured base URL, and |
| 14 |
// the callback path. Encrypt therefore uses a versioned binary payload with |
| 15 |
// varint client identifiers, flag-controlled optional fields, compact |
| 16 |
// session-state codes, binary IP address fields, unpadded URL-safe base64, and |
| 17 |
// an AES-256-GCM envelope. This keeps the command inside the OpenVPN |
| 18 |
// management interface constraint while preserving integrity and expiry checks |
| 19 |
// for untrusted input. |
| 20 |
package state |