diff --git a/daemon/1shared.go b/daemon/1shared.go index 47a41e1..4cb1122 100644 --- a/daemon/1shared.go +++ b/daemon/1shared.go @@ -6,9 +6,9 @@ import ( var binPath, _ = os.Executable() // store binary path -// daemonIsOpen checks if the socket/named pipe for the rcw +// IsOpen checks if the socket/named pipe for the rcw // daemon exists and returns a boolean indicator. -func daemonIsOpen() bool { +func IsOpen() bool { fileInfo, err := os.Stat(socketPath) if err != nil { return false diff --git a/daemon/3client.go b/daemon/3client.go index 7ff5449..d28b3f6 100644 --- a/daemon/3client.go +++ b/daemon/3client.go @@ -9,7 +9,7 @@ import ( // DecryptWithDaemonIfOpen uses the RCW daemon (if one is available) to // decrypt and return data. If no RCW daemon is accessible, nil is returned. func DecryptWithDaemonIfOpen(encBytes []byte) []byte { - if daemonIsOpen() { + if IsOpen() { return getDecFromDaemon(encBytes) } return nil @@ -18,7 +18,7 @@ func DecryptWithDaemonIfOpen(encBytes []byte) []byte { // EncryptWithDaemonIfOpen uses the RCW daemon (if one is available) to // encrypt and return data. If no RCW daemon is accessible, nil is returned. func EncryptWithDaemonIfOpen(decBytes []byte) []byte { - if daemonIsOpen() { + if IsOpen() { return getEncFromDaemon(decBytes) } return nil diff --git a/example.go b/example.go index 261df10..7126eff 100644 --- a/example.go +++ b/example.go @@ -18,6 +18,23 @@ import ( // rcw enc : Encrypts the provided text and outputs the ciphertext to ex-cipher.rcw (attempts to use daemon, falls back to user input for passphrase) // rcw dec : Decrypts ex-cipher.rcw and outputs the plaintext to stdout (attempts to use daemon, falls back to user input for passphrase) +// Implementation Notes: +// There are two main ways to use the RCW library: +// +// 1. Daemon mode: +// The daemon is started with a passphrase and runs in the background. +// All encryption/decryption occurs in the daemon. +// Avoid using the wrapper.Encrypt/Decrypt functions directly. +// Instead, cache the passphrase with the daemon and use the daemon to encrypt/decrypt data. +// +// 2. Standalone mode: +// The wrapper.Encrypt/Decrypt functions are used directly. +// The passphrase is provided directly to the functions. +// +// It is up to the client to perform the sanity check before encrypting data. +// This means that when using the daemon to cache the passphrase, the client should +// perform the sanity check before activating the daemon. + // TODO Tests: // Salt (aes+chacha) // Nonce (aes+chacha) @@ -26,7 +43,6 @@ import ( // RPC password sharing // TODO Enhancements: -// Fix sanity check (should be performed when starting the daemon to ensure the correct passphrase is used) // Standalone cmd: // Usable as symmetric-only GPG replacement @@ -61,6 +77,15 @@ func main() { } // run decrypter daemon // rcw + if daemon.IsOpen() { + fmt.Println("Daemon already running") + return + } + err := wrappers.RunSanityCheck(sanityFile, []byte(os.Args[1])) + if err != nil { + fmt.Println(err) + return + } daemon.Start([]byte(os.Args[1])) case 3: if os.Args[1] == "init" { diff --git a/wrappers/highLevel.go b/wrappers/highLevel.go index be5d0a7..2cbca68 100644 --- a/wrappers/highLevel.go +++ b/wrappers/highLevel.go @@ -1,6 +1,7 @@ package wrappers // Decrypt decrypts the provided byte slice using the provided passphrase. +// Do NOT use directly if using the RCW daemon. func Decrypt(encBytes []byte, passphrase []byte) ([]byte, error) { var err error = nil encBytes, err = decryptCha(encBytes, passphrase) @@ -15,6 +16,7 @@ func Decrypt(encBytes []byte, passphrase []byte) ([]byte, error) { } // Encrypt encrypts the provided byte slice using the provided passphrase. +// Do NOT use directly if using the RCW daemon. func Encrypt(decBytes []byte, passphrase []byte) []byte { decBytes = encryptAES(decBytes, passphrase) decBytes = encryptCha(decBytes, passphrase)