Documentation ¶
Index ¶
- Constants
- Variables
- func BodyParser(c *fiber.Ctx, data interface{}) error
- func ConnectionToken(account string, session string, node uint) (string, error)
- func DebugRouteError(c *fiber.Ctx, msg string)
- func DecryptAES(key, ciphertext []byte) ([]byte, error)
- func DecryptRSA(privateKey *rsa.PrivateKey, ciphertext []byte) ([]byte, error)
- func EncryptAES(key, plaintext []byte) ([]byte, error)
- func EncryptRSA(publicKey *rsa.PublicKey, message []byte) ([]byte, error)
- func FailedRequest(c *fiber.Ctx, error string, err error) error
- func GenerateRSAKey(keySize int) (*rsa.PrivateKey, *rsa.PublicKey, error)
- func GetAcc(c *fiber.Ctx) string
- func GetSession(c *fiber.Ctx) string
- func InvalidRequest(c *fiber.Ctx) error
- func IsExpired(c *fiber.Ctx) bool
- func MakeHiddenJWTValue(c *fiber.Ctx, value []byte) (string, error)
- func NewAESKey() ([]byte, error)
- func PackageRSAPrivateKey(privateKey *rsa.PrivateKey) string
- func PackageRSAPublicKey(publicKey *rsa.PublicKey) string
- func Permission(c *fiber.Ctx, perm string) bool
- func PostRequest(key *rsa.PublicKey, url string, body map[string]interface{}) (map[string]interface{}, error)
- func PostRequestNoTC(url string, body map[string]interface{}) (map[string]interface{}, error)
- func ReadHiddenJWTValue(c *fiber.Ctx, encoded string) ([]byte, error)
- func ReturnJSON(c *fiber.Ctx, data interface{}) error
- func SessionInformationToken(account string, sessions []string) (string, error)
- func SignRSA(privateKey *rsa.PrivateKey, message string) (string, error)
- func SuccessfulRequest(c *fiber.Ctx) error
- func TestAES()
- func Token(session string, account string, lvl uint, exp time.Time) (string, error)
- func UnpackageRSAPrivateKey(priv string) (*rsa.PrivateKey, error)
- func UnpackageRSAPublicKey(pub string) (*rsa.PublicKey, error)
- func VerifyRSASignature(signature string, publicKey *rsa.PublicKey, message string) error
- type ConnectionTokenClaims
Constants ¶
const CodeInvalid = "code.invalid"
const EmailInvalid = "email.invalid"
Auth errors
const EmailRegistered = "email.registered" // When it is already registered
const EnvAppName = "APP_NAME" // Configure the app name
Environment variables
const ErrorMail = "mail.error"
const ErrorNode = "node.error"
General errors
const ErrorServer = "server.error"
const InviteInvalid = "invite.invalid"
const LocalsBody = "body"
const LocalsKey = "key"
const LocalsServerPriv = "srv_priv"
Locals constants
const LocalsServerPub = "srv_pub"
const PasswordInvalid = "password.incorrect"
const PermissionAdmin = "admin"
const PermissionUseServices = "use_services"
Permission names
const StandardKeySize = 2048
const TagInvalid = "tag.invalid"
const UsernameInvalid = "username.invalid"
const UsernameTaken = "username.taken"
Variables ¶
var JWT_SECRET = ""
var LogErrors = true
var NodeProtocol = "http://"
var Permissions = map[string]int16{
"use_services": 10,
"use_video": 50,
"admin": 100,
}
Permissions
var Testing = false
Functions ¶
func ConnectionToken ¶
Generate a connection token for a node
func DebugRouteError ¶
func DebugRouteError(c *fiber.Ctx, msg string)
func DecryptAES ¶
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 ¶
Encrypt encrypts the given plaintext using AES-GCM.
func EncryptRSA ¶
Encrypt a message with a public key. (can't be infinitely long)
func FailedRequest ¶
func GenerateRSAKey ¶
Generate a new RSA key pair.
func GetSession ¶
func GetSession(c *fiber.Ctx) string
func InvalidRequest ¶
func InvalidRequest(c *fiber.Ctx) error
func MakeHiddenJWTValue ¶
Generate a JWT value that the client can't read (can't be really long because of RSA encryption)
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 ¶
PackageRSAPublicKey packages a public key into our own format. Packaging order: modulus, public exponent
func Permission ¶
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 ¶
Send a post request without TC Protection
func ReadHiddenJWTValue ¶
Read a "hidden" JWT value encrypted by the server (referred to as a "hidden value")
func SessionInformationToken ¶
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 UnpackageRSAPrivateKey ¶
func UnpackageRSAPrivateKey(priv string) (*rsa.PrivateKey, error)
Unpackage private key (in our own format that is kinda crappy but who cares)
func UnpackageRSAPublicKey ¶
Unpackage public key (in our own format that is kinda crappy but who cares)
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