Skip to content

Commit 86612ab

Browse files
committed
Remove U2FFido2Server
1 parent 260058e commit 86612ab

3 files changed

Lines changed: 1 addition & 271 deletions

File tree

‎fido2/server.py‎

Lines changed: 0 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@
5555

5656
from cryptography.hazmat.primitives import constant_time
5757
from cryptography.exceptions import InvalidSignature as _InvalidSignature
58-
from dataclasses import replace
59-
from urllib.parse import urlparse
6058
from typing import Sequence, Mapping, Callable, Any, overload
6159

6260
import os
@@ -439,81 +437,3 @@ def _make_internal_state(
439437
"challenge": websafe_encode(challenge),
440438
"user_verification": user_verification,
441439
}
442-
443-
444-
# TODO 2.0: Delete, or move to an example
445-
def verify_app_id(app_id: str, origin: str) -> bool:
446-
"""Checks if a FIDO U2F App ID is usable for a given origin.
447-
448-
:param app_id: The App ID to validate.
449-
:param origin: The origin of the request.
450-
:return: True if the App ID is usable by the origin, False if not.
451-
452-
.. deprecated:: 1.2.0
453-
This will be removed in python-fido2 2.0.
454-
"""
455-
url = urlparse(app_id)
456-
hostname = url.hostname
457-
# Note that FIDO U2F requires a secure context, i.e. an origin with https scheme.
458-
# However, most browsers also treat http://localhost as a secure context. See
459-
# https://groups.google.com/a/chromium.org/g/blink-dev/c/RC9dSw-O3fE/m/E3_0XaT0BAAJ
460-
if url.scheme != "https" and (url.scheme, hostname) != ("http", "localhost"):
461-
return False
462-
if not hostname:
463-
return False
464-
return verify_rp_id(hostname, origin)
465-
466-
467-
# TODO 2.0: Delete, or move to an example
468-
class U2FFido2Server(Fido2Server):
469-
"""Fido2Server which can be used with existing U2F credentials.
470-
471-
This Fido2Server can be used with existing U2F credentials by using the
472-
WebAuthn appid extension, as well as with new WebAuthn credentials.
473-
See https://www.w3.org/TR/webauthn/#sctn-appid-extension for details.
474-
475-
:param app_id: The appId which was used for U2F registration.
476-
:param verify_u2f_origin: (optional) Alternative function to validate an
477-
origin for U2F credentials.
478-
479-
For other parameters, see Fido2Server.
480-
481-
.. deprecated:: 1.2.0
482-
This will be removed in python-fido2 2.0.
483-
"""
484-
485-
def __init__(
486-
self,
487-
app_id: str,
488-
rp: PublicKeyCredentialRpEntity,
489-
verify_u2f_origin: VerifyOrigin | None = None,
490-
*args,
491-
**kwargs,
492-
):
493-
super().__init__(rp, *args, **kwargs)
494-
if verify_u2f_origin:
495-
kwargs["verify_origin"] = verify_u2f_origin
496-
else:
497-
kwargs["verify_origin"] = lambda o: verify_app_id(app_id, o)
498-
self._app_id = app_id
499-
self._app_id_server = Fido2Server(
500-
replace(PublicKeyCredentialRpEntity.from_dict(rp), id=app_id),
501-
*args,
502-
**kwargs,
503-
)
504-
505-
def register_begin(self, *args, **kwargs):
506-
kwargs.setdefault("extensions", {})["appidExclude"] = self._app_id
507-
req, state = super().register_begin(*args, **kwargs)
508-
return req, state
509-
510-
def authenticate_begin(self, *args, **kwargs):
511-
kwargs.setdefault("extensions", {})["appid"] = self._app_id
512-
req, state = super().authenticate_begin(*args, **kwargs)
513-
return req, state
514-
515-
def authenticate_complete(self, *args, **kwargs):
516-
try:
517-
return super().authenticate_complete(*args, **kwargs)
518-
except ValueError:
519-
return self._app_id_server.authenticate_complete(*args, **kwargs)

‎tests/test_server.py‎

Lines changed: 1 addition & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import unittest
22

3-
from fido2.server import Fido2Server, U2FFido2Server, verify_app_id
3+
from fido2.server import Fido2Server
44
from fido2.webauthn import (
55
CollectedClientData,
66
PublicKeyCredentialRpEntity,
@@ -11,58 +11,6 @@
1111
from fido2.utils import websafe_encode
1212

1313
from .test_ctap2 import _ATT_CRED_DATA, _CRED_ID
14-
from .utils import U2FDevice
15-
16-
17-
class TestAppId(unittest.TestCase):
18-
def test_valid_ids(self):
19-
self.assertTrue(
20-
verify_app_id("https://example.com", "https://register.example.com")
21-
)
22-
self.assertTrue(
23-
verify_app_id("https://example.com", "https://fido.example.com")
24-
)
25-
self.assertTrue(
26-
verify_app_id("https://example.com", "https://www.example.com:444")
27-
)
28-
29-
self.assertTrue(
30-
verify_app_id(
31-
"https://companyA.hosting.example.com",
32-
"https://fido.companyA.hosting.example.com",
33-
)
34-
)
35-
self.assertTrue(
36-
verify_app_id(
37-
"https://companyA.hosting.example.com",
38-
"https://xyz.companyA.hosting.example.com",
39-
)
40-
)
41-
42-
def test_invalid_ids(self):
43-
self.assertFalse(verify_app_id("https://example.com", "http://example.com"))
44-
self.assertFalse(verify_app_id("https://example.com", "http://www.example.com"))
45-
self.assertFalse(
46-
verify_app_id("https://example.com", "https://example-test.com")
47-
)
48-
49-
self.assertFalse(
50-
verify_app_id(
51-
"https://companyA.hosting.example.com", "https://register.example.com"
52-
)
53-
)
54-
self.assertFalse(
55-
verify_app_id(
56-
"https://companyA.hosting.example.com",
57-
"https://companyB.hosting.example.com",
58-
)
59-
)
60-
61-
def test_effective_tld_names(self):
62-
self.assertFalse(
63-
verify_app_id("https://appspot.com", "https://foo.appspot.com")
64-
)
65-
self.assertFalse(verify_app_id("https://co.uk", "https://example.co.uk"))
6614

6715

6816
class TestPublicKeyCredentialRpEntity(unittest.TestCase):
@@ -131,93 +79,3 @@ def test_authenticate_complete_invalid_signature(self):
13179
AuthenticatorData(_AUTH_DATA),
13280
b"INVALID",
13381
)
134-
135-
136-
class TestU2FFido2Server(unittest.TestCase):
137-
def test_u2f(self):
138-
rp = PublicKeyCredentialRpEntity("Example", "example.com")
139-
app_id = b"https://example.com"
140-
server = U2FFido2Server(app_id=app_id.decode("ascii"), rp=rp)
141-
142-
state = {
143-
"challenge": "GAZPACHO!",
144-
"user_verification": UserVerificationRequirement.PREFERRED,
145-
}
146-
client_data = CollectedClientData.create(
147-
CollectedClientData.TYPE.GET,
148-
"GAZPACHO!",
149-
"https://example.com",
150-
)
151-
152-
param = b"TOMATO GIVES "
153-
154-
device = U2FDevice(param, app_id)
155-
auth_data = AttestedCredentialData.from_ctap1(param, device.public_key_bytes)
156-
authenticator_data, signature = device.sign(client_data)
157-
158-
server.authenticate_complete(
159-
state,
160-
[auth_data],
161-
device.credential_id,
162-
client_data,
163-
authenticator_data,
164-
signature,
165-
)
166-
167-
def test_u2f_facets(self):
168-
rp = PublicKeyCredentialRpEntity("Example", "example.com")
169-
app_id = b"https://www.example.com/facets.json"
170-
171-
def verify_u2f_origin(origin):
172-
return origin in ("https://oauth.example.com", "https://admin.example.com")
173-
174-
server = U2FFido2Server(
175-
app_id=app_id.decode("ascii"), rp=rp, verify_u2f_origin=verify_u2f_origin
176-
)
177-
178-
state = {
179-
"challenge": "GAZPACHO!",
180-
"user_verification": UserVerificationRequirement.PREFERRED,
181-
}
182-
183-
client_data = CollectedClientData.create(
184-
CollectedClientData.TYPE.GET,
185-
"GAZPACHO!",
186-
"https://oauth.example.com",
187-
)
188-
189-
param = b"TOMATO GIVES "
190-
191-
device = U2FDevice(param, app_id)
192-
auth_data = AttestedCredentialData.from_ctap1(param, device.public_key_bytes)
193-
authenticator_data, signature = device.sign(client_data)
194-
195-
server.authenticate_complete(
196-
state,
197-
[auth_data],
198-
device.credential_id,
199-
client_data,
200-
authenticator_data,
201-
signature,
202-
)
203-
204-
# Now with something not whitelisted
205-
client_data = CollectedClientData.create(
206-
CollectedClientData.TYPE.GET,
207-
"GAZPACHO!",
208-
"https://publicthingy.example.com",
209-
)
210-
211-
authenticator_data, signature = device.sign(client_data)
212-
213-
with self.assertRaisesRegex(
214-
ValueError, "Invalid origin in CollectedClientData."
215-
):
216-
server.authenticate_complete(
217-
state,
218-
[auth_data],
219-
device.credential_id,
220-
client_data,
221-
authenticator_data,
222-
signature,
223-
)

‎tests/utils.py‎

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)