From 27693215558812ed43ae0d0c9daea52ea0165d94 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Mon, 7 May 2018 17:16:54 +0100 Subject: [PATCH] crypt: add --crypt-pass-corrupted-blocks flag --- backend/crypt/cipher.go | 11 ++++++++++- backend/crypt/crypt.go | 12 +++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/backend/crypt/cipher.go b/backend/crypt/cipher.go index ab0656ba8..f1a2efe0a 100644 --- a/backend/crypt/cipher.go +++ b/backend/crypt/cipher.go @@ -144,6 +144,7 @@ type cipher struct { buffers sync.Pool // encrypt/decrypt buffers cryptoRand io.Reader // read crypto random numbers from here dirNameEncrypt bool + passCorrupted bool } // newCipher initialises the cipher. If salt is "" then it uses a built in salt val @@ -163,6 +164,11 @@ func newCipher(mode NameEncryptionMode, password, salt string, dirNameEncrypt bo return c, nil } +// Set to pass corrupted blocks +func (c *cipher) setPassCorrupted(passCorrupted bool) { + c.passCorrupted = passCorrupted +} + // Key creates all the internal keys from the password passed in using // scrypt. // @@ -822,7 +828,10 @@ func (fh *decrypter) fillBuffer() (err error) { if err != nil { return err // return pending error as it is likely more accurate } - return ErrorEncryptedBadBlock + if !fh.c.passCorrupted { + return ErrorEncryptedBadBlock + } + fs.Errorf(nil, "passing corrupted block") } fh.bufIndex = 0 fh.bufSize = n - blockHeaderSize diff --git a/backend/crypt/crypt.go b/backend/crypt/crypt.go index 23fe1c9c0..e74ad1bb4 100644 --- a/backend/crypt/crypt.go +++ b/backend/crypt/crypt.go @@ -17,7 +17,6 @@ import ( "github.com/pkg/errors" ) -// Globals // Register with Fs func init() { fs.Register(&fs.RegInfo{ @@ -80,6 +79,15 @@ names, or for debugging purposes.`, Default: false, Hide: fs.OptionHideConfigurator, Advanced: true, + }, { + Name: "pass_corrupted_blocks", + Help: `Pass through corrupted blocks to the output. + +This is for debugging corruption problems in crypt - it shouldn't be needed normally. +`, + Default: false, + Hide: fs.OptionHideConfigurator, + Advanced: true, }}, }) } @@ -108,6 +116,7 @@ func newCipherForConfig(opt *Options) (Cipher, error) { if err != nil { return nil, errors.Wrap(err, "failed to make cipher") } + cipher.setPassCorrupted(opt.PassCorruptedBlocks) return cipher, nil } @@ -197,6 +206,7 @@ type Options struct { Password string `config:"password"` Password2 string `config:"password2"` ShowMapping bool `config:"show_mapping"` + PassCorruptedBlocks bool `config:"pass_corrupted_blocks"` } // Fs represents a wrapped fs.Fs