Skip to content

Commit

Permalink
Merge pull request #14 from ProtonProtocol/develop
Browse files Browse the repository at this point in the history
ESR Chain Id and PIN validation fixes
  • Loading branch information
Joey Harward authored Jan 21, 2021
2 parents ac32513 + e7949c6 commit 8051aef
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
6 changes: 3 additions & 3 deletions buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ const val kotlinVersion = "1.4.10" // TODO: 1.4.20
const val orchidVersion = "0.21.1"

object ProtonSdk {
const val versionCode = 25
const val versionName = "0.8.0"
const val versionCode = 26
const val versionName = "0.8.1"
}

object BuildPlugins {
Expand Down Expand Up @@ -72,7 +72,7 @@ object Libraries {
const val timber = "4.7.1"
const val gson = "2.8.6"
const val guava = "29.0-jre"
const val esr = "1.0.4"
const val esr = "1.0.6"
}

const val kotlinStdLib = "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,27 @@ class SecureKeys(private val context: Context) {

fun checkPin(pin: String): Boolean {
var isValid = false

SecurePreferences.setSharedPreferencesName(SHARED_PREFS_FILENAME)
val securePrefs = SecurePreferences.getSharedPreferences(context)
if (securePrefs.all.isNotEmpty()) {
isValid = try {
val firstAccount = securePrefs.all.entries.iterator().next()
val publicKey = firstAccount.key
val privateKey = SecurePreferences.getStringValue(context, publicKey, pin, "")
EosPrivateKey(privateKey).publicKey.toString() == publicKey
} catch (e: Exception) {
false

// make sure at least one key is set with PIN
run loop@ {
securePrefs.all.forEach { secureKey ->
isValid = try {
val publicKey = secureKey.key
val privateKey = SecurePreferences.getStringValue(context, publicKey, pin, "")
EosPrivateKey(privateKey).publicKey.toString() == publicKey
} catch (e: Exception) {
false
}

if (isValid) {
return@loop
}
}
}

return isValid
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ public static void setValue(@NonNull Context context,

String transformedValue = "";
if (password != null) {
// HEX
// String encrypted = SecretKeyTool.encryptMessage(key, value, password);
// String encryptedHex = HexUtils.toHex(encrypted.getBytes());
// transformedValue = encryptedHex;

transformedValue = SecretKeyTool.encryptMessage(key, value, password);
} else {
if (!KeystoreTool.keyPairExists()) {
Expand Down Expand Up @@ -167,6 +172,12 @@ public static String getStringValue(@NonNull Context context,
try {
if (!TextUtils.isEmpty(secureValue)) {
if (password != null) {

// HEX
// String secureValueHex = new String(HexUtils.toBytes(secureValue));
// String decrypted = SecretKeyTool.decryptMessage(key, secureValueHex, password);
// return decrypted;

return SecretKeyTool.decryptMessage(key, secureValue, password);
} else {
return KeystoreTool.decryptMessage(context, secureValue);
Expand Down

0 comments on commit 8051aef

Please sign in to comment.