mirror of
https://github.com/permissionlesstech/bitchat-android.git
synced 2026-07-25 02:25:21 +00:00
fix minify errors
This commit is contained in:
Vendored
+11
@@ -5,3 +5,14 @@
|
|||||||
-keep class com.bitchat.android.crypto.** { *; }
|
-keep class com.bitchat.android.crypto.** { *; }
|
||||||
-dontwarn org.bouncycastle.**
|
-dontwarn org.bouncycastle.**
|
||||||
-keep class org.bouncycastle.** { *; }
|
-keep class org.bouncycastle.** { *; }
|
||||||
|
|
||||||
|
# Keep SecureIdentityStateManager from being obfuscated to prevent reflection issues
|
||||||
|
-keep class com.bitchat.android.identity.SecureIdentityStateManager {
|
||||||
|
private android.content.SharedPreferences prefs;
|
||||||
|
*;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Keep all classes that might use reflection
|
||||||
|
-keep class com.bitchat.android.favorites.** { *; }
|
||||||
|
-keep class com.bitchat.android.nostr.** { *; }
|
||||||
|
-keep class com.bitchat.android.identity.** { *; }
|
||||||
|
|||||||
@@ -229,13 +229,8 @@ class FavoritesPersistenceService private constructor(private val context: Conte
|
|||||||
|
|
||||||
private fun loadFavorites() {
|
private fun loadFavorites() {
|
||||||
try {
|
try {
|
||||||
// Use reflection to access encrypted preferences
|
// Use public methods instead of reflection to access encrypted preferences
|
||||||
val clazz = stateManager.javaClass
|
val favoritesJson = stateManager.getSecureValue(FAVORITES_KEY)
|
||||||
val prefsField = clazz.getDeclaredField("prefs")
|
|
||||||
prefsField.isAccessible = true
|
|
||||||
val prefs = prefsField.get(stateManager) as android.content.SharedPreferences
|
|
||||||
|
|
||||||
val favoritesJson = prefs.getString(FAVORITES_KEY, null)
|
|
||||||
if (favoritesJson != null) {
|
if (favoritesJson != null) {
|
||||||
val type = object : TypeToken<Map<String, FavoriteRelationshipData>>() {}.type
|
val type = object : TypeToken<Map<String, FavoriteRelationshipData>>() {}.type
|
||||||
val data: Map<String, FavoriteRelationshipData> = gson.fromJson(favoritesJson, type)
|
val data: Map<String, FavoriteRelationshipData> = gson.fromJson(favoritesJson, type)
|
||||||
@@ -262,15 +257,8 @@ class FavoritesPersistenceService private constructor(private val context: Conte
|
|||||||
|
|
||||||
val favoritesJson = gson.toJson(data)
|
val favoritesJson = gson.toJson(data)
|
||||||
|
|
||||||
// Use reflection to access encrypted preferences
|
// Use public methods instead of reflection to access encrypted preferences
|
||||||
val clazz = stateManager.javaClass
|
stateManager.storeSecureValue(FAVORITES_KEY, favoritesJson)
|
||||||
val prefsField = clazz.getDeclaredField("prefs")
|
|
||||||
prefsField.isAccessible = true
|
|
||||||
val prefs = prefsField.get(stateManager) as android.content.SharedPreferences
|
|
||||||
|
|
||||||
prefs.edit()
|
|
||||||
.putString(FAVORITES_KEY, favoritesJson)
|
|
||||||
.apply()
|
|
||||||
|
|
||||||
Log.d(TAG, "Saved ${favorites.size} favorite relationships")
|
Log.d(TAG, "Saved ${favorites.size} favorite relationships")
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
|||||||
@@ -346,4 +346,45 @@ class SecureIdentityStateManager(private val context: Context) {
|
|||||||
fun hasIdentityData(): Boolean {
|
fun hasIdentityData(): Boolean {
|
||||||
return prefs.contains(KEY_STATIC_PRIVATE_KEY) && prefs.contains(KEY_STATIC_PUBLIC_KEY)
|
return prefs.contains(KEY_STATIC_PRIVATE_KEY) && prefs.contains(KEY_STATIC_PUBLIC_KEY)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - Public SharedPreferences Access (for favorites and Nostr data)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store a string value in secure preferences
|
||||||
|
*/
|
||||||
|
fun storeSecureValue(key: String, value: String) {
|
||||||
|
prefs.edit().putString(key, value).apply()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve a string value from secure preferences
|
||||||
|
*/
|
||||||
|
fun getSecureValue(key: String): String? {
|
||||||
|
return prefs.getString(key, null)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a value from secure preferences
|
||||||
|
*/
|
||||||
|
fun removeSecureValue(key: String) {
|
||||||
|
prefs.edit().remove(key).apply()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a key exists in secure preferences
|
||||||
|
*/
|
||||||
|
fun hasSecureValue(key: String): Boolean {
|
||||||
|
return prefs.contains(key)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear specific keys from secure preferences
|
||||||
|
*/
|
||||||
|
fun clearSecureValues(vararg keys: String) {
|
||||||
|
val editor = prefs.edit()
|
||||||
|
keys.forEach { key ->
|
||||||
|
editor.remove(key)
|
||||||
|
}
|
||||||
|
editor.apply()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -215,17 +215,9 @@ object NostrIdentityBridge {
|
|||||||
// Clear cache first
|
// Clear cache first
|
||||||
geohashIdentityCache.clear()
|
geohashIdentityCache.clear()
|
||||||
|
|
||||||
// Clear Nostr private key
|
// Clear Nostr private key using public methods instead of reflection
|
||||||
try {
|
try {
|
||||||
val clazz = stateManager.javaClass
|
stateManager.clearSecureValues(NOSTR_PRIVATE_KEY, DEVICE_SEED_KEY)
|
||||||
val prefsField = clazz.getDeclaredField("prefs")
|
|
||||||
prefsField.isAccessible = true
|
|
||||||
val prefs = prefsField.get(stateManager) as android.content.SharedPreferences
|
|
||||||
|
|
||||||
prefs.edit()
|
|
||||||
.remove(NOSTR_PRIVATE_KEY)
|
|
||||||
.remove(DEVICE_SEED_KEY)
|
|
||||||
.apply()
|
|
||||||
|
|
||||||
Log.i(TAG, "Cleared all Nostr identity data and cache")
|
Log.i(TAG, "Cleared all Nostr identity data and cache")
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
@@ -237,13 +229,8 @@ object NostrIdentityBridge {
|
|||||||
|
|
||||||
private fun loadNostrPrivateKey(stateManager: SecureIdentityStateManager): String? {
|
private fun loadNostrPrivateKey(stateManager: SecureIdentityStateManager): String? {
|
||||||
return try {
|
return try {
|
||||||
// Use reflection to access the encrypted preferences
|
// Use public methods instead of reflection to access the encrypted preferences
|
||||||
val clazz = stateManager.javaClass
|
stateManager.getSecureValue(NOSTR_PRIVATE_KEY)
|
||||||
val prefsField = clazz.getDeclaredField("prefs")
|
|
||||||
prefsField.isAccessible = true
|
|
||||||
val prefs = prefsField.get(stateManager) as android.content.SharedPreferences
|
|
||||||
|
|
||||||
prefs.getString(NOSTR_PRIVATE_KEY, null)
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e(TAG, "Failed to load Nostr private key: ${e.message}")
|
Log.e(TAG, "Failed to load Nostr private key: ${e.message}")
|
||||||
null
|
null
|
||||||
@@ -252,15 +239,8 @@ object NostrIdentityBridge {
|
|||||||
|
|
||||||
private fun saveNostrPrivateKey(stateManager: SecureIdentityStateManager, privateKeyHex: String) {
|
private fun saveNostrPrivateKey(stateManager: SecureIdentityStateManager, privateKeyHex: String) {
|
||||||
try {
|
try {
|
||||||
// Use reflection to access the encrypted preferences
|
// Use public methods instead of reflection to access the encrypted preferences
|
||||||
val clazz = stateManager.javaClass
|
stateManager.storeSecureValue(NOSTR_PRIVATE_KEY, privateKeyHex)
|
||||||
val prefsField = clazz.getDeclaredField("prefs")
|
|
||||||
prefsField.isAccessible = true
|
|
||||||
val prefs = prefsField.get(stateManager) as android.content.SharedPreferences
|
|
||||||
|
|
||||||
prefs.edit()
|
|
||||||
.putString(NOSTR_PRIVATE_KEY, privateKeyHex)
|
|
||||||
.apply()
|
|
||||||
|
|
||||||
Log.d(TAG, "Saved Nostr private key to secure storage")
|
Log.d(TAG, "Saved Nostr private key to secure storage")
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
@@ -271,13 +251,8 @@ object NostrIdentityBridge {
|
|||||||
|
|
||||||
private fun getOrCreateDeviceSeed(stateManager: SecureIdentityStateManager): ByteArray {
|
private fun getOrCreateDeviceSeed(stateManager: SecureIdentityStateManager): ByteArray {
|
||||||
try {
|
try {
|
||||||
// Use reflection to access the encrypted preferences
|
// Use public methods instead of reflection to access the encrypted preferences
|
||||||
val clazz = stateManager.javaClass
|
val existingSeed = stateManager.getSecureValue(DEVICE_SEED_KEY)
|
||||||
val prefsField = clazz.getDeclaredField("prefs")
|
|
||||||
prefsField.isAccessible = true
|
|
||||||
val prefs = prefsField.get(stateManager) as android.content.SharedPreferences
|
|
||||||
|
|
||||||
val existingSeed = prefs.getString(DEVICE_SEED_KEY, null)
|
|
||||||
if (existingSeed != null) {
|
if (existingSeed != null) {
|
||||||
return android.util.Base64.decode(existingSeed, android.util.Base64.DEFAULT)
|
return android.util.Base64.decode(existingSeed, android.util.Base64.DEFAULT)
|
||||||
}
|
}
|
||||||
@@ -287,9 +262,7 @@ object NostrIdentityBridge {
|
|||||||
SecureRandom().nextBytes(seed)
|
SecureRandom().nextBytes(seed)
|
||||||
|
|
||||||
val seedBase64 = android.util.Base64.encodeToString(seed, android.util.Base64.DEFAULT)
|
val seedBase64 = android.util.Base64.encodeToString(seed, android.util.Base64.DEFAULT)
|
||||||
prefs.edit()
|
stateManager.storeSecureValue(DEVICE_SEED_KEY, seedBase64)
|
||||||
.putString(DEVICE_SEED_KEY, seedBase64)
|
|
||||||
.apply()
|
|
||||||
|
|
||||||
Log.d(TAG, "Generated new device seed for geohash identity derivation")
|
Log.d(TAG, "Generated new device seed for geohash identity derivation")
|
||||||
return seed
|
return seed
|
||||||
|
|||||||
Reference in New Issue
Block a user