server

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2022 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

This package represents the GRPC server exposing functions to interoperate with the node components as well as the wallet

Index

Constants

This section is empty.

Variables

View Source
var ErrEdDSAVerification = errors.New("crypto/ed25519: verification error")

ErrEdDSAVerification is the error triggered when verification of ed25519 signatures within the JWT is not successful.

Functions

func NewAuth

func NewAuth(j *JWTManager) (*Auth, *AuthInterceptor)

NewAuth is the authorization service to manage the session with a client.

func SetupGRPC

func SetupGRPC(conf Setup) (*grpc.Server, error)

SetupGRPC will create a new gRPC server with the correct authentication and TLS settings. This server can then be used to register services. Note that the server still needs to be turned on (`Serve`).

Types

type Auth

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

Auth struct is a bit weird since it contains an array of known public keys, while the client should just be one. Oh well :).

func (*Auth) CreateSession

func (a *Auth) CreateSession(ctx context.Context, req *node.SessionRequest) (*node.Session, error)

CreateSession as defined from the grpc service. Calling createSession from an attached client should refreshes the session token (i.e. drop the current one and create a new one).

func (*Auth) DropSession

func (a *Auth) DropSession(ctx context.Context, req *node.EmptyRequest) (*node.GenericResponse, error)

DropSession as defined from the grpc service.

type AuthInterceptor

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

AuthInterceptor is the grpc interceptor to authenticate grpc calls before they get forwarded to the relevant services.

func (*AuthInterceptor) Unary

Unary returns a UnaryServerInterceptor responsible for authentication.

type ClientClaims

type ClientClaims struct {
	jwt.StandardClaims
	ClientEdPk string `json:"client-edpk"`
}

ClientClaims is a simple extension of jwt.StandardClaims that includes the ED25519 public key of a client.

type JWTManager

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

JWTManager is a simple struct for managing the JWT token lifecycle.

func NewJWTManager

func NewJWTManager(duration time.Duration) (*JWTManager, error)

NewJWTManager creates a JWTManager.

func (*JWTManager) Generate

func (m *JWTManager) Generate(edPkBase64 string) (string, error)

Generate a session token used by the client to authenticate.

func (*JWTManager) Verify

func (m *JWTManager) Verify(accessToken string) (*ClientClaims, error)

Verify the session token.

type Setup

type Setup struct {
	SessionDurationMins uint
	RequireSession      bool
	EnableTLS           bool
	CertFile            string
	KeyFile             string
	Network             string
	Address             string
}

Setup is a configuration struct to setup the GRPC with.

func FromCfg

func FromCfg() Setup

FromCfg creates a Setup from the configuration. This is handy when a configuration should be used (i.e. outside of tests).

type SigningMethodEdDSA

type SigningMethodEdDSA struct{}

SigningMethodEdDSA is the encryption method based on ed25519. It is demanded by the JWT library and implements jwt.SigningMethod interface.

func (*SigningMethodEdDSA) Alg

func (m *SigningMethodEdDSA) Alg() string

Alg complies with jwt.SigningMethod interface.

func (*SigningMethodEdDSA) Sign

func (m *SigningMethodEdDSA) Sign(signingString string, key interface{}) (str string, err error)

Sign complies with jwt.SigningMethod interface for signing.

func (*SigningMethodEdDSA) Verify

func (m *SigningMethodEdDSA) Verify(signingString string, signature string, key interface{}) error

Verify complies with jwt.SigningMethod interface for signature verification.

Jump to

Keyboard shortcuts

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