|
6 | 6 |
|
7 | 7 | import json
|
8 | 8 | from nacl.signing import SigningKey
|
| 9 | +import nacl.bindings as salt |
9 | 10 |
|
10 | 11 |
|
11 | 12 | @app.get("/auth_test/whoami")
|
@@ -492,3 +493,49 @@ def test_auth_legacy(client, db, admin, user, room):
|
492 | 493 | 'body': {'status_code': 200, 'banned_members': []},
|
493 | 494 | },
|
494 | 495 | ]
|
| 496 | + |
| 497 | + |
| 498 | +def test_small_subgroups(client, db): |
| 499 | + # Make some public keys with small subgroup components to make sure sodium rejects them (it |
| 500 | + # does, everythwere that matters here). |
| 501 | + a = SigningKey.generate() |
| 502 | + B = server_pubkey |
| 503 | + headers = x_sogs(a, B, 'GET', '/auth_test/whoami') |
| 504 | + |
| 505 | + assert headers['X-SOGS-Pubkey'].startswith('00') |
| 506 | + A = bytes.fromhex(headers['X-SOGS-Pubkey'][2:]) |
| 507 | + |
| 508 | + assert A == a.verify_key.encode() |
| 509 | + |
| 510 | + if hasattr(salt, 'crypto_core_ed25519_is_valid_point'): |
| 511 | + assert salt.crypto_core_ed25519_is_valid_point(A) |
| 512 | + |
| 513 | + Abad = salt.crypto_core_ed25519_add( |
| 514 | + A, bytes.fromhex('0000000000000000000000000000000000000000000000000000000000000000') |
| 515 | + ) |
| 516 | + |
| 517 | + if hasattr(salt, 'crypto_core_ed25519_is_valid_point'): |
| 518 | + assert not salt.crypto_core_ed25519_is_valid_point(Abad) |
| 519 | + |
| 520 | + headers['X-SOGS-Pubkey'] = '00' + Abad.hex() |
| 521 | + |
| 522 | + r = client.get("/auth_test/whoami", headers=headers) |
| 523 | + assert r.status_code == 400 |
| 524 | + assert r.data == b'Invalid authentication: given X-SOGS-Pubkey is not a valid Ed25519 pubkey' |
| 525 | + |
| 526 | + # Now try with a blinded id: |
| 527 | + headers = x_sogs(a, B, 'GET', '/auth_test/whoami', blinded=True) |
| 528 | + assert headers['X-SOGS-Pubkey'].startswith('15') |
| 529 | + A = bytes.fromhex(headers['X-SOGS-Pubkey'][2:]) |
| 530 | + |
| 531 | + Abad = salt.crypto_core_ed25519_add( |
| 532 | + A, bytes.fromhex('c7176a703d4dd84fba3c0b760d10670f2a2053fa2c39ccc64ec7fd7792ac037a') |
| 533 | + ) |
| 534 | + |
| 535 | + if hasattr(salt, 'crypto_core_ed25519_is_valid_point'): |
| 536 | + assert not salt.crypto_core_ed25519_is_valid_point(Abad) |
| 537 | + |
| 538 | + headers['X-SOGS-Pubkey'] = '15' + Abad.hex() |
| 539 | + r = client.get("/auth_test/whoami", headers=headers) |
| 540 | + assert r.status_code == 400 |
| 541 | + assert r.data == b'Invalid authentication: given X-SOGS-Pubkey is not a valid Ed25519 pubkey' |
0 commit comments