auth

package
v0.0.0-...-4f02c87 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2018 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package auth defines the Authenticator interface and a registry for pluggable authentication providers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Authenticate

func Authenticate(name string, credentials json.RawMessage) (json.RawMessage, error)

Authenticate uses the Authenticator registered as name to authenticate credentials. It panics if there is no Authenticator registered under name.

func DestroyEcdsaPrivateKey

func DestroyEcdsaPrivateKey(key *ecdsa.PrivateKey)

DestroyEcdsaPrivateKey overwrites key's backing storage with zeroes.

func RegisterAuthenticator

func RegisterAuthenticator(name string, implementation Authenticator)

RegisterAuthenticator registers an authenticator under the given name. It panics if there already is an Authenticator registered with the same name.

Types

type Authenticator

type Authenticator interface {

	// Authenticate validates a JSON-encoded credential structure and returns a JSON-encoded bearer token.
	// If the credentials are either wrong or structurally invalid, Authenticate should return a non-nil error.
	Authenticate(credentials json.RawMessage) (token json.RawMessage, e error)

	// RenewToken exchanges an existing token (commonly the one returned by Authenticate) for a new token with a new life time.
	// The old token may or may not continue to be valid. Normally not.
	RenewToken(oldToken json.RawMessage) (newToken json.RawMessage, e error)

	// ExchangeToken validates a JSON-encoded token and exchanges it for a *Key if its valid.
	// Otherwise it should return a non-nil error.
	ExchangeToken(token json.RawMessage) (*Key, error)
}

Authenticator is the interface implemented by authentication providers.

type Key

type Key struct {
	Address    common.Address
	PrivateKey *ecdsa.PrivateKey
}

Key associates an ecdsa.PrivateKey with an Ethereum address.

func BytesToKey

func BytesToKey(bs KeyBytes) (*Key, error)

BytesToKey converts KeyBytes to a *Key and calls Destroy() on bs (only if successful). It returns a non-nil error for invalid KeyBytes.

func ExchangeToken

func ExchangeToken(name string, token json.RawMessage) (*Key, error)

ExchangeToken uses the Authenticator registered as name to exchange token for a key. It panics if there is no Authenticator registered under name.

func (*Key) Destroy

func (k *Key) Destroy()

Destroy erases the private key from memory, overwriting it with zeroes. Auth clients must always safely dispose of keys this way.

type KeyBytes

type KeyBytes []byte

KeyBytes represents a byte-serialized Key

func KeyToBytes

func KeyToBytes(key *Key) KeyBytes

KeyToBytes converts a *Key to KeyBytes and calls Destroy() on key.

func (KeyBytes) Copy

func (bs KeyBytes) Copy() KeyBytes

Copy copies bs.

func (KeyBytes) Destroy

func (bs KeyBytes) Destroy()

Destroy overwrites bs' backing storage with zeroes.

type KeyStore

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

KeyStore implements a quick-and-simple, in-memory encrypted key store. It utilizes a one-time pad scheme.

func NewKeyStore

func NewKeyStore() KeyStore

NewKeyStore makes a new KeyStore

func (KeyStore) Delete

func (s KeyStore) Delete(index [32]byte)

Delete removes an index from the store immediately.

func (KeyStore) Read

func (s KeyStore) Read(index [32]byte, mask []byte) (KeyBytes, error)

Read reads the encrypted key at index and decrypts it using mask. It returns a non-nil error if the index wasn't found or mask is not of the correct length.

func (KeyStore) Write

func (s KeyStore) Write(bs KeyBytes, ttl time.Duration) ([32]byte, []byte)

Write stores plaintext bs for ttl time. If ttl == 0, its stored forever. It returns an index as [32]byte and random bit-mask to use in Read.

Directories

Path Synopsis
Package fs implements a filesystem-based auth.Authenticator.
Package fs implements a filesystem-based auth.Authenticator.

Jump to

Keyboard shortcuts

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