util

package
v0.0.0-...-1376763 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2025 License: Apache-2.0 Imports: 23 Imported by: 1

Documentation

Index

Constants

View Source
const CodeInvalid = "code.invalid"
View Source
const EmailInvalid = "email.invalid"

Auth errors

View Source
const EmailRegistered = "email.registered" // When it is already registered
View Source
const EnvAppName = "APP_NAME" // Configure the app name

Environment variables

View Source
const InviteInvalid = "invite.invalid"
View Source
const LocalsBody = "body"
View Source
const LocalsKey = "key"
View Source
const LocalsServerPriv = "srv_priv"

Locals constants

View Source
const LocalsServerPub = "srv_pub"
View Source
const PasswordInvalid = "password.incorrect"
View Source
const ProtocolVersion = 7

Important variables

View Source
const StandardKeySize = 2048
View Source
const TagInvalid = "tag.invalid"
View Source
const UsernameInvalid = "username.invalid"
View Source
const UsernameTaken = "username.taken"

Variables

View Source
var JWT_SECRET = ""
View Source
var Log = log.New(os.Stdout, "backend ", log.Flags())
View Source
var LogErrors = true
View Source
var NodeProtocol = "http://"
View Source
var Testing = false

Functions

func BodyParser

func BodyParser(c *fiber.Ctx, data interface{}) error

Parse encrypted json

func ConnectionToken

func ConnectionToken(account uuid.UUID, session string, extra string, node uint) (string, error)

Generate a connection token for a node

func DebugRouteError

func DebugRouteError(c *fiber.Ctx, msg localization.Translations)

func DecryptAES

func DecryptAES(key, ciphertext []byte) ([]byte, error)

Decrypt decrypts the given ciphertext using AES-GCM.

func DecryptRSA

func DecryptRSA(privateKey *rsa.PrivateKey, ciphertext []byte) ([]byte, error)

Decrypt a message with a private key. (can't be infinitely long)

func EncryptAES

func EncryptAES(key, plaintext []byte) ([]byte, error)

Encrypt encrypts the given plaintext using AES-GCM.

func EncryptRSA

func EncryptRSA(publicKey *rsa.PublicKey, message []byte) ([]byte, error)

Encrypt a message with a public key. (can't be infinitely long)

func FailedRequest

func FailedRequest(c *fiber.Ctx, message localization.Translations, err error) error

func GenerateRSAKey

func GenerateRSAKey(keySize int) (*rsa.PrivateKey, *rsa.PublicKey, error)

Generate a new RSA key pair.

func GetSystemUUID

func GetSystemUUID() uuid.UUID

Get the system uuid set in the environment variables

func InvalidRequest

func InvalidRequest(c *fiber.Ctx) error

func IsExpired

func IsExpired(c *fiber.Ctx) bool

IsExpired checks if the token is expired

func NewAESKey

func NewAESKey() ([]byte, error)

Generate a new AES key with a length of 32

func PackageRSAPrivateKey

func PackageRSAPrivateKey(privateKey *rsa.PrivateKey) string

PackageRSAPrivateKey packages a private key into our own format. Packaging order: modulus, public exponent, private exponent, p, q

func PackageRSAPublicKey

func PackageRSAPublicKey(publicKey *rsa.PublicKey) string

PackageRSAPublicKey packages a public key into our own format. Packaging order: modulus, public exponent

func PostRequest

func PostRequest(key *rsa.PublicKey, url string, body map[string]interface{}) (map[string]interface{}, error)

Send a post request (with TC protection encryption)

func PostRequestNoTC

func PostRequestNoTC(url string, body map[string]interface{}) (map[string]interface{}, error)

Send a post request without TC Protection

func ReturnJSON

func ReturnJSON(c *fiber.Ctx, data interface{}) error

Return encrypted json

func SignRSA

func SignRSA(privateKey *rsa.PrivateKey, message string) (string, error)

Sign a message with a private key.

func SuccessfulRequest

func SuccessfulRequest(c *fiber.Ctx) error

func TestAES

func TestAES()

func Token

func Token(session uuid.UUID, account uuid.UUID, lvl uint, exp time.Time) (string, error)

Generate a normal authenticated token

func UnpackageRSAPrivateKey

func UnpackageRSAPrivateKey(priv string) (*rsa.PrivateKey, error)

Unpackage private key (in our own format that is kinda crappy but who cares)

func UnpackageRSAPublicKey

func UnpackageRSAPublicKey(pub string) (*rsa.PublicKey, error)

Unpackage public key (in our own format that is kinda crappy but who cares)

func VerifyRSASignature

func VerifyRSASignature(signature string, publicKey *rsa.PublicKey, message string) error

Verify a signature with a public key. (valid signature = nil error)

Types

type ConnectionTokenClaims

type ConnectionTokenClaims struct {
	Account        string `json:"acc"`             // Account id of the connecting client
	ExpiredUnixSec int64  `json:"e_u"`             // Expiration time in unix seconds
	Session        string `json:"ses"`             // Session id of the connecting client
	Node           string `json:"node"`            // Node id of the node the client is connecting to
	Extra          string `json:"extra,omitempty"` // Extra information for the connection

	jwt.RegisteredClaims
}

Connection token struct

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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