mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-12-25 05:06:45 +00:00
always set charset to utf-8 when converting from bytes to string
This commit is contained in:
parent
fd7d2232a1
commit
38818d8222
9 changed files with 18 additions and 11 deletions
|
@ -11,6 +11,7 @@ import com.sparrowwallet.drongo.wallet.*;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
public class CoboVaultSinglesig implements KeystoreFileImport, WalletImport {
|
public class CoboVaultSinglesig implements KeystoreFileImport, WalletImport {
|
||||||
@Override
|
@Override
|
||||||
|
@ -32,7 +33,7 @@ public class CoboVaultSinglesig implements KeystoreFileImport, WalletImport {
|
||||||
public Keystore getKeystore(ScriptType scriptType, InputStream inputStream, String password) throws ImportException {
|
public Keystore getKeystore(ScriptType scriptType, InputStream inputStream, String password) throws ImportException {
|
||||||
try {
|
try {
|
||||||
Gson gson = new Gson();
|
Gson gson = new Gson();
|
||||||
CoboVaultSinglesigKeystore coboKeystore = gson.fromJson(new InputStreamReader(inputStream), CoboVaultSinglesigKeystore.class);
|
CoboVaultSinglesigKeystore coboKeystore = gson.fromJson(new InputStreamReader(inputStream, StandardCharsets.UTF_8), CoboVaultSinglesigKeystore.class);
|
||||||
|
|
||||||
if(coboKeystore.MasterFingerprint == null || coboKeystore.AccountKeyPath == null || coboKeystore.ExtPubKey == null) {
|
if(coboKeystore.MasterFingerprint == null || coboKeystore.AccountKeyPath == null || coboKeystore.ExtPubKey == null) {
|
||||||
throw new ImportException("Not a valid " + getName() + " keystore export");
|
throw new ImportException("Not a valid " + getName() + " keystore export");
|
||||||
|
|
|
@ -13,6 +13,7 @@ import com.sparrowwallet.drongo.wallet.Wallet;
|
||||||
import com.sparrowwallet.drongo.wallet.WalletModel;
|
import com.sparrowwallet.drongo.wallet.WalletModel;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -30,7 +31,7 @@ public class ColdcardMultisig implements WalletImport, KeystoreFileImport, Walle
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Keystore getKeystore(ScriptType scriptType, InputStream inputStream, String password) throws ImportException {
|
public Keystore getKeystore(ScriptType scriptType, InputStream inputStream, String password) throws ImportException {
|
||||||
InputStreamReader reader = new InputStreamReader(inputStream);
|
InputStreamReader reader = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
|
||||||
ColdcardKeystore cck = Storage.getGson().fromJson(reader, ColdcardKeystore.class);
|
ColdcardKeystore cck = Storage.getGson().fromJson(reader, ColdcardKeystore.class);
|
||||||
|
|
||||||
Keystore keystore = new Keystore("Coldcard");
|
Keystore keystore = new Keystore("Coldcard");
|
||||||
|
@ -94,7 +95,7 @@ public class ColdcardMultisig implements WalletImport, KeystoreFileImport, Walle
|
||||||
String derivation = null;
|
String derivation = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
List<String> lines = CharStreams.readLines(new InputStreamReader(inputStream));
|
List<String> lines = CharStreams.readLines(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
|
||||||
for (String line : lines) {
|
for (String line : lines) {
|
||||||
line = line.trim();
|
line = line.trim();
|
||||||
if (line.isEmpty()) {
|
if (line.isEmpty()) {
|
||||||
|
|
|
@ -14,6 +14,7 @@ import java.io.File;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class ColdcardSinglesig implements KeystoreFileImport, WalletImport {
|
public class ColdcardSinglesig implements KeystoreFileImport, WalletImport {
|
||||||
|
@ -53,7 +54,7 @@ public class ColdcardSinglesig implements KeystoreFileImport, WalletImport {
|
||||||
Gson gson = new Gson();
|
Gson gson = new Gson();
|
||||||
Type stringStringMap = new TypeToken<Map<String, JsonElement>>() {
|
Type stringStringMap = new TypeToken<Map<String, JsonElement>>() {
|
||||||
}.getType();
|
}.getType();
|
||||||
Map<String, JsonElement> map = gson.fromJson(new InputStreamReader(inputStream), stringStringMap);
|
Map<String, JsonElement> map = gson.fromJson(new InputStreamReader(inputStream, StandardCharsets.UTF_8), stringStringMap);
|
||||||
|
|
||||||
if (map.get("xfp") == null) {
|
if (map.get("xfp") == null) {
|
||||||
throw new ImportException("File was not a valid Coldcard wallet export");
|
throw new ImportException("File was not a valid Coldcard wallet export");
|
||||||
|
|
|
@ -58,9 +58,9 @@ public class Electrum implements KeystoreFileImport, WalletImport, WalletExport
|
||||||
Reader reader;
|
Reader reader;
|
||||||
if(password != null) {
|
if(password != null) {
|
||||||
ECKey decryptionKey = Pbkdf2KeyDeriver.DEFAULT_INSTANCE.deriveECKey(password);
|
ECKey decryptionKey = Pbkdf2KeyDeriver.DEFAULT_INSTANCE.deriveECKey(password);
|
||||||
reader = new InputStreamReader(new InflaterInputStream(new ECIESInputStream(inputStream, decryptionKey)));
|
reader = new InputStreamReader(new InflaterInputStream(new ECIESInputStream(inputStream, decryptionKey)), StandardCharsets.UTF_8);
|
||||||
} else {
|
} else {
|
||||||
reader = new InputStreamReader(inputStream);
|
reader = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.sparrowwallet.sparrow.io;
|
package com.sparrowwallet.sparrow.io;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
|
||||||
public class IOUtils {
|
public class IOUtils {
|
||||||
|
@ -13,7 +14,7 @@ public class IOUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(file.exists()) {
|
if(file.exists()) {
|
||||||
try(BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file)))) {
|
try(BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8))) {
|
||||||
String line = br.readLine();
|
String line = br.readLine();
|
||||||
if(line.startsWith("01000000") || line.startsWith("cHNid")) {
|
if(line.startsWith("01000000") || line.startsWith("cHNid")) {
|
||||||
return FileType.TEXT;
|
return FileType.TEXT;
|
||||||
|
|
|
@ -12,12 +12,13 @@ import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
public class SpecterDIY implements KeystoreFileImport {
|
public class SpecterDIY implements KeystoreFileImport {
|
||||||
@Override
|
@Override
|
||||||
public Keystore getKeystore(ScriptType scriptType, InputStream inputStream, String password) throws ImportException {
|
public Keystore getKeystore(ScriptType scriptType, InputStream inputStream, String password) throws ImportException {
|
||||||
try {
|
try {
|
||||||
String text = CharStreams.toString(new InputStreamReader(inputStream));
|
String text = CharStreams.toString(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
|
||||||
String outputDesc = "sh(" + text + ")";
|
String outputDesc = "sh(" + text + ")";
|
||||||
OutputDescriptor outputDescriptor = OutputDescriptor.getOutputDescriptor(outputDesc);
|
OutputDescriptor outputDescriptor = OutputDescriptor.getOutputDescriptor(outputDesc);
|
||||||
Wallet wallet = outputDescriptor.toWallet();
|
Wallet wallet = outputDescriptor.toWallet();
|
||||||
|
|
|
@ -51,7 +51,7 @@ public class SpecterDesktop implements WalletImport, WalletExport {
|
||||||
public Wallet importWallet(InputStream inputStream, String password) throws ImportException {
|
public Wallet importWallet(InputStream inputStream, String password) throws ImportException {
|
||||||
try {
|
try {
|
||||||
Gson gson = new Gson();
|
Gson gson = new Gson();
|
||||||
SpecterWallet specterWallet = gson.fromJson(new InputStreamReader(inputStream), SpecterWallet.class);
|
SpecterWallet specterWallet = gson.fromJson(new InputStreamReader(inputStream, StandardCharsets.UTF_8), SpecterWallet.class);
|
||||||
|
|
||||||
if(specterWallet.descriptor != null) {
|
if(specterWallet.descriptor != null) {
|
||||||
OutputDescriptor outputDescriptor = OutputDescriptor.getOutputDescriptor(specterWallet.descriptor);
|
OutputDescriptor outputDescriptor = OutputDescriptor.getOutputDescriptor(specterWallet.descriptor);
|
||||||
|
|
|
@ -12,6 +12,7 @@ import org.slf4j.LoggerFactory;
|
||||||
import javax.net.SocketFactory;
|
import javax.net.SocketFactory;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.locks.Condition;
|
import java.util.concurrent.locks.Condition;
|
||||||
|
@ -130,7 +131,7 @@ public class TcpTransport implements Transport, Closeable {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
}
|
}
|
||||||
|
|
||||||
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream(), StandardCharsets.UTF_8));
|
||||||
|
|
||||||
while(running) {
|
while(running) {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -16,6 +16,7 @@ import javax.net.ssl.HttpsURLConnection;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.security.SignatureException;
|
import java.security.SignatureException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -45,7 +46,7 @@ public class VersionCheckService extends ScheduledService<VersionUpdatedEvent> {
|
||||||
URL url = new URL(VERSION_CHECK_URL);
|
URL url = new URL(VERSION_CHECK_URL);
|
||||||
HttpsURLConnection conn = (HttpsURLConnection)url.openConnection();
|
HttpsURLConnection conn = (HttpsURLConnection)url.openConnection();
|
||||||
|
|
||||||
try(InputStreamReader reader = new InputStreamReader(conn.getInputStream())) {
|
try(InputStreamReader reader = new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8)) {
|
||||||
Gson gson = new Gson();
|
Gson gson = new Gson();
|
||||||
return gson.fromJson(reader, VersionCheck.class);
|
return gson.fromJson(reader, VersionCheck.class);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue