hashers

package
v1.107.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrHashMismatch = errors.New("hash mismatch")
View Source
var ErrUnsupportedSecret = errors.New("unsupported client secret digest")

ErrUnsupportedSecret is returned for a stored or wire secret in neither accepted shape. Its message names the shape, never the value.

View Source
var PBKDF2Pattern = regexp.MustCompile(`^` + regexp.QuoteMeta(pbkdf2Prefix) + strconv.Itoa(pbkdf2Rounds) + `\$\$[A-Za-z0-9./]{86}$`)

PBKDF2Pattern matches the one string Doorkeeper's Pbkdf2Sha512 strategy stored for refresh tokens from 2022-09 and application secrets from 2023-01, until the sha512_oauth rollout in 2025-09: 20000 rounds, an empty salt, and the 64-byte digest as 86 passlib base64 chars ('.' for '+', no padding). gitlab-rails never wrote another shape: gitlab-org/gitlab#632068 note 4068971162 (refresh tokens) and gitlab-org/gitlab#631544 note 4077807690 (applications).

View Source
var SHA512HexPattern = regexp.MustCompile(`^[0-9a-f]{128}$`)

SHA512HexPattern matches a SHA-512 digest as 128 lowercase hex characters, the form Doorkeeper stores (Digest::SHA512.hexdigest). A Doorkeeper plaintext is 64 hex chars (SecureRandom.hex(32)), so an accidentally-sent plaintext fails the match instead of being stored as a digest.

Functions

func ParseStoredSecret added in v1.106.0

func ParseStoredSecret(wire string) ([]byte, error)

ParseStoredSecret turns the hashed_client_secret wire value into the bytes oauth_clients.secret holds: the decoded digest for SHA-512 hex, the PBKDF2 string itself for Doorkeeper's shape, so ClientSecret.Compare can tell them apart.

Types

type ClientSecret added in v1.106.0

type ClientSecret struct {
	// contains filtered or unexported fields
}

ClientSecret verifies client secrets in both shapes gitlab-rails stored: the 64 raw bytes of a SHA-512 digest, or Doorkeeper's PBKDF2 string kept verbatim (PBKDF2Pattern). Hash stays SHA-512: IAM reads PBKDF2, it never writes it.

func (*ClientSecret) Compare added in v1.106.0

func (h *ClientSecret) Compare(ctx context.Context, stored, presented []byte) error

Compare routes on the stored prefix; ParseStoredSecret guarantees a SHA-512 digest never starts with it.

func (*ClientSecret) Hash added in v1.106.0

func (h *ClientSecret) Hash(ctx context.Context, data []byte) ([]byte, error)

type PBKDF2SHA512 added in v1.106.0

type PBKDF2SHA512 struct{}

PBKDF2SHA512 verifies a secret against the string Doorkeeper's Pbkdf2Sha512 strategy stored (PBKDF2Pattern). IAM never writes that shape, so it has no Hash.

func (*PBKDF2SHA512) Compare added in v1.106.0

func (h *PBKDF2SHA512) Compare(_ context.Context, stored, presented []byte) error

type SHA512

type SHA512 struct{}

func (*SHA512) Compare

func (h *SHA512) Compare(ctx context.Context, hash, data []byte) error

func (*SHA512) Hash

func (h *SHA512) Hash(_ context.Context, data []byte) ([]byte, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL