mirror of
https://github.com/basicswap/basicswap.git
synced 2025-11-05 18:38:09 +01:00
ui: Add wallet encryption templates.
tests: Test wallet encryption.
This commit is contained in:
@@ -748,6 +748,9 @@ class BasicSwap(BaseApp):
|
||||
if len(self.swaps_in_progress) > 0:
|
||||
raise ValueError('Can\'t change passwords while swaps are in progress')
|
||||
|
||||
if old_password == new_password:
|
||||
raise ValueError('Passwords must differ')
|
||||
|
||||
# Unlock all wallets to ensure they all have the same password.
|
||||
for c in self.activeCoins():
|
||||
ci = self.ci(c)
|
||||
|
||||
@@ -375,7 +375,7 @@ class CoinInterface:
|
||||
return ticker
|
||||
|
||||
def getExchangeTicker(self, exchange_name):
|
||||
return self.ticker()
|
||||
return chainparams[self.coin_type()]['ticker']
|
||||
|
||||
def getExchangeName(self, exchange_name):
|
||||
return chainparams[self.coin_type()]['name']
|
||||
|
||||
@@ -17,6 +17,7 @@ from . import __version__
|
||||
from .util import (
|
||||
dumpj,
|
||||
ensure,
|
||||
LockedCoinError,
|
||||
format_timestamp,
|
||||
)
|
||||
from .chainparams import (
|
||||
@@ -50,6 +51,7 @@ from .ui.page_offers import page_offers, page_offer, page_newoffer
|
||||
from .ui.page_tor import page_tor, get_tor_established_state
|
||||
from .ui.page_wallet import page_wallets, page_wallet
|
||||
from .ui.page_settings import page_settings
|
||||
from .ui.page_encryption import page_changepassword, page_unlock, page_lock
|
||||
|
||||
env = Environment(loader=PackageLoader('basicswap', 'templates'))
|
||||
env.filters['formatts'] = format_timestamp
|
||||
@@ -623,9 +625,17 @@ class HttpHandler(BaseHTTPRequestHandler):
|
||||
return page_automation_strategy_new(self, url_split, post_string)
|
||||
if page == 'shutdown':
|
||||
return self.page_shutdown(url_split, post_string)
|
||||
if page == 'changepassword':
|
||||
return page_changepassword(self, url_split, post_string)
|
||||
if page == 'unlock':
|
||||
return page_unlock(self, url_split, post_string)
|
||||
if page == 'lock':
|
||||
return page_lock(self, url_split, post_string)
|
||||
if page != '':
|
||||
return self.page_404(url_split)
|
||||
return self.page_index(url_split)
|
||||
except LockedCoinError:
|
||||
return page_unlock(self, url_split, post_string)
|
||||
except Exception as ex:
|
||||
if swap_client.debug is True:
|
||||
swap_client.log.error(traceback.format_exc())
|
||||
|
||||
@@ -1305,6 +1305,8 @@ class BTCInterface(CoinInterface):
|
||||
def changeWalletPassword(self, old_password, new_password):
|
||||
self._log.info('changeWalletPassword - {}'.format(self.ticker()))
|
||||
if old_password == '':
|
||||
if self.isWalletEncrypted():
|
||||
raise ValueError('Old password must be set')
|
||||
return self.rpc_callback('encryptwallet', [new_password])
|
||||
self.rpc_callback('walletpassphrasechange', [old_password, new_password])
|
||||
|
||||
|
||||
@@ -481,7 +481,7 @@ def js_unlock(self, url_split, post_string, is_json):
|
||||
|
||||
def js_lock(self, url_split, post_string, is_json):
|
||||
swap_client = self.server.swap_client
|
||||
post_data = getFormData(post_string, is_json)
|
||||
post_data = {} if post_string == '' else getFormData(post_string, is_json)
|
||||
|
||||
if have_data_entry(post_data, 'coin'):
|
||||
coin = getCoinType(get_data_entry(post_data, 'coin'))
|
||||
|
||||
27
basicswap/templates/changepassword.html
Normal file
27
basicswap/templates/changepassword.html
Normal file
@@ -0,0 +1,27 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<link rel=icon sizes="32x32" type="image/png" href="/static/images/favicon-32.png">
|
||||
<title>{{ title }}</title>
|
||||
</head>
|
||||
<body>
|
||||
<h2>Change password</h2>
|
||||
{% for m in messages %}
|
||||
<p>{{ m }}</p>
|
||||
{% endfor %}
|
||||
{% for m in err_messages %}
|
||||
<p class="error_msg">Error: {{ m }}</p>
|
||||
{% endfor %}
|
||||
<form method="post">
|
||||
<table>
|
||||
<tr><td>Old Password</td><td><input type="text" name="oldpassword"></td></tr>
|
||||
<tr><td>New Password</td><td><input type="text" name="newpassword"></td></tr>
|
||||
<tr><td>Confirm Password</td><td><input type="text" name="confirmpassword"></td></tr>
|
||||
<tr><td><input type="submit" name="unlock" value="Unlock"></td></tr>
|
||||
</table>
|
||||
<input type="hidden" name="formid" value="{{ form_id }}">
|
||||
</form>
|
||||
<p><a href="/">home</a></p>
|
||||
</body>
|
||||
</html>
|
||||
23
basicswap/templates/unlock.html
Normal file
23
basicswap/templates/unlock.html
Normal file
@@ -0,0 +1,23 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<link rel=icon sizes="32x32" type="image/png" href="/static/images/favicon-32.png">
|
||||
<title>{{ title }}</title>
|
||||
</head>
|
||||
<body>
|
||||
<h2>Unlock wallet</h2>
|
||||
{% for m in messages %}
|
||||
<p>{{ m }}</p>
|
||||
{% endfor %}
|
||||
{% for m in err_messages %}
|
||||
<p class="error_msg">Error: {{ m }}</p>
|
||||
{% endfor %}
|
||||
<form method="post">
|
||||
<input type="text" name="password"><br/>
|
||||
<input type="submit" name="unlock" value="Unlock">
|
||||
<input type="hidden" name="formid" value="{{ form_id }}">
|
||||
</form>
|
||||
<p><a href="/">home</a></p>
|
||||
</body>
|
||||
</html>
|
||||
87
basicswap/ui/page_encryption.py
Normal file
87
basicswap/ui/page_encryption.py
Normal file
@@ -0,0 +1,87 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright (c) 2022 tecnovert
|
||||
# Distributed under the MIT software license, see the accompanying
|
||||
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
from .util import (
|
||||
get_data_entry_or,
|
||||
)
|
||||
|
||||
|
||||
def page_changepassword(self, url_split, post_string):
|
||||
server = self.server
|
||||
swap_client = server.swap_client
|
||||
swap_client.checkSystemStatus()
|
||||
|
||||
messages = []
|
||||
err_messages = []
|
||||
|
||||
form_data = self.checkForm(post_string, 'changepassword', err_messages)
|
||||
if form_data:
|
||||
old_password = get_data_entry_or(form_data, 'oldpassword', '')
|
||||
new_password = get_data_entry_or(form_data, 'newpassword', '')
|
||||
confirm_password = get_data_entry_or(form_data, 'confirmpassword', '')
|
||||
|
||||
try:
|
||||
if new_password == '':
|
||||
raise ValueError('New password must be entered.')
|
||||
if new_password != confirm_password:
|
||||
raise ValueError('New password and confirm password must match.')
|
||||
swap_client.changeWalletPasswords(old_password, new_password)
|
||||
messages.append('Password changed')
|
||||
except Exception as e:
|
||||
err_messages.append(str(e))
|
||||
|
||||
template = server.env.get_template('changepassword.html')
|
||||
return self.render_template(template, {
|
||||
'messages': messages,
|
||||
'err_messages': err_messages,
|
||||
})
|
||||
|
||||
|
||||
def page_unlock(self, url_split, post_string):
|
||||
server = self.server
|
||||
swap_client = server.swap_client
|
||||
|
||||
messages = []
|
||||
err_messages = []
|
||||
|
||||
form_data = self.checkForm(post_string, 'unlock', err_messages)
|
||||
if form_data:
|
||||
password = get_data_entry_or(form_data, 'password', '')
|
||||
|
||||
try:
|
||||
if password == '':
|
||||
raise ValueError('Password must be entered.')
|
||||
swap_client.unlockWallets(password)
|
||||
self.send_response(302)
|
||||
self.send_header('Location', '/')
|
||||
self.end_headers()
|
||||
return bytes()
|
||||
except Exception as e:
|
||||
err_messages.append(str(e))
|
||||
|
||||
template = server.env.get_template('unlock.html')
|
||||
return self.render_template(template, {
|
||||
'messages': messages,
|
||||
'err_messages': err_messages,
|
||||
})
|
||||
|
||||
|
||||
def page_lock(self, url_split, post_string):
|
||||
server = self.server
|
||||
swap_client = server.swap_client
|
||||
swap_client.checkSystemStatus()
|
||||
|
||||
swap_client.lockWallets()
|
||||
|
||||
messages = []
|
||||
err_messages = []
|
||||
|
||||
template = server.env.get_template('info.html')
|
||||
return self.render_template(template, {
|
||||
'messages': messages,
|
||||
'err_messages': err_messages,
|
||||
'message_str': 'Wallets locked'
|
||||
})
|
||||
Reference in New Issue
Block a user