protondrive: refuse to read a file whose key isn't signed by its owner
A file whose node passphrase signature didn't verify was read with only an error logged when it was listed, although a server could have substituted a key of its own making and with it any content. Reading such a file now fails unless ignore_signature_errors is set, as for a content key or manifest signature which fails. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8600815384
commit
6065801968
3 files changed
+33
-2
No files matched your search
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)}
|
||||
|
||||
Reference in new issue
Block a user