Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bitcoinj upgrade 0.16.2 -> 0.17 #7

Open
wants to merge 31 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
68cd38c
added new strings for upcoming keystore support
Mar 3, 2024
cf139cc
moved from spending pin menu to wallet protection menu
Mar 3, 2024
7664c50
added prototype for supporting keystore and spending pin in a dialog …
Mar 3, 2024
1a2b0c9
KeyStoreKeyCrypter with biometric authentication (#9)
oliveraemmer Mar 6, 2024
b3cd860
Merge branch 'main' into 4-gui-changes
Mar 8, 2024
c2b9e93
added a working version that supports both keycrypters without user b…
Mar 12, 2024
cd45fbb
small change*
Mar 18, 2024
d8dba19
wip
oliveraemmer Mar 19, 2024
d183b59
working version for encrypt but decrypt only works if its in the timo…
Mar 20, 2024
2c4d77b
wip
oliveraemmer Mar 25, 2024
4978c39
rebase2
oliveraemmer Mar 25, 2024
3a0f972
upgrade build successful, not tested
oliveraemmer Mar 2, 2024
5ae6ad4
rebase
oliveraemmer Mar 25, 2024
fd4b2f5
fixed tx declaration
oliveraemmer Mar 3, 2024
5031b8a
rebase
oliveraemmer Mar 25, 2024
1a67dab
rebase
oliveraemmer Mar 25, 2024
2fdaca6
wip, implemented KeyCrypterFactory
oliveraemmer Mar 26, 2024
a540d30
backup with keystorekeycrypter
oliveraemmer Mar 26, 2024
1e90ecb
small changes for 0.17 upgrade + context propagation in cryptactivity
oliveraemmer Mar 30, 2024
278eeef
sending funds when keystore encrypted fix
oliveraemmer Mar 30, 2024
acac6c6
removed button from CryptActivity, fixed backup export and import
oliveraemmer Mar 30, 2024
8438242
added strings
oliveraemmer Mar 30, 2024
7dddc62
fixed backup with keystore
oliveraemmer Mar 30, 2024
eff508b
added string resources and new EncryptionType
oliveraemmer Apr 1, 2024
abf4b1d
removed scrypt params from KeyStoreKeyCrypter
oliveraemmer Apr 1, 2024
3a5b487
rename KeyStoreKeyCrypter to HWKeyCrypter, fix BitcoinJ and HWKeyCryp…
oliveraemmer Apr 1, 2024
5cb591a
change to accept same sdk as original repository
Apr 3, 2024
13a8011
add text to include iris scan as biometric authentication
Apr 3, 2024
2b19b1c
add functionality to only allow HW encrpytion/decryption if sdk is at…
Apr 3, 2024
e723e97
add functionality to support HW encryption for sdk 28 to 30, refactor…
Apr 3, 2024
798dd08
remove comment in HWKeyCrypter
oliveraemmer Apr 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
.gradle/
gradlew
gradlew.bat
gradle/wrapper
build/
local.properties
.classpath
Expand All @@ -11,3 +10,5 @@ local.properties
*.iml
bin/
gen/
.DS_Store
wallet/.DS_Store
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
classpath 'com.android.tools.build:gradle:4.1.0'
//noinspection GradleDependency
classpath 'net.sf.proguard:proguard-gradle:6.2.2'
classpath('fr.avianey.androidsvgdrawable:gradle-plugin:3.0.2') {
Expand All @@ -19,4 +19,4 @@ allprojects {
mavenCentral()
google()
}
}
}
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
org.gradle.jvmargs=-Xmx2048M
android.enableD8.desugaring=true
android.useAndroidX=true
5 changes: 5 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
7 changes: 7 additions & 0 deletions wallet/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_CONNECTED_DEVICE" />
<uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.NFC" />
<uses-permission android:name="android.permission.USE_BIOMETRIC" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
Expand Down Expand Up @@ -211,6 +212,12 @@
android:theme="@style/My.Theme.ChildActivity"
android:windowSoftInputMode="adjustResize" />

<activity
android:name="de.schildbach.wallet.ui.CryptActivity"
android:configChanges="keyboard|keyboardHidden"
android:label="Biometric Authentication"
android:theme="@style/My.Theme.ChildActivity" />

<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.file_attachment"
Expand Down
14 changes: 8 additions & 6 deletions wallet/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ dependencies {
implementation 'androidx.sqlite:sqlite:2.4.0'
implementation "androidx.room:room-runtime:2.6.1"
annotationProcessor "androidx.room:room-compiler:2.6.1"
implementation 'org.bitcoinj:bitcoinj-core:0.16.2'
implementation 'com.google.guava:guava:33.0.0-android'
implementation 'androidx.biometric:biometric:1.2.0-alpha04'
implementation 'com.google.guava:guava:31.1-android'
implementation 'com.google.zxing:core:3.5.2'
//noinspection GradleDependency
implementation 'com.squareup.okhttp3:okhttp:3.14.9'
Expand All @@ -34,6 +34,7 @@ dependencies {
implementation 'org.slf4j:slf4j-api:2.0.9'
implementation 'com.github.tony19:logback-android:3.0.0'
testImplementation 'junit:junit:4.13.2'
implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
}

ext {
Expand All @@ -42,16 +43,17 @@ ext {

android {
compileSdkVersion 'android-34'
buildToolsVersion '34.0.0'
buildToolsVersion '30.0.3'

defaultConfig {
applicationId 'de.schildbach'
minSdkVersion 26
}

buildTypes {
all {
minifyEnabled true
shrinkResources true
minifyEnabled false
shrinkResources false
crunchPngs false
proguardFile 'proguard.cfg'
}
Expand Down Expand Up @@ -122,4 +124,4 @@ task svgToPngMipmap(type: fr.avianey.androidsvgdrawable.gradle.SvgDrawableTask)
targetedDensities = ['xxhdpi', 'xxxhdpi']
outputFormat = 'PNG'
outputType = 'mipmap'
}
}
Binary file added wallet/libs/bcprov-jdk15to18-1.77.jar
Binary file not shown.
Binary file added wallet/libs/bitcoinj-core-0.17-SNAPSHOT.jar
Binary file not shown.
Binary file added wallet/libs/bitcoinj-wallettool.jar
Binary file not shown.
Binary file added wallet/libs/jcip-annotations-1.0.jar
Binary file not shown.
Binary file not shown.
Binary file added wallet/libs/picocli-4.7.5.jar
Binary file not shown.
Binary file added wallet/libs/protobuf-javalite-3.22.5.jar
Binary file not shown.
23 changes: 23 additions & 0 deletions wallet/res/layout/crypt_content.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp">

<TextView
android:id="@+id/crypt_instruction_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Biometric Authentication"
android:layout_centerHorizontal="true"
android:layout_marginBottom="24dp"
android:layout_above="@+id/progressBar"/>

<ProgressBar
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:indeterminate="true"/>

</RelativeLayout>
23 changes: 21 additions & 2 deletions wallet/res/layout/encrypt_keys_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,28 @@
android:layout_marginRight="@dimen/list_entry_padding_horizontal_lax"
android:orientation="vertical">

<RadioGroup
android:id="@+id/encrypt_keys_dialog_radio_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RadioButton android:id="@+id/encrypt_keys_dialog_radio_spending_pin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="@string/encrypt_keys_dialog_radio_spending_pin"/>
<RadioButton android:id="@+id/encrypt_keys_dialog_radio_keystore"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/encrypt_keys_dialog_radio_keystore"/>
</RadioGroup>

<TextView
android:id="@+id/encrypt_keys_dialog_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/list_entry_padding_vertical"
android:text="@string/encrypt_keys_dialog_message" />
android:text="@string/encrypt_keys_dialog_message_spending_pin" />

<LinearLayout
android:id="@+id/encrypt_keys_dialog_password_old_group"
Expand Down Expand Up @@ -50,6 +67,7 @@
</LinearLayout>

<LinearLayout
android:id="@+id/encrypt_keys_dialog_password_new_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/list_entry_padding_vertical"
Expand Down Expand Up @@ -84,11 +102,12 @@
android:text="@string/encrypt_keys_dialog_show" />

<TextView
android:id="@+id/encrypt_keys_dialog_warning"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/list_entry_padding_vertical_lax"
android:layout_marginTop="@dimen/list_entry_padding_vertical_lax"
android:text="@string/encrypt_keys_dialog_warning"
android:text="@string/encrypt_keys_dialog_warning_spending_pin"
android:textColor="@color/fg_less_significant"
android:textSize="@dimen/font_size_small" />
</LinearLayout>
Expand Down
5 changes: 2 additions & 3 deletions wallet/res/menu/wallet_options.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,9 @@
android:showAsAction="never"
android:title="@string/import_keys_dialog_title" />
<item
android:id="@+id/wallet_options_encrypt_keys"
android:id="@+id/wallet_options_protection"
android:showAsAction="never"
android:title="@string/encrypt_keys_dialog_title"
android:visible="false" />
android:title="@string/encrypt_keys_dialog_title"/>
</menu>
</item>
<item
Expand Down
26 changes: 23 additions & 3 deletions wallet/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,13 @@
<string name="import_export_keys_dialog_show">Show password</string>
<string name="import_export_keys_dialog_failure_title">Error</string>
<string name="import_keys_intent_filter_action">Restore wallet</string>
<string name="encrypt_keys_dialog_title">Spending PIN</string>
<string name="encrypt_keys_dialog_message">Spending from your wallet will be protected with the chosen PIN.</string>
<string name="encrypt_keys_dialog_warning">Important: You need to remember your PIN! Do not use common numbers (like birthdates).</string>
<string name="encrypt_keys_dialog_title">Wallet protection</string>
<string name="encrypt_keys_dialog_radio_spending_pin">Spending PIN</string>
<string name="encrypt_keys_dialog_radio_keystore">KeyStore</string>
<string name="encrypt_keys_dialog_message_keystore">Spending from your wallet will require biometric authentication (fingerprint, iris, face scan).</string>
<string name="encrypt_keys_dialog_message_spending_pin">Spending from your wallet will be protected with the chosen PIN.</string>
<string name="encrypt_keys_dialog_warning_spending_pin">Important: You need to remember your PIN! Do not use common numbers (like birthdates).</string>
<string name="encrypt_keys_dialog_warning_keystore">Important: Your encryption key will be bound to your device. Be sure to make a back up to avoid losing access to your funds if the device is lost.</string>
<string name="encrypt_keys_dialog_password_old">Old PIN</string>
<string name="encrypt_keys_dialog_password_strength_weak">weak</string>
<string name="encrypt_keys_dialog_password_strength_fair">fair</string>
Expand Down Expand Up @@ -339,6 +343,22 @@
<string name="notification_channel_ongoing_name">Background activity</string>
<string name="notification_channel_important_name">Important alerts</string>
<string name="appwidget_wallet_balance_title">Bitcoin balance</string>
<string name="biometric_hardward_not_available">No biometric hardware available</string>
<string name="biometric_hardward_not_available_info">This device does not support biometric authentication. Please use Spending PIN instead of KeyStore encryption</string>
<string name="biometric_hardward_currently_not_available">Biometric hardware is currently unavailable</string>
<string name="biometric_auth_not_enrolled">Biometric authentication not enrolled</string>
<string name="biometric_auth_not_enrolled_info">Please enroll biometric authentication to use KeyStore encryption</string>
<string name="biometric_update_required">Security update required</string>
<string name="biometric_update_required_info">A security update is required to use KeyStore encryption with biometric authentication</string>
<string name="biometric_unsupported_version">Unsupported android version</string>
<string name="biometric_unsupported_version_info">This android version does not support the required strong biometric authentication (fingerprint, iris, or face)</string>
<string name="biometric_unknown_error">Unknown error</string>
<string name="biometric_unknown_error_info">An unknown error occurred. Please make sure this device supports strong biometric authentication (fingerprint, iris, or face)</string>
<string name="biometric_auth">Biometric Authentication</string>
<string name="biometric_auth_required_info">Authentication is required to continue</string>
<string name="biometric_auth_utilised_info">This app uses biometric authentication to protect your data.</string>
<string name="biometric_auth_cancelled">Authentication cancelled</string>


<!-- generic buttons -->
<string name="button_ok">OK</string>
Expand Down
4 changes: 2 additions & 2 deletions wallet/src/de/schildbach/wallet/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
import com.google.common.base.Strings;
import com.google.common.net.HostAndPort;
import de.schildbach.wallet.util.Formats;
import org.bitcoinj.core.Coin;
import org.bitcoinj.utils.MonetaryFormat;
import org.bitcoinj.base.Coin;
import org.bitcoinj.base.utils.MonetaryFormat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
41 changes: 25 additions & 16 deletions wallet/src/de/schildbach/wallet/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@
import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import org.bitcoinj.core.Coin;

import org.bitcoinj.base.BitcoinNetwork;
import org.bitcoinj.base.Coin;
import org.bitcoinj.base.ScriptType;
import org.bitcoinj.core.Context;
import org.bitcoinj.core.NetworkParameters;
import org.bitcoinj.params.BitcoinNetworkParams;
import org.bitcoinj.params.MainNetParams;
import org.bitcoinj.params.TestNet3Params;
import org.bitcoinj.script.Script;
import org.bitcoinj.utils.MonetaryFormat;
import org.bitcoinj.base.utils.MonetaryFormat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -49,16 +52,16 @@ public final class Constants {
public static final Context CONTEXT = new Context(NETWORK_PARAMETERS);

/**
* The type of Bitcoin addresses used for the initial wallet: {@link Script.ScriptType#P2PKH} for classic
* Base58, {@link Script.ScriptType#P2WPKH} for segwit Bech32.
* The type of Bitcoin addresses used for the initial wallet: {@link ScriptType#P2PKH} for classic
* Base58, {@link ScriptType#P2WPKH} for segwit Bech32.
*/
public static final Script.ScriptType DEFAULT_OUTPUT_SCRIPT_TYPE = Script.ScriptType.P2WPKH;
public static final ScriptType DEFAULT_OUTPUT_SCRIPT_TYPE = ScriptType.P2WPKH;

/**
* The type of Bitcoin addresses to upgrade the current wallet to: {@link Script.ScriptType#P2PKH} for classic
* Base58, {@link Script.ScriptType#P2WPKH} for segwit Bech32.
* The type of Bitcoin addresses to upgrade the current wallet to: {@link ScriptType#P2PKH} for classic
* Base58, {@link ScriptType#P2WPKH} for segwit Bech32.
*/
public static final Script.ScriptType UPGRADE_OUTPUT_SCRIPT_TYPE = Script.ScriptType.P2WPKH;
public static final ScriptType UPGRADE_OUTPUT_SCRIPT_TYPE = ScriptType.P2WPKH;

/** Enable switch for synching of the block chain */
public static final boolean ENABLE_BLOCKCHAIN_SYNC = true;
Expand All @@ -71,7 +74,7 @@ public final class Constants {

public final static class Files {
private static final String FILENAME_NETWORK_SUFFIX = NETWORK_PARAMETERS.getId()
.equals(NetworkParameters.ID_MAINNET) ? "" : "-testnet";
.equals(BitcoinNetwork.ID_MAINNET) ? "" : "-testnet";

/** Filename of the wallet. */
public static final String WALLET_FILENAME_PROTOBUF = "wallet-protobuf" + FILENAME_NETWORK_SUFFIX;
Expand Down Expand Up @@ -109,7 +112,7 @@ public final static class Files {

/** URL to fetch version alerts from. */
public static final HttpUrl VERSION_URL = HttpUrl.parse("https://wallet.schildbach.de/version"
+ (NETWORK_PARAMETERS.getId().equals(NetworkParameters.ID_MAINNET) ? "" : "-test"));
+ (NETWORK_PARAMETERS.getId().equals(BitcoinNetwork.ID_MAINNET) ? "" : "-test"));
/** URL to fetch dynamic fees from. */
public static final HttpUrl DYNAMIC_FEES_URL = HttpUrl.parse("https://wallet.schildbach.de/fees");

Expand All @@ -129,7 +132,7 @@ public final static class Files {
public static final String DEFAULT_EXCHANGE_CURRENCY = "USD";

/** Donation address for tip/donate action. */
public static final String DONATION_ADDRESS = NETWORK_PARAMETERS.getId().equals(NetworkParameters.ID_MAINNET)
public static final String DONATION_ADDRESS = NETWORK_PARAMETERS.getId().equals(BitcoinNetwork.ID_MAINNET)
? "bc1q6swnv7p95wvxwdpld8f6a8zrzxwmaumh2qg2n4" : null;

/** Recipient e-mail address for reports. */
Expand Down Expand Up @@ -169,13 +172,13 @@ public final static class Files {
public static final long LAST_USAGE_THRESHOLD_INACTIVE_MS = 4 * DateUtils.WEEK_IN_MILLIS;

public static final Duration SERVICE_STOP_DELAY_AFTER_START =
NETWORK_PARAMETERS.getId().equals(NetworkParameters.ID_MAINNET) ?
NETWORK_PARAMETERS.getId().equals(BitcoinNetwork.ID_MAINNET) ?
Duration.ofMinutes(1) :
Duration.ofMinutes(2);
public static final Duration SERVICE_STOP_DELAY_AFTER_TRANSACTION =
Duration.ofMinutes(5);
public static final Duration SERVICE_STOP_DELAY_AFTER_EVENT =
NETWORK_PARAMETERS.getId().equals(NetworkParameters.ID_MAINNET) ?
NETWORK_PARAMETERS.getId().equals(BitcoinNetwork.ID_MAINNET) ?
Duration.ofSeconds(30) :
Duration.ofMinutes(2);

Expand Down Expand Up @@ -206,11 +209,17 @@ public final static class Files {
public static final int SCRYPT_ITERATIONS_TARGET = 65536;
public static final int SCRYPT_ITERATIONS_TARGET_LOWRAM = 32768;

/** KeyStore Key Reference */
public static final String KEY_STORE_KEY_REF = "BitcoinWalletKey";
/** KeyStore Provider */
public static final String KEY_STORE_PROVIDER = "AndroidKeyStore";
public static final String KEY_STORE_TRANSFORMATION = "AES/GCM/NoPadding";

/** Default ports for Electrum servers */
public static final int ELECTRUM_SERVER_DEFAULT_PORT_TCP = NETWORK_PARAMETERS.getId()
.equals(NetworkParameters.ID_MAINNET) ? 50001 : 51001;
.equals(BitcoinNetwork.ID_MAINNET) ? 50001 : 51001;
public static final int ELECTRUM_SERVER_DEFAULT_PORT_TLS = NETWORK_PARAMETERS.getId()
.equals(NetworkParameters.ID_MAINNET) ? 50002 : 51002;
.equals(BitcoinNetwork.ID_MAINNET) ? 50002 : 51002;

/** Shared HTTP client, can reuse connections */
public static final OkHttpClient HTTP_CLIENT;
Expand Down
Loading