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

Wallet: Support not encrypted wallets (#115) #121

Merged
merged 1 commit into from
Mar 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ abstract class BitcoindCreateOrLoadWalletTask : DefaultTask() {
} else {
loadWallet(walletFile)
}

setPassphrase(walletFile)
}

private fun createWallet(walletFile: File) {
Expand All @@ -30,7 +28,6 @@ abstract class BitcoindCreateOrLoadWalletTask : DefaultTask() {
"createwallet",

"wallet_name=${walletFile.absolutePath}",
"passphrase=bisq"
)
)
}
Expand All @@ -43,15 +40,4 @@ abstract class BitcoindCreateOrLoadWalletTask : DefaultTask() {
)
)
}

private fun setPassphrase(walletFile: File) {
BitcoindRpcClient.walletRpcCall(
walletPath = walletFile.absolutePath,
listOf(
"walletpassphrase",
"bisq",
"10000000"
)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ abstract class ElementsdCreateOrLoadWalletTask : DefaultTask() {
} else {
loadWallet(walletFile)
}

setPassphrase(walletFile)
}

private fun createWallet(walletFile: File) {
Expand All @@ -30,7 +28,6 @@ abstract class ElementsdCreateOrLoadWalletTask : DefaultTask() {
"createwallet",

"wallet_name=${walletFile.absolutePath}",
"passphrase=bisq"
)
)
}
Expand All @@ -43,15 +40,4 @@ abstract class ElementsdCreateOrLoadWalletTask : DefaultTask() {
)
)
}

private fun setPassphrase(walletFile: File) {
ElementsdRpcClient.walletRpcCall(
walletPath = walletFile.absolutePath,
listOf(
"walletpassphrase",
"bisq",
"10000000"
)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ public void onViewDetached() {
}

private void onConnectToWallet() {
String passphrase = model.walletPassphraseProperty.get();
String passphraseValue = model.walletPassphraseProperty.get();
Optional<String> passphrase = passphraseValue.isEmpty() ? Optional.empty()
: Optional.of(passphraseValue);
model.walletPassphraseProperty.setValue(""); // Wipe passphrase from memory
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually to avoid that the passphrase sticks in memory (until GC cleans up) we should use a char array instead of a String and clear the array afterwards. But no need to do it now, just for hardening once we get more production ready.


WalletConfig walletConfig = createWalletConfigFromModel();
Expand Down
3 changes: 2 additions & 1 deletion wallets/src/main/java/bisq/wallets/Wallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
import bisq.wallets.model.Utxo;

import java.util.List;
import java.util.Optional;

public interface Wallet {
void initialize(String walletPassphrase);
void initialize(Optional<String> walletPassphrase);

void shutdown();

Expand Down
4 changes: 2 additions & 2 deletions wallets/src/main/java/bisq/wallets/WalletService.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ public CompletableFuture<Void> tryAutoInitialization() {
if (walletConfig.isEmpty()) {
return CompletableFuture.completedFuture(null);
}
return initialize(walletConfig.get(), "bisq");
return initialize(walletConfig.get(), Optional.empty());
}

public CompletableFuture<Void> initialize(WalletConfig walletConfig, String walletPassphrase) {
public CompletableFuture<Void> initialize(WalletConfig walletConfig, Optional<String> walletPassphrase) {
if (wallet.isPresent()) {
return CompletableFuture.completedFuture(null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.net.MalformedURLException;
import java.nio.file.Path;
import java.util.List;
import java.util.Optional;

public class BitcoinWallet implements Wallet {
private final Path walletPath;
Expand All @@ -51,7 +52,7 @@ public BitcoinWallet(Path walletPath, RpcConfig rpcConfig) {
}

@Override
public void initialize(String walletPassphrase) {
public void initialize(Optional<String> walletPassphrase) {
daemon.createOrLoadWallet(walletPath, walletPassphrase);
wallet.walletPassphrase(walletPassphrase, BitcoindWallet.DEFAULT_WALLET_TIMEOUT);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.nio.file.Path;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;

public class BitcoindDaemon {

Expand All @@ -33,9 +34,9 @@ public BitcoindDaemon(RpcClient rpcClient) {
this.rpcClient = rpcClient;
}

public void createOrLoadWallet(Path walletPath, String passphrase) {
public void createOrLoadWallet(Path walletPath, Optional<String> passphrase) {
if (!doesWalletExist(walletPath)) {
createWallet(walletPath, passphrase);
createWallet(walletPath, passphrase.orElse(""));
} else {
List<String> loadedWallets = listWallets();
if (!loadedWallets.contains(walletPath.toString())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.TimeUnit;

public class BitcoindWallet {
Expand Down Expand Up @@ -134,9 +135,13 @@ public BitcoindWalletCreateFundedPsbtResponse walletCreateFundedPsbt(List<Bitcoi
return rpcClient.invokeAndValidate(rpcCall);
}

public void walletPassphrase(String passphrase, long timeout) {
public void walletPassphrase(Optional<String> passphrase, long timeout) {
if (passphrase.isEmpty()) {
return;
}

var request = BitcoindWalletPassphraseRpcCall.Request.builder()
.passphrase(passphrase)
.passphrase(passphrase.get())
.timeout(timeout)
.build();
var rpcCall = new BitcoindWalletPassphraseRpcCall(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.net.MalformedURLException;
import java.nio.file.Path;
import java.util.List;
import java.util.Optional;

public class LiquidWallet implements Wallet {
private final Path walletPath;
Expand All @@ -52,7 +53,7 @@ public LiquidWallet(Path walletPath, RpcConfig rpcConfig) {
}

@Override
public void initialize(String walletPassphrase) {
public void initialize(Optional<String> walletPassphrase) {
daemon.createOrLoadWallet(walletPath, walletPassphrase);
wallet.walletPassphrase(walletPassphrase, BitcoindWallet.DEFAULT_WALLET_TIMEOUT);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import java.util.Arrays;
import java.util.List;
import java.util.Optional;

public class ElementsdWallet {
private final RpcClient rpcClient;
Expand Down Expand Up @@ -126,9 +127,13 @@ public boolean verifyMessage(String address, String signature, String message) {
return rpcClient.invokeAndValidate(rpcCall);
}

public void walletPassphrase(String passphrase, long timeout) {
public void walletPassphrase(Optional<String> passphrase, long timeout) {
if (passphrase.isEmpty()) {
return;
}

var request = BitcoindWalletPassphraseRpcCall.Request.builder()
.passphrase(passphrase)
.passphrase(passphrase.get())
.timeout(timeout)
.build();
var rpcCall = new BitcoindWalletPassphraseRpcCall(request);
Expand Down