Ejemplo n.º 1
0
def init_unlocked():
    # Check for storage version upgrade.
    version = config.get(_APP, _VERSION)
    if version == b"\x01":
        # Make the U2F counter public and writable even when storage is locked.
        counter = config.get(_APP, _U2F_COUNTER)
        if counter is not None:
            config.set_counter(_APP, _U2F_COUNTER, counter,
                               True)  # writable when locked
            config.delete(_APP, _U2F_COUNTER)
        config.set(_APP, _VERSION, _STORAGE_VERSION)
Ejemplo n.º 2
0
    def test_counter(self):
        config.init()
        config.wipe()

        # Test writable_locked when storage is locked.

        config.lock()

        with self.assertRaises(RuntimeError):
            config.set_counter(1, 2, 0, False)

        with self.assertRaises(RuntimeError):
            config.next_counter(1, 2, False)

        config.set_counter(1, 2, 100, True)
        for i in range(100, 200):
            self.assertEqual(config.next_counter(1, 2, True), i + 1)

        # Test increment with storage unlocked.

        self.assertEqual(config.unlock('', None), True)

        for i in range(200, 300):
            self.assertEqual(config.next_counter(1, 2, True), i + 1)

        # Test counter deletion.

        config.delete(1, 2, True, True)
        self.assertEqual(config.next_counter(1, 2, True), 0)

        # Test overflow protection.

        with self.assertRaises(RuntimeError):
            config.set_counter(1, 2, 0x1_0000_0000, True)

        start = 0xFFFF_FFFF - 100
        config.set_counter(1, 2, start, True)
        for i in range(start, 0xFFFF_FFFF):
            self.assertEqual(config.next_counter(1, 2, True), i + 1)
Ejemplo n.º 3
0
def set_u2f_counter(cntr: int) -> None:
    config.set_counter(_APP, _U2F_COUNTER, cntr, True)  # writable when locked
Ejemplo n.º 4
0
def set_counter(app: int,
                key: int,
                count: int,
                writable_locked: bool = False) -> None:
    config.set_counter(app, key, count, writable_locked)
Ejemplo n.º 5
0
def _set_counter(app: int, key: int, count: int, public: bool = False) -> None:
    config.set_counter(app, key, count, public)