crypto

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2018 License: MIT Imports: 19 Imported by: 6

Documentation

Overview

Package crypto provides functions for managing encryption, keys, etc.

Index

Constants

View Source
const (
	// TokenInvalidErrorMsg says that the token is invalid
	TokenInvalidErrorMsg = "token invalid"

	// TokenExpiredErrorMsg says that the token is expired
	TokenExpiredErrorMsg = "token expired"
)

Variables

View Source
var (
	// TestPrivateKey is an example key for testing purposes
	TestPrivateKey = []byte("very_sekrit_key")

	// TestMasterToken is an example token for testing purposes. This is
	// generated by TestGenerateMasterToken, and is a master token.
	TestMasterToken = "" /* 185-byte string literal not displayed */

	// TestInertiaKeyPath the path to Inertia's test RSA key
	TestInertiaKeyPath = path.Join(os.Getenv("GOPATH"), "/src/github.com/ubclaunchpad/inertia/test/keys/id_rsa")
)
View Source
var (
	// DaemonGithubKeyLocation is the default path of the generated deploy key
	DaemonGithubKeyLocation = os.Getenv("INERTIA_GH_KEY_PATH") //"/app/host/.ssh/id_rsa_inertia_deploy"
)

Functions

func CorrectPassword

func CorrectPassword(hash string, password string) bool

CorrectPassword checks if given password maps correctly to the given hash

func GenerateCertificate

func GenerateCertificate(certPath, keyPath, host, method string) error

GenerateCertificate creates an SSL certificate for HTTPS use

func GenerateKeys

func GenerateKeys() (encryptPublicKey *[32]byte, encryptPrivateKey *[32]byte,
	decryptPublicKey *[32]byte, decryptPrivateKey *[32]byte, err error)

GenerateKeys creates 2 sets of keys - one for decryption, one for encryption

func GenerateMasterToken

func GenerateMasterToken(key []byte) (string, error)

GenerateMasterToken creates a "master" JSON Web Token (JWT) for a client to use when sending HTTP requests to the daemon server.

func GetAPIPrivateKey

func GetAPIPrivateKey(t *jwt.Token) (interface{}, error)

GetAPIPrivateKey returns the private RSA key to authenticate HTTP requests sent to the daemon. For now, we simply use the GitHub deploy key. Retrieves from default DaemonGithubKeyLocation.

func GetFakeAPIKey

func GetFakeAPIKey(tok *jwt.Token) (interface{}, error)

GetFakeAPIKey is a helper function that implements jwt.keyFunc and returns the test private key

func GetGithubKey

func GetGithubKey(pemFile io.Reader) (ssh.AuthMethod, error)

GetGithubKey returns an ssh.AuthMethod from the given io.Reader for use with the go-git library

func HashPassword

func HashPassword(password string) (string, error)

HashPassword generates a bcrypt-encrypted hash from given password

func IsLegalString

func IsLegalString(str string) bool

IsLegalString returns true if `str` only contains characters [A-Z], [a-z], or '_' or '-'

func Seal

func Seal(valueBytes []byte, encryptPrivateKey, decryptPublicKey *[32]byte) ([]byte, error)

Seal encrypts given value

func UndoSeal

func UndoSeal(value []byte, encryptPublicKey, decryptPrivateKey *[32]byte) ([]byte, error)

UndoSeal decrypts sealed value

func ValidateCredentialValues

func ValidateCredentialValues(username, password string) error

ValidateCredentialValues takes a username and password and verifies if they are of sufficient length and if they only contain legal characters

Types

type TokenClaims

type TokenClaims struct {
	SessionID string    `json:"session_id"`
	User      string    `json:"user"`
	Admin     bool      `json:"admin"`
	Expiry    time.Time `json:"expiry"`
}

TokenClaims represents a JWT token's claims

func ValidateToken

func ValidateToken(tokenString string, lookup jwt.Keyfunc) (*TokenClaims, error)

ValidateToken ensures token is valid and returns its metadata

func (*TokenClaims) GenerateToken

func (t *TokenClaims) GenerateToken(key []byte) (string, error)

GenerateToken creates a JWT token from this claim, signed with given key

func (*TokenClaims) IsMaster

func (t *TokenClaims) IsMaster() bool

IsMaster returns true if this is a mster key

func (*TokenClaims) Valid

func (t *TokenClaims) Valid() error

Valid checks if token is authentic

Jump to

Keyboard shortcuts

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