From 991891a5c4b75a8815ebd3add8b453cbcb36012a Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Tue, 26 Jun 2018 20:06:42 +0200 Subject: [PATCH] trezor: add sanity checks for decrypted value Check that the value has changed, is not all-zero and has the right length. --- internal/readpassword/trezor.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/internal/readpassword/trezor.go b/internal/readpassword/trezor.go index be9c22a..9020b33 100644 --- a/internal/readpassword/trezor.go +++ b/internal/readpassword/trezor.go @@ -1,6 +1,8 @@ package readpassword import ( + "bytes" + "log" "os" "github.com/rfjakob/gocryptfs/internal/exitcodes" @@ -96,6 +98,18 @@ func Trezor(payload []byte) []byte { os.Exit(exitcodes.TrezorError) } + // Sanity checks + if len(key) != TrezorPayloadLen { + log.Panicf("BUG: decrypted value has wrong length %d", len(key)) + } + if bytes.Equal(key, payload) { + log.Panicf("BUG: payload and decrypted value are identical") + } + zero := make([]byte, TrezorPayloadLen) + if bytes.Equal(key, zero) { + log.Panicf("BUG: decrypted value is all-zero") + } + // Everything ok return key }