improve open wallet error dialog message

This commit is contained in:
Craig Raw 2020-10-05 12:33:05 +02:00
parent 7e93b6b198
commit 3a885b3a28
2 changed files with 11 additions and 7 deletions

View file

@ -809,7 +809,7 @@ public class AppController implements Initializable {
} else { } else {
if(!attemptImportWallet(file, password)) { if(!attemptImportWallet(file, password)) {
log.error("Error Opening Wallet", exception); log.error("Error Opening Wallet", exception);
showErrorDialog("Error Opening Wallet", exception.getMessage()); showErrorDialog("Error Opening Wallet", exception.getMessage() == null ? "Unsupported file format" : exception.getMessage());
} }
password.clear(); password.clear();
} }
@ -822,7 +822,7 @@ public class AppController implements Initializable {
} catch(Exception e) { } catch(Exception e) {
if(!attemptImportWallet(file, null)) { if(!attemptImportWallet(file, null)) {
log.error("Error opening wallet", e); log.error("Error opening wallet", e);
showErrorDialog("Error Opening Wallet", e.getMessage()); showErrorDialog("Error Opening Wallet", e.getMessage() == null ? "Unsupported file format" : e.getMessage());
} }
} }
} }

View file

@ -222,12 +222,16 @@ public class Storage {
if(read != BINARY_HEADER_LENGTH) { if(read != BINARY_HEADER_LENGTH) {
throw new StorageException("Not a Sparrow wallet - invalid header"); throw new StorageException("Not a Sparrow wallet - invalid header");
} }
try {
byte[] decodedHeader = Base64.getDecoder().decode(header); byte[] decodedHeader = Base64.getDecoder().decode(header);
byte[] magic = Arrays.copyOfRange(decodedHeader, 0, HEADER_MAGIC_1.length()); byte[] magic = Arrays.copyOfRange(decodedHeader, 0, HEADER_MAGIC_1.length());
if(!HEADER_MAGIC_1.equals(new String(magic, StandardCharsets.UTF_8))) { if(!HEADER_MAGIC_1.equals(new String(magic, StandardCharsets.UTF_8))) {
throw new StorageException("Not a Sparrow wallet - invalid magic"); throw new StorageException("Not a Sparrow wallet - invalid magic");
} }
salt = Arrays.copyOfRange(decodedHeader, HEADER_MAGIC_1.length(), decodedHeader.length); salt = Arrays.copyOfRange(decodedHeader, HEADER_MAGIC_1.length(), decodedHeader.length);
} catch(IllegalArgumentException e) {
throw new StorageException("Not a Sparrow wallet - invalid header");
}
} else { } else {
SecureRandom secureRandom = new SecureRandom(); SecureRandom secureRandom = new SecureRandom();
secureRandom.nextBytes(salt); secureRandom.nextBytes(salt);