mirror of
https://github.com/rwinkhart/rcw.git
synced 2026-08-27 20:36:30 -04:00
Specify and solidify usage modes
This commit is contained in:
+2
-2
@@ -6,9 +6,9 @@ import (
|
|||||||
|
|
||||||
var binPath, _ = os.Executable() // store binary path
|
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.
|
// daemon exists and returns a boolean indicator.
|
||||||
func daemonIsOpen() bool {
|
func IsOpen() bool {
|
||||||
fileInfo, err := os.Stat(socketPath)
|
fileInfo, err := os.Stat(socketPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
|
|||||||
+2
-2
@@ -9,7 +9,7 @@ import (
|
|||||||
// DecryptWithDaemonIfOpen uses the RCW daemon (if one is available) to
|
// DecryptWithDaemonIfOpen uses the RCW daemon (if one is available) to
|
||||||
// decrypt and return data. If no RCW daemon is accessible, nil is returned.
|
// decrypt and return data. If no RCW daemon is accessible, nil is returned.
|
||||||
func DecryptWithDaemonIfOpen(encBytes []byte) []byte {
|
func DecryptWithDaemonIfOpen(encBytes []byte) []byte {
|
||||||
if daemonIsOpen() {
|
if IsOpen() {
|
||||||
return getDecFromDaemon(encBytes)
|
return getDecFromDaemon(encBytes)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@@ -18,7 +18,7 @@ func DecryptWithDaemonIfOpen(encBytes []byte) []byte {
|
|||||||
// EncryptWithDaemonIfOpen uses the RCW daemon (if one is available) to
|
// EncryptWithDaemonIfOpen uses the RCW daemon (if one is available) to
|
||||||
// encrypt and return data. If no RCW daemon is accessible, nil is returned.
|
// encrypt and return data. If no RCW daemon is accessible, nil is returned.
|
||||||
func EncryptWithDaemonIfOpen(decBytes []byte) []byte {
|
func EncryptWithDaemonIfOpen(decBytes []byte) []byte {
|
||||||
if daemonIsOpen() {
|
if IsOpen() {
|
||||||
return getEncFromDaemon(decBytes)
|
return getEncFromDaemon(decBytes)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
+26
-1
@@ -18,6 +18,23 @@ import (
|
|||||||
// rcw enc <text> : Encrypts the provided text and outputs the ciphertext to ex-cipher.rcw (attempts to use daemon, falls back to user input for passphrase)
|
// rcw enc <text> : 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)
|
// 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:
|
// TODO Tests:
|
||||||
// Salt (aes+chacha)
|
// Salt (aes+chacha)
|
||||||
// Nonce (aes+chacha)
|
// Nonce (aes+chacha)
|
||||||
@@ -26,7 +43,6 @@ import (
|
|||||||
// RPC password sharing
|
// RPC password sharing
|
||||||
|
|
||||||
// TODO Enhancements:
|
// TODO Enhancements:
|
||||||
// Fix sanity check (should be performed when starting the daemon to ensure the correct passphrase is used)
|
|
||||||
// Standalone cmd:
|
// Standalone cmd:
|
||||||
// Usable as symmetric-only GPG replacement
|
// Usable as symmetric-only GPG replacement
|
||||||
|
|
||||||
@@ -61,6 +77,15 @@ func main() {
|
|||||||
}
|
}
|
||||||
// run decrypter daemon
|
// run decrypter daemon
|
||||||
// rcw <passwd>
|
// rcw <passwd>
|
||||||
|
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]))
|
daemon.Start([]byte(os.Args[1]))
|
||||||
case 3:
|
case 3:
|
||||||
if os.Args[1] == "init" {
|
if os.Args[1] == "init" {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package wrappers
|
package wrappers
|
||||||
|
|
||||||
// Decrypt decrypts the provided byte slice using the provided passphrase.
|
// 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) {
|
func Decrypt(encBytes []byte, passphrase []byte) ([]byte, error) {
|
||||||
var err error = nil
|
var err error = nil
|
||||||
encBytes, err = decryptCha(encBytes, passphrase)
|
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.
|
// 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 {
|
func Encrypt(decBytes []byte, passphrase []byte) []byte {
|
||||||
decBytes = encryptAES(decBytes, passphrase)
|
decBytes = encryptAES(decBytes, passphrase)
|
||||||
decBytes = encryptCha(decBytes, passphrase)
|
decBytes = encryptCha(decBytes, passphrase)
|
||||||
|
|||||||
Reference in New Issue
Block a user