예제 #1
0
def test_softlock_instability(client):
    def load_device():
        debuglink.load_device(
            client,
            mnemonic=MNEMONIC12,
            pin="1234",
            passphrase_protection=False,
            label="test",
        )

    # start from a clean slate:
    resp = client.debug.reseed(0)
    if isinstance(resp, messages.Failure) and not isinstance(
        client.transport, udp.UdpTransport
    ):
        pytest.xfail("reseed only supported on emulator")
    device.wipe(client)
    entropy_after_wipe = misc.get_entropy(client, 16)

    # configure and wipe the device
    load_device()
    client.debug.reseed(0)
    device.wipe(client)
    assert misc.get_entropy(client, 16) == entropy_after_wipe

    load_device()
    # the device has PIN -> lock it
    client.call(messages.LockDevice())
    client.debug.reseed(0)
    # wipe_device should succeed with no need to unlock
    device.wipe(client)
    # the device is now trying to run the lockscreen, which attempts to unlock.
    # If the device actually called config.unlock(), it would use additional randomness.
    # That is undesirable. Assert that the returned entropy is still the same.
    assert misc.get_entropy(client, 16) == entropy_after_wipe
def test_get_entropy_t1(client):
    _assert_protection(client)
    with client:
        client.set_expected_responses([
            messages.ButtonRequest(code=B.ProtectCall),
            messages.Entropy,
        ])
        misc.get_entropy(client, 10)
def test_get_entropy_t2(client):
    _assert_protection(client)
    with client:
        client.use_pin_sequence([PIN4])
        client.set_expected_responses([
            _pin_request(client),
            messages.ButtonRequest(code=B.ProtectCall),
            messages.Entropy,
        ])
        misc.get_entropy(client, 10)
예제 #4
0
def test_entropy(client, entropy_length):
    with client:
        client.set_expected_responses(
            [m.ButtonRequest(code=m.ButtonRequestType.ProtectCall), m.Entropy])
        ent = misc.get_entropy(client, entropy_length)
        assert len(ent) == entropy_length
        print("{} bytes: entropy = {}".format(entropy_length, entropy(ent)))
예제 #5
0
def test_entropy(client, entropy_length):
    with client:
        client.set_expected_responses(
            [m.ButtonRequest(code=m.ButtonRequestType.ProtectCall), m.Entropy()]
        )
        ent = misc.get_entropy(client, entropy_length)
        assert len(ent) == entropy_length
        print("{} bytes: entropy = {}".format(entropy_length, entropy(ent)))
예제 #6
0
파일: trezor.py 프로젝트: aussiehash/tpass
 def getEntropy(self, length):
     self.__getClient()
     trezor_entropy = misc.get_entropy(self.client, length // 2)
     urandom_entropy = os.urandom(length // 2)
     entropy = trezor_entropy + urandom_entropy
     if len(entropy) != length:
         raise ValueError(str(length) + ' bytes entropy expected')
     return entropy
예제 #7
0
def main():
    try:
        client = TrezorClient(get_transport(), ui=ui.ClickUI())
    except Exception as e:
        print(e)
        return

    arg1 = sys.argv[1]                     # output file
    arg2 = int(sys.argv[2], 10)            # total number of how many bytes of entropy to read
    step = 1024 if arg2 >= 1024 else arg2  # trezor will only return 1KB at a time

    with io.open(arg1, 'wb') as f:
        for i in range(0, arg2, step):
            entropy = misc.get_entropy(client, step)
            f.write(entropy)

    client.close()
def main():
    try:
        client = TrezorClient(get_transport(), ui=ui.ClickUI())
    except Exception as e:
        print(e)
        return

    arg1 = sys.argv[1]  # output file
    arg2 = int(sys.argv[2],
               10)  # total number of how many bytes of entropy to read
    step = 1024 if arg2 >= 1024 else arg2  # trezor will only return 1KB at a time

    with io.open(arg1, 'wb') as f:
        for i in range(0, arg2, step):
            entropy = misc.get_entropy(client, step)
            f.write(entropy)

    client.close()
 def test_get_entropy(self, client):
     with client:
         client.set_expected_responses(
             [proto.ButtonRequest(), proto.Entropy()])
         misc.get_entropy(client, 10)
예제 #10
0
 def test_get_entropy(self):
     with self.client:
         self.setup_mnemonic_pin_passphrase()
         self.client.set_expected_responses(
             [proto.ButtonRequest(), proto.Entropy()])
         misc.get_entropy(self.client, 10)
예제 #11
0
 def test_get_entropy(self, client):
     with client:
         client.set_expected_responses(
             [messages.ButtonRequest, messages.Entropy])
         misc.get_entropy(client, 10)
예제 #12
0
 def test_get_entropy(self):
     with self.client:
         self.setup_mnemonic_pin_passphrase()
         self.client.set_expected_responses([proto.ButtonRequest(), proto.Entropy()])
         misc.get_entropy(self.client, 10)