diff --git a/backend/protondrive/account.go b/backend/protondrive/account.go index 7ad53c197..6cb6df408 100644 --- a/backend/protondrive/account.go +++ b/backend/protondrive/account.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "net/url" + "strings" "sync" "github.com/ProtonMail/gopenpgp/v3/crypto" @@ -240,6 +241,17 @@ func (a *account) byEmail(email string) *address { return nil } +// owns reports whether email is one of the account's addresses whose +// keys it holds, ignoring case. +func (a *account) owns(email string) bool { + for _, addr := range a.addresses { + if strings.EqualFold(addr.Email, email) { + return true + } + } + return false +} + // apiCaller makes an API call with the semantics of session.call, // without returning the response; client.apiCall is one which paces // and retries. diff --git a/backend/protondrive/nodes.go b/backend/protondrive/nodes.go index fbbfed600..7675c5c96 100644 --- a/backend/protondrive/nodes.go +++ b/backend/protondrive/nodes.go @@ -335,9 +335,16 @@ func (c *client) bootstrap(ctx context.Context) error { return fmt.Errorf("get drive: decrypt share key: %w", err) } c.shareKeys = shareKeys - if verifyErr != nil { - shareKeys.unverified = verifyErr - fs.Errorf(nil, "protondrive: share %s: signature check of the share key failed: %v", my.Share.ShareID, verifyErr) + // Everything below is trusted because the share and root are the + // user's own: another user's keys would come from the server. + switch { + case !c.acct.owns(my.Share.CreatorEmail): + shareKeys.unverified = fmt.Errorf("the drive's share was created by %q, which is not one of your addresses", my.Share.CreatorEmail) + case verifyErr != nil: + shareKeys.unverified = fmt.Errorf("the drive's share key isn't signed by its creator: %w", verifyErr) + } + if shareKeys.unverified != nil { + fs.Errorf(nil, "protondrive: share %s: %v: reading and writing need ignore_signature_errors", my.Share.ShareID, shareKeys.unverified) } root, unreadable, err := c.decryptNode(ctx, &my.Link, shareKeys) if err == nil && unreadable == nil && !root.IsFolder { @@ -349,6 +356,10 @@ func (c *client) bootstrap(ctx context.Context) error { if err != nil { return fmt.Errorf("get drive: root folder: %w", err) } + if root.keys.unverified == nil && !c.acct.owns(my.Link.Link.SignatureEmail) { + root.keys.unverified = fmt.Errorf("the drive's root folder is signed by %q, which is not one of your addresses", my.Link.Link.SignatureEmail) + fs.Errorf(nil, "protondrive: %v: reading and writing need ignore_signature_errors", root.keys.unverified) + } c.addr = addr c.volumeID = my.Volume.VolumeID c.shareID = my.Share.ShareID diff --git a/backend/protondrive/protontest/drive_test.go b/backend/protondrive/protontest/drive_test.go index 06fd9210d..6cebea695 100644 --- a/backend/protondrive/protontest/drive_test.go +++ b/backend/protondrive/protontest/drive_test.go @@ -611,6 +611,28 @@ func TestSeedForgedFolder(t *testing.T) { } } +func TestForgeShareAndRoot(t *testing.T) { + s := New(t) + u := s.AddUser("user", "pass") + other := s.AddUser("other", "pass") + u.ForgeShareCreator(other) + u.ForgeRootSigner(other) + v := u.view() + assert.Equal(t, other.Email(), v.d.creatorEmail) + _, err := v.unlockShare() + assert.NoError(t, err, "the share verifies against the other user's key") + root := v.d.links[v.d.rootID] + assert.Equal(t, other.Email(), root.signatureEmail) + _, err = v.unlock(v.d.rootID) + assert.NoError(t, err, "the root verifies against the other user's key") + id := u.SeedFile(u.RootID(), "file", []byte("x"), time.Now()) + for _, n := range u.Dump() { + if n.ID == id { + assert.NoError(t, n.Err) + } + } +} + func TestNodeSecrets(t *testing.T) { s := New(t) u := s.AddUser("user", "pass") diff --git a/backend/protondrive/security_test.go b/backend/protondrive/security_test.go index 404051102..904f7f024 100644 --- a/backend/protondrive/security_test.go +++ b/backend/protondrive/security_test.go @@ -305,6 +305,41 @@ func TestHostileServer(t *testing.T) { assert.Error(t, err, "uploaded") }) + for _, forge := range []struct { + name string + apply func(u, other *protontest.User) + }{ + {"drive shared by another user", (*protontest.User).ForgeShareCreator}, + {"root folder signed by another user", (*protontest.User).ForgeRootSigner}, + } { + t.Run(forge.name, func(t *testing.T) { + ctx := context.Background() + remote, srv, u := setupFakeRemote(t) + u.SeedFile(u.RootID(), "file.txt", []byte("content"), time.Now()) + forge.apply(u, srv.AddUser("other", "pass")) + + f := newFakeFs(t, remote, "") + o, err := f.NewObject(ctx, "file.txt") + require.NoError(t, err, "listing works") + got, err := readAll(ctx, o) + require.Error(t, err, "read") + assert.Empty(t, got) + assert.Contains(t, err.Error(), "not one of your addresses") + assert.Contains(t, err.Error(), "ignore_signature_errors") + src := object.NewMemoryObject("new.txt", time.Now(), []byte("secret")) + _, err = operations.Copy(ctx, f, nil, src.Remote(), src) + require.Error(t, err, "uploaded") + assert.Contains(t, err.Error(), "not one of your addresses") + + f = newFakeFs(t, strings.TrimSuffix(remote, ":")+",ignore_signature_errors=true:", "") + o, err = f.NewObject(ctx, "file.txt") + require.NoError(t, err) + got, err = readAll(ctx, o) + require.NoError(t, err, "read with signature checks off") + assert.Equal(t, "content", string(got)) + }) + } + t.Run("updating a file with an attacker-signed passphrase", func(t *testing.T) { ctx := context.Background() remote, _, u := setupFakeRemote(t) diff --git a/docs/DECISIONS.md b/docs/DECISIONS.md index 8399a5b1a..df0b2dbec 100644 --- a/docs/DECISIONS.md +++ b/docs/DECISIONS.md @@ -5,6 +5,29 @@ it with a new one that links back. One entry per decision a future maintainer would otherwise have to reverse-engineer. No index: `grep -n '^## ' docs/DECISIONS.md` lists every entry. +## 2026-11-11 - Proton Drive roots trust in the user's own addresses + +**Status:** accepted +**Context:** "Proton Drive distrusts what a forged folder key vouches +for" and "Proton Drive refuses a file whose node key signature fails" +read as if every key were checked against keys rclone can trust. But +the keys of another user's email come from the server, so a server can +forge a share, root or node "signed" by a foreign address it vouches +for (Task 16 re-review). +**Decision:** Corrects those entries. The My Files share's creator and +the root folder's signer must be addresses whose keys the account +holds (compared ignoring case); otherwise the share or root key is +unverified, which makes the whole drive unreadable and unwritable +without `ignore_signature_errors`, and the error says why. Below the +root, nodes signed under another user's email are still verified +against server-supplied keys: a protocol limit Proton's SDK shares, +documented in spec section 7 and TODO. +**Alternatives:** Pinning other users' keys on first use (state rclone +doesn't keep); trusting server keys at the root too. +**Consequences:** A folder genuinely signed by an address since deleted +from the account, or whose keys no longer unlock, is unverified: writes +into it, and reads beneath it, need `ignore_signature_errors`. + ## 2026-11-11 - Proton Drive won't vouch for a node it couldn't verify **Status:** accepted diff --git a/docs/TODO.md b/docs/TODO.md index 08fbfdf9c..d8d753564 100644 --- a/docs/TODO.md +++ b/docs/TODO.md @@ -8,6 +8,11 @@ Small, specific, independently actionable. Remove only when actually done. ## Next +- [ ] protondrive: below the root, a node signed under another user's + email (a shared folder's members) is verified against public keys the + server supplies (`account.publicKeys`), so a hostile server can forge + it; the SDK does the same. Revisit when Proton offers key transparency + or address-key pinning. - [ ] protondrive: a full read lists every block page before releasing the first byte, one request per 20 blocks in sequence, so a very large file waits (about 12 requests for 1 GiB, about 1280 for 100 GiB) before diff --git a/docs/plans/001-protondrive-tier1.md b/docs/plans/001-protondrive-tier1.md index e933fe7c8..39ed727f1 100644 --- a/docs/plans/001-protondrive-tier1.md +++ b/docs/plans/001-protondrive-tier1.md @@ -590,6 +590,9 @@ library what must stay readable. (a server-made node key sealed to the real parent, signed by a key of the server's) and `func (u *User) SeedAnonymousFolder(parentID, name string) (id string)`. + - Hostile roots (Task 16 fix round 2): + `func (u *User) ForgeShareCreator(signer *User)` and + `func (u *User) ForgeRootSigner(signer *User)`. - `func (u *User) Dump() []DumpedNode` - decrypted tree for assertions (`ID`, `Path`, `IsFolder`, `Content`, `ModTime`, `SHA1`, `State`, and `Err` joining every decryption, signature, block-hash, manifest and diff --git a/docs/specs/001-protondrive-tier1.md b/docs/specs/001-protondrive-tier1.md index db4f617b7..4816287ae 100644 --- a/docs/specs/001-protondrive-tier1.md +++ b/docs/specs/001-protondrive-tier1.md @@ -369,6 +369,16 @@ compatibility-reviewed change. content undetected: encrypted-block hashes, manifest signatures, name and passphrase signatures are verified as the SDK verifies them. Server-supplied names containing `/`, `..` or NUL are rejected, never joined into paths. + Trust is rooted in the user's own addresses, whose keys the account + holds: the My Files share must be created, and its root folder signed, + by one of them, else everything is treated as unverified (readable and + writable only with `ignore_signature_errors`). A key that isn't verified + makes everything beneath it unverified, and rclone never moves, copies, + renames or writes into such nodes without the option. **Limit:** a file + or folder signed under another user's email is checked against public + keys the server itself supplies, so a hostile server can forge those; + Proton's SDK shares this limit, and key transparency or address-key + pinning is the eventual answer. - **Least privilege, as far as Proton allows.** Proton offers no scoped tokens (sdk#7), so a session is a full account session. Browser sign-in means the password is never held; that is the recommended setup in the