Bump wallet version and add missing check (!) to detect wallets from the future. The absence/incompleteness of this feature had not been noticed before, and it means that old apps will fail to read HD wallets due to the new key enum value rather than a more sensible error (but there's still no chance of an old app accepting an HD wallet, so it should still be safe).

This commit is contained in:
Mike Hearn 2014-04-08 14:40:43 +02:00
parent c8850c94ae
commit a807994b9a
4 changed files with 15 additions and 1 deletions

View File

@ -18,4 +18,8 @@ public class UnreadableWalletException extends Exception {
super("Password incorrect");
}
}
public static class FutureVersion extends UnreadableWalletException {
public FutureVersion() { super("Unknown wallet version from the future."); }
}
}

View File

@ -362,6 +362,9 @@ public class WalletProtobufSerializer {
*/
public Wallet readWallet(NetworkParameters params, @Nullable WalletExtension[] extensions,
Protos.Wallet walletProto) throws UnreadableWalletException {
if (walletProto.getVersion() > 1)
throw new UnreadableWalletException.FutureVersion();
// Read the scrypt parameters that specify how encryption and decryption is performed.
KeyChainGroup chain;
if (walletProto.hasEncryptionParameters()) {

View File

@ -332,6 +332,13 @@ public class WalletProtobufSerializerTest {
assertEquals(0, wallet5.getExtensions().size());
}
@Test(expected = UnreadableWalletException.FutureVersion.class)
public void versions() throws Exception {
Protos.Wallet.Builder proto = Protos.Wallet.newBuilder(new WalletProtobufSerializer().walletToProto(myWallet));
proto.setVersion(2);
new WalletProtobufSerializer().readWallet(params, null, proto.build());
}
private static class SomeFooExtension implements WalletExtension {
private final byte[] data = new byte[]{1, 2, 3};

View File

@ -322,7 +322,7 @@ message Wallet {
// The version number of the wallet - used to detect wallets that were produced in the future
// (i.e the wallet may contain some future format this protobuf/ code does not know about)
optional int32 version = 7;
optional int32 version = 7 [default = 1];
// deprecated - do not recycle this numeric identifier
// optional int32 minor_version = 8;