token

package
v1.6.6 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmpty          = errors.New("token storage is empty")
	ErrNoZone         = errors.New("no zone specified")
	ErrTokenInvalid   = errors.New("token is invalid")
	ErrTokenMalformed = errors.New("token malformed")
	ErrTokenUsed      = errors.New("token already used")
	ErrZoneMismatch   = errors.New("zone mismatch")
	ErrZoneTaken      = errors.New("zone taken")
	ErrZoneUnknown    = errors.New("zone unknown")
)

Errors.

Functions

func HandleSetupRequest

func HandleSetupRequest(request *SetupRequest) (*RequestHandlingState, *SetupResponse, error)

HandleSetupRequest handles a setup request for all registered tokens.

func ProcessIssuedTokens

func ProcessIssuedTokens(response *IssuedTokens) error

ProcessIssuedTokens processes issued tokens for all registered tokens.

func RegisterPBlindHandler

func RegisterPBlindHandler(h *PBlindHandler) error

RegisterPBlindHandler registers a pblind handler with the registry.

func RegisterScrambleHandler

func RegisterScrambleHandler(h *ScrambleHandler) error

RegisterScrambleHandler registers a scramble handler with the registry.

func RegistrySize

func RegistrySize() int

RegistrySize returns the amount of handler registered.

func ResetRegistry

func ResetRegistry()

ResetRegistry resets the token handler registry.

func VerifyToken

func VerifyToken(token *Token) error

VerifyToken verifies the given token.

Types

type Handler

type Handler interface {
	// Zone returns the zone name.
	Zone() string

	// ShouldRequest returns whether the new tokens should be requested.
	ShouldRequest() bool

	// Amount returns the current amount of tokens in this handler.
	Amount() int

	// IsFallback returns whether this handler should only be used as a fallback.
	IsFallback() bool

	// GetToken returns a token.
	GetToken() (token *Token, err error)

	// Verify verifies the given token.
	Verify(token *Token) error

	// Save serializes and returns the current tokens.
	Save() ([]byte, error)

	// Load loads the given tokens into the handler.
	Load(data []byte) error

	// Clear clears all the tokens in the handler.
	Clear()
}

Handler represents a token handling system.

func GetHandler

func GetHandler(zone string) (handler Handler, ok bool)

GetHandler returns the handler of the given zone.

type IssuedPBlindTokens

type IssuedPBlindTokens struct {
	Msgs []*pblind.Message3
}

IssuedPBlindTokens are issued pblind tokens.

type IssuedScrambleTokens

type IssuedScrambleTokens struct {
	Tokens []*ScrambleToken
}

IssuedScrambleTokens are issued scrambled tokens.

type IssuedTokens

type IssuedTokens struct {
	PBlind   map[string]*IssuedPBlindTokens   `json:"PB,omitempty"`
	Scramble map[string]*IssuedScrambleTokens `json:"SC,omitempty"`
}

IssuedTokens are issued tokens.

func IssueTokens

func IssueTokens(state *RequestHandlingState, request *TokenRequest) (response *IssuedTokens, err error)

IssueTokens issues tokens for all registered tokens.

type PBlindHandler

type PBlindHandler struct {
	sync.Mutex

	Storage []*PBlindToken
	// contains filtered or unexported fields
}

PBlindHandler is a handler for the pblind tokens.

func NewPBlindHandler

func NewPBlindHandler(opts PBlindOptions) (*PBlindHandler, error)

NewPBlindHandler creates a new pblind handler.

func (*PBlindHandler) Amount

func (pbh *PBlindHandler) Amount() int

Amount returns the current amount of tokens in this handler.

func (*PBlindHandler) Clear

func (pbh *PBlindHandler) Clear()

Clear clears all the tokens in the handler.

func (*PBlindHandler) CreateSetup

func (pbh *PBlindHandler) CreateSetup() (state *PBlindSignerState, setupResponse *PBlindSetupResponse, err error)

CreateSetup sets up signers for a request.

func (*PBlindHandler) CreateTokenRequest

func (pbh *PBlindHandler) CreateTokenRequest(requestSetup *PBlindSetupResponse) (request *PBlindTokenRequest, err error)

CreateTokenRequest creates a token request to be sent to the token server.

func (*PBlindHandler) GetToken

func (pbh *PBlindHandler) GetToken() (token *Token, err error)

GetToken returns a token.

func (*PBlindHandler) IsFallback

func (pbh *PBlindHandler) IsFallback() bool

IsFallback returns whether this handler should only be used as a fallback.

func (*PBlindHandler) IssueTokens

func (pbh *PBlindHandler) IssueTokens(state *PBlindSignerState, request *PBlindTokenRequest) (response *IssuedPBlindTokens, err error)

IssueTokens sign the requested tokens.

func (*PBlindHandler) Load

func (pbh *PBlindHandler) Load(data []byte) error

Load loads the given tokens into the handler.

func (*PBlindHandler) ProcessIssuedTokens

func (pbh *PBlindHandler) ProcessIssuedTokens(issuedTokens *IssuedPBlindTokens) error

ProcessIssuedTokens processes the issued token from the server.

func (*PBlindHandler) Save

func (pbh *PBlindHandler) Save() ([]byte, error)

Save serializes and returns the current tokens.

func (*PBlindHandler) ShouldRequest

func (pbh *PBlindHandler) ShouldRequest() bool

ShouldRequest returns whether the new tokens should be requested.

func (*PBlindHandler) Verify

func (pbh *PBlindHandler) Verify(token *Token) error

Verify verifies the given token.

func (*PBlindHandler) Zone

func (pbh *PBlindHandler) Zone() string

Zone returns the zone name.

type PBlindOptions

type PBlindOptions struct {
	Zone                  string
	CurveName             string
	Curve                 elliptic.Curve
	PublicKey             string
	PrivateKey            string
	BatchSize             int
	UseSerials            bool
	RandomizeOrder        bool
	Fallback              bool
	SignalShouldRequest   func(Handler)
	DoubleSpendProtection func([]byte) error
}

PBlindOptions are options for the PBlindHandler.

type PBlindSetupResponse

type PBlindSetupResponse struct {
	Msgs []*pblind.Message1
}

PBlindSetupResponse is a setup response.

type PBlindSignerState

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

PBlindSignerState is a signer state.

type PBlindStorage

type PBlindStorage struct {
	Storage []*PBlindToken
}

PBlindStorage is a storage for pblind tokens.

type PBlindToken

type PBlindToken struct {
	Serial    int               `json:"N,omitempty"`
	Token     []byte            `json:"T,omitempty"`
	Signature *pblind.Signature `json:"S,omitempty"`
}

PBlindToken is token based on the pblind library.

func UnpackPBlindToken

func UnpackPBlindToken(token []byte) (*PBlindToken, error)

UnpackPBlindToken unpacks the token.

func (*PBlindToken) Pack

func (pbt *PBlindToken) Pack() ([]byte, error)

Pack packs the token.

type PBlindTokenRequest

type PBlindTokenRequest struct {
	Msgs []*pblind.Message2
}

PBlindTokenRequest is a token request.

type RequestHandlingState

type RequestHandlingState struct {
	SessionID string
	PBlind    map[string]*PBlindSignerState
}

RequestHandlingState is a request handling state.

type RequestState

type RequestState struct {
	Token []byte
	State *pblind.StateRequester
}

RequestState is a request state.

type ScrambleHandler

type ScrambleHandler struct {
	sync.Mutex

	Storage []*ScrambleToken
	// contains filtered or unexported fields
}

ScrambleHandler is a handler for the scramble tokens.

func NewScrambleHandler

func NewScrambleHandler(opts ScrambleOptions) (*ScrambleHandler, error)

NewScrambleHandler creates a new scramble handler.

func (*ScrambleHandler) Amount

func (sh *ScrambleHandler) Amount() int

Amount returns the current amount of tokens in this handler.

func (*ScrambleHandler) Clear

func (sh *ScrambleHandler) Clear()

Clear clears all the tokens in the handler.

func (*ScrambleHandler) CreateTokenRequest

func (sh *ScrambleHandler) CreateTokenRequest() (request *ScrambleTokenRequest)

CreateTokenRequest creates a token request to be sent to the token server.

func (*ScrambleHandler) GetToken

func (sh *ScrambleHandler) GetToken() (*Token, error)

GetToken returns a token.

func (*ScrambleHandler) IsFallback

func (sh *ScrambleHandler) IsFallback() bool

IsFallback returns whether this handler should only be used as a fallback.

func (*ScrambleHandler) IssueTokens

func (sh *ScrambleHandler) IssueTokens(request *ScrambleTokenRequest) (response *IssuedScrambleTokens, err error)

IssueTokens sign the requested tokens.

func (*ScrambleHandler) Load

func (sh *ScrambleHandler) Load(data []byte) error

Load loads the given tokens into the handler.

func (*ScrambleHandler) ProcessIssuedTokens

func (sh *ScrambleHandler) ProcessIssuedTokens(issuedTokens *IssuedScrambleTokens) error

ProcessIssuedTokens processes the issued token from the server.

func (*ScrambleHandler) Save

func (sh *ScrambleHandler) Save() ([]byte, error)

Save serializes and returns the current tokens.

func (*ScrambleHandler) ShouldRequest

func (sh *ScrambleHandler) ShouldRequest() bool

ShouldRequest returns whether the new tokens should be requested.

func (*ScrambleHandler) Verify

func (sh *ScrambleHandler) Verify(token *Token) error

Verify verifies the given token.

func (*ScrambleHandler) Zone

func (sh *ScrambleHandler) Zone() string

Zone returns the zone name.

type ScrambleOptions

type ScrambleOptions struct {
	Zone             string
	Algorithm        lhash.Algorithm
	InitialTokens    []string
	InitialVerifiers []string
	Fallback         bool
}

ScrambleOptions are options for the ScrambleHandler.

type ScrambleStorage

type ScrambleStorage struct {
	Storage []*ScrambleToken
}

ScrambleStorage is a storage for scramble tokens.

type ScrambleToken

type ScrambleToken struct {
	Token []byte
}

ScrambleToken is token based on hashing.

func UnpackScrambleToken

func UnpackScrambleToken(token []byte) (*ScrambleToken, error)

UnpackScrambleToken unpacks the token.

func (*ScrambleToken) Pack

func (pbt *ScrambleToken) Pack() ([]byte, error)

Pack packs the token.

type ScrambleTokenRequest

type ScrambleTokenRequest struct{}

ScrambleTokenRequest is a token request.

type SetupRequest

type SetupRequest struct {
	PBlind map[string]struct{} `json:"PB,omitempty"`
}

SetupRequest is a setup request.

func CreateSetupRequest

func CreateSetupRequest() (request *SetupRequest, setupRequired bool)

CreateSetupRequest creates a combined setup request for all registered tokens, if needed.

type SetupResponse

type SetupResponse struct {
	SessionID string                          `json:"ID,omitempty"`
	PBlind    map[string]*PBlindSetupResponse `json:"PB,omitempty"`
}

SetupResponse is a setup response.

type Token

type Token struct {
	Zone string
	Data []byte
}

Token represents a token, consisting of a zone (name) and some data.

func GetToken

func GetToken(zone string) (*Token, error)

GetToken returns a token of the given zone.

func ParseRawToken

func ParseRawToken(code []byte) (*Token, error)

ParseRawToken parses a raw token.

func ParseToken

func ParseToken(code string) (*Token, error)

ParseToken parses a stringified token.

func (*Token) Raw

func (c *Token) Raw() []byte

Raw returns the raw format of the token.

func (*Token) String

func (c *Token) String() string

String returns the stringified format of the token.

type TokenRequest

type TokenRequest struct {
	SessionID string                           `json:"ID,omitempty"`
	PBlind    map[string]*PBlindTokenRequest   `json:"PB,omitempty"`
	Scramble  map[string]*ScrambleTokenRequest `json:"S,omitempty"`
}

TokenRequest is a token request.

func CreateTokenRequest

func CreateTokenRequest(setup *SetupResponse) (request *TokenRequest, requestRequired bool, err error)

CreateTokenRequest creates a token request for all registered tokens.

Jump to

Keyboard shortcuts

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