feat(network): add selectable privacy-preserving discovery
This commit is contained in:
parent
9cf0c8fc9c
commit
4d31fd1517
26 changed files with 959 additions and 153 deletions
98
tests/discovery_privacy_validation.gd
Normal file
98
tests/discovery_privacy_validation.gd
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
extends SceneTree
|
||||
|
||||
const FINGERPRINT: String = (
|
||||
"abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789"
|
||||
)
|
||||
const JoinGamePageScene: PackedScene = preload(
|
||||
"res://ui/network/join_game_page.tscn"
|
||||
)
|
||||
|
||||
|
||||
func _initialize() -> void:
|
||||
call_deferred("_run")
|
||||
|
||||
|
||||
func _run() -> void:
|
||||
var endpoint := EndpointParser.parse("203.0.113.20:49152")
|
||||
assert(endpoint.is_valid())
|
||||
var direct_route := ConnectionRoute.direct(endpoint)
|
||||
assert(direct_route.is_valid())
|
||||
assert("203.0.113.20" not in direct_route.display_description)
|
||||
var route := ConnectionRoute.discovery_direct(
|
||||
endpoint,
|
||||
"opaque-room-id",
|
||||
"Pond Friends",
|
||||
)
|
||||
assert(route.is_valid())
|
||||
assert(route.is_discovery_join())
|
||||
assert(route.display_description == "Pond Friends")
|
||||
assert("203.0.113.20" not in route.display_description)
|
||||
var relay_route := ConnectionRoute.discovery_relay(
|
||||
endpoint,
|
||||
"opaque-room-id",
|
||||
"Pond Friends",
|
||||
)
|
||||
assert(relay_route.is_valid())
|
||||
assert(relay_route.is_discovery_join())
|
||||
assert(relay_route.is_relay())
|
||||
assert("203.0.113.20" not in relay_route.display_description)
|
||||
|
||||
var join_page := JoinGamePageScene.instantiate() as JoinGamePage
|
||||
root.add_child(join_page)
|
||||
assert((join_page.get_node("%Address") as LineEdit).secret)
|
||||
assert(str(join_page.call("_display_endpoint", "203.0.113.20:49152")) == "*****")
|
||||
join_page.set("_addresses_visible", true)
|
||||
join_page.call("_refresh_address_privacy_controls")
|
||||
assert(not (join_page.get_node("%Address") as LineEdit).secret)
|
||||
assert(
|
||||
str(join_page.call("_display_endpoint", "203.0.113.20:49152"))
|
||||
== "203.0.113.20:49152"
|
||||
)
|
||||
var saved_entry := SavedServerEntry.new()
|
||||
saved_entry.kind = SavedServerEntry.Kind.SAVED
|
||||
saved_entry.display_name = "203.0.113.20"
|
||||
saved_entry.host = "203.0.113.20"
|
||||
saved_entry.normalized_host = "203.0.113.20"
|
||||
saved_entry.normalized_endpoint = "203.0.113.20:49152"
|
||||
join_page.set("_addresses_visible", false)
|
||||
assert(str(join_page.call("_display_entry_name", saved_entry)) == "saved server")
|
||||
join_page.set("_addresses_visible", true)
|
||||
assert(str(join_page.call("_display_entry_name", saved_entry)) == "203.0.113.20")
|
||||
|
||||
var data_root := PlayerDataRoot.new()
|
||||
root.add_child(data_root)
|
||||
var portable_path := ProjectSettings.globalize_path(
|
||||
"user://discovery-privacy-validation"
|
||||
)
|
||||
var created := data_root.create_unbound_root(portable_path)
|
||||
assert(bool(created.get("ok", false)))
|
||||
assert(data_root.activate_process_root(portable_path))
|
||||
|
||||
var store := ServerTrustStore.new()
|
||||
root.add_child(store)
|
||||
var trust_path := data_root.path_for(&"server_trust")
|
||||
store.configure_storage(trust_path, data_root)
|
||||
assert(store.verify_identity(FINGERPRINT) == ServerTrustStore.Verification.FIRST_SEEN)
|
||||
assert(store.trust_identity(FINGERPRINT, "Pond Friends"))
|
||||
assert(store.verify_identity(FINGERPRINT) == ServerTrustStore.Verification.MATCH)
|
||||
var saved_text := FileAccess.get_file_as_string(trust_path)
|
||||
assert("203.0.113.20" not in saved_text)
|
||||
assert("normalized_endpoint" not in saved_text)
|
||||
assert("normalized_host" not in saved_text)
|
||||
assert("\"port\"" not in saved_text)
|
||||
|
||||
var reloaded := ServerTrustStore.new()
|
||||
root.add_child(reloaded)
|
||||
reloaded.configure_storage(trust_path, data_root)
|
||||
assert(
|
||||
reloaded.verify_identity(FINGERPRINT)
|
||||
== ServerTrustStore.Verification.MATCH
|
||||
)
|
||||
var record := reloaded.get_identity_record(FINGERPRINT)
|
||||
assert(record.get("route_kind") == "discovery")
|
||||
assert(not record.has("normalized_endpoint"))
|
||||
assert(not record.has("normalized_host"))
|
||||
assert(not record.has("port"))
|
||||
|
||||
print("Discovery privacy validation: PASS")
|
||||
quit()
|
||||
Loading…
Add table
Add a link
Reference in a new issue