dbhandler

package
v0.0.0-...-564440e Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2021 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// We start at 1 so that we know if the UpdateRecord struct is initialized or not
	UpdateCreate = iota + 1
	UpdateDelete
	UpdateMove
	UpdateReplace
	UpdateRotate
	UpdateMkDir
	UpdateRmDir
)

Variables

This section is empty.

Functions

func AddDevice

func AddDevice(wid types.UUID, devid types.UUID, devkey ezn.CryptoString, status string) error

AddDevice is used for adding a device to a workspace. The initial last login is set to when this method is called because a new device is only at certain times, such as at registration or when a user logs into a workspace on a new device.

func AddEntry

func AddEntry(entry *keycard.Entry) error

AddEntry adds an entry to the database. The caller is responsible for validation of *ALL* data passed to this command.

func AddFolderEntry

func AddFolderEntry(wid types.UUID, serverPath string, clientPath ezn.CryptoString) error

AddFolderEntry adds a mapping of a server path to an encrypted client path

func AddSyncRecord

func AddSyncRecord(wid string, rec UpdateRecord) error

AddSyncRecord adds a record to the update table

func AddWorkspace

func AddWorkspace(wid string, uid string, domain string, password string, status string,
	wtype string) error

AddWorkspace is used for adding a workspace to a server. Upon failure, it returns the error state for the failure. It makes the necessary database modifications and creates the folder for the workspace in the filesystem. Note that this function is strictly for adding workspaces for individuals. Shared workspaces are not yet supported/implemented. Status may be 'active', 'pending', or 'disabled'.

func CheckDevice

func CheckDevice(wid types.UUID, devid types.UUID, devkey ezn.CryptoString) (bool, error)

CheckDevice checks if a device has been added to a workspace.

func CheckLockout

func CheckLockout(failType string, id string, source string) (string, error)

CheckLockout corresponds to LogFailure() in that it checks to see if said source has a lockout timestamp and returns it if there is or an empty string if not. It also has the added benefit of resetting a counter to 0 if there is an expired lockout for a particular source. The ID parameter is a string specific to the failure type. For example, for logins, it is the workspace ID. For preregistration codes, it is the IP address of the remote host.

func CheckPasscode

func CheckPasscode(wid types.UUID, passcode string) (bool, error)

CheckPasscode checks the validity of a workspace/passcode combination. This function will return an error of "expired" if the combination is valid but expired.

func CheckPassword

func CheckPassword(wid types.UUID, password string) (bool, error)

CheckPassword checks a password hash against the one stored in the database. It returns true if the two hashes match. It does not perform any validity checking of the input--this should be done when the input is received from the user.

func CheckRegCode

func CheckRegCode(addr types.MAddress, regcode string) (string, string, error)

CheckRegCode handles authenticating a host using a user/workspace ID and registration code provided by PreregWorkspace. Based on authentication it either returns the workspace ID (success) or an empty string (failure). An error is returned only if authentication was not successful. The caller is still responsible for performing the necessary steps to add the workspace to the database.

func CheckUserID

func CheckUserID(uid types.UserID) (bool, string)

CheckUserID works the same as CheckWorkspace except that it checks for user IDs

func CheckWorkspace

func CheckWorkspace(wid string) (bool, string)

CheckWorkspace checks to see if a workspace exists. If the workspace does exist, True is returned along with a string containing the workspace's status. If the workspace does not exist, it returns false and an empty string. The workspace status can be 'active', 'pending', or 'disabled'. Preregistered workspaces have the status 'approved'. Note that this function does not check the validity of the WID string passed to it. This should be done when the input is received from the user.

func Connect

func Connect()

Connect utilizes the viper config system and connects to the specified database. Because problems in the connection are almost always fatal to the successful continuation of the server daemon, if there are problems, it logs the problem and exits the main process.

func CountSyncRecords

func CountSyncRecords(wid string, unixtime int64) (int64, error)

CountSyncRecords returns the number of sync records which occurred after the specified time

func CullOldSyncRecords

func CullOldSyncRecords(wid string, unixtime int64) error

func DeletePasscode

func DeletePasscode(wid types.UUID, passcode string) error

DeletePasscode deletes a workspace/passcode combination

func DeleteRegCode

func DeleteRegCode(addr types.MAddress, regcode string) error

DeleteRegCode removes preregistration data from the database.

func Disconnect

func Disconnect()

Disconnect shuts down the connection to the database server

func GetAliases

func GetAliases(wid types.UUID) (gostringlist.StringList, error)

GetAliases returns a StringList containing the aliases pointing to the specified WID

func GetEncryptionPair

func GetEncryptionPair() (*ezn.EncryptionPair, error)

GetEncryptionPair returns the organization's encryption keypair as an EncryptionPair

func GetLastLogin

func GetLastLogin(wid types.UUID, devid types.UUID) (int64, error)

GetLastLogin gets the last time a device logged in UTC time, UNIX format

func GetOrgEntries

func GetOrgEntries(startIndex int, endIndex int) ([]string, error)

GetOrgEntries pulls one or more entries from the database. If an end index is not desired, set it to 0. Passing a starting index of 0 will return the current entry for the organization.

func GetOrgKeycard

func GetOrgKeycard() (keycard.Keycard, error)

GetOrgKeycard obtains a organization's entire keycard as a Keycard object

func GetPrimarySigningPair

func GetPrimarySigningPair() (*ezn.SigningPair, error)

GetPrimarySigningPair obtains the organization's primary signing and verification keys

func GetQuotaInfo

func GetQuotaInfo(wid types.UUID) (uint64, uint64, error)

GetQuotaInfo returns the disk usage and quota size of a workspace in bytes

func GetUserEntries

func GetUserEntries(wid types.UUID, startIndex int, endIndex int) ([]string, error)

GetUserEntries pulls one or more entries from the database. If an end index is not desired, set it to 0. Passing a starting index of 0 will return the current entry for the workspace specified.

func GetUserKeycard

func GetUserKeycard(wid types.UUID) (keycard.Keycard, error)

GetUserKeycard obtains a user's entire keycard as a Keycard object

func IsAlias

func IsAlias(wid string) (bool, error)

IsAlias returns a bool if the specified workspace is an alias or a real account

func IsConnected

func IsConnected() bool

IsConnected returns a boolean if it has successfully connected to the Mensago server database

func IsDomainLocal

func IsDomainLocal(domain types.DomainT) (bool, error)

IsDomainLocal checks to see if the domain passed to it is managed by this server

func LogFailure

func LogFailure(failType string, wid types.UUID, sourceip string) error

LogFailure adds an entry to the database of a failure which needs tracked. This includes a type (workspace, password, recipient), the source (IP address, WID), and the timestamp of the failure. This function will check the server configuration and if the failure has exceeded the threshold for that type of failure, then a lockout timestamp will be set.

func ModifyQuotaUsage

func ModifyQuotaUsage(wid types.UUID, amount int64) (uint64, error)

ModifyQuotaUsage modifies the disk usage by a relative amount, specified in bytes. Note that if

func PreregWorkspace

func PreregWorkspace(wid types.UUID, uid types.UserID, domain types.DomainT,
	wordList *diceware.Wordlist, wordcount int) (string, error)

PreregWorkspace preregisters a workspace, adding a specified wid to the database and returns a randomly-generated registration code needed to authenticate the first login. Registration codes are stored in the clear, but that's merely because if an attacker already has access to the server to see the codes, the attacker can easily create new workspaces.

func RemoveDevice

func RemoveDevice(wid types.UUID, devid types.UUID) (bool, error)

RemoveDevice removes a device from a workspace. It returns true if successful and false if not.

func RemoveExpiredPasscodes

func RemoveExpiredPasscodes() error

RemoveExpiredPasscodes removes any workspace/passcode combination entries which are expired

func RemoveFolderEntry

func RemoveFolderEntry(wid types.UUID, serverPath string) error

RemoveFolderEntry deletes a folder mapping

func RemoveWorkspace

func RemoveWorkspace(wid string) error

RemoveWorkspace deletes a workspace. It returns an error if unsuccessful. Note that this does not remove all information about the workspace. WIDs and UIDs may not be reused for security purposes, so the uid and wid attached to the workspace will remain in the database for this reason

func ResetPassword

func ResetPassword(wid types.UUID, passcode string, expires string) error

ResetPassword adds a reset code combination to the database for later authentication by the user. All parameters are expected to be populated.

func ResetQuotaUsage

func ResetQuotaUsage() error

ResetQuotaUsage resets the disk quota usage count in the database for all workspaces

func ResolveAddress

func ResolveAddress(addr types.MAddress) (types.UUID, error)

ResolveAddress returns the WID corresponding to an Mensago address.

func ResolveWID

func ResolveWID(wid types.UUID) (types.WAddress, error)

func SetPassword

func SetPassword(wid types.UUID, password string) error

SetPassword does just that: sets the password for a workspace. It returns a boolean state, indicating a match (or lack thereof) and an error state. It will take any input string of up to 64 characters and store it in the database.

func SetQuota

func SetQuota(wid types.UUID, quota uint64) error

SetQuota sets the disk quota for a workspace to the specified number of bytes

func SetQuotaUsage

func SetQuotaUsage(wid types.UUID, total uint64) error

SetQuotaUsage sets the disk quota usage for a workspace to a specified number of bytes. If the usage has not been updated since boot, the total is ignored and the actual value from disk is used.

func SetWorkspaceStatus

func SetWorkspaceStatus(wid string, status string) error

SetWorkspaceStatus sets the status of a workspace. Valid values are "disabled", "active", and "approved". Although a workspace can also have a status of "awaiting", this state is internal to the dbhandler API and cannot be set directly.

func UpdateDevice

func UpdateDevice(wid types.UUID, devid types.UUID, oldkey ezn.CryptoString,
	newkey ezn.CryptoString) error

UpdateDevice replaces a device's old key with a new one

func UpdateLastLogin

func UpdateLastLogin(wid types.UUID, devid types.UUID) error

UpdateLastLogin sets the last login timestamp for a device

func ValidateUUID

func ValidateUUID(uuid string) bool

ValidateUUID just returns whether or not a string is a valid UUID.

Types

type UpdateRecord

type UpdateRecord struct {
	ID   string
	Type UpdateType
	Data string
	Time int64
}

func GetSyncRecords

func GetSyncRecords(wid string, unixtime int64) ([]UpdateRecord, error)

GetSyncRecords gets all the update records after a specified period of time

type UpdateType

type UpdateType int

Jump to

Keyboard shortcuts

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