Skip to content

Commit

Permalink
Simplify mnemonic generation
Browse files Browse the repository at this point in the history
  • Loading branch information
M66B committed Mar 7, 2022
1 parent e7e2c69 commit 15476c7
Show file tree
Hide file tree
Showing 28 changed files with 14 additions and 7,607 deletions.
1 change: 0 additions & 1 deletion ATTRIBUTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,3 @@ FairEmail uses:
* [Cousine font](https://fonts.google.com/specimen/Cousine). By Steve Matteson. [Apache License 2.0](https://fonts.google.com/specimen/Cousine#license).
* [Lato font](https://fonts.google.com/specimen/Lato). By Łukasz Dziedzic. [Apache License 2.0](https://fonts.google.com/specimen/Lato#license).
* [Caladea font](https://fonts.google.com/specimen/Caladea). By Andrés Torresi, Carolina Giovanolli. [Apache License 2.0](https://fonts.google.com/specimen/Caladea#license).
* [BIP39](https://github.com/NovaCrypto/BIP39). Copyright (C) 2017-2019 Alan Evans, NovaCrypto. [GNU General Public License v3.0](https://github.com/NovaCrypto/BIP39/blob/master/LICENCE.txt).
1 change: 0 additions & 1 deletion app/src/main/assets/ATTRIBUTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,3 @@ FairEmail uses:
* [Cousine font](https://fonts.google.com/specimen/Cousine). By Steve Matteson. [Apache License 2.0](https://fonts.google.com/specimen/Cousine#license).
* [Lato font](https://fonts.google.com/specimen/Lato). By Łukasz Dziedzic. [Apache License 2.0](https://fonts.google.com/specimen/Lato#license).
* [Caladea font](https://fonts.google.com/specimen/Caladea). By Andrés Torresi, Carolina Giovanolli. [Apache License 2.0](https://fonts.google.com/specimen/Caladea#license).
* [BIP39](https://github.com/NovaCrypto/BIP39). Copyright (C) 2017-2019 Alan Evans, NovaCrypto. [GNU General Public License v3.0](https://github.com/NovaCrypto/BIP39/blob/master/LICENCE.txt).
Original file line number Diff line number Diff line change
@@ -1,45 +1,7 @@
/*
* BIP39 library, a Java implementation of BIP39
* Copyright (C) 2017-2019 Alan Evans, NovaCrypto
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* Original source: https://github.com/NovaCrypto/BIP39
* You can contact the authors via github issues.
*/
package eu.faircode.email;

package io.github.novacrypto.bip39.wordlists;

import io.github.novacrypto.bip39.WordList;

/**
* Source: https://github.com/bitcoin/bips/blob/master/bip-0039/english.txt
*/
public enum English implements WordList {
INSTANCE;

@Override
public String getWord(final int index) {
return words[index];
}

@Override
public char getSpace() {
return ' ';
}

private final static String[] words = new String[]{
public class BIP39 {
public final static String[] words = new String[]{
"abandon",
"ability",
"able",
Expand Down Expand Up @@ -2089,4 +2051,4 @@ public char getSpace() {
"zone",
"zoo"
};
}
}
20 changes: 10 additions & 10 deletions app/src/main/java/eu/faircode/email/FragmentOptionsPrivacy.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,12 @@
import androidx.webkit.WebViewFeature;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.security.SecureRandom;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

import io.github.novacrypto.bip39.MnemonicGenerator;
import io.github.novacrypto.bip39.Words;
import io.github.novacrypto.bip39.wordlists.English;
import java.util.ArrayList;
import java.util.List;

public class FragmentOptionsPrivacy extends FragmentBase implements SharedPreferences.OnSharedPreferenceChangeListener {
private SwitchCompat swConfirmLinks;
Expand Down Expand Up @@ -107,6 +106,8 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer

private Group grpSafeBrowsing;

private final static int BIP39_WORDS = 6;

private final static String[] RESET_OPTIONS = new String[]{
"confirm_links", "check_links_dbl", "browse_links",
"confirm_images", "ask_images", "html_always_images", "confirm_html", "ask_html",
Expand Down Expand Up @@ -463,12 +464,11 @@ public void onClick(View v) {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
if (checked) {
// https://github.com/NovaCrypto/BIP39
StringBuilder sb = new StringBuilder();
byte[] entropy = new byte[Words.TWELVE.byteLength()];
new SecureRandom().nextBytes(entropy);
new MnemonicGenerator(English.INSTANCE).createMnemonic(entropy, sb::append);
String mnemonic = sb.toString();
List<String> words = new ArrayList<>();
SecureRandom rnd = new SecureRandom();
for (int i = 0; i < BIP39_WORDS; i++)
words.add(BIP39.words[rnd.nextInt(2048)]);
String mnemonic = TextUtils.join(" ", words);

prefs.edit().putString("wipe_mnemonic", mnemonic).apply();
tvMnemonic.setText(mnemonic);
Expand Down

This file was deleted.

58 changes: 0 additions & 58 deletions app/src/main/java/io/github/novacrypto/bip39/ByteUtils.java

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 15476c7

Please sign in to comment.