Skip to content

Commit

Permalink
it's bip39 passphrase not password
Browse files Browse the repository at this point in the history
  • Loading branch information
prusnak committed Dec 8, 2015
1 parent fea9edf commit a506901
Show file tree
Hide file tree
Showing 19 changed files with 66 additions and 66 deletions.
46 changes: 23 additions & 23 deletions public/bitlib/src/main/java/com/mrd/bitlib/crypto/Bip39.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ public static class MasterSeed implements Serializable {
private static final long serialVersionUID = 1L;

private final byte[] _bip39RawEntropy;
private final String _bip39Password;
private final String _bip39Passphrase;
private final byte[] _bip32MasterSeed;
private final byte _wordListType;


private MasterSeed(byte[] bip39RawEntropy, String bip39Password, byte[] bip32MasterSeed) {
private MasterSeed(byte[] bip39RawEntropy, String bip39Passphrase, byte[] bip32MasterSeed) {
_bip39RawEntropy = bip39RawEntropy;
_bip39Password = bip39Password;
_bip39Passphrase = bip39Passphrase;
_bip32MasterSeed = bip32MasterSeed;
_wordListType = ENGLISH_WORD_LIST_TYPE;
}
Expand All @@ -66,8 +66,8 @@ public List<String> getBip39WordList() {
return Arrays.asList(rawEntropyToWords(_bip39RawEntropy));
}

public String getBip39Password() {
return _bip39Password;
public String getBip39Passphrase() {
return _bip39Passphrase;
}

public byte[] getBip32Seed() {
Expand All @@ -94,9 +94,9 @@ public byte[] toBytes(boolean compressed) {
// Add the raw entropy
putByteArray(_bip39RawEntropy, writer);

// Add the password
// Add the passphrase
try {
putByteArray(_bip39Password.getBytes("UTF-8"), writer);
putByteArray(_bip39Passphrase.getBytes("UTF-8"), writer);
} catch (UnsupportedEncodingException e) {
// Never happens
throw new RuntimeException(e);
Expand Down Expand Up @@ -132,24 +132,24 @@ public static Optional<MasterSeed> fromBytes(byte[] bytes, boolean compressed) {
bip39RawEntropy.length != 256 / 8) {
return Optional.absent();
}
String bip39Password;
String bip39Passphrase;
try {
byte[] bip39PasswordBytes = getByteArray(reader);
bip39Password = new String(bip39PasswordBytes, "UTF-8");
byte[] bip39PassphraseBytes = getByteArray(reader);
bip39Passphrase = new String(bip39PassphraseBytes, "UTF-8");
} catch (UnsupportedEncodingException e) {
// Never happens
throw new RuntimeException(e);
}

if (compressed) {
// We are using compressed form, so we have to calculate the actual master seed
return Optional.of(generateSeedFromWordList(rawEntropyToWords(bip39RawEntropy), bip39Password));
return Optional.of(generateSeedFromWordList(rawEntropyToWords(bip39RawEntropy), bip39Passphrase));
} else {
byte[] bip32MasterSeed = getByteArray(reader);
if (bip32MasterSeed.length != BIP32_SEED_LENGTH) {
return Optional.absent();
}
return Optional.of(new MasterSeed(bip39RawEntropy, bip39Password, bip32MasterSeed));
return Optional.of(new MasterSeed(bip39RawEntropy, bip39Passphrase, bip32MasterSeed));
}
} catch (ByteReader.InsufficientBytesException e) {
return Optional.absent();
Expand Down Expand Up @@ -404,11 +404,11 @@ public static MasterSeed createRandomMasterSeed(RandomSource randomSource) {
* This method does not check whether the check sum of the word list id valid
*
* @param wordList the word list
* @param password the optional password
* @param passphrase the optional passphrase
* @return the BIP32 master seed
*/
public static MasterSeed generateSeedFromWordList(String[] wordList, String password) {
return generateSeedFromWordList(new ArrayList<String>(Arrays.asList(wordList)), password);
public static MasterSeed generateSeedFromWordList(String[] wordList, String passphrase) {
return generateSeedFromWordList(new ArrayList<String>(Arrays.asList(wordList)), passphrase);
}

/**
Expand All @@ -417,13 +417,13 @@ public static MasterSeed generateSeedFromWordList(String[] wordList, String pass
* This method does not check whether the check sum of the word list id valid
*
* @param wordList the word list
* @param password the optional password
* @param passphrase the optional passphrase
* @return the BIP32 master seed
*/
public static MasterSeed generateSeedFromWordList(List<String> wordList, String password) {
// Null password defaults to the empty string
if (password == null) {
password = "";
public static MasterSeed generateSeedFromWordList(List<String> wordList, String passphrase) {
// Null passphrase defaults to the empty string
if (passphrase == null) {
passphrase = "";
}

// Concatenate all words using a single space as separator
Expand All @@ -433,8 +433,8 @@ public static MasterSeed generateSeedFromWordList(List<String> wordList, String
}
String mnemonic = sb.toString().trim();

// The salt is is the password with a prefix
String salt = BASE_SALT + password;
// The salt is is the passphrase with a prefix
String salt = BASE_SALT + passphrase;

// Calculate and return the seed
byte[] seed;
Expand All @@ -447,7 +447,7 @@ public static MasterSeed generateSeedFromWordList(List<String> wordList, String
// HMAC-SHA512 should be supported by every system we run on
throw new RuntimeException(e);
}
MasterSeed masterSeed = new MasterSeed(wordListToRawEntropy(wordList.toArray(new String[0])), password, seed);
MasterSeed masterSeed = new MasterSeed(wordListToRawEntropy(wordList.toArray(new String[0])), passphrase, seed);
return masterSeed;
}

Expand Down
6 changes: 3 additions & 3 deletions public/bitlib/src/test/java/com/mrd/bitlib/Bip39Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public void testEnglishVectorsWordsToSeeds() {
String[] wordList = TEST_VECTORS[i * 3 + 1].split(" ");
Bip39.MasterSeed masterSeed = Bip39.generateSeedFromWordList(wordList, "TREZOR");
assertEquals(TEST_VECTORS[i * 3 + 2], HexUtils.toHex(masterSeed.getBip32Seed()));
assertEquals(masterSeed.getBip39Password(), "TREZOR");
assertEquals(masterSeed.getBip39Passphrase(), "TREZOR");
}
}

Expand Down Expand Up @@ -174,11 +174,11 @@ public void testEnglishVectors_WordListInvalid() {
}

@Test
public void testNoPassword() {
public void testNoPassphrase() {
String[] wordList = TEST_NO_PASSWORD_WORDS.split(" ");
Bip39.MasterSeed masterSeed = Bip39.generateSeedFromWordList(wordList, "");
assertEquals(TEST_NO_PASSWORD_SEED, HexUtils.toHex(masterSeed.getBip32Seed()));
assertTrue(masterSeed.getBip39Password().length() == 0);
assertTrue(masterSeed.getBip39Passphrase().length() == 0);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void onCreate(Bundle savedInstanceState) {
}

wordlist = masterSeed.getBip39WordList();
password = masterSeed.getBip39Password();
password = masterSeed.getBip39Passphrase();
currentWordIndex = 0;

btnNextWord = (Button)findViewById(R.id.btOkay);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public static void callMe(Activity activity, int requestCode, boolean returnMast
private ProgressDialog _progress;
private TextView enterWordInfo;
private List<String> enteredWords;
private boolean usesPassword;
private boolean usesPassphrase;
private int numberOfWords;
private int currentWordNum;
private WordAutoCompleterFragment _wordAutoCompleter;
Expand Down Expand Up @@ -116,7 +116,7 @@ public void onCreate(Bundle savedInstanceState) {

private void askForWordNumber() {
final View checkBoxView = View.inflate(this, R.layout.wordlist_checkboxes, null);
final CheckBox checkBox = (CheckBox) checkBoxView.findViewById(R.id.checkboxWordlistPassword);
final CheckBox checkBox = (CheckBox) checkBoxView.findViewById(R.id.checkboxWordlistPassphrase);
final RadioButton words12 = (RadioButton) checkBoxView.findViewById(R.id.wordlist12);
final RadioButton words18 = (RadioButton) checkBoxView.findViewById(R.id.wordlist18);
final RadioButton words24 = (RadioButton) checkBoxView.findViewById(R.id.wordlist24);
Expand All @@ -125,9 +125,9 @@ private void askForWordNumber() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
if (b) {
checkBoxView.findViewById(R.id.tvPasswordInfo).setVisibility(View.VISIBLE);
checkBoxView.findViewById(R.id.tvPassphraseInfo).setVisibility(View.VISIBLE);
} else {
checkBoxView.findViewById(R.id.tvPasswordInfo).setVisibility(View.GONE);
checkBoxView.findViewById(R.id.tvPassphraseInfo).setVisibility(View.GONE);
}
}
});
Expand All @@ -139,7 +139,7 @@ public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
.setCancelable(false)
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
usesPassword = checkBox.isChecked();
usesPassphrase = checkBox.isChecked();
if (words12.isChecked()) {
numberOfWords = 12;
} else if (words18.isChecked()) {
Expand Down Expand Up @@ -188,14 +188,14 @@ private void addWordToList(String selection) {
enteredWords.add(selection);
enterWordInfo.setText(enteredWords.toString());
if (checkIfDone()) {
askForPassword();
askForPassphrase();
} else {
findViewById(R.id.btDeleteLastWord).setEnabled(true);
}
}

private void askForPassword() {
if (usesPassword) {
private void askForPassphrase() {
if (usesPassphrase) {
final EditText pass = new EditText(this);

AlertDialog.Builder builder = new AlertDialog.Builder(this);
Expand Down Expand Up @@ -320,7 +320,7 @@ private void finishOk(UUID account) {
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
super.onSaveInstanceState(savedInstanceState);
savedInstanceState.putBoolean("usepass", usesPassword);
savedInstanceState.putBoolean("usepass", usesPassphrase);
savedInstanceState.putInt("index", currentWordNum);
savedInstanceState.putInt("total", numberOfWords);
savedInstanceState.putStringArray("entered", enteredWords.toArray(new String[enteredWords.size()]));
Expand All @@ -331,7 +331,7 @@ public void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
enteredWords = new ArrayList<String>(Arrays.asList(savedInstanceState.getStringArray("entered")));
enterWordInfo.setText(enteredWords.toString());
usesPassword = savedInstanceState.getBoolean("usepass");
usesPassphrase = savedInstanceState.getBoolean("usepass");
numberOfWords = savedInstanceState.getInt("total");
currentWordNum = savedInstanceState.getInt("index");
findViewById(R.id.btDeleteLastWord).setEnabled(currentWordNum > 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void onCreate(Bundle savedInstanceState) {
}

wordlist = masterSeed.getBip39WordList();
password = masterSeed.getBip39Password();
password = masterSeed.getBip39Passphrase();
currentWordIndex = 0;

_wordAutoCompleter = (WordAutoCompleterFragment) getSupportFragmentManager().findFragmentById(R.id.wordAutoCompleter);
Expand Down
10 changes: 5 additions & 5 deletions public/mbw/src/main/res/layout/wordlist_checkboxes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,24 @@


<CheckBox
android:id="@+id/checkboxWordlistPassword"
android:id="@+id/checkboxWordlistPassphrase"
style="?android:attr/textAppearanceMedium"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:text="@string/checkbox_wordlist_password"/>
android:text="@string/checkbox_wordlist_passphrase"/>

<TextView
android:id="@+id/tvPasswordInfo"
android:id="@+id/tvPassphraseInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="5dp"
android:visibility="gone"
android:text="@string/recover_seed_password_info"
android:text="@string/recover_seed_passphrase_info"
/>
</LinearLayout>
</ScrollView>
</ScrollView>
4 changes: 2 additions & 2 deletions public/mbw/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -486,11 +486,11 @@ Schlüsseln und das Ändern des PIN-Codes verbietet
<string name="account_contains_one_address_info">Enthält eine Adresse.</string>
<string name="verify_backup_ok_message">Das Backup wurde erfolgreich überprüft.</string>
<string name="wordlist_import_invalid_checksum">Die Prüfsumme Ihrer Wortliste ist ungültig, bitte stellen Sie sicher, dass Sie alle Wörter korrekt eingegeben haben.</string>
<string name="checkbox_wordlist_password">Ich habe ein Passwort</string>
<string name="checkbox_wordlist_passphrase">Ich habe ein Passwort</string>
<string name="wordlist_length_12">12 Wörter</string>
<string name="wordlist_length_18">18 Wörter</string>
<string name="wordlist_length_24">24 Wörter</string>
<string name="recover_seed_password_info">Wählen Sie diese Option nur, wenn Sie verstehen, was sie bedeutet. \n Ein normales Mycelium Backup enthält niemals ein Passwort - dies ist nicht Ihre PIN.</string>
<string name="recover_seed_passphrase_info">Wählen Sie diese Option nur, wenn Sie verstehen, was sie bedeutet. \n Ein normales Mycelium Backup enthält niemals ein Passwort - dies ist nicht Ihre PIN.</string>
<string name="import_wordlist_questions">Bitte wählen Sie die Länge der zu importierenden Wortliste um anzugeben, ob sie mittels Kennwort geschützt ist.</string>
<string name="type_password_title">Geben Sie Ihr Passwort ein</string>
<string name="clipboard_not_available">Inhalt der Zwischenablage nicht gültig</string>
Expand Down
4 changes: 2 additions & 2 deletions public/mbw/src/main/res/values-el/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -482,11 +482,11 @@
<string name="account_contains_one_address_info">Περιέχει μια διεύθυνση.</string>
<string name="verify_backup_ok_message">Το αντίγραφο ασφαλείας επιβεβαιώθηκε επιτυχώς.</string>
<string name="wordlist_import_invalid_checksum">Το ψηφίο επιβεβαίωσης της λίστας λέξεών σας είναι μη έγκυρο, παρακαλώ σιγουρευτείτε ότι εισαγάγατε όλες τις λέξεις σωστά.</string>
<string name="checkbox_wordlist_password">Έχω κωδικό πρόσβασης</string>
<string name="checkbox_wordlist_passphrase">Έχω κωδικό πρόσβασης</string>
<string name="wordlist_length_12">12 λέξεις</string>
<string name="wordlist_length_18">18 λέξεις</string>
<string name="wordlist_length_24">24 λέξεις</string>
<string name="recover_seed_password_info">Τσεκάρετε αυτή την επιλογή μόνο εάν κατανοείτε τι σημαίνει.\nΈνα κανονικό αντίγραφο ασφαλείας του Mycelium ποτέ δεν περιλαμβάνει κωδικό πρόσβασης - αυτός δεν είναι o κωδικός PIN.</string>
<string name="recover_seed_passphrase_info">Τσεκάρετε αυτή την επιλογή μόνο εάν κατανοείτε τι σημαίνει.\nΈνα κανονικό αντίγραφο ασφαλείας του Mycelium ποτέ δεν περιλαμβάνει κωδικό πρόσβασης - αυτός δεν είναι o κωδικός PIN.</string>
<string name="import_wordlist_questions">Παρακαλώ επιλέξτε το μέγεθος της λίστας λέξεων γι\' αποκατάσταση, και υποδείξτε εάν προστατεύεται από κωδικό πρόσβασης.</string>
<string name="type_password_title">Εισαγάγετε τον Κωδικό Πρόσβασης</string>
<string name="clipboard_not_available">Μη έγκυρο πρόχειρο</string>
Expand Down
4 changes: 2 additions & 2 deletions public/mbw/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -484,11 +484,11 @@
<string name="account_contains_one_address_info">Contient une adresse.</string>
<string name="verify_backup_ok_message">La sauvegarde a été vérifiée avec succès.</string>
<string name="wordlist_import_invalid_checksum">Le checksum de votre liste de mots a échoué, veuillez vérifier que vous avez entré tous les mots correctement.</string>
<string name="checkbox_wordlist_password">J\'ai un mot de passe</string>
<string name="checkbox_wordlist_passphrase">J\'ai un mot de passe</string>
<string name="wordlist_length_12">12 mots</string>
<string name="wordlist_length_18">18 mots</string>
<string name="wordlist_length_24">24 mots</string>
<string name="recover_seed_password_info">Sélectionnez uniquement cette option si vous comprenez ce qu\'elle signifie.\nUne sauvegarde normale de Mycelium n\'inclut jamais un mot de passe - ce n\'est pas votre code d\'accès.</string>
<string name="recover_seed_passphrase_info">Sélectionnez uniquement cette option si vous comprenez ce qu\'elle signifie.\nUne sauvegarde normale de Mycelium n\'inclut jamais un mot de passe - ce n\'est pas votre code d\'accès.</string>
<string name="import_wordlist_questions">Veuillez sélectionner la longueur de votre liste de mots à restaurer et indiquer si cette liste est protégée par un mot de passe.</string>
<string name="type_password_title">Entrer votre mot de passe</string>
<string name="clipboard_not_available">Presse-papier non valide</string>
Expand Down
2 changes: 1 addition & 1 deletion public/mbw/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@
<string name="account_contains_one_address_info">Contiene un indirizzo.</string>
<string name="verify_backup_ok_message">Backup verificato con successo.</string>
<string name="wordlist_import_invalid_checksum">Il checksum della tua wordlist non è valido, assicurati di aver inserito correttamente tutte le parole.</string>
<string name="checkbox_wordlist_password">Ho una password</string>
<string name="checkbox_wordlist_passphrase">Ho una password</string>
<string name="wordlist_length_12">12 parole</string>
<string name="wordlist_length_18">18 parole</string>
<string name="wordlist_length_24">24 parole</string>
Expand Down
4 changes: 2 additions & 2 deletions public/mbw/src/main/res/values-ja/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -480,11 +480,11 @@
<string name="account_contains_one_address_info">1個のアドレスを含みます。</string>
<string name="verify_backup_ok_message">バックアップの確認に成功しました。</string>
<string name="wordlist_import_invalid_checksum">ワードリストのチェックサムは無効です。すべてのワードが正しいかご確認下さい。</string>
<string name="checkbox_wordlist_password">パスワードがあります</string>
<string name="checkbox_wordlist_passphrase">パスワードがあります</string>
<string name="wordlist_length_12">12ワード</string>
<string name="wordlist_length_18">18ワード</string>
<string name="wordlist_length_24">24ワード</string>
<string name="recover_seed_password_info">意味がわからなければ、この選択はしないで下さい。\n通常のMyceliumバックアップはパスワードは決して含みません。これはピンナンバーではありません。</string>
<string name="recover_seed_passphrase_info">意味がわからなければ、この選択はしないで下さい。\n通常のMyceliumバックアップはパスワードは決して含みません。これはピンナンバーではありません。</string>
<string name="import_wordlist_questions">復元するためワードリストの長さを選択し、パスワードによって保護されるかどうかを決定してください。</string>
<string name="type_password_title">パスワードを入力してください</string>
<string name="clipboard_not_available">クリップボードは無効です。</string>
Expand Down
Loading

0 comments on commit a506901

Please sign in to comment.