Skip to content

Commit

Permalink
Merge pull request #11 from zelcash/feature/encryption
Browse files Browse the repository at this point in the history
Feature/encryption
  • Loading branch information
TheTrunk authored Apr 3, 2019
2 parents fd947b7 + 72fcf8d commit c2e45f1
Show file tree
Hide file tree
Showing 12 changed files with 677 additions and 150 deletions.
124 changes: 124 additions & 0 deletions src/java/com/cabecinha84/zelcashui/ChangePasswordEncryptionDialog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
/************************************************************************************************
* ____________ _ _ _____ _ _____ _ _ _______ __ _ _ _
* |___ / ____| \ | |/ ____| | | / ____| | | |_ _\ \ / / | | | | |
* / /| |__ | \| | | __ _ ___| |__ | | __| | | | | | \ \ /\ / /_ _| | | ___| |_
* / / | __| | . ` | | / _` / __| '_ \| | |_ | | | | | | \ \/ \/ / _` | | |/ _ \ __|
* / /__| |____| |\ | |___| (_| \__ \ | | | |__| | |__| |_| |_ \ /\ / (_| | | | __/ |_
* /_____|______|_| \_|\_____\__,_|___/_| |_|\_____|\____/|_____| \/ \/ \__,_|_|_|\___|\__|
*
* Copyright (c) 2016-2018 The ZEN Developers
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
**********************************************************************************/
package com.cabecinha84.zelcashui;


import java.awt.Font;

import javax.swing.JOptionPane;

import com.cabecinha84.zelcashui.ZelCashJFrame;
import com.cabecinha84.zelcashui.ZelCashJLabel;
import com.cabecinha84.zelcashui.ZelCashJPasswordField;
import com.vaklinov.zcashui.LanguageUtil;
import com.vaklinov.zcashui.PasswordDialog;


/**
* Dialog to get the user password - to encrypt a wallet.
*/
public class ChangePasswordEncryptionDialog
extends PasswordDialog
{
protected ZelCashJPasswordField newPasswordConfirmationField = null;
protected ZelCashJPasswordField passwordConfirmationField = null;
protected String newPassword = null;

private LanguageUtil langUtil;

public ChangePasswordEncryptionDialog(ZelCashJFrame parent)
{
super(parent);
langUtil = LanguageUtil.instance();
this.passwordLabel.setText(langUtil.getString("dialog.change.password.current.password"));

this.upperLabel.setText(langUtil.getString("dialog.change.password.encryption.upper.label.text"));

ZelCashJLabel newLabel = new ZelCashJLabel(langUtil.getString("dialog.change.password.new.password"));
this.freeSlotPanel.add(newLabel);
this.freeSlotPanel.add(newPasswordConfirmationField = new ZelCashJPasswordField(50));
newLabel.setPreferredSize(passwordLabel.getPreferredSize());

ZelCashJLabel confLabel = new ZelCashJLabel(langUtil.getString("dialog.password.encryption.confirmation.label.text"));
this.freeSlotPanel3.add(confLabel);
this.freeSlotPanel3.add(passwordConfirmationField = new ZelCashJPasswordField(50));
confLabel.setPreferredSize(passwordLabel.getPreferredSize());

ZelCashJLabel dividerLabel = new ZelCashJLabel(" ");
dividerLabel.setFont(new Font("Helvetica", Font.PLAIN, 8));
this.freeSlotPanel2.add(dividerLabel);

this.setSize(620, 220);
this.validate();
this.repaint();
}


protected void processOK()
{
String password = this.newPasswordConfirmationField.getText();
String confirmation = this.passwordConfirmationField.getText();

if (password == null)
{
password = "";
}

if (confirmation == null)
{
confirmation = "";
}

if (!password.equals(confirmation))
{
JOptionPane.showMessageDialog(
this.getParent(),
langUtil.getString("dialog.password.encryption.option.pane.mismatch.text"),
langUtil.getString("dialog.password.encryption.option.pane.mismatch.title") ,
JOptionPane.ERROR_MESSAGE);
return;
}
if(password.length()==0) {
JOptionPane.showMessageDialog(
this.getParent(),
langUtil.getString("dialog.password.option.pane.process.text"),
langUtil.getString("dialog.password.option.pane.process.title"),
JOptionPane.ERROR_MESSAGE);
return;
}

super.processOK();
this.newPassword = password;
}

public String getNewPassword()
{
return this.newPassword;
}
}
35 changes: 35 additions & 0 deletions src/java/com/cabecinha84/zelcashui/ZelNodesPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import com.vaklinov.zcashui.LanguageUtil;
import com.vaklinov.zcashui.Log;
import com.vaklinov.zcashui.OSUtil;
import com.vaklinov.zcashui.PasswordDialog;
import com.vaklinov.zcashui.SendCashPanel;
import com.vaklinov.zcashui.StatusUpdateErrorReporter;
import com.vaklinov.zcashui.WalletTabPanel;
import com.vaklinov.zcashui.ZCashClientCaller;
Expand Down Expand Up @@ -274,6 +276,39 @@ private void getZelNodesRewards() {
String amountShielded;
try {
String zAddressSelected = zAddresses[zAddressesCombo.getSelectedIndex()];
// Check for encrypted wallet
final boolean bEncryptedWallet = this.clientCaller.isWalletEncrypted();
if (bEncryptedWallet)
{
boolean passwordOk = false;
int retrys = 0;
while(!passwordOk && retrys<3) {
++retrys;
PasswordDialog pd = new PasswordDialog((ZelCashJFrame)(ZelNodesPanel.this.getRootPane().getParent()));
pd.setVisible(true);

if (!pd.isOKPressed())
{
return;
}
try {
this.clientCaller.unlockWallet(pd.getPassword());
passwordOk = true;
}
catch (Exception ex) {
Log.error("Error unlocking wallet:"+ex.getMessage());
JOptionPane.showMessageDialog(
ZelNodesPanel.this.getRootPane().getParent(),
langUtil.getString("encryption.error.unlocking.message", ex.getMessage()),
langUtil.getString("encryption.error.unlocking.title"),
JOptionPane.ERROR_MESSAGE);
}
}
if(!passwordOk) {
Log.info("Failed to enter correct password for third time, wallet will close.");
System.exit(1);
}
}
JsonObject shieldResult = clientCaller.zShieldCoinBase(zAddressSelected, MAX_UTXO_TXN);
amountShielded = shieldResult.get("shieldingValue").toString();
}
Expand Down
37 changes: 28 additions & 9 deletions src/java/com/vaklinov/zcashui/AddressTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,34 @@ public void actionPerformed(ActionEvent e)
final boolean bEncryptedWallet = caller.isWalletEncrypted();
if (bEncryptedWallet)
{
PasswordDialog pd = new PasswordDialog((ZelCashJFrame)(AddressTable.this.getRootPane().getParent()));
pd.setVisible(true);

if (!pd.isOKPressed())
{
return;
boolean passwordOk = false;
int retrys = 0;
while(!passwordOk && retrys<3) {
++retrys;
PasswordDialog pd = new PasswordDialog((ZelCashJFrame)(AddressTable.this.getRootPane().getParent()));
pd.setVisible(true);

if (!pd.isOKPressed())
{
return;
}
try {
caller.unlockWallet(pd.getPassword());
passwordOk = true;
}
catch (Exception ex) {
Log.error("Error unlocking wallet:"+ex.getMessage());
JOptionPane.showMessageDialog(
AddressTable.this.getRootPane().getParent(),
langUtil.getString("encryption.error.unlocking.message", ex.getMessage()),
langUtil.getString("encryption.error.unlocking.title"),
JOptionPane.ERROR_MESSAGE);
}
}
if(!passwordOk) {
Log.info("Failed to enter correct password for third time, wallet will close.");
System.exit(1);
}

caller.unlockWallet(pd.getPassword());
}

String privateKey = isZAddress ?
Expand All @@ -109,7 +128,7 @@ public void actionPerformed(ActionEvent e)
// Lock the wallet again
if (bEncryptedWallet)
{
caller.lockWallet();
//caller.lockWallet();
}

Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
Expand Down
39 changes: 28 additions & 11 deletions src/java/com/vaklinov/zcashui/AddressesPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -264,17 +264,34 @@ private void createNewAddress(boolean isZAddress, boolean isSapling)
final boolean bEncryptedWallet = this.clientCaller.isWalletEncrypted();
if (bEncryptedWallet && isZAddress)
{
this.setCursor(oldCursor);
PasswordDialog pd = new PasswordDialog((ZelCashJFrame)(this.getRootPane().getParent()));
pd.setVisible(true);

if (!pd.isOKPressed())
{
return;
boolean passwordOk = false;
int retrys = 0;
while(!passwordOk && retrys<3) {
++retrys;
PasswordDialog pd = new PasswordDialog((ZelCashJFrame)(AddressesPanel.this.getRootPane().getParent()));
pd.setVisible(true);

if (!pd.isOKPressed())
{
return;
}
try {
this.clientCaller.unlockWallet(pd.getPassword());
passwordOk = true;
}
catch (Exception e) {
Log.error("Error unlocking wallet:"+e.getMessage());
JOptionPane.showMessageDialog(
this,
langUtil.getString("encryption.error.unlocking.message", e.getMessage()),
langUtil.getString("encryption.error.unlocking.title"),
JOptionPane.ERROR_MESSAGE);
}
}
if(!passwordOk) {
Log.info("Failed to enter correct password for third time, wallet will close.");
System.exit(1);
}

this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
this.clientCaller.unlockWallet(pd.getPassword());
}

// zelcashd has a bug that sometimes supposedly newly returned addresses have actually
Expand All @@ -300,7 +317,7 @@ private void createNewAddress(boolean isZAddress, boolean isSapling)
// Lock the wallet again
if (bEncryptedWallet && isZAddress)
{
this.clientCaller.lockWallet();
//this.clientCaller.lockWallet();
}

String backupMessage = "";
Expand Down
45 changes: 39 additions & 6 deletions src/java/com/vaklinov/zcashui/DashboardPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import javax.swing.DefaultListModel;
import javax.swing.ImageIcon;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.ListCellRenderer;
import javax.swing.ListSelectionModel;
import javax.swing.Timer;
Expand Down Expand Up @@ -249,6 +250,43 @@ public void mouseClicked(MouseEvent e) {

dashboard.add(installationStatusPanel, BorderLayout.SOUTH);

if (this.walletIsEncrypted == null) {
this.walletIsEncrypted = this.clientCaller
.isWalletEncrypted();

if(this.walletIsEncrypted) {
boolean passwordOk = false;
int retrys = 0;
while(!passwordOk && retrys<3) {
++retrys;
PasswordDialog pd = new PasswordDialog(this.parentFrame);
pd.setVisible(true);

if (!pd.isOKPressed())
{
Log.info("User pressed x or cancel on wallet startup - Wallet will be closed.");
System.exit(1);
}
try {
this.clientCaller.unlockWallet(pd.getPassword());
passwordOk = true;
}
catch (Exception e) {
Log.error("Error unlocking wallet:"+e.getMessage());
JOptionPane.showMessageDialog(
this,
langUtil.getString("encryption.error.unlocking.message", e.getMessage()),
langUtil.getString("encryption.error.unlocking.title"),
JOptionPane.ERROR_MESSAGE);
}
}
if(!passwordOk) {
Log.info("Failed to enter correct password for third time, wallet will close.");
System.exit(1);
}

}
}

// Thread and timer to update the daemon status
this.daemonInfoGatheringThread = new DataGatheringThread<DaemonInfo>(
Expand All @@ -273,11 +311,6 @@ public WalletBalance gatherData() throws Exception {
WalletBalance balance = DashboardPanel.this.clientCaller.getWalletInfo();
long end = System.currentTimeMillis();

if (DashboardPanel.this.walletIsEncrypted == null) {
DashboardPanel.this.walletIsEncrypted = DashboardPanel.this.clientCaller
.isWalletEncrypted();
}

Log.info("Gathering of dashboard wallet balance data done in " + (end - start) + "ms.");
DashboardPanel.this.updateWalletStatusLabel(balance);
return balance;
Expand Down Expand Up @@ -375,7 +408,7 @@ private void updateDaemonStatusLabel(DaemonInfo daemonInfo) throws IOException,
+ langUtil.getString("panel.dashboard.deamon.status.encrypted");

walletEncryption = langUtil.getString("panel.dashboard.deamon.status.walletencrypted.text", encryptionText);

}

String text = langUtil.getString("panel.dashboard.deamon.status.text", daemonStatus, runtimeInfo,
Expand Down
6 changes: 5 additions & 1 deletion src/java/com/vaklinov/zcashui/PasswordDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public class PasswordDialog

protected ZelCashJPanel freeSlotPanel;
protected ZelCashJPanel freeSlotPanel2;
protected ZelCashJPanel freeSlotPanel3;
private LanguageUtil langUtil;

public PasswordDialog(ZelCashJFrame parent)
Expand All @@ -89,7 +90,7 @@ public PasswordDialog(ZelCashJFrame parent)

tempPanel = new ZelCashJPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
tempPanel.add(passwordLabel = new ZelCashJLabel(langUtil.getString("dialog.password.temp.panel.password.label.text")));
tempPanel.add(passwordField = new ZelCashJPasswordField(30));
tempPanel.add(passwordField = new ZelCashJPasswordField(50));
controlsPanel.add(tempPanel);

dividerLabel = new ZelCashJLabel(" ");
Expand All @@ -101,6 +102,9 @@ public PasswordDialog(ZelCashJFrame parent)

this.freeSlotPanel2 = new ZelCashJPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
controlsPanel.add(this.freeSlotPanel2);

this.freeSlotPanel3 = new ZelCashJPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
controlsPanel.add(this.freeSlotPanel3);

tempPanel = new ZelCashJPanel(new BorderLayout(0, 0));
tempPanel.add(this.lowerLabel = new ZelCashJLabel(langUtil.getString("dialog.password.temp.panel.lower.label.text")), BorderLayout.CENTER);
Expand Down
Loading

0 comments on commit c2e45f1

Please sign in to comment.