database

package
v0.0.0-...-347cd60 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2024 License: Apache-2.0 Imports: 9 Imported by: 1

Documentation

Index

Constants

View Source
const AuthTypePassword = 0
View Source
const AuthTypeSSO = 1
View Source
const StartStep = 0

Starting step when authenticating

View Source
const StatusError = 3
View Source
const StatusStarted = 1
View Source
const StatusStopped = 2
View Source
const VisibilityConversation = "conv" // Key will be encrypted with the conversation's key
View Source
const VisibilityFriends = "friends" // Key will be stored encrypted with profile key

Types of visibility

Variables

View Source
var DBConn *gorm.DB
View Source
var Order = map[uint]uint{
	AuthTypePassword: 0,
	AuthTypeSSO:      0,
}

Order to autenticate (0 = first, 1 = second, etc.)

Functions

func Connect

func Connect()

Types

type AStoredAction

type AStoredAction struct {
	ID string `json:"id" gorm:"primaryKey"`

	Account   uuid.UUID `json:"-" gorm:"not null"`
	Payload   string    `json:"payload" gorm:"not null"` // Encrypted payload (encrypted with the account's public key)
	CreatedAt int64     `json:"-" gorm:"not null,autoCreateTime:milli"`
}

Authenticated stored actions (stored actions but with a key)

type Account

type Account struct {
	ID uuid.UUID `json:"id" gorm:"primaryKey,type:uuid;default:uuid_generate_v4()"`

	Email       string    `json:"email" gorm:"uniqueIndex"`
	Username    string    `json:"username" gorm:"uniqueIndex"`
	DisplayName string    `json:"display_name"`
	RankID      uint      `json:"rank"`
	CreatedAt   time.Time `json:"created_at"`

	Rank           Rank             `json:"-" gorm:"foreignKey:RankID"`
	Authentication []Authentication `json:"-" gorm:"foreignKey:Account"`
	Sessions       []Session        `json:"-" gorm:"foreignKey:Account"`
}

type App

type App struct {
	ID uint `json:"id" gorm:"primaryKey"`

	Tag         string `json:"tag"` // Application tag (for discovering if a certain app runs on an instance)
	Name        string `json:"name"`
	Description string `json:"description"`
	Version     uint   `json:"version"`
	AccessLevel uint   `json:"access_level"`
}

Apps created on the server

type Authentication

type Authentication struct {
	ID uuid.UUID `json:"id" gorm:"primaryKey,type:uuid;default:uuid_generate_v4()"`

	Account uuid.UUID `json:"account"`
	Type    uint      `json:"type"`
	Secret  string    `json:"secret"`
}

func (*Authentication) Verify

func (a *Authentication) Verify(authType uint, secret string, id uuid.UUID) bool

type CloudFile

type CloudFile struct {
	Id        string    `json:"id,omitempty"`   // Format: a-[accountId]-[objectIdentifier]
	Name      string    `json:"name,omitempty"` // File name (encrypted with file key)
	Type      string    `json:"type,omitempty"` // Mime type
	Key       string    `json:"key,omitempty"`  // Encryption key (encrypted with account public key)
	Account   uuid.UUID `json:"account,omitempty"`
	Size      int64     `json:"size,omitempty"`   // In bytes
	Tag       string    `json:"tag,omitempty"`    // Tag for systems such as the library
	System    bool      `json:"system,omitempty"` // If in use by system
	CreatedAt int64     `json:"created,omitempty" gorm:"not null,autoCreateTime:milli"`
}

All files stored on the server

type Friendship

type Friendship struct {
	ID string `json:"id" gorm:"primaryKey"`

	Account    uuid.UUID `json:"account" gorm:"not null"`
	Hash       string    `json:"hash" gorm:"not null"`
	Payload    string    `json:"friend" gorm:"not null"` // Encrypted (with account's public key) friend key + data
	LastPacket string    `json:"-"`                      // When the last packet was received (to prevent replay attacks, encrypted)
	UpdatedAt  int64     `json:"updated_at" gorm:"autoUpdateTime:milli"`
}

Friend vault

type Invite

type Invite struct {
	ID        uuid.UUID `gorm:"primaryKey,type:uuid;default:uuid_generate_v4()"` // Invite token itself
	Creator   uuid.UUID // Account id of creator
	CreatedAt time.Time `gorm:"autoCreateTime"`
}

Invites generated

type InviteCount

type InviteCount struct {
	Account uuid.UUID `gorm:"primaryKey"`
	Count   int       // How many invites can be generated
}

Invite count for how much individual accounts can generate

type KeyRequest

type KeyRequest struct {
	Session   uuid.UUID `gorm:"primaryKey" json:"session"`
	Account   uuid.UUID `gorm:"not null" json:"-"`
	Key       string    `json:"pub"`       // Public key of the session requesting it
	Signature string    `json:"signature"` // Signature of the session requesting it
	Payload   string    `json:"payload"`   // Encrypted payload (from the session sending it)
	CreatedAt int64     `json:"creation" gorm:"not null,autoCreateTime:milli"`
}

type Node

type Node struct {
	ID uint `json:"id" gorm:"primaryKey"`

	AppID           uint    `json:"app"` // App ID
	Token           string  `json:"token"`
	Domain          string  `json:"domain"`
	Load            float64 `json:"load"`
	PeformanceLevel float32 `json:"performance_level"`

	// 1 - Started, 2 - Stopped, 3 - Error
	Status uint `json:"status"`
}

func (*Node) SendPing

func (n *Node) SendPing() error

Send a ping to see if the node is online

func (*Node) ToEntity

func (n *Node) ToEntity() NodeEntity

Convert the node to a returnable entity

type NodeCreation

type NodeCreation struct {
	Token string    `json:"token" gorm:"primaryKey"`
	Date  time.Time `json:"date"`
}

type NodeEntity

type NodeEntity struct {
	ID     uint   `json:"id"`
	Token  string `json:"token"`
	App    uint   `json:"app"`
	Domain string `json:"domain"`
}

type Post

type Post struct {

	// Data about the post
	ID      uuid.UUID `gorm:"primaryKey"`
	Creator uuid.UUID
	Parent  string // The parent post (in case this is a comment or sth, it's a string cause it can be empty)

	// The content of the post
	Attachments string
	Content     string
	Key         string // Key of the post for the original creator (encrypted with vault key)
	Edited      bool
	Creation    int64 // Unix timestamp (SET BY THE CLIENT, EXTREMELY IMPORTANT FOR SIGNATURES)
}

A regular post

func (Post) ToSent

func (p Post) ToSent(visibilities []PostVisibility) SentPost

A conversion helper to convert it to a sent post

type PostVisibility

type PostVisibility struct {

	// Important data for visibility
	ID   uuid.UUID `gorm:"primaryKey"`
	Post uuid.UUID

	// Cached data from the post (this is cached here to make queries faster)
	Creator  uuid.UUID // Creator of the post
	Creation int64     // Time of creation from the post

	// Identifiers to get the visibilities
	Type       string // The type of visibilty (look above)
	Identifier string // Identifier of the visiblity target (for example the conversation id when the type is conversation)
	Key        string // Key of the post for the people in the visibility group
}

The keys for decrypting

type Profile

type Profile struct {
	ID uuid.UUID `json:"id,omitempty" gorm:"primaryKey"` // Account ID

	//* Picture stuff
	Picture     string `json:"picture,omitempty"`      // File id of the picture
	Container   string `json:"container,omitempty"`    // Attachment container encrypted with profile key
	PictureData string `json:"picture_data,omitempty"` // Profile picture data (zoom, x/y offset) encrypted with profile key

	Data string `json:"data,omitempty"` // Encrypted data (if we need it in the future)
}

! ALL THE DATA IN THIS IS PUBLIC AND CAN BE ACCESED THROUGH /ACCOUNT/PROFILE/GET

type ProfileKey

type ProfileKey struct {
	ID  uuid.UUID `json:"id" gorm:"primaryKey"` // Account id
	Key string    `json:"key"`                  // Encrypted with public key and signed
}

type PublicKey

type PublicKey struct {
	ID  uuid.UUID `json:"id" gorm:"primaryKey"` // Account id
	Key string    `json:"key"`
}

* Public keys

type Rank

type Rank struct {
	ID uint `json:"id" gorm:"primaryKey"`

	Name  string `json:"name"`
	Level uint   `json:"level"`

	Accounts []Account `json:"-" gorm:"foreignKey:RankID"`
}

type SentPost

type SentPost struct {
	ID           string               `json:"id"`
	Creator      string               `json:"cr"`
	Parent       string               `json:"p,omitempty"` // Parent post, string to allow empty value
	Attachments  string               `json:"a"`
	Content      string               `json:"co"`
	Edited       bool                 `json:"e"`
	Creation     int64                `json:"crt"` // Unix timestamp (set by the client)
	Visibilities []SentPostVisibility `json:"v"`
}

A regular post (for sending it with json)

type SentPostVisibility

type SentPostVisibility struct {
	Type       string `json:"t"` // The type of visibility (look above)
	Identifier string `json:"i"` // Identifier of the visibility target
	Key        string `json:"k"` // Key of the post for the people in the visibility group
}

type Session

type Session struct {
	ID    uuid.UUID `json:"id" gorm:"primaryKey,type:uuid;default:uuid_generate_v4()"`
	Token string    `json:"token" gorm:"unique"`

	Verified        bool      `json:"sync"`
	Account         uuid.UUID `json:"account"`
	PermissionLevel uint      `json:"level"`
	Device          string    `json:"device"`
	App             uint      `json:"app"`
	Node            uint      `json:"node"`
	LastUsage       time.Time `json:"last_usage"`
	LastConnection  time.Time `json:"last_connection"` // LastConnection is the last time a new connection was established
}

type Setting

type Setting struct {
	Name  string `gorm:"primaryKey"`
	Value string
}

Settings in the admin panel

type SignatureKey

type SignatureKey struct {
	ID  uuid.UUID `json:"id" gorm:"primaryKey"` // Account id
	Key string    `json:"key"`
}

type StoredAction

type StoredAction struct {
	ID string `json:"id" gorm:"primaryKey"`

	Account   uuid.UUID `json:"-" gorm:"not null"`
	Payload   string    `json:"payload" gorm:"not null"` // Encrypted payload (encrypted with the account's public key)
	CreatedAt int64     `json:"-" gorm:"not null,autoCreateTime:milli"`
}

All stored actions

type StoredActionKey

type StoredActionKey struct {
	ID  uuid.UUID `json:"id" gorm:"primaryKey"` // Account id
	Key string    `json:"key"`                  // Generated on the server
}

* Keys for safety

type VaultEntry

type VaultEntry struct {
	ID string `json:"id" gorm:"primaryKey"`

	Tag       string    `json:"tag" gorm:"not null"` // Tag for the entry (e.g. "conversation")
	Account   uuid.UUID `json:"account" gorm:"not null"`
	Payload   string    `json:"payload" gorm:"not null"` // Encrypted (with account's public key) data
	UpdatedAt int64     `json:"updated_at" gorm:"autoUpdateTime:milli"`
}

Vault for all kinds of things (e.g. conversation tokens, etc.)

type VaultKey

type VaultKey struct {
	ID  uuid.UUID `json:"id" gorm:"primaryKey"` // Account id
	Key string    `json:"key"`                  // Encrypted with public key and signed
}

* Symmetric keys

Jump to

Keyboard shortcuts

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