From 7a48a664fd00a188044da348f34cc2e800b8a3fe Mon Sep 17 00:00:00 2001 From: Sultan Qasim Khan Date: Fri, 12 Feb 2016 19:17:38 -0500 Subject: patternpassword: update large grid password scheme CM13 and up no longer use the two method scheme. Change-Id: I21154becb5d7e77a54a5a07e649fe64829173a01 --- gui/patternpassword.cpp | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) (limited to 'gui/patternpassword.cpp') diff --git a/gui/patternpassword.cpp b/gui/patternpassword.cpp index 96054c15f..90566e219 100644 --- a/gui/patternpassword.cpp +++ b/gui/patternpassword.cpp @@ -15,7 +15,7 @@ extern "C" { #include "../twcommon.h" } #include "../minuitwrp/minui.h" - +#include "../twrp-functions.hpp" #include "rapidxml.hpp" #include "objects.hpp" @@ -403,6 +403,17 @@ int GUIPatternPassword::NotifyVarChange(const std::string& varName, const std::s return 0; } +static unsigned int getSDKVersion(void) { + unsigned int sdkver = 23; + string sdkverstr = TWFunc::System_Property_Get("ro.build.version.sdk"); + if (!sdkverstr.empty()) { + sdkver = (unsigned int)strtoull(sdkverstr.c_str(), NULL, 10); + sdkver = (sdkver != 0) ? sdkver : 23; + } + LOGINFO("sdk version is %u\n", sdkver); + return sdkver; +} + std::string GUIPatternPassword::GeneratePassphrase() { char pattern[mConnectedDotsLen]; @@ -411,12 +422,17 @@ std::string GUIPatternPassword::GeneratePassphrase() } std::stringstream pass; + char buffer[3] = {0}; - for(size_t i = 0; i < mConnectedDotsLen; i++) { - int digit = pattern[i] & 0xff; - + if ((mGridSize == 3) || (getSDKVersion() >= 23)) { + // Marshmallow uses a consistent method + for (size_t i = 0; i < mConnectedDotsLen; i++) { + buffer[0] = (pattern[i] & 0xff) + '1'; + pass << std::string(buffer); + } + } else { /* - * Okay, rant time. + * Okay, rant time for pre-Marshmallow ROMs. * It turns out that Android and CyanogenMod have *two* separate methods * for generating passphrases from patterns. This is a legacy issue, as * Android only supports 3x3 grids, and so we need to support both. @@ -431,14 +447,8 @@ std::string GUIPatternPassword::GeneratePassphrase() * they are generated by taking "%.2x" for each dot index and * concatenating the results (without adding 1). */ - - if(mGridSize == 3) - // Android (legacy) 3x3 grids. - pass << digit + 1; - else { - // Other NxN grids. - char buffer[3]; - snprintf(buffer, 3, "%.2x", digit); + for (size_t i = 0; i < mConnectedDotsLen; i++) { + snprintf(buffer, 3, "%.2x", pattern[i] & 0xff); pass << std::string(buffer); } } -- cgit v1.2.3