mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-12-05 22:46:09 -05:00
Each session renewal issues a PIN with fresh attempts, so without a limit a stolen session could keep guessing. The quota is separate from the one for renewals without a session, so neither can use up the other's.
50 lines
1.9 KiB
Go
50 lines
1.9 KiB
Go
// Copyright 2026 OpenCloud GmbH <mail@opencloud.eu>
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package storage
|
|
|
|
import (
|
|
"errors"
|
|
"time"
|
|
|
|
"github.com/opencloud-eu/opencloud/services/auth-guest/pkg/service/guard"
|
|
)
|
|
|
|
var ErrNotFound = errors.New("record not found")
|
|
var ErrInvalidHash = errors.New("invalid share id hash")
|
|
var ErrConflict = errors.New("record was modified concurrently")
|
|
|
|
// Record holds the data persisted for a guest share token.
|
|
type Record struct {
|
|
ShareID string `json:"shareid"`
|
|
ShareIDHash string `json:"shareidhash"`
|
|
SecretHash string `json:"secrethash"`
|
|
PinHash string `json:"pinhash"`
|
|
Expiry time.Time `json:"expiry,omitzero"`
|
|
PinExpiry time.Time `json:"pinexpiry,omitzero"`
|
|
Redeemed bool `json:"redeemed"`
|
|
Revision uint64 `json:"revision"`
|
|
NonceState guard.NonceState `json:"nonce,omitzero"`
|
|
BackoffLimiterState guard.BackoffLimiterState `json:"backoff_limiter,omitzero"`
|
|
QuotaLimiterState guard.QuotaLimiterState `json:"quota_limiter,omitzero"`
|
|
SessionQuotaLimiterState guard.QuotaLimiterState `json:"session_quota_limiter,omitzero"`
|
|
}
|
|
|
|
// NewRecord returns a record for the given token.
|
|
func NewRecord(shareID, shareIDHash, secretHash string, expiry time.Time) Record {
|
|
return Record{
|
|
ShareID: shareID,
|
|
ShareIDHash: shareIDHash,
|
|
SecretHash: secretHash,
|
|
Expiry: expiry,
|
|
}
|
|
}
|
|
|
|
type Manager interface {
|
|
Add(rec Record) error
|
|
Get(shareIDHash string) (*Record, error)
|
|
Remove(shareIDHash string) error
|
|
Update(shareIDHash string, fn func(*Record) error) error
|
|
UpdateFrom(seen Record, fn func(*Record) error) (*Record, error)
|
|
}
|