Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:bug: Check pending notebook archives before password changes https://github.com/siyuan-note/siyuan/issues/19938

Daniel8ddf67a6de0c
diff --git a/kernel/model/crypto.go b/kernel/model/crypto.go
index e55522438d..3db14821e4 100644
--- a/kernel/model/crypto.go
+++ b/kernel/model/crypto.go
@@ -1752,6 +1752,9 @@ func ChangeMasterPassword(oldPassword, newPassword string) error {
notebookCryptoMu.Lock()
defer notebookCryptoMu.Unlock()
+ if err := checkPendingNotebookArchives(); err != nil {
+ return err
+ }
// 改密期间不能有已 Mount 的加密笔记本(DEK 在内存),否则新旧 KEK 切换会让缓存与磁盘不一致
cachedDEKsLock.RLock()
diff --git a/kernel/model/notebook_archive_test.go b/kernel/model/notebook_archive_test.go
index e41ce05d22..e0f71c41e1 100644
--- a/kernel/model/notebook_archive_test.go
+++ b/kernel/model/notebook_archive_test.go
@@ -11,6 +11,7 @@ import (
"testing"
"github.com/siyuan-note/siyuan/kernel/conf"
+ "github.com/siyuan-note/siyuan/kernel/documentaddressing"
"github.com/siyuan-note/siyuan/kernel/filesys"
"github.com/siyuan-note/siyuan/kernel/util"
)
@@ -189,6 +190,18 @@ func TestNotebookArchivePartialRemovalAndAuthenticatedRecovery(t *testing.T) {
}
func TestNotebookArchiveRejectsChangedSourcesAndRollsBackInterruptedMove(t *testing.T) {
+ testNotebookArchiveInterruptedMove(t)
+}
+
+func TestStructuredTitlesArchiveInterruptedMove(t *testing.T) {
+ if documentaddressing.DefaultMode() != 2 {
+ t.Skip("covered by the structured-title release-gate CI run")
+ }
+ testNotebookArchiveInterruptedMove(t)
+}
+
+func testNotebookArchiveInterruptedMove(t *testing.T) {
+ t.Helper()
notebookArchiveTestWorkspace(t)
if err := EnableEncryptedNotebook("archive-password"); err != nil {
t.Fatal(err)
@@ -226,8 +239,30 @@ func TestNotebookArchiveRejectsChangedSourcesAndRollsBackInterruptedMove(t *test
if err = checkPendingNotebookArchives(); !errors.Is(err, ErrNotebookArchiveBusy) {
t.Fatalf("pending transaction allowed key changes: %v", err)
}
- if err = ChangeMasterPassword("archive-password", "new-password"); !errors.Is(err, ErrNotebookArchiveBusy) {
- t.Fatalf("pending transaction allowed password changes: %v", err)
+ beforeKeys, _ := json.Marshal(currentNotebookCrypto())
+ beforeFiles, err := archiveDirectoryFiles(removed)
+ if err != nil {
+ t.Fatal(err)
+ }
+ changeErr := ChangeMasterPassword("archive-password", "new-password")
+ afterKeys, _ := json.Marshal(currentNotebookCrypto())
+ if !bytes.Equal(beforeKeys, afterKeys) {
+ t.Fatal("pending archive changed encryption keys")
+ }
+ afterFiles, err := archiveDirectoryFiles(removed)
+ if err != nil {
+ t.Fatal(err)
+ }
+ beforeJSON, _ := json.Marshal(beforeFiles)
+ afterJSON, _ := json.Marshal(afterFiles)
+ if !bytes.Equal(beforeJSON, afterJSON) {
+ t.Fatal("pending archive changed ciphertext or recovery files")
+ }
+ if _, err = os.Stat(masterPasswordMigrationPath()); !os.IsNotExist(err) {
+ t.Fatalf("pending archive wrote a password migration: %v", err)
+ }
+ if !errors.Is(changeErr, ErrNotebookArchiveBusy) {
+ t.Fatalf("password change did not report pending archive: %v", changeErr)
}
if err = recoverNotebookArchiveOperations(); err != nil {
t.Fatal(err)