store

package
v0.0.0-...-eeb3e7f Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2024 License: Apache-2.0 Imports: 27 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ID_KEY       = "I"
	TEAMNAME_KEY = "TN"
)
View Source
const (
	NoTokenErrMsg     = "token contains an invalid number of segments"
	UnauthorizeErrMsg = "unauthorized"
	AUTH_KEY          = "au"
)

Variables

View Source
var (
	UnknownTeamErr  = errors.New("Unknown team")
	UnknownTokenErr = errors.New("Unknown token")
)
View Source
var (
	EmptyExTags         = errors.New("Exercise cannot have zero tags")
	ImageNotDefinedErr  = errors.New("image cannot be empty")
	MemoryNotDefinedErr = errors.New("memory cannot be empty")
)
View Source
var (
	UnreachableDBErr = errors.New("Database seems to be unreachable")
	UnauthorizedErr  = errors.New("You seem to not be logged in")
)
View Source
var (
	ErrUnknownTeam        = errors.New("Unknown team")
	ErrEmailAlreadyExists = errors.New("Email is already registered")

	//ErrEmptyTag            = errors.New("Tag cannot be empty")
	ErrUnknownFlag         = errors.New("Unknown flag")
	ErrFlagAlreadyComplete = errors.New("Flag is already completed")
	ErrChallengeDuplicate  = errors.New("Challenge duplication")
	ErrTeamAlreadyExist    = errors.New("Team is already exists")
)
View Source
var (
	UserStoreNoFileErr = errors.New("Unable to find user store file")
	UserExistsErr      = errors.New("User already exists")
	UserNotFoundErr    = errors.New("User not found")
	PasswdTooShortErr  = errors.New("Password too short, requires at least six characters")

	SignupKeyExistsErr   = errors.New("Signup key already exists")
	SignupKeyNotFoundErr = errors.New("Signup key not found")
)
View Source
var (
	ErrInvalidFlagFormat = errors.New("Invalid flag format")
)
View Source
var (
	TagEmptyErr = errors.New("Tag cannot be empty")
)

Functions

func CopyMap

func CopyMap(m map[string][]string) map[string][]string

func GetDirNameForEvent

func GetDirNameForEvent(path string, tag Tag, date *time.Time) (string, error)

func GetTokenForTeam

func GetTokenForTeam(key []byte, t *Team) (string, error)

func NewExerciseClientConn

func NewExerciseClientConn(config ServiceConfig) (eproto.ExerciseStoreClient, error)

NewExerciseClientConn does not require CA file to communicate due to the fact that a script is running on Gitlab CI to push exercises to the service

func NewGRPClientDBConnection

func NewGRPClientDBConnection(dbConn ServiceConfig) (pbc.StoreClient, error)

func NewTeamStore

func NewTeamStore(conf EventConfig, dbc pbc.StoreClient) *teamstore

func TranslateRPCErr

func TranslateRPCErr(err error) error

Types

type Category

type Category struct {
	Tag            Tag    `json:"tag,omitempty"`
	Name           string `json:"name,omitempty"`
	CatDescription string `json:"catDesc,omitempty"`
}

type Challenge

type Challenge struct {
	Name  string //challenge name
	Tag   Tag    //challenge tag
	Value string //challenge flag value
}

type ChildrenChalConfig

type ChildrenChalConfig struct {
	Tag             Tag      `json:"tag,omitempty"`
	Name            string   `json:"name,omitempty"`
	EnvVar          string   `json:"envFlag,omitempty"`
	StaticFlag      string   `json:"static,omitempty"`
	Points          uint     `json:"points,omitempty"`
	Category        string   `json:"category,omitempty"`
	TeamDescription string   `json:"teamDescription,omitempty"`
	PreRequisites   []string `json:"prerequisite,omitempty"`
	Outcomes        []string `json:"outcome,omitempty"`
	StaticChallenge bool     `json:"staticChallenge,omitempty"`
}

func (ChildrenChalConfig) Validate

func (fc ChildrenChalConfig) Validate() error

type ContainerOptions

type ContainerOptions struct {
	DockerConf docker.ContainerConfig
	Records    []RecordConfig
	Challenges []Challenge
}

type Creds

type Creds struct {
	Token    string
	Insecure bool
}

func (Creds) GetRequestMetadata

func (c Creds) GetRequestMetadata(context.Context, ...string) (map[string]string, error)

func (Creds) RequireTransportSecurity

func (c Creds) RequireTransportSecurity() bool

type EmptyVarErr

type EmptyVarErr struct {
	Var  string
	Type string
}

func (*EmptyVarErr) Error

func (eve *EmptyVarErr) Error() string

type EnvVarConfig

type EnvVarConfig struct {
	EnvVar string `json:"name,omitempty"`
	Value  string `json:"value,omitempty"`
}

func (EnvVarConfig) Validate

func (evc EnvVarConfig) Validate() error

type Event

type Event struct {
	Dir string

	TeamStore
	EventConfig
	wg.WireGuardConfig
	// contains filtered or unexported fields
}

func NewEventStore

func NewEventStore(conf EventConfig, eDir string, dbc pbc.StoreClient) (Event, error)

Create the EventSore for the event. It contains: The connection with the DB A new TeamStore that contains all the teams retrieved from the DB (if no teams are retrieved the TeamStore will be empty) The EventConfiguration

func (Event) Finish

func (e Event) Finish(newTag string, time time.Time) error

func (Event) SetCapacity

func (e Event) SetCapacity(n int) error

Change the Capacity of the event and update the DB

func (Event) SetStatus

func (e Event) SetStatus(eventTag string, status int32) error

SetStatus will set status of event on db

type EventConfig

type EventConfig struct {
	Name               string
	Host               string
	Tag                Tag
	Available          int
	Capacity           int
	Lab                Lab
	StartedAt          *time.Time
	FinishExpected     *time.Time
	FinishedAt         *time.Time
	Status             int32
	CreatedBy          string
	OnlyVPN            int32
	VPNAddress         string
	EndPointPort       int
	DisabledChallenges map[string][]string // list of disabled children challenge tags to be used for amigo frontend ...
	AllChallenges      map[string][]string
	SecretKey          string // secret key is a key which is defined by event creator to setup events which are accessible only with signup key

}

func (EventConfig) Validate

func (e EventConfig) Validate() error

type ExerTagExistsErr

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

func (*ExerTagExistsErr) Error

func (eee *ExerTagExistsErr) Error() string

type Exercise

type Exercise struct {
	Tag      Tag    `json:"tag,omitempty"`
	Name     string `json:"name,omitempty"`
	Category string `json:"category,omitempty"`
	Secret   bool   `json:"secret,omitempty"`
	// specifies whether challenge will be on docker/vm or none
	// true: none , false: docker/vm
	Static         bool                     `json:"static,omitempty"`
	Instance       []ExerciseInstanceConfig `json:"instance,omitempty"`
	Status         int                      `json:"status,omitempty"`
	OrgDescription string                   `json:"organizerDescription,omitempty"`
}

todo manage the status somehow

func (Exercise) ChildTags

func (e Exercise) ChildTags() []string

func (Exercise) ContainerOpts

func (e Exercise) ContainerOpts() []ContainerOptions

func (Exercise) Flags

func (e Exercise) Flags() []ChildrenChalConfig

func (Exercise) Validate

func (e Exercise) Validate() error

type ExerciseInstanceConfig

type ExerciseInstanceConfig struct {
	Image    string               `json:"image,omitempty"`
	MemoryMB uint                 `json:"memory,omitempty"`
	CPU      float64              `json:"cpu,omitempty"`
	Envs     []EnvVarConfig       `json:"envs,omitempty"`
	Flags    []ChildrenChalConfig `json:"children,omitempty"`
	Records  []RecordConfig       `json:"records,omitempty"`
}

type Flag

type Flag [flagNumCharsFormat]byte

func NewFlag

func NewFlag() Flag

func (Flag) String

func (f Flag) String() string

type FrontendStore

type FrontendStore interface {
	GetFrontends(...string) []InstanceConfig
	SetMemoryMB(string, uint) error
	SetCpu(string, float64) error
	// contains filtered or unexported methods
}

func NewFrontendsFile

func NewFrontendsFile(path string) (FrontendStore, error)

type InstanceConfig

type InstanceConfig struct {
	Image    string  `yaml:"image"`
	MemoryMB uint    `yaml:"memoryMB"`
	CPU      float64 `yaml:"cpu"`
}

func (InstanceConfig) Validate

func (ic InstanceConfig) Validate() error

type InvalidTagSyntaxErr

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

func (*InvalidTagSyntaxErr) Error

func (ite *InvalidTagSyntaxErr) Error() string

type Lab

type Lab struct {
	Frontends         []InstanceConfig
	Exercises         []Tag
	DisabledExercises []Tag
}

type PChallenge

type PChallenge struct {
	Tag  string `json:"tag,omitempty"`
	Name string `json:"name,omitempty"`
}

type Profile

type Profile struct {
	Name       string       `json:"name,omitempty"`
	Secret     bool         `json:"secret,omitempty"`
	Challenges []PChallenge `json:"challenges,omitempty"`
}

type RecordConfig

type RecordConfig struct {
	Type  string `json:"type,omitempty"`
	Name  string `json:"name,omitempty"`
	RData string `json:"data,omitempty"`
}

func (RecordConfig) Format

func (rc RecordConfig) Format(ip string) string

func (RecordConfig) Validate

func (rc RecordConfig) Validate() error

type ServiceConfig

type ServiceConfig struct {
	Grpc     string
	AuthKey  string
	SignKey  string
	Enabled  bool
	CertFile string
	CertKey  string
	CAFile   string
}

type SignupKey

type SignupKey struct {
	WillBeNPUser    bool   `yaml:"np-user,omitempty"`
	WillBeSuperUser bool   `yaml:"super-user,omitempty"`
	Value           string `yaml:"value,omitempty"`
}

admin has all permissions -- superuser user has all permissions except invitation -- user np-user has limited permissions -- np-user [non-priviledged user]

func NewSignupKey

func NewSignupKey() SignupKey

func (SignupKey) String

func (sk SignupKey) String() string

type SignupKeyStore

type SignupKeyStore interface {
	CreateSignupKey(SignupKey) error
	GetSignupKey(string) (SignupKey, error)
	DeleteSignupKey(SignupKey) error
	ListSignupKeys() []SignupKey
}

func NewSignupKeyStore

func NewSignupKeyStore(keys []SignupKey, hooks ...func([]SignupKey) error) SignupKeyStore

type Tag

type Tag string

func NewTag

func NewTag(s string) (Tag, error)

func (Tag) Validate

func (t Tag) Validate() error

type Team

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

func NewTeam

func NewTeam(email, name, password, id, hashedPass, solvedChalsDB string,
	lastAccessedT time.Time, disabledExs, allChallenges map[string][]string, dbc pbc.StoreClient) *Team

func (*Team) AddChallenge

func (t *Team) AddChallenge(c Challenge) (string, error)

func (*Team) AddDisabledChal

func (t *Team) AddDisabledChal(parentTag string)

func (*Team) CorrectedAssignedLab

func (t *Team) CorrectedAssignedLab()

func (*Team) Email

func (t *Team) Email() string

func (*Team) GetChildChallenges

func (t *Team) GetChildChallenges(parentTag string) []string

func (*Team) GetDisabledChalMap

func (t *Team) GetDisabledChalMap() map[string][]string

func (*Team) GetDisabledChals

func (t *Team) GetDisabledChals() []string

func (*Team) GetHashedPassword

func (t *Team) GetHashedPassword() string

func (*Team) GetHostsInfo

func (t *Team) GetHostsInfo() []string

func (*Team) GetLabInfo

func (t *Team) GetLabInfo() string

func (*Team) GetVPNConn

func (t *Team) GetVPNConn() []string

func (*Team) GetVPNKeys

func (t *Team) GetVPNKeys() map[int]string

func (*Team) ID

func (t *Team) ID() string

func (*Team) IsLabAssigned

func (t *Team) IsLabAssigned() bool

func (*Team) IsPasswordEqual

func (t *Team) IsPasswordEqual(pass string) bool

func (*Team) IsTeamSolvedChallenge

func (t *Team) IsTeamSolvedChallenge(tag string) *time.Time

func (*Team) LastAccessTime

func (t *Team) LastAccessTime() time.Time

func (*Team) ManageDisabledChals

func (t *Team) ManageDisabledChals(parentTag string) bool

func (*Team) Name

func (t *Team) Name() string

func (*Team) SetHostsInfo

func (t *Team) SetHostsInfo(hostInfo []string)

func (*Team) SetLabInfo

func (t *Team) SetLabInfo(labSubnet string)

func (*Team) SetVPNConn

func (t *Team) SetVPNConn(clientConfig []string)

will be taken from amigo side

func (*Team) SetVPNKeys

func (t *Team) SetVPNKeys(id int, key string)

func (*Team) UpdateAllChallenges

func (t *Team) UpdateAllChallenges(challenges map[string][]string)

func (*Team) UpdatePass

func (t *Team) UpdatePass(pass, passRepeat, evTag string) error

func (*Team) UpdateTeamAccessed

func (t *Team) UpdateTeamAccessed(tm time.Time) error

Update the Team access time on the DB

func (*Team) UpdateTeamSolvedChallenges

func (t *Team) UpdateTeamSolvedChallenges(chal TeamChallenge) error

Update the Team Solved Challenges on the DB

func (*Team) VerifyFlag

func (t *Team) VerifyFlag(tag Challenge, f string) error

type TeamChallenge

type TeamChallenge struct {
	Tag         Tag
	CompletedAt *time.Time
}

func ParseSolvedChallenges

func ParseSolvedChallenges(solvedChalsDB string) ([]TeamChallenge, error)

type TeamStore

type TeamStore interface {
	GetTeamByToken(string) (*Team, error)
	SaveTeam(*Team) error
	DeleteTeam(string, string) error
	GetTeamByID(string) (*Team, error)
	GetTeamByUsername(string) (*Team, error)
	GetTeams() []*Team
	SaveTokenForTeam(string, *Team) error
}

type UnknownExerTagErr

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

func (*UnknownExerTagErr) Error

func (uee *UnknownExerTagErr) Error() string

type User

type User struct {
	Username       string    `yaml:"username"`
	Name           string    `yaml:"name"`
	Surname        string    `yaml:"surname"`
	Email          string    `yaml:"email"`
	HashedPassword string    `yaml:"hashed-password"`
	SuperUser      bool      `yaml:"super-user"`
	NPUser         bool      `yaml:"np-user"`
	CreatedAt      time.Time `yaml:"created-at"`
}

func NewUser

func NewUser(username, name, surname, email, password string) (User, error)

func (User) IsCorrectPassword

func (u User) IsCorrectPassword(pass string) bool

type UserStore

type UserStore interface {
	DeleteUserByUsername(string) error
	CreateUser(User) error
	UpdatePasswd(string, string) error
	GetUserByUsername(string) (User, error)
	ListUsers() []User
	IsSuperUser(string) bool
}

func NewUserStore

func NewUserStore(users []User, hooks ...func([]User) error) UserStore

type UsersFile

type UsersFile interface {
	UserStore
	SignupKeyStore
}

func NewUserFile

func NewUserFile(path string) (UsersFile, error)

type VboxConfig

type VboxConfig struct {
	ExerciseInstanceConfig `yaml:",inline"`
}

func (VboxConfig) Validate

func (vc VboxConfig) Validate() error

type VpnConn

type VpnConn struct {
	// client information [Interface]
	IName   string // interface
	PrivKey string // client private key (not server)
	LabDNS  string // lab dns information
	// server information [Peer]
	PubKey     string
	Endpoint   string
	AllowedIps string //lab subnet
	Hosts      string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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