Esempio n. 1
0
def _set_wipe_code(client, wipe_code):
    # Set/change wipe code.
    ret = client.call_raw(messages.ChangeWipeCode())
    assert isinstance(ret, messages.ButtonRequest)

    # Confirm intent to set/change wipe code.
    client.debug.press_yes()
    ret = client.call_raw(messages.ButtonAck())

    if client.features.pin_protection:
        # Send current PIN.
        assert isinstance(ret, messages.PinMatrixRequest)
        pin_encoded = client.debug.read_pin_encoded()
        ret = client.call_raw(messages.PinMatrixAck(pin=pin_encoded))

    # Send the new wipe code for the first time.
    assert isinstance(ret, messages.PinMatrixRequest)
    wipe_code_encoded = client.debug.encode_pin(wipe_code)
    ret = client.call_raw(messages.PinMatrixAck(pin=wipe_code_encoded))

    # Send the new wipe code for the second time.
    assert isinstance(ret, messages.PinMatrixRequest)
    wipe_code_encoded = client.debug.encode_pin(wipe_code)
    ret = client.call_raw(messages.PinMatrixAck(pin=wipe_code_encoded))

    # Now we're done.
    assert isinstance(ret, messages.Success)
Esempio n. 2
0
def test_set_wipe_code_mismatch(client):
    # Check that there is no wipe code protection.
    assert client.features.wipe_code_protection is False

    # Let's set a new wipe code.
    ret = client.call_raw(messages.ChangeWipeCode())
    assert isinstance(ret, messages.ButtonRequest)

    # Confirm intent to set wipe code.
    client.debug.press_yes()
    ret = client.call_raw(messages.ButtonAck())

    # Send the new wipe code for the first time.
    assert isinstance(ret, messages.PinMatrixRequest)
    wipe_code_encoded = client.debug.encode_pin(WIPE_CODE4)
    ret = client.call_raw(messages.PinMatrixAck(pin=wipe_code_encoded))

    # Send the new wipe code for the second time, but different.
    assert isinstance(ret, messages.PinMatrixRequest)
    wipe_code_encoded = client.debug.encode_pin(WIPE_CODE6)
    ret = client.call_raw(messages.PinMatrixAck(pin=wipe_code_encoded))

    # The operation should fail, because the wipe codes are different.
    assert isinstance(ret, messages.Failure)
    assert ret.code == messages.FailureType.WipeCodeMismatch

    # Check that there is no wipe code protection.
    client.init_device()
    assert client.features.wipe_code_protection is False
Esempio n. 3
0
def test_set_wipe_code_to_pin(client):
    # Check that wipe code protection status is not revealed in locked state.
    assert client.features.wipe_code_protection is None

    # Let's try setting the wipe code to the curent PIN value.
    ret = client.call_raw(messages.ChangeWipeCode())
    assert isinstance(ret, messages.ButtonRequest)

    # Confirm intent to set wipe code.
    client.debug.press_yes()
    ret = client.call_raw(messages.ButtonAck())

    # Send current PIN.
    assert isinstance(ret, messages.PinMatrixRequest)
    pin_encoded = client.debug.read_pin_encoded()
    ret = client.call_raw(messages.PinMatrixAck(pin=pin_encoded))

    # Send the new wipe code.
    assert isinstance(ret, messages.PinMatrixRequest)
    pin_encoded = client.debug.read_pin_encoded()
    ret = client.call_raw(messages.PinMatrixAck(pin=pin_encoded))

    # The operation should fail, because the wipe code must be different from the PIN.
    assert isinstance(ret, messages.Failure)
    assert ret.code == messages.FailureType.ProcessError

    # Check that there is no wipe code protection.
    client.init_device()
    assert client.features.wipe_code_protection is False
Esempio n. 4
0
def _remove_wipe_code(client):
    # Remove wipe code
    ret = client.call_raw(messages.ChangeWipeCode(remove=True))
    assert isinstance(ret, messages.ButtonRequest)

    # Confirm intent to remove wipe code.
    client.debug.press_yes()
    ret = client.call_raw(messages.ButtonAck())

    # Send current PIN.
    assert isinstance(ret, messages.PinMatrixRequest)
    pin_encoded = client.debug.read_pin_encoded()
    ret = client.call_raw(messages.PinMatrixAck(pin=pin_encoded))

    # Now we're done.
    assert isinstance(ret, messages.Success)
Esempio n. 5
0
def test_set_wipe_code_invalid(client, invalid_wipe_code):
    # Let's set the wipe code
    ret = client.call_raw(messages.ChangeWipeCode())
    assert isinstance(ret, messages.ButtonRequest)

    # Confirm
    client.debug.press_yes()
    ret = client.call_raw(messages.ButtonAck())

    # Enter a wipe code containing an invalid digit
    assert isinstance(ret, messages.PinMatrixRequest)
    assert ret.type == PinType.WipeCodeFirst
    ret = client.call_raw(messages.PinMatrixAck(pin=invalid_wipe_code))

    # Ensure the invalid wipe code is detected
    assert isinstance(ret, messages.Failure)

    # Check that there's still no wipe code protection.
    client.init_device()
    assert client.features.wipe_code_protection is False