Skip to content

Commit

Permalink
fix: support TLS 1.3 on Android 9 and lower and read fees correctly (#…
Browse files Browse the repository at this point in the history
…1348)

* fix: support TLS 1.3 on >= Android 9

* fix: parsing of FeeInfo from CrowdNode
  • Loading branch information
HashEngineering authored Feb 25, 2025
1 parent a81eab5 commit 8f7be20
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package org.dash.wallet.integrations.crowdnode.model

import android.os.Parcelable
import com.google.gson.Gson
import com.google.gson.annotations.SerializedName
import com.google.gson.reflect.TypeToken
import kotlinx.parcelize.Parcelize
import kotlinx.parcelize.RawValue

@Parcelize
data class FeeLadder(
Expand Down Expand Up @@ -36,15 +37,31 @@ data class FeeLadder(
@Parcelize
data class FeeInfo(
@SerializedName("Key") val key: String,
@SerializedName("Value") val value: @RawValue List<FeeLadder>
@SerializedName("Value") val rawValue: String
) : Parcelable {
companion object {
const val DEFAULT_FEE = 35.0
const val DEFAULT_AMOUNT = 100.0
const val KEY_FEELADDER = "FeeLadder"
const val TYPE_NORMAL = "Normal"
const val TYPE_TRUSTLESS = "Trustless"
val default = FeeInfo("FeeLadder", listOf(FeeLadder("", TYPE_NORMAL, DEFAULT_AMOUNT, DEFAULT_FEE)))
const val DEFAULT_FEE_LADDER = """[
{
\"name\":\"Up to 10 Dash and above\",
\"type\":\"Normal\",
\"amount\":10.0,\"fee\":35.0
},
{
\"name\":\"Trustless up to 100 Dash and above\",
\"type\":\"Trustless\",
\"amount\":100.0,
\"fee\":20.0
}
]"""
val default = FeeInfo(KEY_FEELADDER, DEFAULT_FEE_LADDER)
}
val value: List<FeeLadder> by lazy {
Gson().fromJson(rawValue, object : TypeToken<List<FeeLadder>>() {}.type)
}

fun getNormal() = value.find { it.type == TYPE_NORMAL }
Expand Down
1 change: 1 addition & 0 deletions wallet/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ dependencies {
implementation 'com.squareup.moshi:moshi:1.11.0'
implementation 'com.squareup.moshi:moshi-kotlin:1.11.0'
implementation 'com.squareup.retrofit2:converter-moshi:2.6.4'
implementation 'org.conscrypt:conscrypt-android:2.5.2' // TLS 1.3 support for Android <= 9.0

// UI
implementation "androidx.appcompat:appcompat:$appCompatVersion"
Expand Down
8 changes: 8 additions & 0 deletions wallet/proguard.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,11 @@
-keepattributes *Annotation*
-keepattributes SourceFile,LineNumberTable
-keep class kotlin.Metadata { *; }

# Keep Conscrypt classes
-keep class org.conscrypt.** { *; }
-keep class com.android.org.conscrypt.** { *; }

# Prevent obfuscation of SSL/TLS related classes
-dontwarn org.conscrypt.**
-dontwarn com.android.org.conscrypt.**
8 changes: 8 additions & 0 deletions wallet/src/de/schildbach/wallet/WalletApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
import org.bitcoinj.wallet.WalletProtobufSerializer;
import org.bitcoinj.wallet.authentication.AuthenticationGroupExtension;
import org.bitcoinj.wallet.authentication.AuthenticationKeyUsage;
import org.conscrypt.Conscrypt;
import org.dash.wallet.common.AutoLogoutTimerHandler;
import org.dash.wallet.common.Configuration;
import org.dash.wallet.common.InteractionAwareActivity;
Expand Down Expand Up @@ -111,6 +112,7 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.security.GeneralSecurityException;
import java.security.Security;
import java.util.ArrayList;
import java.util.Collection;
import java.util.EnumSet;
Expand Down Expand Up @@ -334,6 +336,12 @@ private void logState() {
resetBlockchainSyncProgress();
anrSupervisor = new AnrSupervisor();
anrSupervisor.start();

// enable TLS 1.3 support on Android 9 and lower
// Android 10 and above support TLS 1.3 by default
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.Q) {
Security.insertProviderAt(Conscrypt.newProvider(), 1);
}
}

private void syncExploreData() {
Expand Down

0 comments on commit 8f7be20

Please sign in to comment.