Documentation ¶
Overview ¶
Package encrypter is suitable for encrypting messages you would like to securely share between two points. Useful for providing end to end encryption (E2EE). It uses Box (NaCl) for encrypting the messages. tldr is it uses Elliptic Curves (Curve25519) for the keys, XSalsa20 and Poly1305 for encryption. You can read more here https://godoc.org/golang.org/x/crypto/nacl/box.
msg := []byte("super safe message.") alice, err := NewEncrypter("alice_priv_key.pem", "alice_pub_key.pem") if err != nil { log.Fatal(err) } bob, err := NewEncrypter("bob_priv_key.pem", "bob_pub_key.pem") if err != nil { log.Fatal(err) } encrypted, err := alice.Encrypt(msg, bob.PublicKey()) if err != nil { log.Fatal(err) } data, err := bob.Decrypt(encrypted, alice.PublicKey()) if err != nil { log.Fatal(err) } fmt.Println(string(data))
Index ¶
- Constants
- func FetchToken(appURL *url.URL, appInfo *AppInfo, log *zerolog.Logger) (string, error)
- func FetchTokenWithRedirect(appURL *url.URL, appInfo *AppInfo, log *zerolog.Logger) (string, error)
- func GenerateAppTokenFilePathFromURL(appDomain, aud string, suffix string) (string, error)
- func GenerateSSHCertFilePathFromURL(url *url.URL, suffix string) (string, error)
- func GetAppTokenIfExists(appInfo *AppInfo) (string, error)
- func GetOrgTokenIfExists(authDomain string) (string, error)
- func Init(version string)
- func OpenBrowser(url string) error
- func RemoveTokenIfExists(appInfo *AppInfo) error
- func RunTransfer(transferURL *url.URL, appAUD, resourceName, key, value string, ...) ([]byte, error)
- type AppInfo
- type Encrypter
Constants ¶
const ( AccessLoginWorkerPath = "/cdn-cgi/access/login" AccessAuthorizedWorkerPath = "/cdn-cgi/access/authorized" )
Variables ¶
This section is empty.
Functions ¶
func FetchToken ¶
FetchToken will either load a stored token or generate a new one it appends the host of the appURL as the redirect URL to the access cli request if opening the browser
func FetchTokenWithRedirect ¶
FetchTokenWithRedirect will either load a stored token or generate a new one it appends the full url as the redirect URL to the access cli request if opening the browser
func GenerateAppTokenFilePathFromURL ¶
GenerateAppTokenFilePathFromURL will return a filepath for given Access org token
func GenerateSSHCertFilePathFromURL ¶
GenerateSSHCertFilePathFromURL will return a file path for creating short lived certificates
func GetAppTokenIfExists ¶
func GetOrgTokenIfExists ¶
func OpenBrowser ¶
OpenBrowser opens the specified URL in the default browser of the user
func RemoveTokenIfExists ¶
RemoveTokenIfExists removes the a token from local storage if it exists
func RunTransfer ¶
func RunTransfer(transferURL *url.URL, appAUD, resourceName, key, value string, shouldEncrypt bool, useHostOnly bool, log *zerolog.Logger) ([]byte, error)
RunTransfer does the transfer "dance" with the end result downloading the supported resource. The expanded description is run is encapsulation of shared business logic needed to request a resource (token/cert/etc) from the transfer service (loginhelper). The "dance" we refer to is building a HTTP request, opening that in a browser waiting for the user to complete an action, while it long polls in the background waiting for an action to be completed to download the resource.
Types ¶
type Encrypter ¶
type Encrypter struct {
// contains filtered or unexported fields
}
Encrypter represents a keypair value with auxiliary functions to make doing encryption and decryption easier
func NewEncrypter ¶
NewEncrypter returns a new encrypter with initialized keypair
func (*Encrypter) Decrypt ¶
Decrypt data that was encrypted using our publicKey. It will use our privateKey and the sender's publicKey to decrypt data is an encrypted buffer of data, mostly like from the Encrypt function. Messages contain the nonce data on the front of the message. senderPublicKey is a base64 encoded version of the sender's public key (most likely from the PublicKey function). The return value is the decrypted buffer or an error.
func (*Encrypter) Encrypt ¶
Encrypt data using our privateKey and the recipient publicKey data is a buffer of data that we would like to encrypt. Messages will have the nonce added to front as they have to unique for each message shared. recipientPublicKey is a base64 encoded version of the sender's public key (most likely from the PublicKey function). The return value is the encrypted buffer or an error.