Merge pull request #742 from trezor/language

common: change language field to IETF BCP 47 language tag
pull/758/head
Pavol Rusnak 4 years ago committed by GitHub
commit e5bdf0d51b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -227,7 +227,7 @@ message LoadDevice {
repeated string mnemonics = 1; // seed encoded as mnemonic (12, 18 or 24 words for BIP39, 20 or 33 for SLIP39)
optional string pin = 3; // set PIN protection
optional bool passphrase_protection = 4; // enable master node encryption using passphrase
optional string language = 5 [default='english']; // device language
optional string language = 5 [default='en-US']; // device language (IETF BCP 47 language tag)
optional string label = 6; // device label
optional bool skip_checksum = 7; // do not test mnemonic for valid BIP-39 checksum
optional uint32 u2f_counter = 8; // U2F counter
@ -246,7 +246,7 @@ message ResetDevice {
optional uint32 strength = 2 [default=256]; // strength of seed in bits
optional bool passphrase_protection = 3; // enable master node encryption using passphrase
optional bool pin_protection = 4; // enable PIN protection
optional string language = 5 [default='english']; // device language
optional string language = 5 [default='en-US']; // device language (IETF BCP 47 language tag)
optional string label = 6; // device label
optional uint32 u2f_counter = 7; // U2F counter
optional bool skip_backup = 8; // postpone seed backup to BackupDevice workflow
@ -287,7 +287,7 @@ message RecoveryDevice {
optional uint32 word_count = 1; // number of words in BIP-39 mnemonic
optional bool passphrase_protection = 2; // enable master node encryption using passphrase
optional bool pin_protection = 3; // enable PIN protection
optional string language = 4 [default='english']; // device language
optional string language = 4 [default='en-US']; // device language (IETF BCP 47 language tag)
optional string label = 5; // device label
optional bool enforce_wordlist = 6; // enforce BIP-39 wordlist during the process
// 7 reserved for unused recovery method

@ -23,7 +23,7 @@ if False:
def get_features() -> Features:
f = Features()
f.vendor = "trezor.io"
f.language = "english"
f.language = "en-US"
f.major_version = utils.VERSION_MAJOR
f.minor_version = utils.VERSION_MINOR
f.patch_version = utils.VERSION_PATCH

@ -41,7 +41,7 @@ class LoadDevice(p.MessageType):
1: ('mnemonics', p.UnicodeType, p.FLAG_REPEATED),
3: ('pin', p.UnicodeType, 0),
4: ('passphrase_protection', p.BoolType, 0),
5: ('language', p.UnicodeType, 0), # default=english
5: ('language', p.UnicodeType, 0), # default=en-US
6: ('label', p.UnicodeType, 0),
7: ('skip_checksum', p.BoolType, 0),
8: ('u2f_counter', p.UVarintType, 0),

@ -42,7 +42,7 @@ class RecoveryDevice(p.MessageType):
1: ('word_count', p.UVarintType, 0),
2: ('passphrase_protection', p.BoolType, 0),
3: ('pin_protection', p.BoolType, 0),
4: ('language', p.UnicodeType, 0), # default=english
4: ('language', p.UnicodeType, 0), # default=en-US
5: ('label', p.UnicodeType, 0),
6: ('enforce_wordlist', p.BoolType, 0),
8: ('type', p.EnumType("RecoveryDeviceType", (0, 1)), 0),

@ -45,7 +45,7 @@ class ResetDevice(p.MessageType):
2: ('strength', p.UVarintType, 0), # default=256
3: ('passphrase_protection', p.BoolType, 0),
4: ('pin_protection', p.BoolType, 0),
5: ('language', p.UnicodeType, 0), # default=english
5: ('language', p.UnicodeType, 0), # default=en-US
6: ('label', p.UnicodeType, 0),
7: ('u2f_counter', p.UVarintType, 0),
8: ('skip_backup', p.BoolType, 0),

@ -520,7 +520,7 @@ void config_setLanguage(const char *lang) {
}
// Sanity check.
if (strcmp(lang, "english") != 0) {
if (strcmp(lang, "en-US") != 0) {
return;
}
storage_set(KEY_LANGUAGE, lang, strnlen(lang, MAX_LANGUAGE_LEN));
@ -665,7 +665,17 @@ bool config_getLabel(char *dest, uint16_t dest_size) {
}
bool config_getLanguage(char *dest, uint16_t dest_size) {
return sectrue == config_get_string(KEY_LANGUAGE, dest, dest_size);
if (sectrue == config_get_string(KEY_LANGUAGE, dest, dest_size)) {
if (dest_size == 7 && (strcmp(dest, "english") != 0)) {
// fallthrough -> return "en-US"
} else {
// other language -> return the value
return true;
}
}
strcpy(dest, "en-US");
dest_size = 5;
return true;
}
bool config_getHomescreen(uint8_t *dest, uint16_t dest_size) {

@ -129,7 +129,7 @@ def load(
pin=pin,
passphrase_protection=passphrase_protection,
label=label,
language="english",
language="en-US",
skip_checksum=ignore_checksum,
needs_backup=needs_backup,
no_backup=no_backup,
@ -170,7 +170,7 @@ def recover(
passphrase_protection=passphrase_protection,
pin_protection=pin_protection,
label=label,
language="english",
language="en-US",
input_callback=input_callback,
type=rec_type,
dry_run=dry_run,
@ -224,7 +224,7 @@ def setup(
passphrase_protection=passphrase_protection,
pin_protection=pin_protection,
label=label,
language="english",
language="en-US",
u2f_counter=u2f_counter,
skip_backup=skip_backup,
no_backup=no_backup,

@ -456,7 +456,7 @@ def load_device(
pin,
passphrase_protection,
label,
language="english",
language="en-US",
skip_checksum=False,
needs_backup=False,
no_backup=False,

@ -117,7 +117,7 @@ def recover(
passphrase_protection=False,
pin_protection=True,
label=None,
language="english",
language="en-US",
input_callback=None,
type=messages.RecoveryDeviceType.ScrambledWords,
dry_run=False,
@ -171,7 +171,7 @@ def reset(
passphrase_protection=False,
pin_protection=True,
label=None,
language="english",
language="en-US",
u2f_counter=0,
skip_backup=False,
no_backup=False,

@ -41,7 +41,7 @@ class LoadDevice(p.MessageType):
1: ('mnemonics', p.UnicodeType, p.FLAG_REPEATED),
3: ('pin', p.UnicodeType, 0),
4: ('passphrase_protection', p.BoolType, 0),
5: ('language', p.UnicodeType, 0), # default=english
5: ('language', p.UnicodeType, 0), # default=en-US
6: ('label', p.UnicodeType, 0),
7: ('skip_checksum', p.BoolType, 0),
8: ('u2f_counter', p.UVarintType, 0),

@ -42,7 +42,7 @@ class RecoveryDevice(p.MessageType):
1: ('word_count', p.UVarintType, 0),
2: ('passphrase_protection', p.BoolType, 0),
3: ('pin_protection', p.BoolType, 0),
4: ('language', p.UnicodeType, 0), # default=english
4: ('language', p.UnicodeType, 0), # default=en-US
5: ('label', p.UnicodeType, 0),
6: ('enforce_wordlist', p.BoolType, 0),
8: ('type', p.EnumType("RecoveryDeviceType", (0, 1)), 0),

@ -45,7 +45,7 @@ class ResetDevice(p.MessageType):
2: ('strength', p.UVarintType, 0), # default=256
3: ('passphrase_protection', p.BoolType, 0),
4: ('pin_protection', p.BoolType, 0),
5: ('language', p.UnicodeType, 0), # default=english
5: ('language', p.UnicodeType, 0), # default=en-US
6: ('label', p.UnicodeType, 0),
7: ('u2f_counter', p.UVarintType, 0),
8: ('skip_backup', p.BoolType, 0),

@ -116,7 +116,7 @@ def client(request):
pin=setup_params["pin"],
passphrase_protection=setup_params["passphrase"],
label="test",
language="english",
language="en-US",
needs_backup=setup_params["needs_backup"],
no_backup=setup_params["no_backup"],
)

@ -44,13 +44,13 @@ class TestMsgApplysettings:
@pytest.mark.skip_t2
def test_invalid_language(self, client):
assert client.features.language == "english"
assert client.features.language == "en-US"
with client:
_set_expected_responses(client)
device.apply_settings(client, language="nonexistent")
assert client.features.language == "english"
assert client.features.language == "en-US"
@pytest.mark.setup_client(pin=True, passphrase=False)
def test_apply_settings_passphrase(self, client):

@ -306,6 +306,6 @@ def test_no_backup_show_entropy_fails(client):
passphrase_protection=False,
pin_protection=False,
label="test",
language="english",
language="en-US",
no_backup=True,
)

@ -44,7 +44,6 @@ from ..common import MNEMONIC12
)
@pytest.mark.setup_client(mnemonic=MNEMONIC12)
def test_cardano_get_address(client, path, expected_address):
# data from https://iancoleman.io/bip39/#english
# data from https://iancoleman.io/bip39/
address = get_address(client, parse_path(path))
assert address == expected_address

@ -115,7 +115,7 @@ class TestDeviceLoad:
pin="",
passphrase_protection=True,
label="test",
language="english",
language="en-US",
skip_checksum=True,
)
if client.features.model == "T":
@ -130,7 +130,7 @@ class TestDeviceLoad:
pin="",
passphrase_protection=True,
label="test",
language="english",
language="en-US",
skip_checksum=True,
)
if client.features.model == "T":
@ -145,7 +145,7 @@ class TestDeviceLoad:
pin="",
passphrase_protection=True,
label="test",
language="english",
language="en-US",
skip_checksum=True,
)
if client.features.model == "T":
@ -160,7 +160,7 @@ class TestDeviceLoad:
pin="",
passphrase_protection=True,
label="test",
language="english",
language="en-US",
skip_checksum=True,
)
if client.features.model == "T":

@ -35,7 +35,7 @@ class TestMsgRecoverydevice:
passphrase_protection=True,
pin_protection=True,
label="label",
language="english",
language="en-US",
enforce_wordlist=True,
)
)
@ -98,7 +98,7 @@ class TestMsgRecoverydevice:
passphrase_protection=False,
pin_protection=False,
label="label",
language="english",
language="en-US",
enforce_wordlist=True,
)
)
@ -152,7 +152,7 @@ class TestMsgRecoverydevice:
passphrase_protection=False,
pin_protection=False,
label="label",
language="english",
language="en-US",
enforce_wordlist=True,
)
)
@ -180,7 +180,7 @@ class TestMsgRecoverydevice:
passphrase_protection=True,
pin_protection=True,
label="label",
language="english",
language="en-US",
enforce_wordlist=True,
)
)
@ -207,5 +207,5 @@ class TestMsgRecoverydevice:
def test_already_initialized(self, client):
with pytest.raises(RuntimeError):
device.recover(
client, 12, False, False, "label", "english", client.mnemonic_callback
client, 12, False, False, "label", "en-US", client.mnemonic_callback
)

@ -149,5 +149,5 @@ class TestMsgRecoverydeviceT2:
def test_already_initialized(self, client):
with pytest.raises(RuntimeError):
device.recover(
client, 12, False, False, "label", "english", client.mnemonic_callback
client, 12, False, False, "label", "en-US", client.mnemonic_callback
)

@ -55,7 +55,7 @@ def test_2of3_dryrun(client):
passphrase_protection=False,
pin_protection=False,
label="label",
language="english",
language="en-US",
dry_run=True,
)
@ -87,6 +87,6 @@ def test_2of3_invalid_seed_dryrun(client):
passphrase_protection=False,
pin_protection=False,
label="label",
language="english",
language="en-US",
dry_run=True,
)

@ -52,7 +52,7 @@ def test_2of3_dryrun(client):
passphrase_protection=False,
pin_protection=False,
label="label",
language="english",
language="en-US",
dry_run=True,
)
@ -82,6 +82,6 @@ def test_2of3_invalid_seed_dryrun(client):
passphrase_protection=False,
pin_protection=False,
label="label",
language="english",
language="en-US",
dry_run=True,
)

@ -36,7 +36,7 @@ class TestMsgResetDevice:
strength=strength,
passphrase_protection=False,
pin_protection=False,
language="english",
language="en-US",
label="test",
)
)
@ -106,7 +106,7 @@ class TestMsgResetDevice:
strength=strength,
passphrase_protection=True,
pin_protection=True,
language="english",
language="en-US",
label="test",
)
)
@ -195,7 +195,7 @@ class TestMsgResetDevice:
strength=strength,
passphrase_protection=True,
pin_protection=True,
language="english",
language="en-US",
label="test",
)
)
@ -230,4 +230,4 @@ class TestMsgResetDevice:
def test_already_initialized(self, client):
with pytest.raises(Exception):
device.reset(client, False, 128, True, True, "label", "english")
device.reset(client, False, 128, True, True, "label", "en-US")

@ -36,7 +36,7 @@ class TestMsgResetDeviceSkipbackup:
strength=self.strength,
passphrase_protection=False,
pin_protection=False,
language="english",
language="en-US",
label="test",
skip_backup=True,
)
@ -106,7 +106,7 @@ class TestMsgResetDeviceSkipbackup:
strength=self.strength,
passphrase_protection=False,
pin_protection=False,
language="english",
language="en-US",
label="test",
skip_backup=True,
)
@ -163,7 +163,7 @@ class TestMsgResetDeviceSkipbackup:
strength=self.strength,
passphrase_protection=False,
pin_protection=False,
language="english",
language="en-US",
label="test",
skip_backup=True,
)

@ -87,7 +87,7 @@ class TestMsgResetDeviceT2:
passphrase_protection=False,
pin_protection=False,
label="test",
language="english",
language="en-US",
)
# generate mnemonic locally
@ -189,7 +189,7 @@ class TestMsgResetDeviceT2:
passphrase_protection=True,
pin_protection=True,
label="test",
language="english",
language="en-US",
)
# generate mnemonic locally
@ -235,4 +235,4 @@ class TestMsgResetDeviceT2:
@pytest.mark.setup_client(mnemonic=MNEMONIC12)
def test_already_initialized(self, client):
with pytest.raises(Exception):
device.reset(client, False, 128, True, True, "label", "english")
device.reset(client, False, 128, True, True, "label", "en-US")

@ -159,7 +159,7 @@ class TestMsgResetDeviceT2:
passphrase_protection=False,
pin_protection=False,
label="test",
language="english",
language="en-US",
backup_type=BackupType.Slip39_Advanced,
)

@ -106,7 +106,7 @@ class TestMsgResetDeviceT2:
passphrase_protection=False,
pin_protection=False,
label="test",
language="english",
language="en-US",
backup_type=BackupType.Slip39_Basic,
)

@ -31,7 +31,7 @@ CUSTOM_MNEMONIC = (
@pytest.mark.skip_t1 # T1 support is not planned
class TestMsgRippleGetAddress:
def test_ripple_get_address(self, client):
# data from https://iancoleman.io/bip39/#english
# data from https://iancoleman.io/bip39/
address = get_address(client, parse_path("m/44'/144'/0'/0/0"))
assert address == "rNaqKtKrMSwpwZSzRckPf7S96DkimjkF4H"
address = get_address(client, parse_path("m/44'/144'/0'/0/1"))

@ -115,7 +115,7 @@ class TestProtectionLevels:
+ [proto.ButtonRequest()] * 24
+ [proto.Success(), proto.Features()]
)
device.reset(client, False, 128, True, False, "label", "english")
device.reset(client, False, 128, True, False, "label", "en-US")
with pytest.raises(TrezorFailure):
# This must fail, because device is already initialized
@ -127,7 +127,7 @@ class TestProtectionLevels:
passphrase_protection=True,
pin_protection=False,
label="label",
language="english",
language="en-US",
)
)
@ -142,7 +142,7 @@ class TestProtectionLevels:
)
device.recover(
client, 12, False, False, "label", "english", client.mnemonic_callback
client, 12, False, False, "label", "en-US", client.mnemonic_callback
)
with pytest.raises(TrezorFailure):
@ -154,7 +154,7 @@ class TestProtectionLevels:
passphrase_protection=False,
pin_protection=False,
label="label",
language="english",
language="en-US",
)
)

@ -87,7 +87,7 @@ def reset(client, strength=128, skip_backup=False):
passphrase_protection=False,
pin_protection=False,
label="test",
language="english",
language="en-US",
backup_type=BackupType.Bip39,
)

@ -176,7 +176,7 @@ def reset(client, strength=128):
passphrase_protection=False,
pin_protection=False,
label="test",
language="english",
language="en-US",
backup_type=BackupType.Slip39_Advanced,
)

@ -111,7 +111,7 @@ def reset(client, strength=128):
passphrase_protection=False,
pin_protection=False,
label="test",
language="english",
language="en-US",
backup_type=BackupType.Slip39_Basic,
)

@ -36,7 +36,7 @@ MNEMONIC = " ".join(["all"] * 12)
PATH = [H_(44), H_(0), H_(0), 0, 0]
ADDRESS = "1JAd7XCBzGudGpJQSDSfpmJhiygtLQWaGL"
LABEL = "test"
LANGUAGE = "english"
LANGUAGE = "en-US"
STRENGTH = 128
@ -83,7 +83,6 @@ def test_upgrade_load(gen, from_tag, to_tag):
assert not client.features.passphrase_protection
assert client.features.initialized
assert client.features.label == LABEL
assert client.features.language == LANGUAGE
assert btc.get_address(client, "Bitcoin", PATH) == ADDRESS
with EmulatorWrapper(gen, from_tag) as emu:
@ -102,6 +101,7 @@ def test_upgrade_load(gen, from_tag, to_tag):
with EmulatorWrapper(gen, to_tag, storage=storage) as emu:
assert device_id == emu.client.features.device_id
asserts(to_tag, emu.client)
assert emu.client.features.language == LANGUAGE
@for_all("legacy")
@ -111,7 +111,6 @@ def test_upgrade_reset(gen, from_tag, to_tag):
assert not client.features.passphrase_protection
assert client.features.initialized
assert client.features.label == LABEL
assert client.features.language == LANGUAGE
assert not client.features.needs_backup
assert not client.features.unfinished_backup
assert not client.features.no_backup
@ -134,6 +133,7 @@ def test_upgrade_reset(gen, from_tag, to_tag):
with EmulatorWrapper(gen, to_tag, storage=storage) as emu:
assert device_id == emu.client.features.device_id
asserts(to_tag, emu.client)
assert emu.client.features.language == LANGUAGE
assert btc.get_address(emu.client, "Bitcoin", PATH) == address
@ -144,7 +144,6 @@ def test_upgrade_reset_skip_backup(gen, from_tag, to_tag):
assert not client.features.passphrase_protection
assert client.features.initialized
assert client.features.label == LABEL
assert client.features.language == LANGUAGE
assert client.features.needs_backup
assert not client.features.unfinished_backup
assert not client.features.no_backup
@ -168,6 +167,7 @@ def test_upgrade_reset_skip_backup(gen, from_tag, to_tag):
with EmulatorWrapper(gen, to_tag, storage=storage) as emu:
assert device_id == emu.client.features.device_id
asserts(to_tag, emu.client)
assert emu.client.features.language == LANGUAGE
assert btc.get_address(emu.client, "Bitcoin", PATH) == address
@ -178,7 +178,6 @@ def test_upgrade_reset_no_backup(gen, from_tag, to_tag):
assert not client.features.passphrase_protection
assert client.features.initialized
assert client.features.label == LABEL
assert client.features.language == LANGUAGE
assert not client.features.needs_backup
assert not client.features.unfinished_backup
assert client.features.no_backup
@ -202,6 +201,7 @@ def test_upgrade_reset_no_backup(gen, from_tag, to_tag):
with EmulatorWrapper(gen, to_tag, storage=storage) as emu:
assert device_id == emu.client.features.device_id
asserts(to_tag, emu.client)
assert emu.client.features.language == LANGUAGE
assert btc.get_address(emu.client, "Bitcoin", PATH) == address

@ -1 +1 @@
Subproject commit 67f0023be4913a86f62bedf700f86ca3079cf842
Subproject commit f81bb68dabf90d76ebe57e665363370bf56b77f9
Loading…
Cancel
Save