server

package module
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2024 License: MIT Imports: 24 Imported by: 2

README

Cwtch Server

Building

Pretty straight forward:

  • build the app in app/ with go build
  • build the docker container in docker/ with docker build . -t openpriv/server
Windows

The server package relies on sqlite which in turn requires the use of CGO. As per this issue that means TDM-GCC is required to be installed and used to compile on Windows

Running

  • cd app
  • go build
  • ./app

The app takes the following arguments

  • -debug: enabled debug logging
  • -exportServerBundle: Export the server bundle to a file called serverbundle
  • -disableMetrics: Disable metrics reporting to serverMonitor.txt and associated tracking routines
  • -dir [directory]: specify a directory to store server files (default is current directory)

The app takes the following environment variables

  • CWTCH_HOME: sets the config dir for the app
  • DISABLE_METRICS: if set to any value ('1') it disables metrics reporting to serverMonitor.txt and associated tracking routines

env CONFIG_HOME=./conf ./app

Using the Server

When run the app will output standard log lines, one of which will contain the serverbundle in purple. This is the part you need to capture and import into a Cwtch client app so you can use the server for hosting groups

Docker

Build by executing docker build -f docker/Dockerfile .

or run our prebuild ones with

pull openpriv/cwtch-server

and run it. It stores all Cwtch data in a Volume at /var/lib/cwtch so if you want the server data to persist you would run

docker run -v /var/lib/cwtch/server01:/var/lib/cwtch openpriv/cwtch-server

to create a persistent container you might try a command like:

docker run --name cwtch -v /var/lib/cwtch/server01:/var/lib/cwtch --restart always openpriv/cwtch-server

Documentation

Index

Constants

View Source
const (
	// AttrAutostart is the attribute key for autostart setting
	AttrAutostart = "autostart"

	// AttrDescription is the attribute key for a user set server description
	AttrDescription = "description"

	// AttrStorageType is used by clients that may need info about stored server config types/styles
	AttrStorageType = "storageType"
)
View Source
const (
	// StorageTypeDefaultPassword is a AttrStorageType that indicated a app default password was used
	StorageTypeDefaultPassword = "storage-default-password"

	// StorageTypePassword is a AttrStorageType that indicated a user password was used to protect the profile
	StorageTypePassword = "storage-password"

	// StoreageTypeNoPassword is a AttrStorageType that indicated a no password was used to protect the profile
	StoreageTypeNoPassword = "storage-no-password"
)
View Source
const MessagesPerMB = 250

messages are ~4kb of storage

View Source
const (
	// ServerConfigFile is the standard filename for a server's config to be written to in a directory
	ServerConfigFile = "serverConfig.json"
)

Variables

This section is empty.

Functions

func NewTokenBoardServer

func NewTokenBoardServer(store storage.MessageStoreInterface, tokenService *privacypass.TokenServer) tapir.Application

NewTokenBoardServer generates new Server for Token Board

Types

type Config

type Config struct {
	ConfigDir string `json:"-"`
	FilePath  string `json:"-"`
	Encrypted bool   `json:"-"`

	PublicKey  ed25519.PublicKey  `json:"publicKey"`
	PrivateKey ed25519.PrivateKey `json:"privateKey"`

	TokenServerPublicKey  ed25519.PublicKey  `json:"tokenServerPublicKey"`
	TokenServerPrivateKey ed25519.PrivateKey `json:"tokenServerPrivateKey"`

	TokenServiceK ristretto255.Scalar `json:"tokenServiceK"`

	ServerReporting Reporting `json:"serverReporting"`

	Attributes map[string]string `json:"attributes"`

	// messages are ~4kb of storage
	// -1 == infinite
	MaxStorageMBs int `json:"maxStorageMBs"`
	// contains filtered or unexported fields
}

Config is a struct for storing basic server configuration

func CreateConfig

func CreateConfig(configDir, filename string, encrypted bool, password string, defaultLogToFile bool) (*Config, error)

CreateConfig creates a default config and saves it to a json file specified by filename if the encrypted flag is true the config is store encrypted by password

func LoadConfig

func LoadConfig(configDir, filename string, encrypted bool, password string) (*Config, error)

LoadConfig loads a Config from a json file specified by filename

func LoadCreateDefaultConfigFile

func LoadCreateDefaultConfigFile(configDir, filename string, encrypted bool, password string, defaultLogToFile bool) (*Config, error)

LoadCreateDefaultConfigFile loads a Config from or creates a default config and saves it to a json file specified by filename if the encrypted flag is true the config is store encrypted by password

func (*Config) CheckPassword

func (config *Config) CheckPassword(checkpass string) bool

CheckPassword returns true if the given password produces the same key as the current stored key, otherwise false.

func (*Config) GetAttribute

func (config *Config) GetAttribute(key string) string

GetAttribute gets a server attribute

func (*Config) GetMaxMessageMBs

func (config *Config) GetMaxMessageMBs() int

func (*Config) GetMaxMessages

func (config *Config) GetMaxMessages() int

GetMaxMessages returns the config setting for Max messages converting from MaxMB to messages or -1 for infinite

func (*Config) Identity

func (config *Config) Identity() primitives.Identity

Identity returns an encapsulation of the servers keys

func (*Config) Onion

func (config *Config) Onion() string

Onion returns the .onion url for the server

func (*Config) Save

func (config *Config) Save() error

Save dumps the latest version of the config to a json file given by filename

func (*Config) SetAttribute

func (config *Config) SetAttribute(key, val string)

SetAttribute sets a server attribute

func (*Config) SetMaxMessageMBs

func (config *Config) SetMaxMessageMBs(newval int)

func (*Config) TokenServiceIdentity

func (config *Config) TokenServiceIdentity() primitives.Identity

TokenServiceIdentity returns an encapsulation of the servers token server (experimental)

type Reporting

type Reporting struct {
	LogMetricsToFile bool `json:"logMetricsToFile"`
}

Reporting is a struct for storing a the config a server needs to be a peer, and connect to a group to report

type Server

type Server interface {
	Identity() primitives.Identity
	Run(acn connectivity.ACN) error
	KeyBundle() *model.KeyBundle
	CheckStatus() (bool, error)
	Stop()
	Destroy()
	GetStatistics() Statistics
	Delete(password string) error
	Onion() string
	ServerBundle() string
	TofuBundle() string
	GetAttribute(string) string
	SetAttribute(string, string)
	SetMonitorLogging(bool)
}

Server encapsulates a complete, compliant Cwtch server.

func NewServer

func NewServer(serverConfig *Config) Server

NewServer creates and configures a new server based on the supplied configuration

type Servers

type Servers interface {
	LoadServers(password string) ([]string, error)
	CreateServer(password string) (Server, error)

	GetServer(onion string) Server
	ListServers() []string
	DeleteServer(onion string, currentPassword string) error

	LaunchServer(string)
	StopServer(string)
	Stop()
	Destroy()
}

Servers is an interface to manage multiple Cwtch servers Unlike a standalone server, server's dirs will be under one "$CwtchDir/servers" and use a cwtch style localID to obscure what servers are hosted. Users are of course free to use a default password. This means Config file will be encrypted with cwtch/storage/v1/file_enc and monitor files will not be generated

func NewServers

func NewServers(acn connectivity.ACN, directory string) Servers

NewServers returns a Servers interface to manage a collection of servers expecting directory: $CWTCH_HOME/servers

type Statistics

type Statistics struct {
	TotalMessages    int
	TotalConnections int
}

Statistics is an encapsulation of information about the server that an operator might want to know at a glance.

type TokenboardServer

type TokenboardServer struct {
	applications.AuthApp

	TokenService       *privacypass.TokenServer
	LegacyMessageStore storage.MessageStoreInterface
	// contains filtered or unexported fields
}

TokenboardServer defines the token board server

func (*TokenboardServer) Init

func (ta *TokenboardServer) Init(connection tapir.Connection)

Init initializes the cryptographic TokenBoardApp

func (*TokenboardServer) Listen

func (ta *TokenboardServer) Listen()

Listen processes the messages for this application

func (*TokenboardServer) NewInstance

func (ta *TokenboardServer) NewInstance() tapir.Application

NewInstance creates a new TokenBoardApp

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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