mirror of
https://github.com/rwinkhart/libmutton.git
synced 2026-08-27 20:36:29 -04:00
Rename all occurrences of "passphrase" to "password"
This commit is contained in:
+7
-7
@@ -14,8 +14,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// LibmuttonInit creates the libmutton config structure based on user input.
|
// LibmuttonInit creates the libmutton config structure based on user input.
|
||||||
// rcwPassphrase and clientSpecificIniData can be left blank if not needed.
|
// rcwPassword and clientSpecificIniData can be left blank if not needed.
|
||||||
func LibmuttonInit(inputCB func(prompt string) string, clientSpecificIniData [][3]string, rcwPassphrase []byte, preserveOldConfigDir bool) error {
|
func LibmuttonInit(inputCB func(prompt string) string, clientSpecificIniData [][3]string, rcwPassword []byte, preserveOldConfigDir bool) error {
|
||||||
r := strings.ToLower(inputCB("Configure SSH settings (for synchronization)? (Y/n)"))
|
r := strings.ToLower(inputCB("Configure SSH settings (for synchronization)? (Y/n)"))
|
||||||
if len(r) > 0 && r[0] == 'n' {
|
if len(r) > 0 && r[0] == 'n' {
|
||||||
// initialize libmutton directories
|
// initialize libmutton directories
|
||||||
@@ -35,7 +35,7 @@ func LibmuttonInit(inputCB func(prompt string) string, clientSpecificIniData [][
|
|||||||
} else {
|
} else {
|
||||||
// ensure ssh key file exists (and is a file)
|
// ensure ssh key file exists (and is a file)
|
||||||
fallbackSSHKey := back.Home + global.PathSeparator + ".ssh" + global.PathSeparator + "id_ed25519"
|
fallbackSSHKey := back.Home + global.PathSeparator + ".ssh" + global.PathSeparator + "id_ed25519"
|
||||||
sshKeyPath := cmp.Or(back.ExpandPathWithHome(inputCB(back.AnsiBold+"Note:"+back.AnsiReset+" Only key-based authentication is supported (keys may optionally be passphrase-protected).\n The remote server must already be in your ~"+global.PathSeparator+".ssh"+global.PathSeparator+"known_hosts file.\n\nSSH private identity file path (falls back to \""+fallbackSSHKey+"\"):")), fallbackSSHKey)
|
sshKeyPath := cmp.Or(back.ExpandPathWithHome(inputCB(back.AnsiBold+"Note:"+back.AnsiReset+" Only key-based authentication is supported (keys may optionally be password-protected).\n The remote server must already be in your ~"+global.PathSeparator+".ssh"+global.PathSeparator+"known_hosts file.\n\nSSH private identity file path (falls back to \""+fallbackSSHKey+"\"):")), fallbackSSHKey)
|
||||||
_, err := back.TargetIsFile(sshKeyPath, true)
|
_, err := back.TargetIsFile(sshKeyPath, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New("unable to find SSH identity file: " + err.Error())
|
return errors.New("unable to find SSH identity file: " + err.Error())
|
||||||
@@ -84,8 +84,8 @@ func LibmuttonInit(inputCB func(prompt string) string, clientSpecificIniData [][
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// generate rcw sanity check file (if requested)
|
// generate rcw sanity check file (if requested)
|
||||||
if len(rcwPassphrase) > 0 {
|
if len(rcwPassword) > 0 {
|
||||||
err := RCWSanityCheckGen(rcwPassphrase)
|
err := RCWSanityCheckGen(rcwPassword)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -94,8 +94,8 @@ func LibmuttonInit(inputCB func(prompt string) string, clientSpecificIniData [][
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RCWSanityCheckGen generates the RCW sanity check file for libmutton.
|
// RCWSanityCheckGen generates the RCW sanity check file for libmutton.
|
||||||
func RCWSanityCheckGen(passphrase []byte) error {
|
func RCWSanityCheckGen(password []byte) error {
|
||||||
err := wrappers.GenSanityCheck(global.ConfigDir+global.PathSeparator+"sanity.rcw", passphrase)
|
err := wrappers.GenSanityCheck(global.ConfigDir+global.PathSeparator+"sanity.rcw", password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New("unable to generate sanity check file: " + err.Error())
|
return errors.New("unable to generate sanity check file: " + err.Error())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,14 +21,14 @@ func WriteEntry(targetLocation string, decBytes []byte) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// EntryRefresh re-encrypts all libmutton entries with a new passphrase
|
// EntryRefresh re-encrypts all libmutton entries with a new password
|
||||||
// and optimizes each entry to ensure they are as slim as possible.
|
// and optimizes each entry to ensure they are as slim as possible.
|
||||||
// This includes stripping trailing whitespace/newlines/carriage returns
|
// This includes stripping trailing whitespace/newlines/carriage returns
|
||||||
// from each field and running each note through ClampTrailingWhitespace
|
// from each field and running each note through ClampTrailingWhitespace
|
||||||
// to ensure each note line is optimized as possible without breaking
|
// to ensure each note line is optimized as possible without breaking
|
||||||
// Markdown formatting.
|
// Markdown formatting.
|
||||||
// Be sure to verify passphrases before using as input for this function!!
|
// Be sure to verify passwords before using as input for this function!!
|
||||||
func EntryRefresh(oldRCWPassphrase, newRCWPassphrase []byte, removeOldDir bool) error {
|
func EntryRefresh(oldRCWPassword, newRCWPassword []byte, removeOldDir bool) error {
|
||||||
// ensure global.EntryRoot+"-new" and global.EntryRoot-"old" do not exist
|
// ensure global.EntryRoot+"-new" and global.EntryRoot-"old" do not exist
|
||||||
dirEnds := []string{"-new", "-old"}
|
dirEnds := []string{"-new", "-old"}
|
||||||
for i, dirEnd := range dirEnds {
|
for i, dirEnd := range dirEnds {
|
||||||
@@ -63,7 +63,7 @@ func EntryRefresh(oldRCWPassphrase, newRCWPassphrase []byte, removeOldDir bool)
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New("unable to open \"" + targetLocation + "\" for decryption: " + err.Error())
|
return errors.New("unable to open \"" + targetLocation + "\" for decryption: " + err.Error())
|
||||||
}
|
}
|
||||||
decBytes, err := wrappers.Decrypt(encBytes, oldRCWPassphrase)
|
decBytes, err := wrappers.Decrypt(encBytes, oldRCWPassword)
|
||||||
decryptedEntry := strings.Split(string(decBytes), "\n")
|
decryptedEntry := strings.Split(string(decBytes), "\n")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -91,8 +91,8 @@ func EntryRefresh(oldRCWPassphrase, newRCWPassphrase []byte, removeOldDir bool)
|
|||||||
decryptedEntry = append(fieldsMain, fieldsNote...)
|
decryptedEntry = append(fieldsMain, fieldsNote...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// re-encrypt the entry with the new passphrase
|
// re-encrypt the entry with the new password
|
||||||
encBytes = wrappers.Encrypt([]byte(strings.Join(decryptedEntry, "\n")), newRCWPassphrase)
|
encBytes = wrappers.Encrypt([]byte(strings.Join(decryptedEntry, "\n")), newRCWPassword)
|
||||||
|
|
||||||
// write the entry to the new directory
|
// write the entry to the new directory
|
||||||
err = os.WriteFile(global.EntryRoot+"-new"+strings.ReplaceAll(entryName, "/", global.PathSeparator), encBytes, 0600)
|
err = os.WriteFile(global.EntryRoot+"-new"+strings.ReplaceAll(entryName, "/", global.PathSeparator), encBytes, 0600)
|
||||||
@@ -101,7 +101,7 @@ func EntryRefresh(oldRCWPassphrase, newRCWPassphrase []byte, removeOldDir bool)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// generate new sanity check file
|
// generate new sanity check file
|
||||||
err = RCWSanityCheckGen(newRCWPassphrase)
|
err = RCWSanityCheckGen(newRCWPassword)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
+21
-21
@@ -14,15 +14,15 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var Daemonize = true
|
var Daemonize = true
|
||||||
var RetryPassphrase = true
|
var RetryPassword = true
|
||||||
|
|
||||||
// RCWDArgument reads the passphrase from stdin and caches it via an RCW daemon.
|
// RCWDArgument reads the password from stdin and caches it via an RCW daemon.
|
||||||
func RCWDArgument() {
|
func RCWDArgument() {
|
||||||
passphrase := back.ReadFromStdin()
|
password := back.ReadFromStdin()
|
||||||
if passphrase == "" {
|
if password == "" {
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
daemon.Start([]byte(passphrase))
|
daemon.Start([]byte(password))
|
||||||
}
|
}
|
||||||
|
|
||||||
// DecryptFileToSlice decrypts an RCW wrapped file and returns the contents as a slice of (trimmed) strings.
|
// DecryptFileToSlice decrypts an RCW wrapped file and returns the contents as a slice of (trimmed) strings.
|
||||||
@@ -34,14 +34,14 @@ func DecryptFileToSlice(targetLocation string) ([]string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// decrypt data using RCW daemon
|
// decrypt data using RCW daemon
|
||||||
passphrase := launchRCWDProcess()
|
password := launchRCWDProcess()
|
||||||
if passphrase == nil {
|
if password == nil {
|
||||||
// if daemon is already running, use it to decrypt the data
|
// if daemon is already running, use it to decrypt the data
|
||||||
return strings.Split(string(daemon.GetDec(encBytes)), "\n"), nil
|
return strings.Split(string(daemon.GetDec(encBytes)), "\n"), nil
|
||||||
}
|
}
|
||||||
// if the daemon is not already running, use wrappers.Decrypt
|
// if the daemon is not already running, use wrappers.Decrypt
|
||||||
// directly to avoid waiting for socket file creation
|
// directly to avoid waiting for socket file creation
|
||||||
decBytes, err := wrappers.Decrypt(encBytes, passphrase)
|
decBytes, err := wrappers.Decrypt(encBytes, password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.New("unable to decrypt \"" + targetLocation + "\": " + err.Error())
|
return nil, errors.New("unable to decrypt \"" + targetLocation + "\": " + err.Error())
|
||||||
}
|
}
|
||||||
@@ -50,43 +50,43 @@ func DecryptFileToSlice(targetLocation string) ([]string, error) {
|
|||||||
|
|
||||||
// EncryptBytes encrypts a byte slice using RCW and returns the encrypted data.
|
// EncryptBytes encrypts a byte slice using RCW and returns the encrypted data.
|
||||||
func EncryptBytes(decBytes []byte) []byte {
|
func EncryptBytes(decBytes []byte) []byte {
|
||||||
passphrase := launchRCWDProcess()
|
password := launchRCWDProcess()
|
||||||
if passphrase == nil {
|
if password == nil {
|
||||||
// if daemon is already running, use it to encrypt the data
|
// if daemon is already running, use it to encrypt the data
|
||||||
return daemon.GetEnc(decBytes)
|
return daemon.GetEnc(decBytes)
|
||||||
}
|
}
|
||||||
// if the daemon is not already running, use wrappers.Encrypt
|
// if the daemon is not already running, use wrappers.Encrypt
|
||||||
// directly to avoid waiting for socket file creation
|
// directly to avoid waiting for socket file creation
|
||||||
return wrappers.Encrypt(decBytes, passphrase)
|
return wrappers.Encrypt(decBytes, password)
|
||||||
}
|
}
|
||||||
|
|
||||||
// launchRCWDProcess launches an RCW daemon to cache a passphrase.
|
// launchRCWDProcess launches an RCW daemon to cache a password.
|
||||||
// If the daemon is not already running OR if not running in daemonize mode,
|
// If the daemon is not already running OR if not running in daemonize mode,
|
||||||
// it collects and returns the passphrase (otherwise returns nil).
|
// it collects and returns the password (otherwise returns nil).
|
||||||
func launchRCWDProcess() []byte {
|
func launchRCWDProcess() []byte {
|
||||||
if Daemonize && daemon.IsOpen() {
|
if Daemonize && daemon.IsOpen() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
var passphrase []byte
|
var password []byte
|
||||||
if RetryPassphrase {
|
if RetryPassword {
|
||||||
for {
|
for {
|
||||||
passphrase = global.GetPassphrase("RCW Passphrase:")
|
password = global.GetPassword("RCW Password:")
|
||||||
err := wrappers.RunSanityCheck(global.ConfigDir+global.PathSeparator+"sanity.rcw", passphrase)
|
err := wrappers.RunSanityCheck(global.ConfigDir+global.PathSeparator+"sanity.rcw", password)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
fmt.Println(back.AnsiError + "Incorrect passphrase" + back.AnsiReset)
|
fmt.Println(back.AnsiError + "Incorrect password" + back.AnsiReset)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// in this mode, it is up to the client to perform the sanity check
|
// in this mode, it is up to the client to perform the sanity check
|
||||||
passphrase = global.GetPassphrase("RCW Passphrase:")
|
password = global.GetPassword("RCW Password:")
|
||||||
}
|
}
|
||||||
|
|
||||||
if Daemonize {
|
if Daemonize {
|
||||||
cmd := exec.Command(os.Args[0], "startrcwd")
|
cmd := exec.Command(os.Args[0], "startrcwd")
|
||||||
_ = back.WriteToStdin(cmd, string(passphrase))
|
_ = back.WriteToStdin(cmd, string(password))
|
||||||
_ = cmd.Start()
|
_ = cmd.Start()
|
||||||
}
|
}
|
||||||
|
|
||||||
return passphrase
|
return password
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -3,7 +3,7 @@ package global
|
|||||||
type ByteInputFetcher func(prompt string) []byte
|
type ByteInputFetcher func(prompt string) []byte
|
||||||
|
|
||||||
var (
|
var (
|
||||||
GetPassphrase ByteInputFetcher // Clients should set this to a function that fetches hidden input from the user
|
GetPassword ByteInputFetcher // Clients should set this to a function that fetches hidden input from the user
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import (
|
|||||||
// offlineMode (whether the client is in offline mode).
|
// offlineMode (whether the client is in offline mode).
|
||||||
// sshIsWindows (whether the remote server is running Windows),
|
// sshIsWindows (whether the remote server is running Windows),
|
||||||
// sshEntryRoot (the root directory for entries on the remote server),
|
// sshEntryRoot (the root directory for entries on the remote server),
|
||||||
// Only supports key-based authentication (passphrases are supported for CLI-based implementations).
|
// Only supports key-based authentication (passwords are supported for CLI-based implementations).
|
||||||
func GetSSHClient() (*ssh.Client, bool, bool, string, error) {
|
func GetSSHClient() (*ssh.Client, bool, bool, string, error) {
|
||||||
// get SSH config info
|
// get SSH config info
|
||||||
sshUserConfig, err := cfg.ParseConfig([][2]string{{"LIBMUTTON", "offlineMode"}, {"LIBMUTTON", "sshUser"}, {"LIBMUTTON", "sshIP"}, {"LIBMUTTON", "sshPort"}, {"LIBMUTTON", "sshKey"}, {"LIBMUTTON", "sshKeyProtected"}, {"LIBMUTTON", "sshEntryRoot"}, {"LIBMUTTON", "sshIsWindows"}})
|
sshUserConfig, err := cfg.ParseConfig([][2]string{{"LIBMUTTON", "offlineMode"}, {"LIBMUTTON", "sshUser"}, {"LIBMUTTON", "sshIP"}, {"LIBMUTTON", "sshPort"}, {"LIBMUTTON", "sshKey"}, {"LIBMUTTON", "sshKeyProtected"}, {"LIBMUTTON", "sshEntryRoot"}, {"LIBMUTTON", "sshIsWindows"}})
|
||||||
@@ -70,7 +70,7 @@ func GetSSHClient() (*ssh.Client, bool, bool, string, error) {
|
|||||||
if keyFileProtected != "true" {
|
if keyFileProtected != "true" {
|
||||||
parsedKey, err = ssh.ParsePrivateKey(key)
|
parsedKey, err = ssh.ParsePrivateKey(key)
|
||||||
} else {
|
} else {
|
||||||
parsedKey, err = ssh.ParsePrivateKeyWithPassphrase(key, global.GetPassphrase("Enter passphrase for your SSH keyfile:"))
|
parsedKey, err = ssh.ParsePrivateKeyWithPassphrase(key, global.GetPassword("Enter password for your SSH keyfile:"))
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, false, false, "", errors.New("unable to parse private key: " + keyFile)
|
return nil, false, false, "", errors.New("unable to parse private key: " + keyFile)
|
||||||
|
|||||||
+3
-3
@@ -16,12 +16,12 @@ These are as follows:
|
|||||||
- `termux`: Allows creating an Android binary that can interact with the Termux clipboard (for Android)
|
- `termux`: Allows creating an Android binary that can interact with the Termux clipboard (for Android)
|
||||||
|
|
||||||
## Required Global Variable Manipulation
|
## Required Global Variable Manipulation
|
||||||
- `global.GetPassphrase` must be set to allow for different types of clients (CLI, GUI, TUI) to prompt for the passphrase in the most appropriate way.
|
- `global.GetPassword` must be set to allow for different types of clients (CLI, GUI, TUI) to prompt for the password in the most appropriate way.
|
||||||
- `crypt.Daemonize`, true by default, determines whether to make use of the RCW daemon for passphrase caching. This may be best to disable for interactive clients.
|
- `crypt.Daemonize`, true by default, determines whether to make use of the RCW daemon for password caching. This may be best to disable for interactive clients.
|
||||||
|
|
||||||
## Required Arguments
|
## Required Arguments
|
||||||
- `clipclear`: Should be accepted by all non-interactive CLI libmutton implementations (not required for interactive GUI/TUI implementations). In order to clear the clipboard on a timer, non-interactive libmutton-based password managers call another instance of their executable with the `clipclear` argument (e.g. `mutn clipclear`) with the intended clipboard contents provided via STDIN. If after 30 seconds the clipboard contents have not changed, they are cleared. Please accept a `clipclear` argument that calls `core.ClipClearArgument()`.
|
- `clipclear`: Should be accepted by all non-interactive CLI libmutton implementations (not required for interactive GUI/TUI implementations). In order to clear the clipboard on a timer, non-interactive libmutton-based password managers call another instance of their executable with the `clipclear` argument (e.g. `mutn clipclear`) with the intended clipboard contents provided via STDIN. If after 30 seconds the clipboard contents have not changed, they are cleared. Please accept a `clipclear` argument that calls `core.ClipClearArgument()`.
|
||||||
- `startrcwd`: Should be accepted by all libmutton implementations making use of the RCW daemon to cache passphrases. Please accept a `startrcwd` argument that calls `core.RCWDArgument()`.
|
- `startrcwd`: Should be accepted by all libmutton implementations making use of the RCW daemon to cache passwords. Please accept a `startrcwd` argument that calls `core.RCWDArgument()`.
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
libmutton-based password manager clients should all share the same INI configuration file.
|
libmutton-based password manager clients should all share the same INI configuration file.
|
||||||
|
|||||||
Reference in New Issue
Block a user