xeals / signal-back

Decrypt Signal encrypted backups outside the app
Apache License 2.0
704 stars 67 forks source link

Panic: runtime error: invalid memory address or nil pointer dereference #12

Closed compops closed 6 years ago

compops commented 6 years ago

I did a reinstall of my Signal and could not restore my backup using the app. So I turned to your work to be able to recover some old chat history.

I get the following error when running the program

> ./signal-back_linux_amd64 format -p [pass] signal-[date].backup > out.xml
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x559e6c]

goroutine 1 [running]:
github.com/xeals/signal-back/types.(*BackupFile).DecryptAttachment(0xc4200ec0e0, 0xc42009b230, 0x5e42a0, 0x6e0048, 0x550c7dc3243185be, 0x80deb1fe72be5d74)
    /home/travis/gopath/src/github.com/xeals/signal-back/types/backup.go:136 +0x12c
github.com/xeals/signal-back/cmd.XML(0xc4200ec0e0, 0x5e40a0, 0xc420094008, 0x3, 0x3)
    /home/travis/gopath/src/github.com/xeals/signal-back/cmd/format.go:153 +0x3dd
github.com/xeals/signal-back/cmd.glob..func3(0xc4200ae420, 0x0, 0xc4200ae420)
    /home/travis/gopath/src/github.com/xeals/signal-back/cmd/format.go:71 +0x246
github.com/xeals/signal-back/vendor/github.com/urfave/cli.HandleAction(0x587380, 0x5ccf48, 0xc4200ae420, 0xc4200a8000, 0x0)
    /home/travis/gopath/src/github.com/xeals/signal-back/vendor/github.com/urfave/cli/app.go:490 +0xc8
github.com/xeals/signal-back/vendor/github.com/urfave/cli.Command.Run(0x5c171c, 0x6, 0x0, 0x0, 0x0, 0x0, 0x0, 0x5c7567, 0x1f, 0x5cc2b1, ...)
    /home/travis/gopath/src/github.com/xeals/signal-back/vendor/github.com/urfave/cli/command.go:210 +0xa36
github.com/xeals/signal-back/vendor/github.com/urfave/cli.(*App).Run(0xc4200aa1a0, 0xc4200960f0, 0x5, 0x5, 0x0, 0x0)
    /home/travis/gopath/src/github.com/xeals/signal-back/vendor/github.com/urfave/cli/app.go:255 +0x6a0
main.main()
    /home/travis/gopath/src/github.com/xeals/signal-back/main.go:51 +0x2d8

The program manages to successfully recover a backup that I did after the reinstall. Does this mean that I have written down my encryption code for the old backup incorrectly? Or is something strange with the older backup file.

Thanks for your work!

xeals commented 6 years ago

I'm assuming this is the backup that the app couldn't restore from? What message does the app give you?

compops commented 6 years ago

Thanks for your reply. Yes, that is correct. When trying to restore using the Signal app on Android I get the message "Incorrect backup passphrase". However, it seems to be a common problem not to be able to restore backups, see #7637 on Signal-Android. That is why I wanted to try signal-back instead.

I do get the same error using signal-back as in the first comment in this issue if I try to restore a new backup that I made after the reinstall (which decrypts correctly using signal-back and the correct passphrase) with the wrong passphrase. So I guess that it could be possible that the older backup taken before the reinstall is corrupted or encrypted using another passphrase than the one displayed to the screen in the Signal app on Android.

xeals commented 6 years ago

I suspect that might be the case. Unfortunately, signal-back (to my knowledge) uses the exact same decryption process as the Signal app, so if it doesn't work with one, it probably won't work with the other. The error comes from expecting an attachment to be next in the file, but not finding any of the information an attachment should have; this suggests to me that it's been compressed or otherwise corrupted.

compops commented 6 years ago

Thanks again