From 866f0ce501701141abd3b0fa14db94725d6e5953 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Mon, 9 Sep 2019 03:23:09 -0500 Subject: [PATCH] added vanity address support --- onionr/httpapi/insertblock.py | 5 +++- onionr/onionrcommands/parser/arguments.py | 1 + onionr/onionrcommands/pubkeymanager.py | 35 ++++++++++++++++++++++- onionr/static-data/www/mail/index.html | 1 + onionr/static-data/www/mail/mail.js | 20 ++++++++----- onionr/static-data/www/mail/sendmail.js | 14 ++++++--- requirements.in | 1 + requirements.txt | 2 ++ 8 files changed, 66 insertions(+), 13 deletions(-) diff --git a/onionr/httpapi/insertblock.py b/onionr/httpapi/insertblock.py index ddba750f..3680ee4d 100644 --- a/onionr/httpapi/insertblock.py +++ b/onionr/httpapi/insertblock.py @@ -22,6 +22,7 @@ from flask import Blueprint, Response, request, g import onionrblocks from onionrcrypto import hashers from onionrutils import bytesconverter +from onionrutils import mnemonickeys ib = Blueprint('insertblock', __name__) @ib.route('/insertblock', methods=['POST']) @@ -48,7 +49,9 @@ def client_api_insert_block(): to = '' try: if bData['encrypt']: - to = bData['to'] + to = bData['to'].strip() + if " " in to: + to = mnemonickeys.get_base32(to) encrypt = True encryptType = 'asym' except KeyError: diff --git a/onionr/onionrcommands/parser/arguments.py b/onionr/onionrcommands/parser/arguments.py index 487aa95b..9ad000f4 100644 --- a/onionr/onionrcommands/parser/arguments.py +++ b/onionr/onionrcommands/parser/arguments.py @@ -46,6 +46,7 @@ def get_arguments(): ('importblocks', 'import-blocks', 'import-block'): importnewblocks.import_new_blocks, ('addid', 'add-id'): pubkeymanager.add_ID, ('changeid', 'change-id'): pubkeymanager.change_ID, + ('add-vanity', 'addvanity'): pubkeymanager.add_vanity, ('resettor', 'reset-tor'): resettor.reset_tor, ('resetplugins', 'reset-plugins'): resetplugins.reset, ('reset-tor-node-transport',): resettor.reset_tor_key_pair, diff --git a/onionr/onionrcommands/pubkeymanager.py b/onionr/onionrcommands/pubkeymanager.py index 6e5e2b57..b6ad4746 100755 --- a/onionr/onionrcommands/pubkeymanager.py +++ b/onionr/onionrcommands/pubkeymanager.py @@ -19,14 +19,19 @@ ''' import sys, getpass + +import unpaddedbase32 +import vanityonionr +import mnemonic + import logger, onionrexceptions from onionrutils import stringvalidators, bytesconverter from onionrusers import onionrusers, contactmanager import config from coredb import keydb import keymanager, onionrcrypto -import unpaddedbase32 from etc import onionrvalues + DETERMINISTIC_REQUIREMENT = onionrvalues.PASSWORD_LENGTH def add_ID(): key_manager = keymanager.KeyManager() @@ -80,3 +85,31 @@ def change_ID(): logger.warn('That key does not exist', terminal=True) else: logger.warn('Invalid key %s' % (key,), terminal=True) + +def add_vanity(): + key_manager = keymanager.KeyManager() + tell = lambda tell: logger.info(tell, terminal=True) + words = '' + m = mnemonic.Mnemonic('english') + length = len(sys.argv) - 2 + if length == 0: return + for i in range(2, len(sys.argv)): + words += ' ' + words += sys.argv[i] + try: + if length == 1: + tell('Finding vanity, this should only take a few moments.') + else: + tell('Finding vanity, this will probably take a really long time.') + try: + vanity = vanityonionr.find_multiprocess(words) + except ValueError: + logger.warn('Vanity words must be valid english bip39', terminal=True) + else: + b32_pub = unpaddedbase32.b32encode(vanity[0]) + tell('Found vanity address:\n' + m.to_mnemonic(vanity[0])) + tell('Base32 Public key: %s' % (b32_pub.decode(),)) + key_manager.addKey(b32_pub, unpaddedbase32.b32encode(vanity[1])) + except KeyboardInterrupt: + pass +add_vanity.onionr_help = " - Generates and stores an Onionr vanity address (see https://github.com/trezor/python-mnemonic/blob/master/mnemonic/wordlist/english.txt)" \ No newline at end of file diff --git a/onionr/static-data/www/mail/index.html b/onionr/static-data/www/mail/index.html index 5be550b9..cf04e60d 100755 --- a/onionr/static-data/www/mail/index.html +++ b/onionr/static-data/www/mail/index.html @@ -17,6 +17,7 @@ + diff --git a/onionr/static-data/www/mail/mail.js b/onionr/static-data/www/mail/mail.js index 2c25abd8..2a4edac7 100755 --- a/onionr/static-data/www/mail/mail.js +++ b/onionr/static-data/www/mail/mail.js @@ -177,19 +177,25 @@ function loadInboxEntries(bHash){ humanDate.setUTCSeconds(resp['meta']['time']) humanDate = humanDate.toString() validSig.style.display = 'none' - if (resp['meta']['signer'] != ''){ - senderInput.value = httpGet('/friends/getinfo/' + resp['meta']['signer'] + '/name') + if (typeof resp['meta']['signer'] != 'undefined' && resp['meta']['signer'] != ''){ + let name = httpGet('/friends/getinfo/' + resp['meta']['signer'] + '/name') + if (name.length == 0){ + setHumanReadableValue(senderInput, resp['meta']['signer']) + entry.setAttribute('data-nameSet', false) + } + else{ + entry.setAttribute('data-nameSet', true) + } + } + else{ + senderInput.value = 'Anonymous' + entry.setAttribute('data-nameSet', false) } if (! resp['meta']['validSig']){ validSig.style.display = 'inline' validSig.innerText = 'Signature Validity: Bad' validSig.style.color = 'red' } - entry.setAttribute('data-nameSet', true) - if (senderInput.value == ''){ - senderInput.value = resp['meta']['signer'] || 'Anonymous' - entry.setAttribute('data-nameSet', false) - } //bHashDisplay.innerText = bHash.substring(0, 10) entry.setAttribute('data-hash', bHash) entry.setAttribute('data-pubkey', resp['meta']['signer']) diff --git a/onionr/static-data/www/mail/sendmail.js b/onionr/static-data/www/mail/sendmail.js index e2d34c1f..88f6c6d8 100755 --- a/onionr/static-data/www/mail/sendmail.js +++ b/onionr/static-data/www/mail/sendmail.js @@ -38,7 +38,9 @@ function sendMail(to, message, subject){ .then((resp) => resp.text()) // Transform the data into json .then(function(data) { sendForm.style.display = 'block' - alert('Queued for sending!') + PNotify.success({ + text: 'Queued for sending!' + }) }) } @@ -50,12 +52,16 @@ friendPicker.onchange = function(){ sendForm.onsubmit = function(){ if (friendPicker.value.trim().length !== 0 && to.value.trim().length !== 0){ if (friendPicker.value !== to.value){ - alert('You have selected both a friend and entered a public key manually.') + PNotify.error({ + text: 'You have selected both a friend and entered a public key manually.' + }) return false } } - if (to.value.length !== 56 && to.value.length !== 52){ - alert('Public key is not valid') + if (! to.value.includes(" ") && to.value.length !== 56 && to.value.length !== 52){ + PNotify.error({ + text: 'User ID is not valid' + }) } else{ sendMail(to.value, messageContent.value, subject.value) diff --git a/requirements.in b/requirements.in index 7bbb9f7a..199b6c56 100644 --- a/requirements.in +++ b/requirements.in @@ -11,3 +11,4 @@ streamedrequests==1.0.0 jinja2==2.10.1 toomanyobjs==1.1.0 mnemonic==0.18 +vanityonionr==0.0.0 \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index ca9ed0a8..6e42f8e8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -185,6 +185,8 @@ unpaddedbase32==0.1.0 \ urllib3==1.24.2 \ --hash=sha256:4c291ca23bbb55c76518905869ef34bdd5f0e46af7afe6861e8375643ffee1a0 \ --hash=sha256:9a247273df709c4fedb38c711e44292304f73f39ab01beda9f6b9fc375669ac3 +vanityonionr==0.0.0 \ + --hash=sha256:a61976c62363f05cc9f92e57c2c2deaad7753abc9e5d3ee9ad5745330b8d942e werkzeug==0.15.5 \ --hash=sha256:87ae4e5b5366da2347eb3116c0e6c681a0e939a33b2805e2c0cbd282664932c4 \ --hash=sha256:a13b74dd3c45f758d4ebdb224be8f1ab8ef58b3c0ffc1783a8c7d9f4f50227e6 \