mirror of
https://github.com/hanzoai/iam.git
synced 2026-11-19 18:37:16 +00:00
This repo is public and its LICENSE called the source "confidential and
proprietary ... All rights reserved". Public visibility contradicts
confidentiality, and HIP-0130 puts `iam` in the OSS core tier. The declaration
now matches both.
LICENSE-APACHE and LICENSE-MIT carry the canonical texts, unedited —
LICENSE-APACHE is byte-identical to apache.org/licenses/LICENSE-2.0.txt
(sha256 cfc7749b…, 11358 bytes, blob d645695). LICENSE declares the pair.
LICENSE-MIT carries the copyright line the notice requires.
249 Go files led with `// Copyright 2026 Hanzo AI, Inc. All rights reserved.`
— the classic proprietary reservation, and a per-file contradiction of the new
grant. Each now carries `// SPDX-License-Identifier: MIT OR Apache-2.0`. The
word "confidential" survives untouched in the OIDC sense (confidential client),
which is protocol vocabulary, not a licence claim.
There is nothing else to declare: `go.mod` has no licence field and this repo
ships no Cargo/npm/PyPI manifest.
Relicensing is ours alone to do. The tree is original work, not a fork:
`fork: false` with no parent, its own root commit, and no Casdoor-lineage tag
is an ancestor of `main`. The retired Casdoor fork is `hanzoai/iam-v1`; the
provenance note in LICENSE names it, restoring the vendor name a clean-room
assertion needs in order to say what it is clean of.
Build, vet and all 29 test packages green.
Co-authored-by: Hanzo Dev <[email protected]>
63 lines
2.4 KiB
Go
63 lines
2.4 KiB
Go
// Copyright 2026 Hanzo AI, Inc.
|
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
|
|
|
package oidc
|
|
|
|
import (
|
|
"crypto/subtle"
|
|
"errors"
|
|
|
|
"github.com/hanzoai/iam/pkg/pkce"
|
|
)
|
|
|
|
// PKCE (RFC 7636) — S256 only. iam permanently rejects the "plain" method:
|
|
// a downgrade to plain defeats the point of PKCE (the verifier travels in the
|
|
// clear), so an authorize request that stored a plain challenge, or a token
|
|
// request that presents one, is refused.
|
|
|
|
var (
|
|
// ErrPKCEPlainRejected is returned when a challenge method other than S256
|
|
// is presented. Never accept "plain".
|
|
ErrPKCEPlainRejected = errors.New("pkce: only S256 is supported (plain is rejected)")
|
|
// ErrPKCEMismatch is returned when the verifier does not derive the stored
|
|
// challenge. Constant-time — the error is identical regardless of where the
|
|
// bytes diverge.
|
|
ErrPKCEMismatch = errors.New("pkce: code_verifier does not match code_challenge")
|
|
// ErrPKCEMissing is returned when a challenge was stored but no verifier was
|
|
// presented (or vice-versa).
|
|
ErrPKCEMissing = errors.New("pkce: code_verifier required")
|
|
)
|
|
|
|
// VerifyPKCE checks a code_verifier against a stored (challenge, method).
|
|
//
|
|
// - A stored challenge with method != "S256" is refused (ErrPKCEPlainRejected)
|
|
// — including an empty method, which some clients send for plain.
|
|
// - An empty stored challenge means the authorization code was minted WITHOUT
|
|
// PKCE; the caller decides whether that path is allowed (public clients must
|
|
// require it). This function returns nil for (empty, empty) so a caller can
|
|
// treat "no PKCE on either side" as not-an-error and enforce its own policy.
|
|
// - A stored challenge with an empty verifier is ErrPKCEMissing.
|
|
// - Otherwise the verifier is hashed and compared to the challenge in constant
|
|
// time (subtle.ConstantTimeCompare), so a mismatch leaks no position.
|
|
func VerifyPKCE(verifier, challenge, method string) error {
|
|
if challenge == "" {
|
|
if verifier != "" {
|
|
// A verifier with no stored challenge is a protocol error, but it is
|
|
// not a match either — treat as missing so the caller fails closed.
|
|
return ErrPKCEMissing
|
|
}
|
|
return nil // no PKCE on either side; caller enforces public-client policy
|
|
}
|
|
if method != pkce.Method {
|
|
return ErrPKCEPlainRejected
|
|
}
|
|
if verifier == "" {
|
|
return ErrPKCEMissing
|
|
}
|
|
want := pkce.Challenge(verifier)
|
|
if subtle.ConstantTimeCompare([]byte(want), []byte(challenge)) != 1 {
|
|
return ErrPKCEMismatch
|
|
}
|
|
return nil
|
|
}
|