From 48e956c27c7d8597aa6267d507aa76fcdf1a410d Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Sun, 29 Sep 2019 20:55:59 -0500 Subject: [PATCH] moved to niceware from mnemonic --- Makefile | 2 +- onionr.sh | 2 +- onionr/onionrutils/mnemonickeys.py | 9 ++++----- onionr/vanityonionr/__init__.py | 7 +++---- requirements.in | 2 +- requirements.txt | 8 +++----- tests/test_highlevelcrypto.py | 2 +- 7 files changed, 14 insertions(+), 18 deletions(-) diff --git a/Makefile b/Makefile index 46722351..f98a9381 100755 --- a/Makefile +++ b/Makefile @@ -30,7 +30,7 @@ soft-reset: reset: @echo "Hard-resetting Onionr..." - rm -rf onionr/$(ONIONR_HOME)/ | true > /dev/null 2>&1 + rm -rf $(ONIONR_HOME)/ | true > /dev/null 2>&1 cd onionr/static-data/www/ui/; rm -rf ./dist; python compile.py #@./onionr.sh version | grep -v "Failed" --color=always diff --git a/onionr.sh b/onionr.sh index 783d1f05..ef955eec 100755 --- a/onionr.sh +++ b/onionr.sh @@ -1,5 +1,5 @@ #!/bin/sh ORIG_ONIONR_RUN_DIR=`pwd` cd "$(dirname "$0")" -cd onionr/ +cd onionr ./__init__.py "$@" diff --git a/onionr/onionrutils/mnemonickeys.py b/onionr/onionrutils/mnemonickeys.py index 84bdcdc6..38669578 100644 --- a/onionr/onionrutils/mnemonickeys.py +++ b/onionr/onionrutils/mnemonickeys.py @@ -19,7 +19,7 @@ ''' import base64 -import mnemonic +import niceware import unpaddedbase32 import onionrcrypto @@ -27,8 +27,6 @@ from etc import onionrvalues DELIMITER = '-' -m = mnemonic.Mnemonic('english') - def get_human_readable_ID(pub=''): '''gets a human readable ID from a public key''' if pub == '': @@ -37,8 +35,9 @@ def get_human_readable_ID(pub=''): if not len(pub) == onionrvalues.MAIN_PUBLIC_KEY_SIZE: pub = base64.b32decode(pub) - return m.to_mnemonic(pub).replace(' ', DELIMITER) + return DELIMITER.join(niceware.bytes_to_passphrase(pub)) + #return niceware.bytes_to_passphrase(pub).replace(' ', DELIMITER) def get_base32(words): '''converts mnemonic to base32''' - return unpaddedbase32.b32encode(m.to_entropy(words.replace(DELIMITER, ' '))) + return unpaddedbase32.b32encode(niceware.passphrase_to_bytes(words.replace(DELIMITER, ' '))) diff --git a/onionr/vanityonionr/__init__.py b/onionr/vanityonionr/__init__.py index 72038e35..2f9fd18f 100644 --- a/onionr/vanityonionr/__init__.py +++ b/onionr/vanityonionr/__init__.py @@ -21,7 +21,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . """ -import mnemonic +import niceware import nacl.signing, nacl.encoding import multiprocessing @@ -29,8 +29,7 @@ from multiprocessing import Process, Pipe, Queue import re, time import threading -m = mnemonic.Mnemonic("english") -wordlist = m.wordlist +wordlist = niceware.WORD_LIST def find_vanity_mnemonic(start_words: str, queue): @@ -41,7 +40,7 @@ def find_vanity_mnemonic(start_words: str, queue): key = nacl.signing.SigningKey.generate() key_pair[1] = key.encode(nacl.encoding.RawEncoder) key_pair[0] = key.verify_key.encode(encoder=nacl.encoding.RawEncoder) - vanity_key = m.to_mnemonic(key_pair[0]) + vanity_key = niceware.bytes_to_passphrasec(key_pair[0]) check += 1 else: queue.put(key_pair) diff --git a/requirements.in b/requirements.in index 7bbb9f7a..df17ef29 100644 --- a/requirements.in +++ b/requirements.in @@ -10,4 +10,4 @@ unpaddedbase32==0.1.0 streamedrequests==1.0.0 jinja2==2.10.1 toomanyobjs==1.1.0 -mnemonic==0.18 +niceware==0.2.1 diff --git a/requirements.txt b/requirements.txt index ca9ed0a8..1827ed91 100644 --- a/requirements.txt +++ b/requirements.txt @@ -137,11 +137,9 @@ markupsafe==1.1.1 \ --hash=sha256:cd5df75523866410809ca100dc9681e301e3c27567cf498077e8551b6d20e42f \ --hash=sha256:e249096428b3ae81b08327a63a485ad0878de3fb939049038579ac0ef61e17e7 \ # via jinja2 -mnemonic==0.18 \ - --hash=sha256:02a7306a792370f4a0c106c2cf1ce5a0c84b9dbd7e71c6792fdb9ad88a727f1d -pbkdf2==1.3 \ - --hash=sha256:ac6397369f128212c43064a2b4878038dab78dab41875364554aaf2a684e6979 \ - # via mnemonic +niceware==0.2.1 \ + --hash=sha256:0f8b192f2a1e800e068474f6e208be9c7e2857664b33a96f4045340de4e5c69c \ + --hash=sha256:cf2dc0e1567d36d067c61b32fed0f1b9c4534ed511f9eeead4ba548d03b5c9eb pycparser==2.19 \ --hash=sha256:a988718abfad80b6b157acce7bf130a30876d27603738ac39f140993246b25b3 \ # via cffi diff --git a/tests/test_highlevelcrypto.py b/tests/test_highlevelcrypto.py index 79ddf42f..35f395ed 100755 --- a/tests/test_highlevelcrypto.py +++ b/tests/test_highlevelcrypto.py @@ -51,7 +51,7 @@ class OnionrCryptoTests(unittest.TestCase): def test_human_readable_length(self): human = mnemonickeys.get_human_readable_ID() - self.assertTrue(len(human.split('-')) == 24) + self.assertTrue(len(human.split('-')) == 16) def test_safe_compare(self): self.assertTrue(crypto.cryptoutils.safe_compare('test', 'test'))