Merge pull request #700 from trezor/tsusanka/upgrade-u2f-check
Get next u2f counter and add tests for itpull/704/head
commit
85d7215bf3
@ -0,0 +1,20 @@
|
||||
import storage.device
|
||||
from trezor import ui, wire
|
||||
from trezor.messages import ButtonRequestType
|
||||
from trezor.messages.GetNextU2FCounter import GetNextU2FCounter
|
||||
from trezor.messages.NextU2FCounter import NextU2FCounter
|
||||
from trezor.ui.text import Text
|
||||
|
||||
from apps.common.confirm import require_confirm
|
||||
|
||||
|
||||
async def get_next_u2f_counter(
|
||||
ctx: wire.Context, msg: GetNextU2FCounter
|
||||
) -> NextU2FCounter:
|
||||
text = Text("Get next U2F counter", ui.ICON_CONFIG)
|
||||
text.normal("Do you really want to")
|
||||
text.bold("increase and retrieve")
|
||||
text.normal("the U2F counter?")
|
||||
await require_confirm(ctx, text, code=ButtonRequestType.ProtectCall)
|
||||
|
||||
return NextU2FCounter(storage.device.next_u2f_counter())
|
@ -0,0 +1,14 @@
|
||||
# Automatically generated by pb2py
|
||||
# fmt: off
|
||||
import protobuf as p
|
||||
|
||||
if __debug__:
|
||||
try:
|
||||
from typing import Dict, List # noqa: F401
|
||||
from typing_extensions import Literal # noqa: F401
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
|
||||
class GetNextU2FCounter(p.MessageType):
|
||||
MESSAGE_WIRE_TYPE = 80
|
@ -0,0 +1,26 @@
|
||||
# Automatically generated by pb2py
|
||||
# fmt: off
|
||||
import protobuf as p
|
||||
|
||||
if __debug__:
|
||||
try:
|
||||
from typing import Dict, List # noqa: F401
|
||||
from typing_extensions import Literal # noqa: F401
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
|
||||
class NextU2FCounter(p.MessageType):
|
||||
MESSAGE_WIRE_TYPE = 81
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
u2f_counter: int = None,
|
||||
) -> None:
|
||||
self.u2f_counter = u2f_counter
|
||||
|
||||
@classmethod
|
||||
def get_fields(cls) -> Dict:
|
||||
return {
|
||||
1: ('u2f_counter', p.UVarintType, 0),
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
# Automatically generated by pb2py
|
||||
# fmt: off
|
||||
from .. import protobuf as p
|
||||
|
||||
if __debug__:
|
||||
try:
|
||||
from typing import Dict, List # noqa: F401
|
||||
from typing_extensions import Literal # noqa: F401
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
|
||||
class GetNextU2FCounter(p.MessageType):
|
||||
MESSAGE_WIRE_TYPE = 80
|
@ -0,0 +1,26 @@
|
||||
# Automatically generated by pb2py
|
||||
# fmt: off
|
||||
from .. import protobuf as p
|
||||
|
||||
if __debug__:
|
||||
try:
|
||||
from typing import Dict, List # noqa: F401
|
||||
from typing_extensions import Literal # noqa: F401
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
|
||||
class NextU2FCounter(p.MessageType):
|
||||
MESSAGE_WIRE_TYPE = 81
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
u2f_counter: int = None,
|
||||
) -> None:
|
||||
self.u2f_counter = u2f_counter
|
||||
|
||||
@classmethod
|
||||
def get_fields(cls) -> Dict:
|
||||
return {
|
||||
1: ('u2f_counter', p.UVarintType, 0),
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
# This file is part of the Trezor project.
|
||||
#
|
||||
# Copyright (C) 2012-2019 SatoshiLabs and contributors
|
||||
#
|
||||
# This library is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License version 3
|
||||
# as published by the Free Software Foundation.
|
||||
#
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the License along with this library.
|
||||
# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
|
||||
|
||||
from trezorlib import device
|
||||
|
||||
|
||||
def test_u2f_counter(client):
|
||||
assert device.get_next_u2f_counter(client) == 0
|
||||
assert device.get_next_u2f_counter(client) == 1
|
||||
device.set_u2f_counter(client, 111111)
|
||||
assert device.get_next_u2f_counter(client) == 111112
|
||||
assert device.get_next_u2f_counter(client) == 111113
|
||||
device.set_u2f_counter(client, 0)
|
||||
assert device.get_next_u2f_counter(client) == 1
|
Loading…
Reference in new issue