auth

package
v2.0.1-0...-5e4f78d Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2022 License: BSD-2-Clause Imports: 12 Imported by: 3

Documentation

Overview

package auth implements Sauerbraten's player authentication mechanism.

The mechanism relies on the associativity of scalar multiplication on elliptic curves: private keys are random (big) scalars, and the corresponding public key is created by multiplying the curve base point with the private key. (This means the public key is another point on the curve.) To check for posession of the private key belonging to a public key known to the server, the base point is multiplied with another random, big scalar (the "secret") and the resulting point is sent to the user as "challenge". The user multiplies the challenge curve point with his private key (a scalar), and sends the X coordinate of the resulting point back to the server. The server instead multiplies the user's public key with the secret scalar. Since pub = base * priv, pub * secret = (base * priv) * secret = (base * secret) * priv = challenge * priv. Because of the curve's symmetry, there are exactly two points on the curve at any given X. For simplicity (and maybe performance), the server is satisfied when the user responds with the correct X.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateChallenge

func GenerateChallenge(pub PublicKey) (challenge, solution string, err error)

func GenerateKeyPair

func GenerateKeyPair() (priv PrivateKey, pub PublicKey, err error)

func Solve

func Solve(challenge string, priv PrivateKey) (string, error)

Types

type InMemoryProvider

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

func NewInMemoryProvider

func NewInMemoryProvider(users []*User) *InMemoryProvider

func (*InMemoryProvider) ConfirmAnswer

func (p *InMemoryProvider) ConfirmAnswer(reqID uint32, answ string, callback func(role.ID, error))

func (*InMemoryProvider) GenerateChallenge

func (p *InMemoryProvider) GenerateChallenge(name string, callback func(uint32, string, error))

type Manager

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

func NewManager

func NewManager(providers map[string]Provider, roles map[string]role.ID) *Manager

func (*Manager) CheckAnswer

func (m *Manager) CheckAnswer(reqID uint32, domain string, answ string) (err error)

func (*Manager) TryAuthentication

func (m *Manager) TryAuthentication(domain, name string, onChal func(reqID uint32, chal string), onSuccess func(role.ID), onFailure func(error))

type PrivateKey

type PrivateKey []byte

func ParsePrivateKey

func ParsePrivateKey(s string) (PrivateKey, error)

func (PrivateKey) String

func (k PrivateKey) String() string

type Provider

type Provider interface {
	GenerateChallenge(name string, callback func(reqID uint32, chal string, err error))
	ConfirmAnswer(reqID uint32, answ string, callback func(ok bool, err error))
}

type PublicKey

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

func ParsePublicKey

func ParsePublicKey(s string) (PublicKey, error)

func (PublicKey) MarshalJSON

func (k PublicKey) MarshalJSON() ([]byte, error)

func (PublicKey) String

func (k PublicKey) String() string

func (*PublicKey) UnmarshalJSON

func (k *PublicKey) UnmarshalJSON(data []byte) error

type RemoteProvider

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

func NewRemoteProvider

func NewRemoteProvider(inc <-chan string, out chan<- string, rol role.ID) *RemoteProvider

func (*RemoteProvider) ConfirmAnswer

func (p *RemoteProvider) ConfirmAnswer(reqID uint32, answ string, callback func(role.ID, error))

func (*RemoteProvider) GenerateChallenge

func (p *RemoteProvider) GenerateChallenge(name string, callback func(reqID uint32, chal string, err error))

type User

type User struct {
	Name      string    `json:"name"`
	PublicKey PublicKey `json:"public_key"`
	Role      role.ID   `json:"-"`
}

func (*User) MarshalJSON

func (u *User) MarshalJSON() ([]byte, error)

func (*User) UnmarshalJSON

func (u *User) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

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