|
1 | 1 | import unittest |
2 | 2 |
|
3 | | -from fido2.server import Fido2Server, U2FFido2Server, verify_app_id |
| 3 | +from fido2.server import Fido2Server |
4 | 4 | from fido2.webauthn import ( |
5 | 5 | CollectedClientData, |
6 | 6 | PublicKeyCredentialRpEntity, |
|
11 | 11 | from fido2.utils import websafe_encode |
12 | 12 |
|
13 | 13 | 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")) |
66 | 14 |
|
67 | 15 |
|
68 | 16 | class TestPublicKeyCredentialRpEntity(unittest.TestCase): |
@@ -131,93 +79,3 @@ def test_authenticate_complete_invalid_signature(self): |
131 | 79 | AuthenticatorData(_AUTH_DATA), |
132 | 80 | b"INVALID", |
133 | 81 | ) |
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 | | - ) |
0 commit comments