Files
iam/pkg/pkce/pkce.go
zeekayandHanzo Dev 084011934f legal: dual MIT OR Apache-2.0, canonical licence text
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]>
2026-08-04 01:09:51 -07:00

40 lines
1.6 KiB
Go

// Copyright 2026 Hanzo AI, Inc.
// SPDX-License-Identifier: MIT OR Apache-2.0
// Package pkce is the RFC 7636 S256 transform, in one importable place.
//
// It exists because iam is the authorization server: it decides what a
// code_challenge is, and every client that sends one has to derive it by the
// server's rule. When the rule lives inside iam's internal/ tree, a client
// cannot import it and copies the two statements instead -- which is exactly
// what happened, twice over in hanzoai/cloud. Copies of a transform do not
// stay honest for free; they stay honest because nobody has changed the rule
// yet.
//
// So the derivation lives here, outside internal/, and both sides call it.
package pkce
import (
"crypto/sha256"
"encoding/base64"
)
// Method is the only code_challenge_method iam accepts.
//
// "plain" is permanently refused: under plain the challenge IS the verifier,
// so it travels in the clear on the authorize leg and PKCE stops protecting
// anything. Clients should send this constant rather than their own literal,
// so a client cannot be pointed at a method the server will reject.
const Method = "S256"
// Challenge derives the RFC 7636 code_challenge from a verifier:
// BASE64URL-ENCODE(SHA256(ASCII(verifier))), without padding.
//
// Unpadded is not a detail -- RFC 7636 section 4.2 specifies base64url with
// the trailing '=' removed, so a padded encoding produces a challenge the
// server will not match.
func Challenge(verifier string) string {
sum := sha256.Sum256([]byte(verifier))
return base64.RawURLEncoding.EncodeToString(sum[:])
}