Skip to content

Commit

Permalink
Light Wallet: encrypt communication with server
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanielhourt committed Jan 27, 2015
1 parent db23155 commit 115c6eb
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ namespace bts { namespace light_wallet {
light_wallet(const fc::path& data_dir);
~light_wallet();

void connect( const string& host, const string& user = "any", const string& pass = "none", uint16_t port = 0 );
void connect( const string& host, const string& user = "any", const string& pass = "none", uint16_t port = 0,
const public_key_type& server_key = public_key_type() );
bool is_connected()const;
void disconnect();

Expand Down
5 changes: 3 additions & 2 deletions libraries/light_wallet/light_wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ void light_wallet::fetch_welcome_package()
_network_fee = asset(welcome_package["network_fee_amount"].as<share_type>());
}

void light_wallet::connect( const string& host, const string& user, const string& pass, uint16_t port )
void light_wallet::connect(const string& host, const string& user, const string& pass, uint16_t port,
const public_key_type& server_key)
{
string last_error;
auto resolved = fc::resolve( host, port ? port : BTS_LIGHT_WALLET_PORT );
Expand All @@ -51,7 +52,7 @@ void light_wallet::connect( const string& host, const string& user, const string
for( auto item : resolved )
{
try {
_rpc.connect_to( item );
_rpc.connect_to( item, blockchain::public_key_type(server_key) );
if( user != "any" && pass != "none" )
_rpc.login( user, pass );

Expand Down
9 changes: 6 additions & 3 deletions programs/light_wallet/LightWallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,21 @@ bool LightWallet::verifyBrainKey(QString key) const
return !m_brainKey.isEmpty() && normalize(key) == normalize(m_brainKey);
}

void LightWallet::connectToServer(QString host, quint16 port, QString user, QString password)
void LightWallet::connectToServer(QString host, quint16 port, QString serverKey, QString user, QString password)
{
IN_THREAD
qDebug() << "Connecting to" << host << ':' << port << "as" << user << ':' << password;
try {
m_wallet.connect(convert(host), convert(user), convert(password), port);
if( serverKey.isEmpty() )
m_wallet.connect(convert(host), convert(user), convert(password), port);
else
m_wallet.connect(convert(host), convert(user), convert(password), port,
bts::blockchain::public_key_type(convert(serverKey)));
Q_EMIT connectedChanged(isConnected());
} catch (fc::exception e) {
m_connectionError = convert(e.get_log().begin()->get_message()).replace("\n", " ");
Q_EMIT errorConnecting(m_connectionError);
}

END_THREAD
}

Expand Down
7 changes: 4 additions & 3 deletions programs/light_wallet/LightWallet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,10 @@ class LightWallet : public QObject
Q_INVOKABLE bool verifyBrainKey(QString key) const;

public Q_SLOTS:
void connectToServer( QString host, quint16 port,
QString user = QString("any"),
QString password = QString("none") );
void connectToServer(QString host, quint16 port,
QString serverKey = QString(),
QString user = QString("any"),
QString password = QString("none"));
void disconnectFromServer();

void createWallet(QString accountName, QString password);
Expand Down
7 changes: 6 additions & 1 deletion programs/light_wallet/qml/OnboardingLayout.qml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ MainView {
text: wallet.account? wallet.account.name : ""
helperText: defaultHelperText
characterLimit: 64
onEditingFinished: nameAvailable()
onEditingFinished: if( wallet.connected ) nameAvailable()
transform: ShakeAnimation { id: nameShaker }

property string defaultHelperText: qsTr("May contain letters, numbers and hyphens.\n" +
Expand Down Expand Up @@ -139,6 +139,11 @@ MainView {
if( wallet.account )
wallet.account.name = nameField.text

if( !wallet.connected ) {
showError("Unable to connect to server.", "Try Again", connectToServer)
return
}

if( !nameField.nameAvailable() )
return nameShaker.shake()

Expand Down
42 changes: 42 additions & 0 deletions programs/light_wallet/qml/ShakeAnimation.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import QtQuick 2.4
import QtQuick.Controls 1.3
import QtQuick.Layouts 1.1
import QtGraphicalEffects 1.0

import Material 0.1

Translate {
id: passwordTransform
x: 0

function shake() {
shaker.restart()
}

property SequentialAnimation shaker: SequentialAnimation {
loops: 2
alwaysRunToEnd: true

PropertyAnimation {
target: passwordTransform
property: "x"
from: 0; to: units.dp(10)
easing.type: Easing.InQuad
duration: 25
}
PropertyAnimation {
target: passwordTransform
property: "x"
from: units.dp(10); to: units.dp(-10)
easing.type: Easing.OutInQuad
duration: 50
}
PropertyAnimation {
target: passwordTransform
property: "x"
from: units.dp(-10); to: 0
easing.type: Easing.OutQuad
duration: 25
}
}
}
3 changes: 2 additions & 1 deletion programs/light_wallet/qml/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ ApplicationWindow {

function connectToServer() {
if( !wallet.connected )
wallet.connectToServer("localhost", 6691, "user", "pass")
wallet.connectToServer("localhost", 5656, "XTS7pq7tZnghnrnYvQg8aktrSCLVHE5SGyHFeYJBRdcFVvNCBBDjd",
"user", "pass")
}
function showError(error, buttonName, buttonCallback) {
snack.text = error
Expand Down

0 comments on commit 115c6eb

Please sign in to comment.