deriveOAuthSigningKey produces a 32-byte HMAC key dedicated to fosite from the master secret used for X-E2A-Auth-* header signing. Key separation matters here: the master also signs HITL approval links and email headers, and rotating one signing domain shouldn't tear down the other two. HKDF-SHA256
(master []byte)
| 33 | // production mode — a short dev secret would otherwise reach fosite |
| 34 | // and panic at the first Generate. |
| 35 | func deriveOAuthSigningKey(master []byte) ([]byte, error) { |
| 36 | if len(master) < 32 { |
| 37 | return nil, fmt.Errorf("oauth: master hmac secret is %d bytes, need ≥32", len(master)) |
| 38 | } |
| 39 | kdf := hkdf.New(sha256.New, master, nil, []byte(oauthSigningKeyLabel)) |
| 40 | out := make([]byte, 32) |
| 41 | if _, err := io.ReadFull(kdf, out); err != nil { |
| 42 | return nil, fmt.Errorf("oauth: derive signing key: %w", err) |
| 43 | } |
| 44 | return out, nil |
| 45 | } |
| 46 | |
| 47 | // Token / code lifetimes. Exported as constants so handler code that |
| 48 | // needs to write them onto the session before persistence can stay in |