mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-11-01 21:17:13 +00:00
MnemonicCode: Add null check for passphrase.
The null check is added due to a likely undesirable outcome when supplying a null passphrase. If allowed, the salt will be "mnemonicnull", when one would expect only "mnemonic" due to the following from BIP39 "If a passphrase is not present, an empty string "" is used instead."
This commit is contained in:
committed by
Andreas Schildbach
parent
335a8e9fd3
commit
f5f97c7d94
@@ -34,6 +34,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.bitcoinj.core.Utils.HEX;
|
||||
|
||||
/**
|
||||
@@ -119,6 +120,7 @@ public class MnemonicCode {
|
||||
* Convert mnemonic word list to seed.
|
||||
*/
|
||||
public static byte[] toSeed(List<String> words, String passphrase) {
|
||||
checkNotNull(passphrase, "A null passphrase is not allowed.");
|
||||
|
||||
// To create binary seed from mnemonic, we use PBKDF2 function
|
||||
// with mnemonic sentence (in UTF-8) used as a password and
|
||||
|
||||
@@ -212,6 +212,12 @@ public class MnemonicCodeTest {
|
||||
mc.toMnemonic(entropy);
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
public void testNullPassphrase() throws Exception {
|
||||
List<String> code = split("legal winner thank year wave sausage worth useful legal winner thank yellow");
|
||||
MnemonicCode.toSeed(code, null);
|
||||
}
|
||||
|
||||
public static List<String> split(String words) {
|
||||
return new ArrayList<String>(Arrays.asList(words.split("\\s+")));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user