[Xiaomi Mi 5 Guides, News, & Discussion] coronafire:
Ah safetynet, the thorn in the side of every technical android user who wants to use Android Pay.

It's even worse on a xiaomi device, because once you've been granted a bootloader unlock after waiting for days, you don't want to re-lock it for fear of locking yourself out of the device and having to wait another 30 days before you can get a new unlock permission!

There is a lot of old information around about hiding root, custom kernels, installing things in particular orders and I'm pretty sure I've tried them all - including compiling kernels from scratch with a few different versions of the unlocked bootloader hiding patch.... never getting past the dreaded CTS Mismatch

But all of a sudden I happened on a little known secret found by [MENTION=4861355]kyasu[/MENTION] that the build fingerprint is also checked : https://xdaforums.com/showpost.php?p=70831797&postcount=3665

Also, conveniently, Magisk (since v9) patches the ro.boot.verifiedbootstate and related props that SafetyNet checks.

This now gives us two options to enable safetynet regardless of bootloader state.

You will need either a kernel with bootloader state hidden OR magisk, as well as a method of changing the build fingerprint.

This also assumes you've got TWRP installed and are comfortable using it.

Tested on Mi5 Lineage OS 14.1-20170206-NIGHTLY-gemini and various xiamoi.eu 7.2.X and 7.3.X versions:

NOTE: Magisk Hide on MIUI currently does not work (21st July 2017)

This has been widely reported and there are a number of open issues:

https://github.com/topjohnwu/Magisk/issues?utf8=✓&q=is:issue is:open miui

A fix may have been found, not ready to test however:

https://github.com/topjohnwu/Magisk/issues/298#issuecomment-316687923

Magisk

:

Remove any previous root, usually this can be done by simply dirty flashing your current rom in twrp.

From TWRP install Magisk v13.3: https://xdaforums.com/apps/magisk/official-magisk-v7-universal-systemless-t3473445

Restart and Magisk Manager app should be installed.

Hit the test safetynet button in Magisk Manager, if it passes stop here! Latest lineage roms don't need my magisk fingerprint module anymore, they just work.

Otherwise, download this magisk module on your phone: https://gitlab.com/alelec/magisk-ge...2bbf9dc8/magisk-gemini-safetynet-props-v3.zip

In Magisk Manager, go to modules and install the magisk-gemini-safetynet-props zip just downloaded. It should prompt to restart to enable module, do so.

After restart, fire up Magisk Manager and "tap to start SafetyNet check", fingers crossed it comes up Green!

Note: After each rom update you will need to reinstall Magisk in twrp, but the safetynet enabling module above should stick just fine and not need reinstall.

Custom Kernel

:

I don't test this as often, as I prefer the Magisk method, however this is an option for people who don't want any kind of root on their phones.

I also don't maintain any patched kernel for miui based roms as the one's I've tried are just too buggy.

Remove any previous root, usually this can be done by simply dirty flashing your current rom in twrp.

Install gemini-safetynetpass-stable-fingerprint-20170217.zip

this package is based on gemini-safetynetpass-20170213.zip by [MENTION=4861355]kyasu[/MENTION] but only changes the build prop fingerprint, the old custom kernel has been removed:

Install a patched kernel, you can either use my autobuild of a patched latest LineageOS kernel for Mi5 (includes fingerprint fix):

https://gitlab.com/alelec/android_kernel_xiaomi_msm8996/tags (LineageOS-gemini-safetynet-kernel_XXXXXX.zip links)

or recent DragonXia kernels appear to be patched

https://xdaforums.com/mi-5/development/kernel-brand-kernel-cm13-alpha-1-0-t3480663 (LineageOS)

https://xdaforums.com/mi-5/development/kernel-dragonxia-kernel-v1-0-t3546619 (MIUI)

Note: Both the kernel and fingerprint zip above will need to be re-installed after each rom update.

On a related note, if you want to use Android Pay on MIUI based roms, make sure the HCE wallet configuration and permissions are set correctly.

See the following for more details: http://en.miui.com/thread-405166-1-1.html