utils

package
v0.0.0-...-560f09a Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2023 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const SkipIpValidation = "skip_ip_validation"

Variables

This section is empty.

Functions

func CheckPassword

func CheckPassword(password string, hash string) (bool, error)

CheckPassword Checks a hashed password against a string

password   - string, the password that will be compared
hash       - string, the hashed password that will be compared

Returns:

out        - bool, whether the passed password matches the hash

func CreateExternalJWT

func CreateExternalJWT(storageEngine storage.Storage, userID string, ip string, hours int, minutes int, payload map[string]interface{}) (string, error)

CreateExternalJWT Creates a JWT for http API authentication

		userID    - string, the user ID that this JWT will be used for
		ip        - string, the IP address of the machine that will be using this JWT
     hours     - int, amount of hours the JWT will be active for
		minutes   - int, amount of minutes the JWT will be active for
		payload   - map[string]interface{}, optional set of key, value pairs to be added to the JWT payload

Returns:

out      - string, JWT containing the pertinent claims and signed by the global private key

func CreateExternalJWTNoIP

func CreateExternalJWTNoIP(storageEngine storage.Storage, userID string, hours int, minutes int, payload map[string]interface{}) (string, error)

CreateExternalJWTNoIP Creates a JWT for http API authentication

		userID    - string, the user ID that this JWT will be used for
		ip        - string, the IP address of the machine that will be using this JWT
     hours     - int, amount of hours the JWT will be active for
		minutes   - int, amount of minutes the JWT will be active for
		payload   - map[string]interface{}, optional set of key, value pairs to be added to the JWT payload

Returns:

out      - string, JWT containing the pertinent claims and signed by the global private key

func CreateInternalJWT

func CreateInternalJWT(storageEngine storage.Storage, service string, ip string, hours int) (string, error)

CreateInternalJWT Creates a JWT for internal_api API authentication

		service   - string, the service that this JWT will be used for
		ip        - string, the IP address of the machine that will be using this JWT
     hours     - int, amount of hours the JWT will be active for

Returns:

out       - string, JWT containing the pertinent claims and signed by the global private key

func GenerateEmailToken

func GenerateEmailToken() (string, error)

func HashData

func HashData(data []byte) (string, error)

HashData Hashes the passed data with SHA3-256

data   - []byte, the data that will be hashed

Returns:

out    - string, hex encoded SHA3-256 hash made of the passed data

func HashFile

func HashFile(fp string) (string, error)

HashFile Hashes the contents of a file with SHA3-256

fp   - string, the file path for the file that will be hashes

Returns:

out  - string, hex encoded SHA3-256 hash made of passed file's contents

func HashPassword

func HashPassword(password string) (string, error)

HashPassword Hashes a password with bcrypt

password   - string, the password that will be hashed

Returns:

out        - string, a string representation of the hashed password

func LoadKeyFileRSA

func LoadKeyFileRSA(buf io.ReadCloser) (*rsa.PrivateKey, *rsa.PublicKey, error)

LoadKeyFileRSA Loads RSA key from .pem file

path    - string, filepath to the .pem file

Returns:

block   - *rsa.PrivateKey, RSA private key loaded from file
rest    - *rsa.PublicKey, RSA public key loaded from file

func LoadToken

func LoadToken(path string) (string, error)

LoadToken Loads authentication token from the specified path Args:

path   - string, the file path of the authentication token

Returns:

out         - string, JWT token loaded from the passed file

func NormalizeURLForHash

func NormalizeURLForHash(uri string) (string, error)

NormalizeURLForHash Normalizes a URL for hash calculation Strips url of all query parameters and fragments Args:

uri    - string, url that will be normalized for hashing

Returns:

out    - string, url that has been stripped of all of its query parameters and fragments

func PathExists

func PathExists(path string) (bool, error)

PathExists Checks if a file path exists on the filesystem Args:

path   - string, the file path of the source file

Returns:

out    - bool, whether the filepath was found to exist on the filesystem

func ValidateExternalJWT

func ValidateExternalJWT(storageEngine storage.Storage, tokenString string, ip string, payload map[string]interface{}) (bool, int64, map[string]interface{}, error)

ValidateExternalJWT Validates a JWT for internal_api API authentication

     tokenString   - string, JWT string that will be validated
		ip            - string, IP address of the machine that will be using this JWT
		payload       - map[string]interface{}, optional set of key, value pairs to be checked for in the JWT payload

Returns:

valid         - bool, success status for the JWT validation
userID        - string, id of the user stored in the JWT
payload       - map[string]interface, payload of the jwt

func ValidateInternalJWT

func ValidateInternalJWT(storageEngine storage.Storage, tokenString string, service string, ip string, validateIP bool) (bool, error)

ValidateInternalJWT Validates a JWT for internal_api API authentication

     tokenString   - string, JWT string that will be validated
		service       - string, service that this JWT will be used for
		ip            - string, IP address of the machine that will be using this JWT
		validateIP    - bool, validate the IP stored inside the JWT

Returns:

out           - bool, success status for the JWT validation

Types

This section is empty.

Jump to

Keyboard shortcuts

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