mirror of
https://github.com/permissionlesstech/bitchat-android.git
synced 2026-07-24 22:25:19 +00:00
fix minify errors
This commit is contained in:
Vendored
+11
@@ -5,3 +5,14 @@
|
||||
-keep class com.bitchat.android.crypto.** { *; }
|
||||
-dontwarn 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() {
|
||||
try {
|
||||
// Use reflection to access encrypted preferences
|
||||
val clazz = stateManager.javaClass
|
||||
val prefsField = clazz.getDeclaredField("prefs")
|
||||
prefsField.isAccessible = true
|
||||
val prefs = prefsField.get(stateManager) as android.content.SharedPreferences
|
||||
|
||||
val favoritesJson = prefs.getString(FAVORITES_KEY, null)
|
||||
// Use public methods instead of reflection to access encrypted preferences
|
||||
val favoritesJson = stateManager.getSecureValue(FAVORITES_KEY)
|
||||
if (favoritesJson != null) {
|
||||
val type = object : TypeToken<Map<String, FavoriteRelationshipData>>() {}.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)
|
||||
|
||||
// Use reflection to access encrypted preferences
|
||||
val clazz = stateManager.javaClass
|
||||
val prefsField = clazz.getDeclaredField("prefs")
|
||||
prefsField.isAccessible = true
|
||||
val prefs = prefsField.get(stateManager) as android.content.SharedPreferences
|
||||
|
||||
prefs.edit()
|
||||
.putString(FAVORITES_KEY, favoritesJson)
|
||||
.apply()
|
||||
// Use public methods instead of reflection to access encrypted preferences
|
||||
stateManager.storeSecureValue(FAVORITES_KEY, favoritesJson)
|
||||
|
||||
Log.d(TAG, "Saved ${favorites.size} favorite relationships")
|
||||
} catch (e: Exception) {
|
||||
|
||||
@@ -346,4 +346,45 @@ class SecureIdentityStateManager(private val context: Context) {
|
||||
fun hasIdentityData(): Boolean {
|
||||
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
|
||||
geohashIdentityCache.clear()
|
||||
|
||||
// Clear Nostr private key
|
||||
// Clear Nostr private key using public methods instead of reflection
|
||||
try {
|
||||
val clazz = stateManager.javaClass
|
||||
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()
|
||||
stateManager.clearSecureValues(NOSTR_PRIVATE_KEY, DEVICE_SEED_KEY)
|
||||
|
||||
Log.i(TAG, "Cleared all Nostr identity data and cache")
|
||||
} catch (e: Exception) {
|
||||
@@ -237,13 +229,8 @@ object NostrIdentityBridge {
|
||||
|
||||
private fun loadNostrPrivateKey(stateManager: SecureIdentityStateManager): String? {
|
||||
return try {
|
||||
// Use reflection to access the encrypted preferences
|
||||
val clazz = stateManager.javaClass
|
||||
val prefsField = clazz.getDeclaredField("prefs")
|
||||
prefsField.isAccessible = true
|
||||
val prefs = prefsField.get(stateManager) as android.content.SharedPreferences
|
||||
|
||||
prefs.getString(NOSTR_PRIVATE_KEY, null)
|
||||
// Use public methods instead of reflection to access the encrypted preferences
|
||||
stateManager.getSecureValue(NOSTR_PRIVATE_KEY)
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Failed to load Nostr private key: ${e.message}")
|
||||
null
|
||||
@@ -252,15 +239,8 @@ object NostrIdentityBridge {
|
||||
|
||||
private fun saveNostrPrivateKey(stateManager: SecureIdentityStateManager, privateKeyHex: String) {
|
||||
try {
|
||||
// Use reflection to access the encrypted preferences
|
||||
val clazz = stateManager.javaClass
|
||||
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()
|
||||
// Use public methods instead of reflection to access the encrypted preferences
|
||||
stateManager.storeSecureValue(NOSTR_PRIVATE_KEY, privateKeyHex)
|
||||
|
||||
Log.d(TAG, "Saved Nostr private key to secure storage")
|
||||
} catch (e: Exception) {
|
||||
@@ -271,13 +251,8 @@ object NostrIdentityBridge {
|
||||
|
||||
private fun getOrCreateDeviceSeed(stateManager: SecureIdentityStateManager): ByteArray {
|
||||
try {
|
||||
// Use reflection to access the encrypted preferences
|
||||
val clazz = stateManager.javaClass
|
||||
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)
|
||||
// Use public methods instead of reflection to access the encrypted preferences
|
||||
val existingSeed = stateManager.getSecureValue(DEVICE_SEED_KEY)
|
||||
if (existingSeed != null) {
|
||||
return android.util.Base64.decode(existingSeed, android.util.Base64.DEFAULT)
|
||||
}
|
||||
@@ -287,9 +262,7 @@ object NostrIdentityBridge {
|
||||
SecureRandom().nextBytes(seed)
|
||||
|
||||
val seedBase64 = android.util.Base64.encodeToString(seed, android.util.Base64.DEFAULT)
|
||||
prefs.edit()
|
||||
.putString(DEVICE_SEED_KEY, seedBase64)
|
||||
.apply()
|
||||
stateManager.storeSecureValue(DEVICE_SEED_KEY, seedBase64)
|
||||
|
||||
Log.d(TAG, "Generated new device seed for geohash identity derivation")
|
||||
return seed
|
||||
|
||||
Reference in New Issue
Block a user