mirror of https://github.com/nucypher/nucypher.git
properly handle both ipv4 and ipv6 addresses
parent
a712706e7b
commit
e553014446
|
@ -216,14 +216,15 @@ def _is_global_ipv4(ip: str) -> bool:
|
|||
return False
|
||||
|
||||
|
||||
def _ipv6_to_ipv4(ip: str) -> Optional[str]:
|
||||
def _resolve_ipv4(ip: str) -> Optional[str]:
|
||||
try:
|
||||
ip = ip_address(ip.strip())
|
||||
if isinstance(ip, IPv6Address) and ip.ipv4_mapped:
|
||||
return str(ip.ipv4_mapped)
|
||||
except AddressValueError:
|
||||
return None
|
||||
return None
|
||||
if isinstance(ip, IPv6Address) and ip.ipv4_mapped:
|
||||
return str(ip.ipv4_mapped)
|
||||
elif isinstance(ip, IPv4Address):
|
||||
return str(ip)
|
||||
|
||||
|
||||
def _ip_sources(request: Request, trusted_proxies: Optional[List[str]] = None) -> str:
|
||||
|
@ -258,6 +259,6 @@ def get_request_global_ipv4(
|
|||
Optionally, a list of trusted proxies can be provided to help mitigate spoofing attacks.
|
||||
"""
|
||||
for ip_str in _ip_sources(request=request, trusted_proxies=trusted_proxies):
|
||||
ipv4_address = _ipv6_to_ipv4(ip_str)
|
||||
ipv4_address = _resolve_ipv4(ip_str)
|
||||
if ipv4_address and _is_global_ipv4(ipv4_address):
|
||||
return ipv4_address
|
||||
|
|
|
@ -14,6 +14,7 @@ def _policy_info_kwargs(enacted_policy):
|
|||
alice_verifying_key=enacted_policy.publisher_verifying_key,
|
||||
)
|
||||
|
||||
|
||||
def test_retrieval_kit(enacted_policy, ursulas):
|
||||
messages, message_kits = make_message_kits(enacted_policy.public_key)
|
||||
|
||||
|
|
Loading…
Reference in New Issue