Browse Source

trustedcoin: sanitize error messages coming from 2fa server

related https://github.com/spesmilo/electrum/issues/9096
master
SomberNight 2 years ago
parent
commit
2eb51bcbe6
No known key found for this signature in database
GPG Key ID: B33B5F232C6271E9
  1. 2
      electrum/gui/qml/components/OtpDialog.qml
  2. 2
      electrum/plugins/trustedcoin/qml.py
  3. 18
      electrum/plugins/trustedcoin/trustedcoin.py

2
electrum/gui/qml/components/OtpDialog.qml

@ -52,6 +52,8 @@ ElDialog {
Layout.topMargin: constants.paddingMedium Layout.topMargin: constants.paddingMedium
Layout.bottomMargin: constants.paddingMedium Layout.bottomMargin: constants.paddingMedium
Layout.alignment: Qt.AlignHCenter Layout.alignment: Qt.AlignHCenter
Layout.fillWidth: true
wrapMode: Text.Wrap
text: _otpError text: _otpError
color: constants.colorError color: constants.colorError

2
electrum/plugins/trustedcoin/qml.py

@ -109,7 +109,7 @@ class Plugin(TrustedCoinPlugin):
else: else:
self.on_failure(_('Service Error') + ':\n' + str(e)) self.on_failure(_('Service Error') + ':\n' + str(e))
except Exception as e: except Exception as e:
self.on_failure(_('Error') + ':\n' + str(e)) self.on_failure(_('Error') + ':\n' + str(e))
else: else:
self.on_success(self.tx) self.on_success(self.tx)

18
electrum/plugins/trustedcoin/trustedcoin.py

@ -27,9 +27,9 @@ import json
import time import time
import hashlib import hashlib
from typing import Dict, Union, Sequence, List, TYPE_CHECKING from typing import Dict, Union, Sequence, List, TYPE_CHECKING
from urllib.parse import urljoin from urllib.parse import urljoin
from urllib.parse import quote from urllib.parse import quote
from aiohttp import ClientResponse from aiohttp import ClientResponse
from electrum import ecc, constants, keystore, version, bip32, bitcoin from electrum import ecc, constants, keystore, version, bip32, bitcoin
@ -40,7 +40,7 @@ from electrum.mnemonic import Mnemonic, calc_seed_type, is_any_2fa_seed_type
from electrum.wallet import Multisig_Wallet, Deterministic_Wallet from electrum.wallet import Multisig_Wallet, Deterministic_Wallet
from electrum.i18n import _ from electrum.i18n import _
from electrum.plugin import BasePlugin, hook from electrum.plugin import BasePlugin, hook
from electrum.util import NotEnoughFunds, UserFacingException from electrum.util import NotEnoughFunds, UserFacingException, error_text_str_to_safe_str
from electrum.network import Network from electrum.network import Network
from electrum.logging import Logger from electrum.logging import Logger
@ -103,8 +103,14 @@ RESTORE_MSG = _("Enter the seed for your 2-factor wallet:")
class TrustedCoinException(Exception): class TrustedCoinException(Exception):
def __init__(self, message, status_code=0): def __init__(self, message, *, status_code=0):
Exception.__init__(self, message) # note: 'message' is arbitrary text coming from the server
safer_message = (
f"Received error from 2FA server\n"
f"[DO NOT TRUST THIS MESSAGE]:\n\n"
f"status_code={status_code}\n\n"
f"{error_text_str_to_safe_str(message)}")
Exception.__init__(self, safer_message)
self.status_code = status_code self.status_code = status_code
@ -134,7 +140,7 @@ class TrustedCoinCosignerClient(Logger):
message = r['message'] message = r['message']
except Exception: except Exception:
message = await resp.text() message = await resp.text()
raise TrustedCoinException(message, resp.status) raise TrustedCoinException(message, status_code=resp.status)
try: try:
return await resp.json() return await resp.json()
except Exception: except Exception:
@ -304,7 +310,7 @@ class Wallet_2fa(Multisig_Wallet):
fee=None, fee=None,
change_addr: str = None, change_addr: str = None,
is_sweep=False, is_sweep=False,
rbf=False) -> PartialTransaction: rbf=False) -> PartialTransaction: # FIXME method signature
mk_tx = lambda o: Multisig_Wallet.make_unsigned_transaction( mk_tx = lambda o: Multisig_Wallet.make_unsigned_transaction(
self, coins=coins, outputs=o, fee=fee, change_addr=change_addr, rbf=rbf) self, coins=coins, outputs=o, fee=fee, change_addr=change_addr, rbf=rbf)

Loading…
Cancel
Save