aboutsummaryrefslogtreecommitdiff
path: root/internal/crud
diff options
context:
space:
mode:
Diffstat (limited to 'internal/crud')
-rw-r--r--internal/crud/cli_edit.go2
-rw-r--r--internal/crud/cli_new.go15
2 files changed, 12 insertions, 5 deletions
diff --git a/internal/crud/cli_edit.go b/internal/crud/cli_edit.go
index 0213a81..db56450 100644
--- a/internal/crud/cli_edit.go
+++ b/internal/crud/cli_edit.go
@@ -153,7 +153,7 @@ func EditNoteSSH(notePath, privKeyPath, editorString string) error {
os.WriteFile(tmpFile.Name(), make([]byte, len(newContent)), 0600)
- encrypted, err := crypt.EncryptBytesSSH(newContent, pubKeys)
+ encrypted, _, err := crypt.EncryptBytesSSH(newContent, pubKeys)
if err != nil {
return err
}
diff --git a/internal/crud/cli_new.go b/internal/crud/cli_new.go
index c8303a0..cd06455 100644
--- a/internal/crud/cli_new.go
+++ b/internal/crud/cli_new.go
@@ -230,7 +230,7 @@ func NewNoteSSH(output string, defaultPubKeyBytes []byte) error {
tmptxt := []byte(string(utils.RandomLettersNumbers(37))+"\nYou can Delete all of this ^^^")
- encrypted, err := crypt.EncryptBytesSSH(tmptxt, pubKeys)
+ encrypted, _, err := crypt.EncryptBytesSSH(tmptxt, pubKeys)
if err != nil {
return err
}
@@ -327,10 +327,12 @@ func NewNoteSSHEdit(output string, defaultPubKeyBytes []byte, defaultPrivKeyPath
preExisting := err == nil
initialContent := []byte(string(utils.RandomLettersNumbers(37)) + "\nYou can Delete all of this ^^^")
- encrypted, err := crypt.EncryptBytesSSH(initialContent, pubKeys)
+ encrypted, noteKey, err := crypt.EncryptBytesSSH(initialContent, pubKeys)
if err != nil {
return err
}
+ crypt.TryMlock(noteKey)
+ defer clear(noteKey)
file, err := os.Create(output)
if err != nil {
@@ -355,7 +357,12 @@ func NewNoteSSHEdit(output string, defaultPubKeyBytes []byte, defaultPrivKeyPath
return err
}
- plaintext, err := crypt.DecryptBytesSSH(ciphertext, defaultPrivKeyPath)
+ var plaintext []byte
+ if useDefault {
+ plaintext, err = crypt.DecryptBytesSSH(ciphertext, defaultPrivKeyPath)
+ } else {
+ plaintext, err = crypt.DecryptBytesSSHWithKey(ciphertext, noteKey)
+ }
if err != nil {
return err
}
@@ -384,7 +391,7 @@ func NewNoteSSHEdit(output string, defaultPubKeyBytes []byte, defaultPrivKeyPath
os.WriteFile(tmpFile.Name(), make([]byte, len(newContent)), 0600)
- encrypted, err = crypt.EncryptBytesSSH(newContent, pubKeys)
+ encrypted, _, err = crypt.EncryptBytesSSH(newContent, pubKeys)
if err != nil {
return err
}