Documentation ¶
Index ¶
- Constants
- Variables
- func AESDecrypt(key, message []byte) ([]byte, error)
- func AESDecryptHexString(key []byte, message string) ([]byte, error)
- func AESEncrypt(key, message []byte) ([]byte, error)
- func AESGenKey() (*[KeySize]byte, error)
- func AESGenNonce() (*[NonceSize]byte, error)
- func ArrayContainsInt(s []int, e int) bool
- func ArrayContainsString(s []string, e string) bool
- func CalculateTotp(dbcode string) (string, string, string)
- func CallTrasaAPI(path string, reqBody interface{}, insecure bool) (resp models.TrasaResponseStruct, err error)
- func ConvertPublicKeyToSSHFormat(publicKey *rsa.PublicKey) ([]byte, error)
- func CreateDirIfNotExist(dir string)
- func DecodeBase64(s string) ([]byte, error)
- func DeducerAndDecryptor(shards [][]byte, secretData string) (string, error)
- func DomainFromEmail(email string) string
- func ECDHComputeSecret(yourPrivateKey *[32]byte, remotePublicKey *[32]byte) (secret []byte)
- func ECDHGenKeyPair() (privateKey *[32]byte, publicKey *[32]byte, err error)
- func EncodeBase64(buf []byte) string
- func EncodePrivateKeyToPEM(privateKey *rsa.PrivateKey) []byte
- func EncryptorAndSharder(secretData string) (string, []string)
- func GeneratePrivateKey(bitSize int) (*rsa.PrivateKey, error)
- func GenerateTotpSecret() string
- func GetConstraintErrorMessage(err error) string
- func GetETCDir() string
- func GetEcdsaPublicKeyBytes(pub *ecdsa.PublicKey) []byte
- func GetEcdsaPublicKeyFromBytes(r *u2f.Registration, pub []byte) error
- func GetHttpClient(insecure bool) *http.Client
- func GetIPFromAddr(addr net.Addr) string
- func GetIp(r *http.Request) string
- func GetRandomBytes(length int) []byte
- func GetRandomString(length int) string
- func GetTmpDir() string
- func GetUUID() string
- func GetVarDir() string
- func HoldVaultRootKryShards()
- func IsPrivateIP(ip net.IP) bool
- func LoadJSONWebKey(json []byte, pub bool) (*jose.JSONWebKey, error)
- func LoadPrivateKey(data []byte) (interface{}, error)
- func LoadPublicKey(data []byte) (interface{}, error)
- func MarshallStructByte(s interface{}) []byte
- func MarshallStructStr(s interface{}) string
- func MoveFile(sourcePath, destPath string) error
- func NaclDeCrypt(encryptedData string, decryptionKey []byte) (string, error)
- func NaclEnCrypt(secretData string, secretkeyByte []byte) string
- func NormalizeString(s string) string
- func ParseAndValidateRequest(r *http.Request, reqStruct interface{}) error
- func ParseTrasaResponse(data []byte) (resp models.TrasaResponseStruct, err error)
- func ShamirDeducer(keys [][]byte) ([]byte, error)
- func ShamirSharder(key []byte, shards, threshold int) []string
- func ToStringArr(vals []interface{}) ([]string, error)
- func TrasaResponse(w http.ResponseWriter, httpRespCode int, status, reason string, intent string, ...)
- func TrasaResponseWithDataString(w http.ResponseWriter, httpRespCode int, status, reason string, ...)
- func TrasaResponseWithTrail(w http.ResponseWriter, httpRespCode int, ...)
- type Checker
- type Totp
Constants ¶
const ( KeySize = 32 NonceSize = 12 )
/////////////////////////////////////////////////////////////// ////////////////// AES Encryption ///////////////// ///////////////////////////////////////////////////////////////
Variables ¶
var ( ErrEncrypt = errors.New("secret: encryption failed") ErrDecrypt = errors.New("secret: decryption failed") )
var Validator *validator.Validate
Functions ¶
func AESDecrypt ¶
AESDecrypt computes AES GCM decryption
func AESEncrypt ¶
AESEncrypt computes AES GCM encryption
func AESGenNonce ¶
AESGenNonce creates a new random nonce.
func ArrayContainsInt ¶
ArrayContainsInt check if int array contains certain int
func ArrayContainsString ¶
ArrayContainsString check if an string array contains a string
func CalculateTotp ¶
we are adding three return string since first and last one wil be for skew values.
func CallTrasaAPI ¶
func CallTrasaAPI(path string, reqBody interface{}, insecure bool) (resp models.TrasaResponseStruct, err error)
CallTrasaAPI is generic function to call TRASA API
func ConvertPublicKeyToSSHFormat ¶ added in v1.1.4
ConvertPublicKeyToSSHFormat takes a rsa.PublicKey and return bytes suitable for writing to .pub file returns in the format "ssh-rsa ..."
func CreateDirIfNotExist ¶
func CreateDirIfNotExist(dir string)
CreateDirIfNotExist creates directory if it doesn't exists
func DecodeBase64 ¶
func DeducerAndDecryptor ¶
func DomainFromEmail ¶
DomainFromEmail deduce domain name from email address. this domain is used to create subdomain on trasa-cloud
func ECDHComputeSecret ¶
ECDHComputeSecret takes private key, remote peers public key and computes secret key.
func ECDHGenKeyPair ¶
ECDHGenKeyPair generated public and private key pair to be used in curve25519.ScalarBaseMult() This function should be called in both client and server independently. Reference from https://cr.yp.to/ecdh.html. Inspiration from https://github.com/aead/ecdh
func EncodeBase64 ¶
func EncodePrivateKeyToPEM ¶
func EncodePrivateKeyToPEM(privateKey *rsa.PrivateKey) []byte
EncodePrivateKeyToPEM encodes Private Key from RSA to PEM format
func EncryptorAndSharder ¶
func GeneratePrivateKey ¶
func GeneratePrivateKey(bitSize int) (*rsa.PrivateKey, error)
GeneratePrivateKey creates a RSA Private Key of specified byte size
func GenerateTotpSecret ¶
func GenerateTotpSecret() string
func GetConstraintErrorMessage ¶
GetConstraintErrorMessage returns user readable error according to violated database constraints. It is used while creating and updating
func GetEcdsaPublicKeyBytes ¶
func GetEcdsaPublicKeyFromBytes ¶
func GetEcdsaPublicKeyFromBytes(r *u2f.Registration, pub []byte) error
func GetHttpClient ¶
GetHttpClient return a http client
func GetIPFromAddr ¶
GetIPFromAddr returns IP address as string from net.Addr type
func GetRandomBytes ¶
GetRandomBytes returns crypto rand bytes
func GetRandomString ¶
GetRandomString returns random string
func HoldVaultRootKryShards ¶
func HoldVaultRootKryShards()
func IsPrivateIP ¶
IsPrivateIP returns boolean value based on ip type
func LoadJSONWebKey ¶
func LoadPrivateKey ¶
LoadPrivateKey loads a private key from PEM/DER/JWK-encoded data.
func LoadPublicKey ¶
LoadPublicKey loads a public key from PEM/DER/JWK-encoded data.
func MarshallStructByte ¶
func MarshallStructByte(s interface{}) []byte
MarshallStructByte marshalls interface into bytes ignoring errors
func MarshallStructStr ¶
func MarshallStructStr(s interface{}) string
func NaclEnCrypt ¶
func NormalizeString ¶
NormalizeString trims spaces and convert into lowercase
func ParseAndValidateRequest ¶
ParseAndValidateRequest unmarshalls request body into given struct and also verify json fields
func ParseTrasaResponse ¶
func ParseTrasaResponse(data []byte) (resp models.TrasaResponseStruct, err error)
func ShamirDeducer ¶
func ShamirSharder ¶
func ToStringArr ¶
ToStringArr casts interface array into string array
func TrasaResponse ¶
func TrasaResponse(w http.ResponseWriter, httpRespCode int, status, reason string, intent string, data ...interface{})
TrasaResponse is generic response function for http api
Use TrasaResponseWithTrail if in apptrail is needed. TrasaResponseWithTrail has separate trailDecription for inapp trail description
func TrasaResponseWithDataString ¶
func TrasaResponseWithDataString(w http.ResponseWriter, httpRespCode int, status, reason string, intent, data string)
TrasaResponseWithDataString expects string value in data
func TrasaResponseWithTrail ¶
func TrasaResponseWithTrail(w http.ResponseWriter, httpRespCode int, status, reason, intent, trailDecription string, data ...interface{})
TrasaResponseWithTrail is generic response function for http api.
Types ¶
type Checker ¶
type Checker struct {
// contains filtered or unexported fields
}
Borrowed from traefik! Checker allows to check that addresses are in a trusted IPs
func NewChecker ¶
NewChecker builds a new Checker given a list of CIDR-Strings to trusted IPs
func (*Checker) ContainsIP ¶
ContainsIP checks if provided address is in the trusted IPs