import "github.com/ubclaunchpad/inertia/daemon/inertiad/crypto"
Package crypto provides functions for managing encryption, keys, etc.
authtest.go certificate.go doc.go key_derivation.go keys.go password.go symmetric.go token.go totp.go verify.go
const ( // KeyDerivationSaltLength is the length of the salt in bytes KeyDerivationSaltLength = 8 // KeyDerivationKeyLength is the length of the key derived in bytes KeyDerivationKeyLength = 32 )
const ( // SymmetricKeyLength is the length of the symmetric key in bytes SymmetricKeyLength = 32 )
var ( TestPrivateKey = []byte("very_sekrit_key") TestMasterToken = "" /* 187 byte string literal not displayed */ TestInertiaKeyPath = "../../../test/keys/id_rsa" )
var ( // ErrInvalidToken says that the token is invalid ErrInvalidToken = errors.New("token invalid") // ErrTokenExpired says that the token is expired ErrTokenExpired = errors.New("token expired") )
var ( // DaemonInertiaKeyLocation is the default path of the generated deploy key DaemonInertiaKeyLocation = os.Getenv("INERTIA_GH_KEY_PATH") //"/app/host/.ssh/id_rsa_inertia_deploy" )
CorrectPassword checks if given password maps correctly to the given hash
Decrypt decrypts ciphertext using given key in AES GCM mode
DeriveKey derives an AES encryption key based on salt + user's password using PBKDF2 with HMAC-SHA256
Encrypt encrypts plaintext using given key in AES GCM mode
GenerateBackupCodes generates an array of backup code strings in Github format.
Example: b2e03-ffbcf cebe6-b1bdd ...
GenerateCertificate creates an SSL certificate for HTTPS use
GenerateMasterToken creates a "master" JSON Web Token (JWT) for a client to use when sending HTTP requests to the daemon server.
GenerateSalt returns a random hex encoded salt for KD algorithm
GenerateSecretKey creates a new key which can be turned into string or image
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 DaemonInertiaKeyLocation.
GetFakeAPIKey is a helper function that implements jwt.keyFunc and returns the test private key
GetInertiaKey returns an ssh.AuthMethod from the given io.Reader for use with the go-git library
HashPassword generates a bcrypt-encrypted hash from given password
IsCredentialFormatError returns true if the given error is one related to username/password format
IsLegalString returns true if `str` only contains characters [A-Z], [a-z], or '_' or '-'
ValidateCredentialValues takes a username and password and verifies if they are of sufficient length and if they only contain legal characters
ValidatePasscode validates one-time passcode against original secret key
ValidateSignature validates the HMAC signature for the given payload. Based off of https://github.com/google/go-github
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
ValidateToken ensures token is valid and returns its metadata
func (t *TokenClaims) GenerateToken(key []byte) (string, error)
GenerateToken creates a JWT token from this claim, signed with given key
func (t *TokenClaims) IsMaster() bool
IsMaster returns true if this is a master key
func (t *TokenClaims) Valid() error
Valid checks if token is authentic
Package crypto imports 28 packages (graph) and is imported by 6 packages. Updated 2021-01-09. Refresh now. Tools for package owners.