util

package
v0.0.0-...-0c84f12 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: GPL-3.0 Imports: 22 Imported by: 0

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 ErrorMail = "mail.error"
View Source
const ErrorNode = "node.error"

General errors

View Source
const ErrorServer = "server.error"
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 PermissionAdmin = "admin"
View Source
const PermissionUseServices = "use_services"

Permission names

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 Permissions = map[string]int16{
	"use_services": 10,
	"use_video":    50,
	"admin":        100,
}

Permissions

View Source
var Testing = false

Functions

func BodyParser

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

Parse encrypted json

func ConnectionToken

func ConnectionToken(account string, session string, node uint) (string, error)

Generate a connection token for a node

func DebugRouteError

func DebugRouteError(c *fiber.Ctx, msg string)

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, error string, err error) error

func GenerateRSAKey

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

Generate a new RSA key pair.

func GetAcc

func GetAcc(c *fiber.Ctx) string

func GetSession

func GetSession(c *fiber.Ctx) string

func InvalidRequest

func InvalidRequest(c *fiber.Ctx) error

func IsExpired

func IsExpired(c *fiber.Ctx) bool

IsExpired checks if the token is expired

func MakeHiddenJWTValue

func MakeHiddenJWTValue(c *fiber.Ctx, value []byte) (string, error)

Generate a JWT value that the client can't read (can't be really long because of RSA encryption)

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 Permission

func Permission(c *fiber.Ctx, perm string) bool

Permission checks if the user has the required permission level

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 ReadHiddenJWTValue

func ReadHiddenJWTValue(c *fiber.Ctx, encoded string) ([]byte, error)

Read a "hidden" JWT value encrypted by the server (referred to as a "hidden value")

func ReturnJSON

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

Return encrypted json

func SessionInformationToken

func SessionInformationToken(account string, sessions []string) (string, error)

Create a token with current session information (some nodes may require this)

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 string, account string, 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

	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