diff --git a/backend/protondrive/download.go b/backend/protondrive/download.go index 19a0a74d6..6f5bf95b9 100644 --- a/backend/protondrive/download.go +++ b/backend/protondrive/download.go @@ -73,8 +73,9 @@ const ( // // A read from offset 0 to the end checks the manifest signature last: // if it fails, the final Read returns errIntegrity, unless -// IgnoreSignatureErrors is set, when it is logged. A content key -// signature which fails is errIntegrity from open, on the same terms. +// IgnoreSignatureErrors is set, when it is logged. A node key or +// content key signature which fails is errIntegrity from open, on the +// same terms. // The reader must be closed. func (c *client) open(ctx context.Context, n *node, offset, limit int64) (io.ReadCloser, error) { if n.IsFolder || n.link == nil || n.link.File == nil || n.RevisionID == "" { @@ -164,7 +165,14 @@ func blockAt(sizes []int64, pos int64) (index int, offset int64) { // contentKey returns the content session key of file n, checking its // signature as the SDK's decryptContentKeyPacket does. +// +// A node passphrase signature which failed is errIntegrity too: a key +// someone else made could decrypt any content they chose. func (c *client) contentKey(n *node) (*crypto.SessionKey, error) { + if n.keyErr != nil && !c.opt.IgnoreSignatureErrors { + // decryptNode has logged it. + return nil, fmt.Errorf("node key: %w: %w: %s", errIntegrity, n.keyErr, signatureHint) + } f := n.link.File now := c.s.serverTime() sk, verifyErr, err := decryptContentKey(f.ContentKeyPacket, f.ContentKeyPacketSignature, n.keys.keyRing, n.keyVerifyKR, now) diff --git a/backend/protondrive/download_internal_test.go b/backend/protondrive/download_internal_test.go index 82265405e..2e7ef489d 100644 --- a/backend/protondrive/download_internal_test.go +++ b/backend/protondrive/download_internal_test.go @@ -238,6 +238,27 @@ func TestDownloadContentKey(t *testing.T) { } } +func TestDownloadNodeKeySignature(t *testing.T) { + t.Parallel() + c, srv, u := newTestClient(t) + content := testContent(1000) + id := u.SeedFile(u.RootID(), "f", content, time.Now()) + u.Corrupt(id, "passphrase-signature") + n := getTestNode(t, c, id) + + data, err := readRange(t, c, n, 0, -1) + require.ErrorIs(t, err, errIntegrity) + assert.Contains(t, err.Error(), "ignore_signature_errors") + assert.Empty(t, data) + _, err = readRange(t, c, n, 10, 10) + require.ErrorIs(t, err, errIntegrity, "a ranged read") + + ignoring := newTestClientFor(t, srv, u, clientOptions{IgnoreSignatureErrors: true}) + data, err = readRange(t, ignoring, getTestNode(t, ignoring, id), 0, -1) + require.NoError(t, err) + assert.Equal(t, content, data) +} + func TestDownloadBlockHashMismatch(t *testing.T) { t.Parallel() c, srv, u := newTestClient(t) diff --git a/backend/protondrive/nodes.go b/backend/protondrive/nodes.go index f3b41d1c8..b1ac16da6 100644 --- a/backend/protondrive/nodes.go +++ b/backend/protondrive/nodes.go @@ -116,6 +116,7 @@ type node struct { keys *nodeKeys hashKey []byte // folders only; nil if it can't be decrypted keyVerifyKR *crypto.KeyRing // verifies the node's key and content key signatures + keyErr error // why the node passphrase signature failed; nil if it verified link *api.LinkDetails // the encrypted metadata } @@ -484,6 +485,7 @@ func (c *client) decryptNode(ctx context.Context, d *api.LinkDetails, parentKR * ServerModTime: time.Unix(l.ModifyTime, 0), keys: keys, keyVerifyKR: keyVerifyKR, + keyErr: keyVerifyErr, link: d, } verifyErrs := []error{annotate("name", nameVerifyErr), annotate("node key", keyVerifyErr)}