Add files using upload-large-folder tool
Browse files- tool_server/.venv/lib/python3.12/site-packages/dns/dnssecalgs/__init__.py +121 -0
- tool_server/.venv/lib/python3.12/site-packages/dns/dnssecalgs/base.py +89 -0
- tool_server/.venv/lib/python3.12/site-packages/dns/dnssecalgs/cryptography.py +68 -0
- tool_server/.venv/lib/python3.12/site-packages/dns/dnssecalgs/dsa.py +106 -0
- tool_server/.venv/lib/python3.12/site-packages/dns/dnssecalgs/ecdsa.py +97 -0
- tool_server/.venv/lib/python3.12/site-packages/dns/dnssecalgs/eddsa.py +70 -0
- tool_server/.venv/lib/python3.12/site-packages/dns/dnssecalgs/rsa.py +124 -0
- tool_server/.venv/lib/python3.12/site-packages/dns/quic/__init__.py +80 -0
- tool_server/.venv/lib/python3.12/site-packages/dns/quic/_asyncio.py +267 -0
- tool_server/.venv/lib/python3.12/site-packages/dns/quic/_common.py +339 -0
- tool_server/.venv/lib/python3.12/site-packages/dns/quic/_sync.py +295 -0
- tool_server/.venv/lib/python3.12/site-packages/dns/quic/_trio.py +246 -0
- tool_server/.venv/lib/python3.12/site-packages/dns/rdtypes/__init__.py +33 -0
- tool_server/.venv/lib/python3.12/site-packages/dns/rdtypes/dnskeybase.py +87 -0
- tool_server/.venv/lib/python3.12/site-packages/dns/rdtypes/dsbase.py +85 -0
- tool_server/.venv/lib/python3.12/site-packages/dns/rdtypes/euibase.py +70 -0
- tool_server/.venv/lib/python3.12/site-packages/dns/rdtypes/mxbase.py +87 -0
- tool_server/.venv/lib/python3.12/site-packages/dns/rdtypes/nsbase.py +63 -0
- tool_server/.venv/lib/python3.12/site-packages/dns/rdtypes/svcbbase.py +585 -0
- tool_server/.venv/lib/python3.12/site-packages/dns/rdtypes/tlsabase.py +71 -0
tool_server/.venv/lib/python3.12/site-packages/dns/dnssecalgs/__init__.py
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Dict, Optional, Tuple, Type, Union
|
| 2 |
+
|
| 3 |
+
import dns.name
|
| 4 |
+
from dns.dnssecalgs.base import GenericPrivateKey
|
| 5 |
+
from dns.dnssectypes import Algorithm
|
| 6 |
+
from dns.exception import UnsupportedAlgorithm
|
| 7 |
+
from dns.rdtypes.ANY.DNSKEY import DNSKEY
|
| 8 |
+
|
| 9 |
+
if dns._features.have("dnssec"):
|
| 10 |
+
from dns.dnssecalgs.dsa import PrivateDSA, PrivateDSANSEC3SHA1
|
| 11 |
+
from dns.dnssecalgs.ecdsa import PrivateECDSAP256SHA256, PrivateECDSAP384SHA384
|
| 12 |
+
from dns.dnssecalgs.eddsa import PrivateED448, PrivateED25519
|
| 13 |
+
from dns.dnssecalgs.rsa import (
|
| 14 |
+
PrivateRSAMD5,
|
| 15 |
+
PrivateRSASHA1,
|
| 16 |
+
PrivateRSASHA1NSEC3SHA1,
|
| 17 |
+
PrivateRSASHA256,
|
| 18 |
+
PrivateRSASHA512,
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
_have_cryptography = True
|
| 22 |
+
else:
|
| 23 |
+
_have_cryptography = False
|
| 24 |
+
|
| 25 |
+
AlgorithmPrefix = Optional[Union[bytes, dns.name.Name]]
|
| 26 |
+
|
| 27 |
+
algorithms: Dict[Tuple[Algorithm, AlgorithmPrefix], Type[GenericPrivateKey]] = {}
|
| 28 |
+
if _have_cryptography:
|
| 29 |
+
# pylint: disable=possibly-used-before-assignment
|
| 30 |
+
algorithms.update(
|
| 31 |
+
{
|
| 32 |
+
(Algorithm.RSAMD5, None): PrivateRSAMD5,
|
| 33 |
+
(Algorithm.DSA, None): PrivateDSA,
|
| 34 |
+
(Algorithm.RSASHA1, None): PrivateRSASHA1,
|
| 35 |
+
(Algorithm.DSANSEC3SHA1, None): PrivateDSANSEC3SHA1,
|
| 36 |
+
(Algorithm.RSASHA1NSEC3SHA1, None): PrivateRSASHA1NSEC3SHA1,
|
| 37 |
+
(Algorithm.RSASHA256, None): PrivateRSASHA256,
|
| 38 |
+
(Algorithm.RSASHA512, None): PrivateRSASHA512,
|
| 39 |
+
(Algorithm.ECDSAP256SHA256, None): PrivateECDSAP256SHA256,
|
| 40 |
+
(Algorithm.ECDSAP384SHA384, None): PrivateECDSAP384SHA384,
|
| 41 |
+
(Algorithm.ED25519, None): PrivateED25519,
|
| 42 |
+
(Algorithm.ED448, None): PrivateED448,
|
| 43 |
+
}
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def get_algorithm_cls(
|
| 48 |
+
algorithm: Union[int, str], prefix: AlgorithmPrefix = None
|
| 49 |
+
) -> Type[GenericPrivateKey]:
|
| 50 |
+
"""Get Private Key class from Algorithm.
|
| 51 |
+
|
| 52 |
+
*algorithm*, a ``str`` or ``int`` specifying the DNSKEY algorithm.
|
| 53 |
+
|
| 54 |
+
Raises ``UnsupportedAlgorithm`` if the algorithm is unknown.
|
| 55 |
+
|
| 56 |
+
Returns a ``dns.dnssecalgs.GenericPrivateKey``
|
| 57 |
+
"""
|
| 58 |
+
algorithm = Algorithm.make(algorithm)
|
| 59 |
+
cls = algorithms.get((algorithm, prefix))
|
| 60 |
+
if cls:
|
| 61 |
+
return cls
|
| 62 |
+
raise UnsupportedAlgorithm(
|
| 63 |
+
f'algorithm "{Algorithm.to_text(algorithm)}" not supported by dnspython'
|
| 64 |
+
)
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
def get_algorithm_cls_from_dnskey(dnskey: DNSKEY) -> Type[GenericPrivateKey]:
|
| 68 |
+
"""Get Private Key class from DNSKEY.
|
| 69 |
+
|
| 70 |
+
*dnskey*, a ``DNSKEY`` to get Algorithm class for.
|
| 71 |
+
|
| 72 |
+
Raises ``UnsupportedAlgorithm`` if the algorithm is unknown.
|
| 73 |
+
|
| 74 |
+
Returns a ``dns.dnssecalgs.GenericPrivateKey``
|
| 75 |
+
"""
|
| 76 |
+
prefix: AlgorithmPrefix = None
|
| 77 |
+
if dnskey.algorithm == Algorithm.PRIVATEDNS:
|
| 78 |
+
prefix, _ = dns.name.from_wire(dnskey.key, 0)
|
| 79 |
+
elif dnskey.algorithm == Algorithm.PRIVATEOID:
|
| 80 |
+
length = int(dnskey.key[0])
|
| 81 |
+
prefix = dnskey.key[0 : length + 1]
|
| 82 |
+
return get_algorithm_cls(dnskey.algorithm, prefix)
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
def register_algorithm_cls(
|
| 86 |
+
algorithm: Union[int, str],
|
| 87 |
+
algorithm_cls: Type[GenericPrivateKey],
|
| 88 |
+
name: Optional[Union[dns.name.Name, str]] = None,
|
| 89 |
+
oid: Optional[bytes] = None,
|
| 90 |
+
) -> None:
|
| 91 |
+
"""Register Algorithm Private Key class.
|
| 92 |
+
|
| 93 |
+
*algorithm*, a ``str`` or ``int`` specifying the DNSKEY algorithm.
|
| 94 |
+
|
| 95 |
+
*algorithm_cls*: A `GenericPrivateKey` class.
|
| 96 |
+
|
| 97 |
+
*name*, an optional ``dns.name.Name`` or ``str``, for for PRIVATEDNS algorithms.
|
| 98 |
+
|
| 99 |
+
*oid*: an optional BER-encoded `bytes` for PRIVATEOID algorithms.
|
| 100 |
+
|
| 101 |
+
Raises ``ValueError`` if a name or oid is specified incorrectly.
|
| 102 |
+
"""
|
| 103 |
+
if not issubclass(algorithm_cls, GenericPrivateKey):
|
| 104 |
+
raise TypeError("Invalid algorithm class")
|
| 105 |
+
algorithm = Algorithm.make(algorithm)
|
| 106 |
+
prefix: AlgorithmPrefix = None
|
| 107 |
+
if algorithm == Algorithm.PRIVATEDNS:
|
| 108 |
+
if name is None:
|
| 109 |
+
raise ValueError("Name required for PRIVATEDNS algorithms")
|
| 110 |
+
if isinstance(name, str):
|
| 111 |
+
name = dns.name.from_text(name)
|
| 112 |
+
prefix = name
|
| 113 |
+
elif algorithm == Algorithm.PRIVATEOID:
|
| 114 |
+
if oid is None:
|
| 115 |
+
raise ValueError("OID required for PRIVATEOID algorithms")
|
| 116 |
+
prefix = bytes([len(oid)]) + oid
|
| 117 |
+
elif name:
|
| 118 |
+
raise ValueError("Name only supported for PRIVATEDNS algorithm")
|
| 119 |
+
elif oid:
|
| 120 |
+
raise ValueError("OID only supported for PRIVATEOID algorithm")
|
| 121 |
+
algorithms[(algorithm, prefix)] = algorithm_cls
|
tool_server/.venv/lib/python3.12/site-packages/dns/dnssecalgs/base.py
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from abc import ABC, abstractmethod # pylint: disable=no-name-in-module
|
| 2 |
+
from typing import Any, Optional, Type
|
| 3 |
+
|
| 4 |
+
import dns.rdataclass
|
| 5 |
+
import dns.rdatatype
|
| 6 |
+
from dns.dnssectypes import Algorithm
|
| 7 |
+
from dns.exception import AlgorithmKeyMismatch
|
| 8 |
+
from dns.rdtypes.ANY.DNSKEY import DNSKEY
|
| 9 |
+
from dns.rdtypes.dnskeybase import Flag
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
class GenericPublicKey(ABC):
|
| 13 |
+
algorithm: Algorithm
|
| 14 |
+
|
| 15 |
+
@abstractmethod
|
| 16 |
+
def __init__(self, key: Any) -> None:
|
| 17 |
+
pass
|
| 18 |
+
|
| 19 |
+
@abstractmethod
|
| 20 |
+
def verify(self, signature: bytes, data: bytes) -> None:
|
| 21 |
+
"""Verify signed DNSSEC data"""
|
| 22 |
+
|
| 23 |
+
@abstractmethod
|
| 24 |
+
def encode_key_bytes(self) -> bytes:
|
| 25 |
+
"""Encode key as bytes for DNSKEY"""
|
| 26 |
+
|
| 27 |
+
@classmethod
|
| 28 |
+
def _ensure_algorithm_key_combination(cls, key: DNSKEY) -> None:
|
| 29 |
+
if key.algorithm != cls.algorithm:
|
| 30 |
+
raise AlgorithmKeyMismatch
|
| 31 |
+
|
| 32 |
+
def to_dnskey(self, flags: int = Flag.ZONE, protocol: int = 3) -> DNSKEY:
|
| 33 |
+
"""Return public key as DNSKEY"""
|
| 34 |
+
return DNSKEY(
|
| 35 |
+
rdclass=dns.rdataclass.IN,
|
| 36 |
+
rdtype=dns.rdatatype.DNSKEY,
|
| 37 |
+
flags=flags,
|
| 38 |
+
protocol=protocol,
|
| 39 |
+
algorithm=self.algorithm,
|
| 40 |
+
key=self.encode_key_bytes(),
|
| 41 |
+
)
|
| 42 |
+
|
| 43 |
+
@classmethod
|
| 44 |
+
@abstractmethod
|
| 45 |
+
def from_dnskey(cls, key: DNSKEY) -> "GenericPublicKey":
|
| 46 |
+
"""Create public key from DNSKEY"""
|
| 47 |
+
|
| 48 |
+
@classmethod
|
| 49 |
+
@abstractmethod
|
| 50 |
+
def from_pem(cls, public_pem: bytes) -> "GenericPublicKey":
|
| 51 |
+
"""Create public key from PEM-encoded SubjectPublicKeyInfo as specified
|
| 52 |
+
in RFC 5280"""
|
| 53 |
+
|
| 54 |
+
@abstractmethod
|
| 55 |
+
def to_pem(self) -> bytes:
|
| 56 |
+
"""Return public-key as PEM-encoded SubjectPublicKeyInfo as specified
|
| 57 |
+
in RFC 5280"""
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
class GenericPrivateKey(ABC):
|
| 61 |
+
public_cls: Type[GenericPublicKey]
|
| 62 |
+
|
| 63 |
+
@abstractmethod
|
| 64 |
+
def __init__(self, key: Any) -> None:
|
| 65 |
+
pass
|
| 66 |
+
|
| 67 |
+
@abstractmethod
|
| 68 |
+
def sign(
|
| 69 |
+
self,
|
| 70 |
+
data: bytes,
|
| 71 |
+
verify: bool = False,
|
| 72 |
+
deterministic: bool = True,
|
| 73 |
+
) -> bytes:
|
| 74 |
+
"""Sign DNSSEC data"""
|
| 75 |
+
|
| 76 |
+
@abstractmethod
|
| 77 |
+
def public_key(self) -> "GenericPublicKey":
|
| 78 |
+
"""Return public key instance"""
|
| 79 |
+
|
| 80 |
+
@classmethod
|
| 81 |
+
@abstractmethod
|
| 82 |
+
def from_pem(
|
| 83 |
+
cls, private_pem: bytes, password: Optional[bytes] = None
|
| 84 |
+
) -> "GenericPrivateKey":
|
| 85 |
+
"""Create private key from PEM-encoded PKCS#8"""
|
| 86 |
+
|
| 87 |
+
@abstractmethod
|
| 88 |
+
def to_pem(self, password: Optional[bytes] = None) -> bytes:
|
| 89 |
+
"""Return private key as PEM-encoded PKCS#8"""
|
tool_server/.venv/lib/python3.12/site-packages/dns/dnssecalgs/cryptography.py
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Any, Optional, Type
|
| 2 |
+
|
| 3 |
+
from cryptography.hazmat.primitives import serialization
|
| 4 |
+
|
| 5 |
+
from dns.dnssecalgs.base import GenericPrivateKey, GenericPublicKey
|
| 6 |
+
from dns.exception import AlgorithmKeyMismatch
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class CryptographyPublicKey(GenericPublicKey):
|
| 10 |
+
key: Any = None
|
| 11 |
+
key_cls: Any = None
|
| 12 |
+
|
| 13 |
+
def __init__(self, key: Any) -> None: # pylint: disable=super-init-not-called
|
| 14 |
+
if self.key_cls is None:
|
| 15 |
+
raise TypeError("Undefined private key class")
|
| 16 |
+
if not isinstance( # pylint: disable=isinstance-second-argument-not-valid-type
|
| 17 |
+
key, self.key_cls
|
| 18 |
+
):
|
| 19 |
+
raise AlgorithmKeyMismatch
|
| 20 |
+
self.key = key
|
| 21 |
+
|
| 22 |
+
@classmethod
|
| 23 |
+
def from_pem(cls, public_pem: bytes) -> "GenericPublicKey":
|
| 24 |
+
key = serialization.load_pem_public_key(public_pem)
|
| 25 |
+
return cls(key=key)
|
| 26 |
+
|
| 27 |
+
def to_pem(self) -> bytes:
|
| 28 |
+
return self.key.public_bytes(
|
| 29 |
+
encoding=serialization.Encoding.PEM,
|
| 30 |
+
format=serialization.PublicFormat.SubjectPublicKeyInfo,
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
class CryptographyPrivateKey(GenericPrivateKey):
|
| 35 |
+
key: Any = None
|
| 36 |
+
key_cls: Any = None
|
| 37 |
+
public_cls: Type[CryptographyPublicKey]
|
| 38 |
+
|
| 39 |
+
def __init__(self, key: Any) -> None: # pylint: disable=super-init-not-called
|
| 40 |
+
if self.key_cls is None:
|
| 41 |
+
raise TypeError("Undefined private key class")
|
| 42 |
+
if not isinstance( # pylint: disable=isinstance-second-argument-not-valid-type
|
| 43 |
+
key, self.key_cls
|
| 44 |
+
):
|
| 45 |
+
raise AlgorithmKeyMismatch
|
| 46 |
+
self.key = key
|
| 47 |
+
|
| 48 |
+
def public_key(self) -> "CryptographyPublicKey":
|
| 49 |
+
return self.public_cls(key=self.key.public_key())
|
| 50 |
+
|
| 51 |
+
@classmethod
|
| 52 |
+
def from_pem(
|
| 53 |
+
cls, private_pem: bytes, password: Optional[bytes] = None
|
| 54 |
+
) -> "GenericPrivateKey":
|
| 55 |
+
key = serialization.load_pem_private_key(private_pem, password=password)
|
| 56 |
+
return cls(key=key)
|
| 57 |
+
|
| 58 |
+
def to_pem(self, password: Optional[bytes] = None) -> bytes:
|
| 59 |
+
encryption_algorithm: serialization.KeySerializationEncryption
|
| 60 |
+
if password:
|
| 61 |
+
encryption_algorithm = serialization.BestAvailableEncryption(password)
|
| 62 |
+
else:
|
| 63 |
+
encryption_algorithm = serialization.NoEncryption()
|
| 64 |
+
return self.key.private_bytes(
|
| 65 |
+
encoding=serialization.Encoding.PEM,
|
| 66 |
+
format=serialization.PrivateFormat.PKCS8,
|
| 67 |
+
encryption_algorithm=encryption_algorithm,
|
| 68 |
+
)
|
tool_server/.venv/lib/python3.12/site-packages/dns/dnssecalgs/dsa.py
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import struct
|
| 2 |
+
|
| 3 |
+
from cryptography.hazmat.backends import default_backend
|
| 4 |
+
from cryptography.hazmat.primitives import hashes
|
| 5 |
+
from cryptography.hazmat.primitives.asymmetric import dsa, utils
|
| 6 |
+
|
| 7 |
+
from dns.dnssecalgs.cryptography import CryptographyPrivateKey, CryptographyPublicKey
|
| 8 |
+
from dns.dnssectypes import Algorithm
|
| 9 |
+
from dns.rdtypes.ANY.DNSKEY import DNSKEY
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
class PublicDSA(CryptographyPublicKey):
|
| 13 |
+
key: dsa.DSAPublicKey
|
| 14 |
+
key_cls = dsa.DSAPublicKey
|
| 15 |
+
algorithm = Algorithm.DSA
|
| 16 |
+
chosen_hash = hashes.SHA1()
|
| 17 |
+
|
| 18 |
+
def verify(self, signature: bytes, data: bytes) -> None:
|
| 19 |
+
sig_r = signature[1:21]
|
| 20 |
+
sig_s = signature[21:]
|
| 21 |
+
sig = utils.encode_dss_signature(
|
| 22 |
+
int.from_bytes(sig_r, "big"), int.from_bytes(sig_s, "big")
|
| 23 |
+
)
|
| 24 |
+
self.key.verify(sig, data, self.chosen_hash)
|
| 25 |
+
|
| 26 |
+
def encode_key_bytes(self) -> bytes:
|
| 27 |
+
"""Encode a public key per RFC 2536, section 2."""
|
| 28 |
+
pn = self.key.public_numbers()
|
| 29 |
+
dsa_t = (self.key.key_size // 8 - 64) // 8
|
| 30 |
+
if dsa_t > 8:
|
| 31 |
+
raise ValueError("unsupported DSA key size")
|
| 32 |
+
octets = 64 + dsa_t * 8
|
| 33 |
+
res = struct.pack("!B", dsa_t)
|
| 34 |
+
res += pn.parameter_numbers.q.to_bytes(20, "big")
|
| 35 |
+
res += pn.parameter_numbers.p.to_bytes(octets, "big")
|
| 36 |
+
res += pn.parameter_numbers.g.to_bytes(octets, "big")
|
| 37 |
+
res += pn.y.to_bytes(octets, "big")
|
| 38 |
+
return res
|
| 39 |
+
|
| 40 |
+
@classmethod
|
| 41 |
+
def from_dnskey(cls, key: DNSKEY) -> "PublicDSA":
|
| 42 |
+
cls._ensure_algorithm_key_combination(key)
|
| 43 |
+
keyptr = key.key
|
| 44 |
+
(t,) = struct.unpack("!B", keyptr[0:1])
|
| 45 |
+
keyptr = keyptr[1:]
|
| 46 |
+
octets = 64 + t * 8
|
| 47 |
+
dsa_q = keyptr[0:20]
|
| 48 |
+
keyptr = keyptr[20:]
|
| 49 |
+
dsa_p = keyptr[0:octets]
|
| 50 |
+
keyptr = keyptr[octets:]
|
| 51 |
+
dsa_g = keyptr[0:octets]
|
| 52 |
+
keyptr = keyptr[octets:]
|
| 53 |
+
dsa_y = keyptr[0:octets]
|
| 54 |
+
return cls(
|
| 55 |
+
key=dsa.DSAPublicNumbers( # type: ignore
|
| 56 |
+
int.from_bytes(dsa_y, "big"),
|
| 57 |
+
dsa.DSAParameterNumbers(
|
| 58 |
+
int.from_bytes(dsa_p, "big"),
|
| 59 |
+
int.from_bytes(dsa_q, "big"),
|
| 60 |
+
int.from_bytes(dsa_g, "big"),
|
| 61 |
+
),
|
| 62 |
+
).public_key(default_backend()),
|
| 63 |
+
)
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
class PrivateDSA(CryptographyPrivateKey):
|
| 67 |
+
key: dsa.DSAPrivateKey
|
| 68 |
+
key_cls = dsa.DSAPrivateKey
|
| 69 |
+
public_cls = PublicDSA
|
| 70 |
+
|
| 71 |
+
def sign(
|
| 72 |
+
self,
|
| 73 |
+
data: bytes,
|
| 74 |
+
verify: bool = False,
|
| 75 |
+
deterministic: bool = True,
|
| 76 |
+
) -> bytes:
|
| 77 |
+
"""Sign using a private key per RFC 2536, section 3."""
|
| 78 |
+
public_dsa_key = self.key.public_key()
|
| 79 |
+
if public_dsa_key.key_size > 1024:
|
| 80 |
+
raise ValueError("DSA key size overflow")
|
| 81 |
+
der_signature = self.key.sign(data, self.public_cls.chosen_hash)
|
| 82 |
+
dsa_r, dsa_s = utils.decode_dss_signature(der_signature)
|
| 83 |
+
dsa_t = (public_dsa_key.key_size // 8 - 64) // 8
|
| 84 |
+
octets = 20
|
| 85 |
+
signature = (
|
| 86 |
+
struct.pack("!B", dsa_t)
|
| 87 |
+
+ int.to_bytes(dsa_r, length=octets, byteorder="big")
|
| 88 |
+
+ int.to_bytes(dsa_s, length=octets, byteorder="big")
|
| 89 |
+
)
|
| 90 |
+
if verify:
|
| 91 |
+
self.public_key().verify(signature, data)
|
| 92 |
+
return signature
|
| 93 |
+
|
| 94 |
+
@classmethod
|
| 95 |
+
def generate(cls, key_size: int) -> "PrivateDSA":
|
| 96 |
+
return cls(
|
| 97 |
+
key=dsa.generate_private_key(key_size=key_size),
|
| 98 |
+
)
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
class PublicDSANSEC3SHA1(PublicDSA):
|
| 102 |
+
algorithm = Algorithm.DSANSEC3SHA1
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
class PrivateDSANSEC3SHA1(PrivateDSA):
|
| 106 |
+
public_cls = PublicDSANSEC3SHA1
|
tool_server/.venv/lib/python3.12/site-packages/dns/dnssecalgs/ecdsa.py
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from cryptography.hazmat.backends import default_backend
|
| 2 |
+
from cryptography.hazmat.primitives import hashes
|
| 3 |
+
from cryptography.hazmat.primitives.asymmetric import ec, utils
|
| 4 |
+
|
| 5 |
+
from dns.dnssecalgs.cryptography import CryptographyPrivateKey, CryptographyPublicKey
|
| 6 |
+
from dns.dnssectypes import Algorithm
|
| 7 |
+
from dns.rdtypes.ANY.DNSKEY import DNSKEY
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
class PublicECDSA(CryptographyPublicKey):
|
| 11 |
+
key: ec.EllipticCurvePublicKey
|
| 12 |
+
key_cls = ec.EllipticCurvePublicKey
|
| 13 |
+
algorithm: Algorithm
|
| 14 |
+
chosen_hash: hashes.HashAlgorithm
|
| 15 |
+
curve: ec.EllipticCurve
|
| 16 |
+
octets: int
|
| 17 |
+
|
| 18 |
+
def verify(self, signature: bytes, data: bytes) -> None:
|
| 19 |
+
sig_r = signature[0 : self.octets]
|
| 20 |
+
sig_s = signature[self.octets :]
|
| 21 |
+
sig = utils.encode_dss_signature(
|
| 22 |
+
int.from_bytes(sig_r, "big"), int.from_bytes(sig_s, "big")
|
| 23 |
+
)
|
| 24 |
+
self.key.verify(sig, data, ec.ECDSA(self.chosen_hash))
|
| 25 |
+
|
| 26 |
+
def encode_key_bytes(self) -> bytes:
|
| 27 |
+
"""Encode a public key per RFC 6605, section 4."""
|
| 28 |
+
pn = self.key.public_numbers()
|
| 29 |
+
return pn.x.to_bytes(self.octets, "big") + pn.y.to_bytes(self.octets, "big")
|
| 30 |
+
|
| 31 |
+
@classmethod
|
| 32 |
+
def from_dnskey(cls, key: DNSKEY) -> "PublicECDSA":
|
| 33 |
+
cls._ensure_algorithm_key_combination(key)
|
| 34 |
+
ecdsa_x = key.key[0 : cls.octets]
|
| 35 |
+
ecdsa_y = key.key[cls.octets : cls.octets * 2]
|
| 36 |
+
return cls(
|
| 37 |
+
key=ec.EllipticCurvePublicNumbers(
|
| 38 |
+
curve=cls.curve,
|
| 39 |
+
x=int.from_bytes(ecdsa_x, "big"),
|
| 40 |
+
y=int.from_bytes(ecdsa_y, "big"),
|
| 41 |
+
).public_key(default_backend()),
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
class PrivateECDSA(CryptographyPrivateKey):
|
| 46 |
+
key: ec.EllipticCurvePrivateKey
|
| 47 |
+
key_cls = ec.EllipticCurvePrivateKey
|
| 48 |
+
public_cls = PublicECDSA
|
| 49 |
+
|
| 50 |
+
def sign(
|
| 51 |
+
self,
|
| 52 |
+
data: bytes,
|
| 53 |
+
verify: bool = False,
|
| 54 |
+
deterministic: bool = True,
|
| 55 |
+
) -> bytes:
|
| 56 |
+
"""Sign using a private key per RFC 6605, section 4."""
|
| 57 |
+
algorithm = ec.ECDSA(
|
| 58 |
+
self.public_cls.chosen_hash, deterministic_signing=deterministic
|
| 59 |
+
)
|
| 60 |
+
der_signature = self.key.sign(data, algorithm)
|
| 61 |
+
dsa_r, dsa_s = utils.decode_dss_signature(der_signature)
|
| 62 |
+
signature = int.to_bytes(
|
| 63 |
+
dsa_r, length=self.public_cls.octets, byteorder="big"
|
| 64 |
+
) + int.to_bytes(dsa_s, length=self.public_cls.octets, byteorder="big")
|
| 65 |
+
if verify:
|
| 66 |
+
self.public_key().verify(signature, data)
|
| 67 |
+
return signature
|
| 68 |
+
|
| 69 |
+
@classmethod
|
| 70 |
+
def generate(cls) -> "PrivateECDSA":
|
| 71 |
+
return cls(
|
| 72 |
+
key=ec.generate_private_key(
|
| 73 |
+
curve=cls.public_cls.curve, backend=default_backend()
|
| 74 |
+
),
|
| 75 |
+
)
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
class PublicECDSAP256SHA256(PublicECDSA):
|
| 79 |
+
algorithm = Algorithm.ECDSAP256SHA256
|
| 80 |
+
chosen_hash = hashes.SHA256()
|
| 81 |
+
curve = ec.SECP256R1()
|
| 82 |
+
octets = 32
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
class PrivateECDSAP256SHA256(PrivateECDSA):
|
| 86 |
+
public_cls = PublicECDSAP256SHA256
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
class PublicECDSAP384SHA384(PublicECDSA):
|
| 90 |
+
algorithm = Algorithm.ECDSAP384SHA384
|
| 91 |
+
chosen_hash = hashes.SHA384()
|
| 92 |
+
curve = ec.SECP384R1()
|
| 93 |
+
octets = 48
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
class PrivateECDSAP384SHA384(PrivateECDSA):
|
| 97 |
+
public_cls = PublicECDSAP384SHA384
|
tool_server/.venv/lib/python3.12/site-packages/dns/dnssecalgs/eddsa.py
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Type
|
| 2 |
+
|
| 3 |
+
from cryptography.hazmat.primitives import serialization
|
| 4 |
+
from cryptography.hazmat.primitives.asymmetric import ed448, ed25519
|
| 5 |
+
|
| 6 |
+
from dns.dnssecalgs.cryptography import CryptographyPrivateKey, CryptographyPublicKey
|
| 7 |
+
from dns.dnssectypes import Algorithm
|
| 8 |
+
from dns.rdtypes.ANY.DNSKEY import DNSKEY
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
class PublicEDDSA(CryptographyPublicKey):
|
| 12 |
+
def verify(self, signature: bytes, data: bytes) -> None:
|
| 13 |
+
self.key.verify(signature, data)
|
| 14 |
+
|
| 15 |
+
def encode_key_bytes(self) -> bytes:
|
| 16 |
+
"""Encode a public key per RFC 8080, section 3."""
|
| 17 |
+
return self.key.public_bytes(
|
| 18 |
+
encoding=serialization.Encoding.Raw, format=serialization.PublicFormat.Raw
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
@classmethod
|
| 22 |
+
def from_dnskey(cls, key: DNSKEY) -> "PublicEDDSA":
|
| 23 |
+
cls._ensure_algorithm_key_combination(key)
|
| 24 |
+
return cls(
|
| 25 |
+
key=cls.key_cls.from_public_bytes(key.key),
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
class PrivateEDDSA(CryptographyPrivateKey):
|
| 30 |
+
public_cls: Type[PublicEDDSA]
|
| 31 |
+
|
| 32 |
+
def sign(
|
| 33 |
+
self,
|
| 34 |
+
data: bytes,
|
| 35 |
+
verify: bool = False,
|
| 36 |
+
deterministic: bool = True,
|
| 37 |
+
) -> bytes:
|
| 38 |
+
"""Sign using a private key per RFC 8080, section 4."""
|
| 39 |
+
signature = self.key.sign(data)
|
| 40 |
+
if verify:
|
| 41 |
+
self.public_key().verify(signature, data)
|
| 42 |
+
return signature
|
| 43 |
+
|
| 44 |
+
@classmethod
|
| 45 |
+
def generate(cls) -> "PrivateEDDSA":
|
| 46 |
+
return cls(key=cls.key_cls.generate())
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
class PublicED25519(PublicEDDSA):
|
| 50 |
+
key: ed25519.Ed25519PublicKey
|
| 51 |
+
key_cls = ed25519.Ed25519PublicKey
|
| 52 |
+
algorithm = Algorithm.ED25519
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
class PrivateED25519(PrivateEDDSA):
|
| 56 |
+
key: ed25519.Ed25519PrivateKey
|
| 57 |
+
key_cls = ed25519.Ed25519PrivateKey
|
| 58 |
+
public_cls = PublicED25519
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
class PublicED448(PublicEDDSA):
|
| 62 |
+
key: ed448.Ed448PublicKey
|
| 63 |
+
key_cls = ed448.Ed448PublicKey
|
| 64 |
+
algorithm = Algorithm.ED448
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
class PrivateED448(PrivateEDDSA):
|
| 68 |
+
key: ed448.Ed448PrivateKey
|
| 69 |
+
key_cls = ed448.Ed448PrivateKey
|
| 70 |
+
public_cls = PublicED448
|
tool_server/.venv/lib/python3.12/site-packages/dns/dnssecalgs/rsa.py
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import math
|
| 2 |
+
import struct
|
| 3 |
+
|
| 4 |
+
from cryptography.hazmat.backends import default_backend
|
| 5 |
+
from cryptography.hazmat.primitives import hashes
|
| 6 |
+
from cryptography.hazmat.primitives.asymmetric import padding, rsa
|
| 7 |
+
|
| 8 |
+
from dns.dnssecalgs.cryptography import CryptographyPrivateKey, CryptographyPublicKey
|
| 9 |
+
from dns.dnssectypes import Algorithm
|
| 10 |
+
from dns.rdtypes.ANY.DNSKEY import DNSKEY
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
class PublicRSA(CryptographyPublicKey):
|
| 14 |
+
key: rsa.RSAPublicKey
|
| 15 |
+
key_cls = rsa.RSAPublicKey
|
| 16 |
+
algorithm: Algorithm
|
| 17 |
+
chosen_hash: hashes.HashAlgorithm
|
| 18 |
+
|
| 19 |
+
def verify(self, signature: bytes, data: bytes) -> None:
|
| 20 |
+
self.key.verify(signature, data, padding.PKCS1v15(), self.chosen_hash)
|
| 21 |
+
|
| 22 |
+
def encode_key_bytes(self) -> bytes:
|
| 23 |
+
"""Encode a public key per RFC 3110, section 2."""
|
| 24 |
+
pn = self.key.public_numbers()
|
| 25 |
+
_exp_len = math.ceil(int.bit_length(pn.e) / 8)
|
| 26 |
+
exp = int.to_bytes(pn.e, length=_exp_len, byteorder="big")
|
| 27 |
+
if _exp_len > 255:
|
| 28 |
+
exp_header = b"\0" + struct.pack("!H", _exp_len)
|
| 29 |
+
else:
|
| 30 |
+
exp_header = struct.pack("!B", _exp_len)
|
| 31 |
+
if pn.n.bit_length() < 512 or pn.n.bit_length() > 4096:
|
| 32 |
+
raise ValueError("unsupported RSA key length")
|
| 33 |
+
return exp_header + exp + pn.n.to_bytes((pn.n.bit_length() + 7) // 8, "big")
|
| 34 |
+
|
| 35 |
+
@classmethod
|
| 36 |
+
def from_dnskey(cls, key: DNSKEY) -> "PublicRSA":
|
| 37 |
+
cls._ensure_algorithm_key_combination(key)
|
| 38 |
+
keyptr = key.key
|
| 39 |
+
(bytes_,) = struct.unpack("!B", keyptr[0:1])
|
| 40 |
+
keyptr = keyptr[1:]
|
| 41 |
+
if bytes_ == 0:
|
| 42 |
+
(bytes_,) = struct.unpack("!H", keyptr[0:2])
|
| 43 |
+
keyptr = keyptr[2:]
|
| 44 |
+
rsa_e = keyptr[0:bytes_]
|
| 45 |
+
rsa_n = keyptr[bytes_:]
|
| 46 |
+
return cls(
|
| 47 |
+
key=rsa.RSAPublicNumbers(
|
| 48 |
+
int.from_bytes(rsa_e, "big"), int.from_bytes(rsa_n, "big")
|
| 49 |
+
).public_key(default_backend())
|
| 50 |
+
)
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
class PrivateRSA(CryptographyPrivateKey):
|
| 54 |
+
key: rsa.RSAPrivateKey
|
| 55 |
+
key_cls = rsa.RSAPrivateKey
|
| 56 |
+
public_cls = PublicRSA
|
| 57 |
+
default_public_exponent = 65537
|
| 58 |
+
|
| 59 |
+
def sign(
|
| 60 |
+
self,
|
| 61 |
+
data: bytes,
|
| 62 |
+
verify: bool = False,
|
| 63 |
+
deterministic: bool = True,
|
| 64 |
+
) -> bytes:
|
| 65 |
+
"""Sign using a private key per RFC 3110, section 3."""
|
| 66 |
+
signature = self.key.sign(data, padding.PKCS1v15(), self.public_cls.chosen_hash)
|
| 67 |
+
if verify:
|
| 68 |
+
self.public_key().verify(signature, data)
|
| 69 |
+
return signature
|
| 70 |
+
|
| 71 |
+
@classmethod
|
| 72 |
+
def generate(cls, key_size: int) -> "PrivateRSA":
|
| 73 |
+
return cls(
|
| 74 |
+
key=rsa.generate_private_key(
|
| 75 |
+
public_exponent=cls.default_public_exponent,
|
| 76 |
+
key_size=key_size,
|
| 77 |
+
backend=default_backend(),
|
| 78 |
+
)
|
| 79 |
+
)
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
class PublicRSAMD5(PublicRSA):
|
| 83 |
+
algorithm = Algorithm.RSAMD5
|
| 84 |
+
chosen_hash = hashes.MD5()
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
class PrivateRSAMD5(PrivateRSA):
|
| 88 |
+
public_cls = PublicRSAMD5
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
class PublicRSASHA1(PublicRSA):
|
| 92 |
+
algorithm = Algorithm.RSASHA1
|
| 93 |
+
chosen_hash = hashes.SHA1()
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
class PrivateRSASHA1(PrivateRSA):
|
| 97 |
+
public_cls = PublicRSASHA1
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
class PublicRSASHA1NSEC3SHA1(PublicRSA):
|
| 101 |
+
algorithm = Algorithm.RSASHA1NSEC3SHA1
|
| 102 |
+
chosen_hash = hashes.SHA1()
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
class PrivateRSASHA1NSEC3SHA1(PrivateRSA):
|
| 106 |
+
public_cls = PublicRSASHA1NSEC3SHA1
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
class PublicRSASHA256(PublicRSA):
|
| 110 |
+
algorithm = Algorithm.RSASHA256
|
| 111 |
+
chosen_hash = hashes.SHA256()
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
class PrivateRSASHA256(PrivateRSA):
|
| 115 |
+
public_cls = PublicRSASHA256
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
class PublicRSASHA512(PublicRSA):
|
| 119 |
+
algorithm = Algorithm.RSASHA512
|
| 120 |
+
chosen_hash = hashes.SHA512()
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
class PrivateRSASHA512(PrivateRSA):
|
| 124 |
+
public_cls = PublicRSASHA512
|
tool_server/.venv/lib/python3.12/site-packages/dns/quic/__init__.py
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license
|
| 2 |
+
|
| 3 |
+
from typing import List, Tuple
|
| 4 |
+
|
| 5 |
+
import dns._features
|
| 6 |
+
import dns.asyncbackend
|
| 7 |
+
|
| 8 |
+
if dns._features.have("doq"):
|
| 9 |
+
import aioquic.quic.configuration # type: ignore
|
| 10 |
+
|
| 11 |
+
from dns._asyncbackend import NullContext
|
| 12 |
+
from dns.quic._asyncio import (
|
| 13 |
+
AsyncioQuicConnection,
|
| 14 |
+
AsyncioQuicManager,
|
| 15 |
+
AsyncioQuicStream,
|
| 16 |
+
)
|
| 17 |
+
from dns.quic._common import AsyncQuicConnection, AsyncQuicManager
|
| 18 |
+
from dns.quic._sync import SyncQuicConnection, SyncQuicManager, SyncQuicStream
|
| 19 |
+
|
| 20 |
+
have_quic = True
|
| 21 |
+
|
| 22 |
+
def null_factory(
|
| 23 |
+
*args, # pylint: disable=unused-argument
|
| 24 |
+
**kwargs, # pylint: disable=unused-argument
|
| 25 |
+
):
|
| 26 |
+
return NullContext(None)
|
| 27 |
+
|
| 28 |
+
def _asyncio_manager_factory(
|
| 29 |
+
context, *args, **kwargs # pylint: disable=unused-argument
|
| 30 |
+
):
|
| 31 |
+
return AsyncioQuicManager(*args, **kwargs)
|
| 32 |
+
|
| 33 |
+
# We have a context factory and a manager factory as for trio we need to have
|
| 34 |
+
# a nursery.
|
| 35 |
+
|
| 36 |
+
_async_factories = {"asyncio": (null_factory, _asyncio_manager_factory)}
|
| 37 |
+
|
| 38 |
+
if dns._features.have("trio"):
|
| 39 |
+
import trio
|
| 40 |
+
|
| 41 |
+
from dns.quic._trio import ( # pylint: disable=ungrouped-imports
|
| 42 |
+
TrioQuicConnection,
|
| 43 |
+
TrioQuicManager,
|
| 44 |
+
TrioQuicStream,
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
def _trio_context_factory():
|
| 48 |
+
return trio.open_nursery()
|
| 49 |
+
|
| 50 |
+
def _trio_manager_factory(context, *args, **kwargs):
|
| 51 |
+
return TrioQuicManager(context, *args, **kwargs)
|
| 52 |
+
|
| 53 |
+
_async_factories["trio"] = (_trio_context_factory, _trio_manager_factory)
|
| 54 |
+
|
| 55 |
+
def factories_for_backend(backend=None):
|
| 56 |
+
if backend is None:
|
| 57 |
+
backend = dns.asyncbackend.get_default_backend()
|
| 58 |
+
return _async_factories[backend.name()]
|
| 59 |
+
|
| 60 |
+
else: # pragma: no cover
|
| 61 |
+
have_quic = False
|
| 62 |
+
|
| 63 |
+
from typing import Any
|
| 64 |
+
|
| 65 |
+
class AsyncQuicStream: # type: ignore
|
| 66 |
+
pass
|
| 67 |
+
|
| 68 |
+
class AsyncQuicConnection: # type: ignore
|
| 69 |
+
async def make_stream(self) -> Any:
|
| 70 |
+
raise NotImplementedError
|
| 71 |
+
|
| 72 |
+
class SyncQuicStream: # type: ignore
|
| 73 |
+
pass
|
| 74 |
+
|
| 75 |
+
class SyncQuicConnection: # type: ignore
|
| 76 |
+
def make_stream(self) -> Any:
|
| 77 |
+
raise NotImplementedError
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
Headers = List[Tuple[bytes, bytes]]
|
tool_server/.venv/lib/python3.12/site-packages/dns/quic/_asyncio.py
ADDED
|
@@ -0,0 +1,267 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license
|
| 2 |
+
|
| 3 |
+
import asyncio
|
| 4 |
+
import socket
|
| 5 |
+
import ssl
|
| 6 |
+
import struct
|
| 7 |
+
import time
|
| 8 |
+
|
| 9 |
+
import aioquic.quic.configuration # type: ignore
|
| 10 |
+
import aioquic.quic.connection # type: ignore
|
| 11 |
+
import aioquic.quic.events # type: ignore
|
| 12 |
+
|
| 13 |
+
import dns.asyncbackend
|
| 14 |
+
import dns.exception
|
| 15 |
+
import dns.inet
|
| 16 |
+
from dns.quic._common import (
|
| 17 |
+
QUIC_MAX_DATAGRAM,
|
| 18 |
+
AsyncQuicConnection,
|
| 19 |
+
AsyncQuicManager,
|
| 20 |
+
BaseQuicStream,
|
| 21 |
+
UnexpectedEOF,
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
class AsyncioQuicStream(BaseQuicStream):
|
| 26 |
+
def __init__(self, connection, stream_id):
|
| 27 |
+
super().__init__(connection, stream_id)
|
| 28 |
+
self._wake_up = asyncio.Condition()
|
| 29 |
+
|
| 30 |
+
async def _wait_for_wake_up(self):
|
| 31 |
+
async with self._wake_up:
|
| 32 |
+
await self._wake_up.wait()
|
| 33 |
+
|
| 34 |
+
async def wait_for(self, amount, expiration):
|
| 35 |
+
while True:
|
| 36 |
+
timeout = self._timeout_from_expiration(expiration)
|
| 37 |
+
if self._buffer.have(amount):
|
| 38 |
+
return
|
| 39 |
+
self._expecting = amount
|
| 40 |
+
try:
|
| 41 |
+
await asyncio.wait_for(self._wait_for_wake_up(), timeout)
|
| 42 |
+
except TimeoutError:
|
| 43 |
+
raise dns.exception.Timeout
|
| 44 |
+
self._expecting = 0
|
| 45 |
+
|
| 46 |
+
async def wait_for_end(self, expiration):
|
| 47 |
+
while True:
|
| 48 |
+
timeout = self._timeout_from_expiration(expiration)
|
| 49 |
+
if self._buffer.seen_end():
|
| 50 |
+
return
|
| 51 |
+
try:
|
| 52 |
+
await asyncio.wait_for(self._wait_for_wake_up(), timeout)
|
| 53 |
+
except TimeoutError:
|
| 54 |
+
raise dns.exception.Timeout
|
| 55 |
+
|
| 56 |
+
async def receive(self, timeout=None):
|
| 57 |
+
expiration = self._expiration_from_timeout(timeout)
|
| 58 |
+
if self._connection.is_h3():
|
| 59 |
+
await self.wait_for_end(expiration)
|
| 60 |
+
return self._buffer.get_all()
|
| 61 |
+
else:
|
| 62 |
+
await self.wait_for(2, expiration)
|
| 63 |
+
(size,) = struct.unpack("!H", self._buffer.get(2))
|
| 64 |
+
await self.wait_for(size, expiration)
|
| 65 |
+
return self._buffer.get(size)
|
| 66 |
+
|
| 67 |
+
async def send(self, datagram, is_end=False):
|
| 68 |
+
data = self._encapsulate(datagram)
|
| 69 |
+
await self._connection.write(self._stream_id, data, is_end)
|
| 70 |
+
|
| 71 |
+
async def _add_input(self, data, is_end):
|
| 72 |
+
if self._common_add_input(data, is_end):
|
| 73 |
+
async with self._wake_up:
|
| 74 |
+
self._wake_up.notify()
|
| 75 |
+
|
| 76 |
+
async def close(self):
|
| 77 |
+
self._close()
|
| 78 |
+
|
| 79 |
+
# Streams are async context managers
|
| 80 |
+
|
| 81 |
+
async def __aenter__(self):
|
| 82 |
+
return self
|
| 83 |
+
|
| 84 |
+
async def __aexit__(self, exc_type, exc_val, exc_tb):
|
| 85 |
+
await self.close()
|
| 86 |
+
async with self._wake_up:
|
| 87 |
+
self._wake_up.notify()
|
| 88 |
+
return False
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
class AsyncioQuicConnection(AsyncQuicConnection):
|
| 92 |
+
def __init__(self, connection, address, port, source, source_port, manager=None):
|
| 93 |
+
super().__init__(connection, address, port, source, source_port, manager)
|
| 94 |
+
self._socket = None
|
| 95 |
+
self._handshake_complete = asyncio.Event()
|
| 96 |
+
self._socket_created = asyncio.Event()
|
| 97 |
+
self._wake_timer = asyncio.Condition()
|
| 98 |
+
self._receiver_task = None
|
| 99 |
+
self._sender_task = None
|
| 100 |
+
self._wake_pending = False
|
| 101 |
+
|
| 102 |
+
async def _receiver(self):
|
| 103 |
+
try:
|
| 104 |
+
af = dns.inet.af_for_address(self._address)
|
| 105 |
+
backend = dns.asyncbackend.get_backend("asyncio")
|
| 106 |
+
# Note that peer is a low-level address tuple, but make_socket() wants
|
| 107 |
+
# a high-level address tuple, so we convert.
|
| 108 |
+
self._socket = await backend.make_socket(
|
| 109 |
+
af, socket.SOCK_DGRAM, 0, self._source, (self._peer[0], self._peer[1])
|
| 110 |
+
)
|
| 111 |
+
self._socket_created.set()
|
| 112 |
+
async with self._socket:
|
| 113 |
+
while not self._done:
|
| 114 |
+
(datagram, address) = await self._socket.recvfrom(
|
| 115 |
+
QUIC_MAX_DATAGRAM, None
|
| 116 |
+
)
|
| 117 |
+
if address[0] != self._peer[0] or address[1] != self._peer[1]:
|
| 118 |
+
continue
|
| 119 |
+
self._connection.receive_datagram(datagram, address, time.time())
|
| 120 |
+
# Wake up the timer in case the sender is sleeping, as there may be
|
| 121 |
+
# stuff to send now.
|
| 122 |
+
await self._wakeup()
|
| 123 |
+
except Exception:
|
| 124 |
+
pass
|
| 125 |
+
finally:
|
| 126 |
+
self._done = True
|
| 127 |
+
await self._wakeup()
|
| 128 |
+
self._handshake_complete.set()
|
| 129 |
+
|
| 130 |
+
async def _wakeup(self):
|
| 131 |
+
self._wake_pending = True
|
| 132 |
+
async with self._wake_timer:
|
| 133 |
+
self._wake_timer.notify_all()
|
| 134 |
+
|
| 135 |
+
async def _wait_for_wake_timer(self):
|
| 136 |
+
async with self._wake_timer:
|
| 137 |
+
if not self._wake_pending:
|
| 138 |
+
await self._wake_timer.wait()
|
| 139 |
+
self._wake_pending = False
|
| 140 |
+
|
| 141 |
+
async def _sender(self):
|
| 142 |
+
await self._socket_created.wait()
|
| 143 |
+
while not self._done:
|
| 144 |
+
datagrams = self._connection.datagrams_to_send(time.time())
|
| 145 |
+
for datagram, address in datagrams:
|
| 146 |
+
assert address == self._peer
|
| 147 |
+
await self._socket.sendto(datagram, self._peer, None)
|
| 148 |
+
(expiration, interval) = self._get_timer_values()
|
| 149 |
+
try:
|
| 150 |
+
await asyncio.wait_for(self._wait_for_wake_timer(), interval)
|
| 151 |
+
except Exception:
|
| 152 |
+
pass
|
| 153 |
+
self._handle_timer(expiration)
|
| 154 |
+
await self._handle_events()
|
| 155 |
+
|
| 156 |
+
async def _handle_events(self):
|
| 157 |
+
count = 0
|
| 158 |
+
while True:
|
| 159 |
+
event = self._connection.next_event()
|
| 160 |
+
if event is None:
|
| 161 |
+
return
|
| 162 |
+
if isinstance(event, aioquic.quic.events.StreamDataReceived):
|
| 163 |
+
if self.is_h3():
|
| 164 |
+
h3_events = self._h3_conn.handle_event(event)
|
| 165 |
+
for h3_event in h3_events:
|
| 166 |
+
if isinstance(h3_event, aioquic.h3.events.HeadersReceived):
|
| 167 |
+
stream = self._streams.get(event.stream_id)
|
| 168 |
+
if stream:
|
| 169 |
+
if stream._headers is None:
|
| 170 |
+
stream._headers = h3_event.headers
|
| 171 |
+
elif stream._trailers is None:
|
| 172 |
+
stream._trailers = h3_event.headers
|
| 173 |
+
if h3_event.stream_ended:
|
| 174 |
+
await stream._add_input(b"", True)
|
| 175 |
+
elif isinstance(h3_event, aioquic.h3.events.DataReceived):
|
| 176 |
+
stream = self._streams.get(event.stream_id)
|
| 177 |
+
if stream:
|
| 178 |
+
await stream._add_input(
|
| 179 |
+
h3_event.data, h3_event.stream_ended
|
| 180 |
+
)
|
| 181 |
+
else:
|
| 182 |
+
stream = self._streams.get(event.stream_id)
|
| 183 |
+
if stream:
|
| 184 |
+
await stream._add_input(event.data, event.end_stream)
|
| 185 |
+
elif isinstance(event, aioquic.quic.events.HandshakeCompleted):
|
| 186 |
+
self._handshake_complete.set()
|
| 187 |
+
elif isinstance(event, aioquic.quic.events.ConnectionTerminated):
|
| 188 |
+
self._done = True
|
| 189 |
+
self._receiver_task.cancel()
|
| 190 |
+
elif isinstance(event, aioquic.quic.events.StreamReset):
|
| 191 |
+
stream = self._streams.get(event.stream_id)
|
| 192 |
+
if stream:
|
| 193 |
+
await stream._add_input(b"", True)
|
| 194 |
+
|
| 195 |
+
count += 1
|
| 196 |
+
if count > 10:
|
| 197 |
+
# yield
|
| 198 |
+
count = 0
|
| 199 |
+
await asyncio.sleep(0)
|
| 200 |
+
|
| 201 |
+
async def write(self, stream, data, is_end=False):
|
| 202 |
+
self._connection.send_stream_data(stream, data, is_end)
|
| 203 |
+
await self._wakeup()
|
| 204 |
+
|
| 205 |
+
def run(self):
|
| 206 |
+
if self._closed:
|
| 207 |
+
return
|
| 208 |
+
self._receiver_task = asyncio.Task(self._receiver())
|
| 209 |
+
self._sender_task = asyncio.Task(self._sender())
|
| 210 |
+
|
| 211 |
+
async def make_stream(self, timeout=None):
|
| 212 |
+
try:
|
| 213 |
+
await asyncio.wait_for(self._handshake_complete.wait(), timeout)
|
| 214 |
+
except TimeoutError:
|
| 215 |
+
raise dns.exception.Timeout
|
| 216 |
+
if self._done:
|
| 217 |
+
raise UnexpectedEOF
|
| 218 |
+
stream_id = self._connection.get_next_available_stream_id(False)
|
| 219 |
+
stream = AsyncioQuicStream(self, stream_id)
|
| 220 |
+
self._streams[stream_id] = stream
|
| 221 |
+
return stream
|
| 222 |
+
|
| 223 |
+
async def close(self):
|
| 224 |
+
if not self._closed:
|
| 225 |
+
self._manager.closed(self._peer[0], self._peer[1])
|
| 226 |
+
self._closed = True
|
| 227 |
+
self._connection.close()
|
| 228 |
+
# sender might be blocked on this, so set it
|
| 229 |
+
self._socket_created.set()
|
| 230 |
+
await self._wakeup()
|
| 231 |
+
try:
|
| 232 |
+
await self._receiver_task
|
| 233 |
+
except asyncio.CancelledError:
|
| 234 |
+
pass
|
| 235 |
+
try:
|
| 236 |
+
await self._sender_task
|
| 237 |
+
except asyncio.CancelledError:
|
| 238 |
+
pass
|
| 239 |
+
await self._socket.close()
|
| 240 |
+
|
| 241 |
+
|
| 242 |
+
class AsyncioQuicManager(AsyncQuicManager):
|
| 243 |
+
def __init__(
|
| 244 |
+
self, conf=None, verify_mode=ssl.CERT_REQUIRED, server_name=None, h3=False
|
| 245 |
+
):
|
| 246 |
+
super().__init__(conf, verify_mode, AsyncioQuicConnection, server_name, h3)
|
| 247 |
+
|
| 248 |
+
def connect(
|
| 249 |
+
self, address, port=853, source=None, source_port=0, want_session_ticket=True
|
| 250 |
+
):
|
| 251 |
+
(connection, start) = self._connect(
|
| 252 |
+
address, port, source, source_port, want_session_ticket
|
| 253 |
+
)
|
| 254 |
+
if start:
|
| 255 |
+
connection.run()
|
| 256 |
+
return connection
|
| 257 |
+
|
| 258 |
+
async def __aenter__(self):
|
| 259 |
+
return self
|
| 260 |
+
|
| 261 |
+
async def __aexit__(self, exc_type, exc_val, exc_tb):
|
| 262 |
+
# Copy the iterator into a list as exiting things will mutate the connections
|
| 263 |
+
# table.
|
| 264 |
+
connections = list(self._connections.values())
|
| 265 |
+
for connection in connections:
|
| 266 |
+
await connection.close()
|
| 267 |
+
return False
|
tool_server/.venv/lib/python3.12/site-packages/dns/quic/_common.py
ADDED
|
@@ -0,0 +1,339 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license
|
| 2 |
+
|
| 3 |
+
import base64
|
| 4 |
+
import copy
|
| 5 |
+
import functools
|
| 6 |
+
import socket
|
| 7 |
+
import struct
|
| 8 |
+
import time
|
| 9 |
+
import urllib
|
| 10 |
+
from typing import Any, Optional
|
| 11 |
+
|
| 12 |
+
import aioquic.h3.connection # type: ignore
|
| 13 |
+
import aioquic.h3.events # type: ignore
|
| 14 |
+
import aioquic.quic.configuration # type: ignore
|
| 15 |
+
import aioquic.quic.connection # type: ignore
|
| 16 |
+
|
| 17 |
+
import dns.inet
|
| 18 |
+
|
| 19 |
+
QUIC_MAX_DATAGRAM = 2048
|
| 20 |
+
MAX_SESSION_TICKETS = 8
|
| 21 |
+
# If we hit the max sessions limit we will delete this many of the oldest connections.
|
| 22 |
+
# The value must be a integer > 0 and <= MAX_SESSION_TICKETS.
|
| 23 |
+
SESSIONS_TO_DELETE = MAX_SESSION_TICKETS // 4
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
class UnexpectedEOF(Exception):
|
| 27 |
+
pass
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
class Buffer:
|
| 31 |
+
def __init__(self):
|
| 32 |
+
self._buffer = b""
|
| 33 |
+
self._seen_end = False
|
| 34 |
+
|
| 35 |
+
def put(self, data, is_end):
|
| 36 |
+
if self._seen_end:
|
| 37 |
+
return
|
| 38 |
+
self._buffer += data
|
| 39 |
+
if is_end:
|
| 40 |
+
self._seen_end = True
|
| 41 |
+
|
| 42 |
+
def have(self, amount):
|
| 43 |
+
if len(self._buffer) >= amount:
|
| 44 |
+
return True
|
| 45 |
+
if self._seen_end:
|
| 46 |
+
raise UnexpectedEOF
|
| 47 |
+
return False
|
| 48 |
+
|
| 49 |
+
def seen_end(self):
|
| 50 |
+
return self._seen_end
|
| 51 |
+
|
| 52 |
+
def get(self, amount):
|
| 53 |
+
assert self.have(amount)
|
| 54 |
+
data = self._buffer[:amount]
|
| 55 |
+
self._buffer = self._buffer[amount:]
|
| 56 |
+
return data
|
| 57 |
+
|
| 58 |
+
def get_all(self):
|
| 59 |
+
assert self.seen_end()
|
| 60 |
+
data = self._buffer
|
| 61 |
+
self._buffer = b""
|
| 62 |
+
return data
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
class BaseQuicStream:
|
| 66 |
+
def __init__(self, connection, stream_id):
|
| 67 |
+
self._connection = connection
|
| 68 |
+
self._stream_id = stream_id
|
| 69 |
+
self._buffer = Buffer()
|
| 70 |
+
self._expecting = 0
|
| 71 |
+
self._headers = None
|
| 72 |
+
self._trailers = None
|
| 73 |
+
|
| 74 |
+
def id(self):
|
| 75 |
+
return self._stream_id
|
| 76 |
+
|
| 77 |
+
def headers(self):
|
| 78 |
+
return self._headers
|
| 79 |
+
|
| 80 |
+
def trailers(self):
|
| 81 |
+
return self._trailers
|
| 82 |
+
|
| 83 |
+
def _expiration_from_timeout(self, timeout):
|
| 84 |
+
if timeout is not None:
|
| 85 |
+
expiration = time.time() + timeout
|
| 86 |
+
else:
|
| 87 |
+
expiration = None
|
| 88 |
+
return expiration
|
| 89 |
+
|
| 90 |
+
def _timeout_from_expiration(self, expiration):
|
| 91 |
+
if expiration is not None:
|
| 92 |
+
timeout = max(expiration - time.time(), 0.0)
|
| 93 |
+
else:
|
| 94 |
+
timeout = None
|
| 95 |
+
return timeout
|
| 96 |
+
|
| 97 |
+
# Subclass must implement receive() as sync / async and which returns a message
|
| 98 |
+
# or raises.
|
| 99 |
+
|
| 100 |
+
# Subclass must implement send() as sync / async and which takes a message and
|
| 101 |
+
# an EOF indicator.
|
| 102 |
+
|
| 103 |
+
def send_h3(self, url, datagram, post=True):
|
| 104 |
+
if not self._connection.is_h3():
|
| 105 |
+
raise SyntaxError("cannot send H3 to a non-H3 connection")
|
| 106 |
+
url_parts = urllib.parse.urlparse(url)
|
| 107 |
+
path = url_parts.path.encode()
|
| 108 |
+
if post:
|
| 109 |
+
method = b"POST"
|
| 110 |
+
else:
|
| 111 |
+
method = b"GET"
|
| 112 |
+
path += b"?dns=" + base64.urlsafe_b64encode(datagram).rstrip(b"=")
|
| 113 |
+
headers = [
|
| 114 |
+
(b":method", method),
|
| 115 |
+
(b":scheme", url_parts.scheme.encode()),
|
| 116 |
+
(b":authority", url_parts.netloc.encode()),
|
| 117 |
+
(b":path", path),
|
| 118 |
+
(b"accept", b"application/dns-message"),
|
| 119 |
+
]
|
| 120 |
+
if post:
|
| 121 |
+
headers.extend(
|
| 122 |
+
[
|
| 123 |
+
(b"content-type", b"application/dns-message"),
|
| 124 |
+
(b"content-length", str(len(datagram)).encode()),
|
| 125 |
+
]
|
| 126 |
+
)
|
| 127 |
+
self._connection.send_headers(self._stream_id, headers, not post)
|
| 128 |
+
if post:
|
| 129 |
+
self._connection.send_data(self._stream_id, datagram, True)
|
| 130 |
+
|
| 131 |
+
def _encapsulate(self, datagram):
|
| 132 |
+
if self._connection.is_h3():
|
| 133 |
+
return datagram
|
| 134 |
+
l = len(datagram)
|
| 135 |
+
return struct.pack("!H", l) + datagram
|
| 136 |
+
|
| 137 |
+
def _common_add_input(self, data, is_end):
|
| 138 |
+
self._buffer.put(data, is_end)
|
| 139 |
+
try:
|
| 140 |
+
return (
|
| 141 |
+
self._expecting > 0 and self._buffer.have(self._expecting)
|
| 142 |
+
) or self._buffer.seen_end
|
| 143 |
+
except UnexpectedEOF:
|
| 144 |
+
return True
|
| 145 |
+
|
| 146 |
+
def _close(self):
|
| 147 |
+
self._connection.close_stream(self._stream_id)
|
| 148 |
+
self._buffer.put(b"", True) # send EOF in case we haven't seen it.
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
class BaseQuicConnection:
|
| 152 |
+
def __init__(
|
| 153 |
+
self,
|
| 154 |
+
connection,
|
| 155 |
+
address,
|
| 156 |
+
port,
|
| 157 |
+
source=None,
|
| 158 |
+
source_port=0,
|
| 159 |
+
manager=None,
|
| 160 |
+
):
|
| 161 |
+
self._done = False
|
| 162 |
+
self._connection = connection
|
| 163 |
+
self._address = address
|
| 164 |
+
self._port = port
|
| 165 |
+
self._closed = False
|
| 166 |
+
self._manager = manager
|
| 167 |
+
self._streams = {}
|
| 168 |
+
if manager.is_h3():
|
| 169 |
+
self._h3_conn = aioquic.h3.connection.H3Connection(connection, False)
|
| 170 |
+
else:
|
| 171 |
+
self._h3_conn = None
|
| 172 |
+
self._af = dns.inet.af_for_address(address)
|
| 173 |
+
self._peer = dns.inet.low_level_address_tuple((address, port))
|
| 174 |
+
if source is None and source_port != 0:
|
| 175 |
+
if self._af == socket.AF_INET:
|
| 176 |
+
source = "0.0.0.0"
|
| 177 |
+
elif self._af == socket.AF_INET6:
|
| 178 |
+
source = "::"
|
| 179 |
+
else:
|
| 180 |
+
raise NotImplementedError
|
| 181 |
+
if source:
|
| 182 |
+
self._source = (source, source_port)
|
| 183 |
+
else:
|
| 184 |
+
self._source = None
|
| 185 |
+
|
| 186 |
+
def is_h3(self):
|
| 187 |
+
return self._h3_conn is not None
|
| 188 |
+
|
| 189 |
+
def close_stream(self, stream_id):
|
| 190 |
+
del self._streams[stream_id]
|
| 191 |
+
|
| 192 |
+
def send_headers(self, stream_id, headers, is_end=False):
|
| 193 |
+
self._h3_conn.send_headers(stream_id, headers, is_end)
|
| 194 |
+
|
| 195 |
+
def send_data(self, stream_id, data, is_end=False):
|
| 196 |
+
self._h3_conn.send_data(stream_id, data, is_end)
|
| 197 |
+
|
| 198 |
+
def _get_timer_values(self, closed_is_special=True):
|
| 199 |
+
now = time.time()
|
| 200 |
+
expiration = self._connection.get_timer()
|
| 201 |
+
if expiration is None:
|
| 202 |
+
expiration = now + 3600 # arbitrary "big" value
|
| 203 |
+
interval = max(expiration - now, 0)
|
| 204 |
+
if self._closed and closed_is_special:
|
| 205 |
+
# lower sleep interval to avoid a race in the closing process
|
| 206 |
+
# which can lead to higher latency closing due to sleeping when
|
| 207 |
+
# we have events.
|
| 208 |
+
interval = min(interval, 0.05)
|
| 209 |
+
return (expiration, interval)
|
| 210 |
+
|
| 211 |
+
def _handle_timer(self, expiration):
|
| 212 |
+
now = time.time()
|
| 213 |
+
if expiration <= now:
|
| 214 |
+
self._connection.handle_timer(now)
|
| 215 |
+
|
| 216 |
+
|
| 217 |
+
class AsyncQuicConnection(BaseQuicConnection):
|
| 218 |
+
async def make_stream(self, timeout: Optional[float] = None) -> Any:
|
| 219 |
+
pass
|
| 220 |
+
|
| 221 |
+
|
| 222 |
+
class BaseQuicManager:
|
| 223 |
+
def __init__(
|
| 224 |
+
self, conf, verify_mode, connection_factory, server_name=None, h3=False
|
| 225 |
+
):
|
| 226 |
+
self._connections = {}
|
| 227 |
+
self._connection_factory = connection_factory
|
| 228 |
+
self._session_tickets = {}
|
| 229 |
+
self._tokens = {}
|
| 230 |
+
self._h3 = h3
|
| 231 |
+
if conf is None:
|
| 232 |
+
verify_path = None
|
| 233 |
+
if isinstance(verify_mode, str):
|
| 234 |
+
verify_path = verify_mode
|
| 235 |
+
verify_mode = True
|
| 236 |
+
if h3:
|
| 237 |
+
alpn_protocols = ["h3"]
|
| 238 |
+
else:
|
| 239 |
+
alpn_protocols = ["doq", "doq-i03"]
|
| 240 |
+
conf = aioquic.quic.configuration.QuicConfiguration(
|
| 241 |
+
alpn_protocols=alpn_protocols,
|
| 242 |
+
verify_mode=verify_mode,
|
| 243 |
+
server_name=server_name,
|
| 244 |
+
)
|
| 245 |
+
if verify_path is not None:
|
| 246 |
+
conf.load_verify_locations(verify_path)
|
| 247 |
+
self._conf = conf
|
| 248 |
+
|
| 249 |
+
def _connect(
|
| 250 |
+
self,
|
| 251 |
+
address,
|
| 252 |
+
port=853,
|
| 253 |
+
source=None,
|
| 254 |
+
source_port=0,
|
| 255 |
+
want_session_ticket=True,
|
| 256 |
+
want_token=True,
|
| 257 |
+
):
|
| 258 |
+
connection = self._connections.get((address, port))
|
| 259 |
+
if connection is not None:
|
| 260 |
+
return (connection, False)
|
| 261 |
+
conf = self._conf
|
| 262 |
+
if want_session_ticket:
|
| 263 |
+
try:
|
| 264 |
+
session_ticket = self._session_tickets.pop((address, port))
|
| 265 |
+
# We found a session ticket, so make a configuration that uses it.
|
| 266 |
+
conf = copy.copy(conf)
|
| 267 |
+
conf.session_ticket = session_ticket
|
| 268 |
+
except KeyError:
|
| 269 |
+
# No session ticket.
|
| 270 |
+
pass
|
| 271 |
+
# Whether or not we found a session ticket, we want a handler to save
|
| 272 |
+
# one.
|
| 273 |
+
session_ticket_handler = functools.partial(
|
| 274 |
+
self.save_session_ticket, address, port
|
| 275 |
+
)
|
| 276 |
+
else:
|
| 277 |
+
session_ticket_handler = None
|
| 278 |
+
if want_token:
|
| 279 |
+
try:
|
| 280 |
+
token = self._tokens.pop((address, port))
|
| 281 |
+
# We found a token, so make a configuration that uses it.
|
| 282 |
+
conf = copy.copy(conf)
|
| 283 |
+
conf.token = token
|
| 284 |
+
except KeyError:
|
| 285 |
+
# No token
|
| 286 |
+
pass
|
| 287 |
+
# Whether or not we found a token, we want a handler to save # one.
|
| 288 |
+
token_handler = functools.partial(self.save_token, address, port)
|
| 289 |
+
else:
|
| 290 |
+
token_handler = None
|
| 291 |
+
|
| 292 |
+
qconn = aioquic.quic.connection.QuicConnection(
|
| 293 |
+
configuration=conf,
|
| 294 |
+
session_ticket_handler=session_ticket_handler,
|
| 295 |
+
token_handler=token_handler,
|
| 296 |
+
)
|
| 297 |
+
lladdress = dns.inet.low_level_address_tuple((address, port))
|
| 298 |
+
qconn.connect(lladdress, time.time())
|
| 299 |
+
connection = self._connection_factory(
|
| 300 |
+
qconn, address, port, source, source_port, self
|
| 301 |
+
)
|
| 302 |
+
self._connections[(address, port)] = connection
|
| 303 |
+
return (connection, True)
|
| 304 |
+
|
| 305 |
+
def closed(self, address, port):
|
| 306 |
+
try:
|
| 307 |
+
del self._connections[(address, port)]
|
| 308 |
+
except KeyError:
|
| 309 |
+
pass
|
| 310 |
+
|
| 311 |
+
def is_h3(self):
|
| 312 |
+
return self._h3
|
| 313 |
+
|
| 314 |
+
def save_session_ticket(self, address, port, ticket):
|
| 315 |
+
# We rely on dictionaries keys() being in insertion order here. We
|
| 316 |
+
# can't just popitem() as that would be LIFO which is the opposite of
|
| 317 |
+
# what we want.
|
| 318 |
+
l = len(self._session_tickets)
|
| 319 |
+
if l >= MAX_SESSION_TICKETS:
|
| 320 |
+
keys_to_delete = list(self._session_tickets.keys())[0:SESSIONS_TO_DELETE]
|
| 321 |
+
for key in keys_to_delete:
|
| 322 |
+
del self._session_tickets[key]
|
| 323 |
+
self._session_tickets[(address, port)] = ticket
|
| 324 |
+
|
| 325 |
+
def save_token(self, address, port, token):
|
| 326 |
+
# We rely on dictionaries keys() being in insertion order here. We
|
| 327 |
+
# can't just popitem() as that would be LIFO which is the opposite of
|
| 328 |
+
# what we want.
|
| 329 |
+
l = len(self._tokens)
|
| 330 |
+
if l >= MAX_SESSION_TICKETS:
|
| 331 |
+
keys_to_delete = list(self._tokens.keys())[0:SESSIONS_TO_DELETE]
|
| 332 |
+
for key in keys_to_delete:
|
| 333 |
+
del self._tokens[key]
|
| 334 |
+
self._tokens[(address, port)] = token
|
| 335 |
+
|
| 336 |
+
|
| 337 |
+
class AsyncQuicManager(BaseQuicManager):
|
| 338 |
+
def connect(self, address, port=853, source=None, source_port=0):
|
| 339 |
+
raise NotImplementedError
|
tool_server/.venv/lib/python3.12/site-packages/dns/quic/_sync.py
ADDED
|
@@ -0,0 +1,295 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license
|
| 2 |
+
|
| 3 |
+
import selectors
|
| 4 |
+
import socket
|
| 5 |
+
import ssl
|
| 6 |
+
import struct
|
| 7 |
+
import threading
|
| 8 |
+
import time
|
| 9 |
+
|
| 10 |
+
import aioquic.quic.configuration # type: ignore
|
| 11 |
+
import aioquic.quic.connection # type: ignore
|
| 12 |
+
import aioquic.quic.events # type: ignore
|
| 13 |
+
|
| 14 |
+
import dns.exception
|
| 15 |
+
import dns.inet
|
| 16 |
+
from dns.quic._common import (
|
| 17 |
+
QUIC_MAX_DATAGRAM,
|
| 18 |
+
BaseQuicConnection,
|
| 19 |
+
BaseQuicManager,
|
| 20 |
+
BaseQuicStream,
|
| 21 |
+
UnexpectedEOF,
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
# Function used to create a socket. Can be overridden if needed in special
|
| 25 |
+
# situations.
|
| 26 |
+
socket_factory = socket.socket
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
class SyncQuicStream(BaseQuicStream):
|
| 30 |
+
def __init__(self, connection, stream_id):
|
| 31 |
+
super().__init__(connection, stream_id)
|
| 32 |
+
self._wake_up = threading.Condition()
|
| 33 |
+
self._lock = threading.Lock()
|
| 34 |
+
|
| 35 |
+
def wait_for(self, amount, expiration):
|
| 36 |
+
while True:
|
| 37 |
+
timeout = self._timeout_from_expiration(expiration)
|
| 38 |
+
with self._lock:
|
| 39 |
+
if self._buffer.have(amount):
|
| 40 |
+
return
|
| 41 |
+
self._expecting = amount
|
| 42 |
+
with self._wake_up:
|
| 43 |
+
if not self._wake_up.wait(timeout):
|
| 44 |
+
raise dns.exception.Timeout
|
| 45 |
+
self._expecting = 0
|
| 46 |
+
|
| 47 |
+
def wait_for_end(self, expiration):
|
| 48 |
+
while True:
|
| 49 |
+
timeout = self._timeout_from_expiration(expiration)
|
| 50 |
+
with self._lock:
|
| 51 |
+
if self._buffer.seen_end():
|
| 52 |
+
return
|
| 53 |
+
with self._wake_up:
|
| 54 |
+
if not self._wake_up.wait(timeout):
|
| 55 |
+
raise dns.exception.Timeout
|
| 56 |
+
|
| 57 |
+
def receive(self, timeout=None):
|
| 58 |
+
expiration = self._expiration_from_timeout(timeout)
|
| 59 |
+
if self._connection.is_h3():
|
| 60 |
+
self.wait_for_end(expiration)
|
| 61 |
+
with self._lock:
|
| 62 |
+
return self._buffer.get_all()
|
| 63 |
+
else:
|
| 64 |
+
self.wait_for(2, expiration)
|
| 65 |
+
with self._lock:
|
| 66 |
+
(size,) = struct.unpack("!H", self._buffer.get(2))
|
| 67 |
+
self.wait_for(size, expiration)
|
| 68 |
+
with self._lock:
|
| 69 |
+
return self._buffer.get(size)
|
| 70 |
+
|
| 71 |
+
def send(self, datagram, is_end=False):
|
| 72 |
+
data = self._encapsulate(datagram)
|
| 73 |
+
self._connection.write(self._stream_id, data, is_end)
|
| 74 |
+
|
| 75 |
+
def _add_input(self, data, is_end):
|
| 76 |
+
if self._common_add_input(data, is_end):
|
| 77 |
+
with self._wake_up:
|
| 78 |
+
self._wake_up.notify()
|
| 79 |
+
|
| 80 |
+
def close(self):
|
| 81 |
+
with self._lock:
|
| 82 |
+
self._close()
|
| 83 |
+
|
| 84 |
+
def __enter__(self):
|
| 85 |
+
return self
|
| 86 |
+
|
| 87 |
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
| 88 |
+
self.close()
|
| 89 |
+
with self._wake_up:
|
| 90 |
+
self._wake_up.notify()
|
| 91 |
+
return False
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
class SyncQuicConnection(BaseQuicConnection):
|
| 95 |
+
def __init__(self, connection, address, port, source, source_port, manager):
|
| 96 |
+
super().__init__(connection, address, port, source, source_port, manager)
|
| 97 |
+
self._socket = socket_factory(self._af, socket.SOCK_DGRAM, 0)
|
| 98 |
+
if self._source is not None:
|
| 99 |
+
try:
|
| 100 |
+
self._socket.bind(
|
| 101 |
+
dns.inet.low_level_address_tuple(self._source, self._af)
|
| 102 |
+
)
|
| 103 |
+
except Exception:
|
| 104 |
+
self._socket.close()
|
| 105 |
+
raise
|
| 106 |
+
self._socket.connect(self._peer)
|
| 107 |
+
(self._send_wakeup, self._receive_wakeup) = socket.socketpair()
|
| 108 |
+
self._receive_wakeup.setblocking(False)
|
| 109 |
+
self._socket.setblocking(False)
|
| 110 |
+
self._handshake_complete = threading.Event()
|
| 111 |
+
self._worker_thread = None
|
| 112 |
+
self._lock = threading.Lock()
|
| 113 |
+
|
| 114 |
+
def _read(self):
|
| 115 |
+
count = 0
|
| 116 |
+
while count < 10:
|
| 117 |
+
count += 1
|
| 118 |
+
try:
|
| 119 |
+
datagram = self._socket.recv(QUIC_MAX_DATAGRAM)
|
| 120 |
+
except BlockingIOError:
|
| 121 |
+
return
|
| 122 |
+
with self._lock:
|
| 123 |
+
self._connection.receive_datagram(datagram, self._peer, time.time())
|
| 124 |
+
|
| 125 |
+
def _drain_wakeup(self):
|
| 126 |
+
while True:
|
| 127 |
+
try:
|
| 128 |
+
self._receive_wakeup.recv(32)
|
| 129 |
+
except BlockingIOError:
|
| 130 |
+
return
|
| 131 |
+
|
| 132 |
+
def _worker(self):
|
| 133 |
+
try:
|
| 134 |
+
sel = selectors.DefaultSelector()
|
| 135 |
+
sel.register(self._socket, selectors.EVENT_READ, self._read)
|
| 136 |
+
sel.register(self._receive_wakeup, selectors.EVENT_READ, self._drain_wakeup)
|
| 137 |
+
while not self._done:
|
| 138 |
+
(expiration, interval) = self._get_timer_values(False)
|
| 139 |
+
items = sel.select(interval)
|
| 140 |
+
for key, _ in items:
|
| 141 |
+
key.data()
|
| 142 |
+
with self._lock:
|
| 143 |
+
self._handle_timer(expiration)
|
| 144 |
+
self._handle_events()
|
| 145 |
+
with self._lock:
|
| 146 |
+
datagrams = self._connection.datagrams_to_send(time.time())
|
| 147 |
+
for datagram, _ in datagrams:
|
| 148 |
+
try:
|
| 149 |
+
self._socket.send(datagram)
|
| 150 |
+
except BlockingIOError:
|
| 151 |
+
# we let QUIC handle any lossage
|
| 152 |
+
pass
|
| 153 |
+
finally:
|
| 154 |
+
with self._lock:
|
| 155 |
+
self._done = True
|
| 156 |
+
self._socket.close()
|
| 157 |
+
# Ensure anyone waiting for this gets woken up.
|
| 158 |
+
self._handshake_complete.set()
|
| 159 |
+
|
| 160 |
+
def _handle_events(self):
|
| 161 |
+
while True:
|
| 162 |
+
with self._lock:
|
| 163 |
+
event = self._connection.next_event()
|
| 164 |
+
if event is None:
|
| 165 |
+
return
|
| 166 |
+
if isinstance(event, aioquic.quic.events.StreamDataReceived):
|
| 167 |
+
if self.is_h3():
|
| 168 |
+
h3_events = self._h3_conn.handle_event(event)
|
| 169 |
+
for h3_event in h3_events:
|
| 170 |
+
if isinstance(h3_event, aioquic.h3.events.HeadersReceived):
|
| 171 |
+
with self._lock:
|
| 172 |
+
stream = self._streams.get(event.stream_id)
|
| 173 |
+
if stream:
|
| 174 |
+
if stream._headers is None:
|
| 175 |
+
stream._headers = h3_event.headers
|
| 176 |
+
elif stream._trailers is None:
|
| 177 |
+
stream._trailers = h3_event.headers
|
| 178 |
+
if h3_event.stream_ended:
|
| 179 |
+
stream._add_input(b"", True)
|
| 180 |
+
elif isinstance(h3_event, aioquic.h3.events.DataReceived):
|
| 181 |
+
with self._lock:
|
| 182 |
+
stream = self._streams.get(event.stream_id)
|
| 183 |
+
if stream:
|
| 184 |
+
stream._add_input(h3_event.data, h3_event.stream_ended)
|
| 185 |
+
else:
|
| 186 |
+
with self._lock:
|
| 187 |
+
stream = self._streams.get(event.stream_id)
|
| 188 |
+
if stream:
|
| 189 |
+
stream._add_input(event.data, event.end_stream)
|
| 190 |
+
elif isinstance(event, aioquic.quic.events.HandshakeCompleted):
|
| 191 |
+
self._handshake_complete.set()
|
| 192 |
+
elif isinstance(event, aioquic.quic.events.ConnectionTerminated):
|
| 193 |
+
with self._lock:
|
| 194 |
+
self._done = True
|
| 195 |
+
elif isinstance(event, aioquic.quic.events.StreamReset):
|
| 196 |
+
with self._lock:
|
| 197 |
+
stream = self._streams.get(event.stream_id)
|
| 198 |
+
if stream:
|
| 199 |
+
stream._add_input(b"", True)
|
| 200 |
+
|
| 201 |
+
def write(self, stream, data, is_end=False):
|
| 202 |
+
with self._lock:
|
| 203 |
+
self._connection.send_stream_data(stream, data, is_end)
|
| 204 |
+
self._send_wakeup.send(b"\x01")
|
| 205 |
+
|
| 206 |
+
def send_headers(self, stream_id, headers, is_end=False):
|
| 207 |
+
with self._lock:
|
| 208 |
+
super().send_headers(stream_id, headers, is_end)
|
| 209 |
+
if is_end:
|
| 210 |
+
self._send_wakeup.send(b"\x01")
|
| 211 |
+
|
| 212 |
+
def send_data(self, stream_id, data, is_end=False):
|
| 213 |
+
with self._lock:
|
| 214 |
+
super().send_data(stream_id, data, is_end)
|
| 215 |
+
if is_end:
|
| 216 |
+
self._send_wakeup.send(b"\x01")
|
| 217 |
+
|
| 218 |
+
def run(self):
|
| 219 |
+
if self._closed:
|
| 220 |
+
return
|
| 221 |
+
self._worker_thread = threading.Thread(target=self._worker)
|
| 222 |
+
self._worker_thread.start()
|
| 223 |
+
|
| 224 |
+
def make_stream(self, timeout=None):
|
| 225 |
+
if not self._handshake_complete.wait(timeout):
|
| 226 |
+
raise dns.exception.Timeout
|
| 227 |
+
with self._lock:
|
| 228 |
+
if self._done:
|
| 229 |
+
raise UnexpectedEOF
|
| 230 |
+
stream_id = self._connection.get_next_available_stream_id(False)
|
| 231 |
+
stream = SyncQuicStream(self, stream_id)
|
| 232 |
+
self._streams[stream_id] = stream
|
| 233 |
+
return stream
|
| 234 |
+
|
| 235 |
+
def close_stream(self, stream_id):
|
| 236 |
+
with self._lock:
|
| 237 |
+
super().close_stream(stream_id)
|
| 238 |
+
|
| 239 |
+
def close(self):
|
| 240 |
+
with self._lock:
|
| 241 |
+
if self._closed:
|
| 242 |
+
return
|
| 243 |
+
self._manager.closed(self._peer[0], self._peer[1])
|
| 244 |
+
self._closed = True
|
| 245 |
+
self._connection.close()
|
| 246 |
+
self._send_wakeup.send(b"\x01")
|
| 247 |
+
self._worker_thread.join()
|
| 248 |
+
|
| 249 |
+
|
| 250 |
+
class SyncQuicManager(BaseQuicManager):
|
| 251 |
+
def __init__(
|
| 252 |
+
self, conf=None, verify_mode=ssl.CERT_REQUIRED, server_name=None, h3=False
|
| 253 |
+
):
|
| 254 |
+
super().__init__(conf, verify_mode, SyncQuicConnection, server_name, h3)
|
| 255 |
+
self._lock = threading.Lock()
|
| 256 |
+
|
| 257 |
+
def connect(
|
| 258 |
+
self,
|
| 259 |
+
address,
|
| 260 |
+
port=853,
|
| 261 |
+
source=None,
|
| 262 |
+
source_port=0,
|
| 263 |
+
want_session_ticket=True,
|
| 264 |
+
want_token=True,
|
| 265 |
+
):
|
| 266 |
+
with self._lock:
|
| 267 |
+
(connection, start) = self._connect(
|
| 268 |
+
address, port, source, source_port, want_session_ticket, want_token
|
| 269 |
+
)
|
| 270 |
+
if start:
|
| 271 |
+
connection.run()
|
| 272 |
+
return connection
|
| 273 |
+
|
| 274 |
+
def closed(self, address, port):
|
| 275 |
+
with self._lock:
|
| 276 |
+
super().closed(address, port)
|
| 277 |
+
|
| 278 |
+
def save_session_ticket(self, address, port, ticket):
|
| 279 |
+
with self._lock:
|
| 280 |
+
super().save_session_ticket(address, port, ticket)
|
| 281 |
+
|
| 282 |
+
def save_token(self, address, port, token):
|
| 283 |
+
with self._lock:
|
| 284 |
+
super().save_token(address, port, token)
|
| 285 |
+
|
| 286 |
+
def __enter__(self):
|
| 287 |
+
return self
|
| 288 |
+
|
| 289 |
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
| 290 |
+
# Copy the iterator into a list as exiting things will mutate the connections
|
| 291 |
+
# table.
|
| 292 |
+
connections = list(self._connections.values())
|
| 293 |
+
for connection in connections:
|
| 294 |
+
connection.close()
|
| 295 |
+
return False
|
tool_server/.venv/lib/python3.12/site-packages/dns/quic/_trio.py
ADDED
|
@@ -0,0 +1,246 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license
|
| 2 |
+
|
| 3 |
+
import socket
|
| 4 |
+
import ssl
|
| 5 |
+
import struct
|
| 6 |
+
import time
|
| 7 |
+
|
| 8 |
+
import aioquic.quic.configuration # type: ignore
|
| 9 |
+
import aioquic.quic.connection # type: ignore
|
| 10 |
+
import aioquic.quic.events # type: ignore
|
| 11 |
+
import trio
|
| 12 |
+
|
| 13 |
+
import dns.exception
|
| 14 |
+
import dns.inet
|
| 15 |
+
from dns._asyncbackend import NullContext
|
| 16 |
+
from dns.quic._common import (
|
| 17 |
+
QUIC_MAX_DATAGRAM,
|
| 18 |
+
AsyncQuicConnection,
|
| 19 |
+
AsyncQuicManager,
|
| 20 |
+
BaseQuicStream,
|
| 21 |
+
UnexpectedEOF,
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
class TrioQuicStream(BaseQuicStream):
|
| 26 |
+
def __init__(self, connection, stream_id):
|
| 27 |
+
super().__init__(connection, stream_id)
|
| 28 |
+
self._wake_up = trio.Condition()
|
| 29 |
+
|
| 30 |
+
async def wait_for(self, amount):
|
| 31 |
+
while True:
|
| 32 |
+
if self._buffer.have(amount):
|
| 33 |
+
return
|
| 34 |
+
self._expecting = amount
|
| 35 |
+
async with self._wake_up:
|
| 36 |
+
await self._wake_up.wait()
|
| 37 |
+
self._expecting = 0
|
| 38 |
+
|
| 39 |
+
async def wait_for_end(self):
|
| 40 |
+
while True:
|
| 41 |
+
if self._buffer.seen_end():
|
| 42 |
+
return
|
| 43 |
+
async with self._wake_up:
|
| 44 |
+
await self._wake_up.wait()
|
| 45 |
+
|
| 46 |
+
async def receive(self, timeout=None):
|
| 47 |
+
if timeout is None:
|
| 48 |
+
context = NullContext(None)
|
| 49 |
+
else:
|
| 50 |
+
context = trio.move_on_after(timeout)
|
| 51 |
+
with context:
|
| 52 |
+
if self._connection.is_h3():
|
| 53 |
+
await self.wait_for_end()
|
| 54 |
+
return self._buffer.get_all()
|
| 55 |
+
else:
|
| 56 |
+
await self.wait_for(2)
|
| 57 |
+
(size,) = struct.unpack("!H", self._buffer.get(2))
|
| 58 |
+
await self.wait_for(size)
|
| 59 |
+
return self._buffer.get(size)
|
| 60 |
+
raise dns.exception.Timeout
|
| 61 |
+
|
| 62 |
+
async def send(self, datagram, is_end=False):
|
| 63 |
+
data = self._encapsulate(datagram)
|
| 64 |
+
await self._connection.write(self._stream_id, data, is_end)
|
| 65 |
+
|
| 66 |
+
async def _add_input(self, data, is_end):
|
| 67 |
+
if self._common_add_input(data, is_end):
|
| 68 |
+
async with self._wake_up:
|
| 69 |
+
self._wake_up.notify()
|
| 70 |
+
|
| 71 |
+
async def close(self):
|
| 72 |
+
self._close()
|
| 73 |
+
|
| 74 |
+
# Streams are async context managers
|
| 75 |
+
|
| 76 |
+
async def __aenter__(self):
|
| 77 |
+
return self
|
| 78 |
+
|
| 79 |
+
async def __aexit__(self, exc_type, exc_val, exc_tb):
|
| 80 |
+
await self.close()
|
| 81 |
+
async with self._wake_up:
|
| 82 |
+
self._wake_up.notify()
|
| 83 |
+
return False
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
class TrioQuicConnection(AsyncQuicConnection):
|
| 87 |
+
def __init__(self, connection, address, port, source, source_port, manager=None):
|
| 88 |
+
super().__init__(connection, address, port, source, source_port, manager)
|
| 89 |
+
self._socket = trio.socket.socket(self._af, socket.SOCK_DGRAM, 0)
|
| 90 |
+
self._handshake_complete = trio.Event()
|
| 91 |
+
self._run_done = trio.Event()
|
| 92 |
+
self._worker_scope = None
|
| 93 |
+
self._send_pending = False
|
| 94 |
+
|
| 95 |
+
async def _worker(self):
|
| 96 |
+
try:
|
| 97 |
+
if self._source:
|
| 98 |
+
await self._socket.bind(
|
| 99 |
+
dns.inet.low_level_address_tuple(self._source, self._af)
|
| 100 |
+
)
|
| 101 |
+
await self._socket.connect(self._peer)
|
| 102 |
+
while not self._done:
|
| 103 |
+
(expiration, interval) = self._get_timer_values(False)
|
| 104 |
+
if self._send_pending:
|
| 105 |
+
# Do not block forever if sends are pending. Even though we
|
| 106 |
+
# have a wake-up mechanism if we've already started the blocking
|
| 107 |
+
# read, the possibility of context switching in send means that
|
| 108 |
+
# more writes can happen while we have no wake up context, so
|
| 109 |
+
# we need self._send_pending to avoid (effectively) a "lost wakeup"
|
| 110 |
+
# race.
|
| 111 |
+
interval = 0.0
|
| 112 |
+
with trio.CancelScope(
|
| 113 |
+
deadline=trio.current_time() + interval
|
| 114 |
+
) as self._worker_scope:
|
| 115 |
+
datagram = await self._socket.recv(QUIC_MAX_DATAGRAM)
|
| 116 |
+
self._connection.receive_datagram(datagram, self._peer, time.time())
|
| 117 |
+
self._worker_scope = None
|
| 118 |
+
self._handle_timer(expiration)
|
| 119 |
+
await self._handle_events()
|
| 120 |
+
# We clear this now, before sending anything, as sending can cause
|
| 121 |
+
# context switches that do more sends. We want to know if that
|
| 122 |
+
# happens so we don't block a long time on the recv() above.
|
| 123 |
+
self._send_pending = False
|
| 124 |
+
datagrams = self._connection.datagrams_to_send(time.time())
|
| 125 |
+
for datagram, _ in datagrams:
|
| 126 |
+
await self._socket.send(datagram)
|
| 127 |
+
finally:
|
| 128 |
+
self._done = True
|
| 129 |
+
self._socket.close()
|
| 130 |
+
self._handshake_complete.set()
|
| 131 |
+
|
| 132 |
+
async def _handle_events(self):
|
| 133 |
+
count = 0
|
| 134 |
+
while True:
|
| 135 |
+
event = self._connection.next_event()
|
| 136 |
+
if event is None:
|
| 137 |
+
return
|
| 138 |
+
if isinstance(event, aioquic.quic.events.StreamDataReceived):
|
| 139 |
+
if self.is_h3():
|
| 140 |
+
h3_events = self._h3_conn.handle_event(event)
|
| 141 |
+
for h3_event in h3_events:
|
| 142 |
+
if isinstance(h3_event, aioquic.h3.events.HeadersReceived):
|
| 143 |
+
stream = self._streams.get(event.stream_id)
|
| 144 |
+
if stream:
|
| 145 |
+
if stream._headers is None:
|
| 146 |
+
stream._headers = h3_event.headers
|
| 147 |
+
elif stream._trailers is None:
|
| 148 |
+
stream._trailers = h3_event.headers
|
| 149 |
+
if h3_event.stream_ended:
|
| 150 |
+
await stream._add_input(b"", True)
|
| 151 |
+
elif isinstance(h3_event, aioquic.h3.events.DataReceived):
|
| 152 |
+
stream = self._streams.get(event.stream_id)
|
| 153 |
+
if stream:
|
| 154 |
+
await stream._add_input(
|
| 155 |
+
h3_event.data, h3_event.stream_ended
|
| 156 |
+
)
|
| 157 |
+
else:
|
| 158 |
+
stream = self._streams.get(event.stream_id)
|
| 159 |
+
if stream:
|
| 160 |
+
await stream._add_input(event.data, event.end_stream)
|
| 161 |
+
elif isinstance(event, aioquic.quic.events.HandshakeCompleted):
|
| 162 |
+
self._handshake_complete.set()
|
| 163 |
+
elif isinstance(event, aioquic.quic.events.ConnectionTerminated):
|
| 164 |
+
self._done = True
|
| 165 |
+
self._socket.close()
|
| 166 |
+
elif isinstance(event, aioquic.quic.events.StreamReset):
|
| 167 |
+
stream = self._streams.get(event.stream_id)
|
| 168 |
+
if stream:
|
| 169 |
+
await stream._add_input(b"", True)
|
| 170 |
+
count += 1
|
| 171 |
+
if count > 10:
|
| 172 |
+
# yield
|
| 173 |
+
count = 0
|
| 174 |
+
await trio.sleep(0)
|
| 175 |
+
|
| 176 |
+
async def write(self, stream, data, is_end=False):
|
| 177 |
+
self._connection.send_stream_data(stream, data, is_end)
|
| 178 |
+
self._send_pending = True
|
| 179 |
+
if self._worker_scope is not None:
|
| 180 |
+
self._worker_scope.cancel()
|
| 181 |
+
|
| 182 |
+
async def run(self):
|
| 183 |
+
if self._closed:
|
| 184 |
+
return
|
| 185 |
+
async with trio.open_nursery() as nursery:
|
| 186 |
+
nursery.start_soon(self._worker)
|
| 187 |
+
self._run_done.set()
|
| 188 |
+
|
| 189 |
+
async def make_stream(self, timeout=None):
|
| 190 |
+
if timeout is None:
|
| 191 |
+
context = NullContext(None)
|
| 192 |
+
else:
|
| 193 |
+
context = trio.move_on_after(timeout)
|
| 194 |
+
with context:
|
| 195 |
+
await self._handshake_complete.wait()
|
| 196 |
+
if self._done:
|
| 197 |
+
raise UnexpectedEOF
|
| 198 |
+
stream_id = self._connection.get_next_available_stream_id(False)
|
| 199 |
+
stream = TrioQuicStream(self, stream_id)
|
| 200 |
+
self._streams[stream_id] = stream
|
| 201 |
+
return stream
|
| 202 |
+
raise dns.exception.Timeout
|
| 203 |
+
|
| 204 |
+
async def close(self):
|
| 205 |
+
if not self._closed:
|
| 206 |
+
self._manager.closed(self._peer[0], self._peer[1])
|
| 207 |
+
self._closed = True
|
| 208 |
+
self._connection.close()
|
| 209 |
+
self._send_pending = True
|
| 210 |
+
if self._worker_scope is not None:
|
| 211 |
+
self._worker_scope.cancel()
|
| 212 |
+
await self._run_done.wait()
|
| 213 |
+
|
| 214 |
+
|
| 215 |
+
class TrioQuicManager(AsyncQuicManager):
|
| 216 |
+
def __init__(
|
| 217 |
+
self,
|
| 218 |
+
nursery,
|
| 219 |
+
conf=None,
|
| 220 |
+
verify_mode=ssl.CERT_REQUIRED,
|
| 221 |
+
server_name=None,
|
| 222 |
+
h3=False,
|
| 223 |
+
):
|
| 224 |
+
super().__init__(conf, verify_mode, TrioQuicConnection, server_name, h3)
|
| 225 |
+
self._nursery = nursery
|
| 226 |
+
|
| 227 |
+
def connect(
|
| 228 |
+
self, address, port=853, source=None, source_port=0, want_session_ticket=True
|
| 229 |
+
):
|
| 230 |
+
(connection, start) = self._connect(
|
| 231 |
+
address, port, source, source_port, want_session_ticket
|
| 232 |
+
)
|
| 233 |
+
if start:
|
| 234 |
+
self._nursery.start_soon(connection.run)
|
| 235 |
+
return connection
|
| 236 |
+
|
| 237 |
+
async def __aenter__(self):
|
| 238 |
+
return self
|
| 239 |
+
|
| 240 |
+
async def __aexit__(self, exc_type, exc_val, exc_tb):
|
| 241 |
+
# Copy the iterator into a list as exiting things will mutate the connections
|
| 242 |
+
# table.
|
| 243 |
+
connections = list(self._connections.values())
|
| 244 |
+
for connection in connections:
|
| 245 |
+
await connection.close()
|
| 246 |
+
return False
|
tool_server/.venv/lib/python3.12/site-packages/dns/rdtypes/__init__.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license
|
| 2 |
+
|
| 3 |
+
# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc.
|
| 4 |
+
#
|
| 5 |
+
# Permission to use, copy, modify, and distribute this software and its
|
| 6 |
+
# documentation for any purpose with or without fee is hereby granted,
|
| 7 |
+
# provided that the above copyright notice and this permission notice
|
| 8 |
+
# appear in all copies.
|
| 9 |
+
#
|
| 10 |
+
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
|
| 11 |
+
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
| 12 |
+
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
| 13 |
+
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
| 14 |
+
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
| 15 |
+
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
| 16 |
+
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
| 17 |
+
|
| 18 |
+
"""DNS rdata type classes"""
|
| 19 |
+
|
| 20 |
+
__all__ = [
|
| 21 |
+
"ANY",
|
| 22 |
+
"IN",
|
| 23 |
+
"CH",
|
| 24 |
+
"dnskeybase",
|
| 25 |
+
"dsbase",
|
| 26 |
+
"euibase",
|
| 27 |
+
"mxbase",
|
| 28 |
+
"nsbase",
|
| 29 |
+
"svcbbase",
|
| 30 |
+
"tlsabase",
|
| 31 |
+
"txtbase",
|
| 32 |
+
"util",
|
| 33 |
+
]
|
tool_server/.venv/lib/python3.12/site-packages/dns/rdtypes/dnskeybase.py
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license
|
| 2 |
+
|
| 3 |
+
# Copyright (C) 2004-2007, 2009-2011 Nominum, Inc.
|
| 4 |
+
#
|
| 5 |
+
# Permission to use, copy, modify, and distribute this software and its
|
| 6 |
+
# documentation for any purpose with or without fee is hereby granted,
|
| 7 |
+
# provided that the above copyright notice and this permission notice
|
| 8 |
+
# appear in all copies.
|
| 9 |
+
#
|
| 10 |
+
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
|
| 11 |
+
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
| 12 |
+
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
| 13 |
+
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
| 14 |
+
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
| 15 |
+
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
| 16 |
+
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
| 17 |
+
|
| 18 |
+
import base64
|
| 19 |
+
import enum
|
| 20 |
+
import struct
|
| 21 |
+
|
| 22 |
+
import dns.dnssectypes
|
| 23 |
+
import dns.exception
|
| 24 |
+
import dns.immutable
|
| 25 |
+
import dns.rdata
|
| 26 |
+
|
| 27 |
+
# wildcard import
|
| 28 |
+
__all__ = ["SEP", "REVOKE", "ZONE"] # noqa: F822
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
class Flag(enum.IntFlag):
|
| 32 |
+
SEP = 0x0001
|
| 33 |
+
REVOKE = 0x0080
|
| 34 |
+
ZONE = 0x0100
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
@dns.immutable.immutable
|
| 38 |
+
class DNSKEYBase(dns.rdata.Rdata):
|
| 39 |
+
"""Base class for rdata that is like a DNSKEY record"""
|
| 40 |
+
|
| 41 |
+
__slots__ = ["flags", "protocol", "algorithm", "key"]
|
| 42 |
+
|
| 43 |
+
def __init__(self, rdclass, rdtype, flags, protocol, algorithm, key):
|
| 44 |
+
super().__init__(rdclass, rdtype)
|
| 45 |
+
self.flags = Flag(self._as_uint16(flags))
|
| 46 |
+
self.protocol = self._as_uint8(protocol)
|
| 47 |
+
self.algorithm = dns.dnssectypes.Algorithm.make(algorithm)
|
| 48 |
+
self.key = self._as_bytes(key)
|
| 49 |
+
|
| 50 |
+
def to_text(self, origin=None, relativize=True, **kw):
|
| 51 |
+
return "%d %d %d %s" % (
|
| 52 |
+
self.flags,
|
| 53 |
+
self.protocol,
|
| 54 |
+
self.algorithm,
|
| 55 |
+
dns.rdata._base64ify(self.key, **kw),
|
| 56 |
+
)
|
| 57 |
+
|
| 58 |
+
@classmethod
|
| 59 |
+
def from_text(
|
| 60 |
+
cls, rdclass, rdtype, tok, origin=None, relativize=True, relativize_to=None
|
| 61 |
+
):
|
| 62 |
+
flags = tok.get_uint16()
|
| 63 |
+
protocol = tok.get_uint8()
|
| 64 |
+
algorithm = tok.get_string()
|
| 65 |
+
b64 = tok.concatenate_remaining_identifiers().encode()
|
| 66 |
+
key = base64.b64decode(b64)
|
| 67 |
+
return cls(rdclass, rdtype, flags, protocol, algorithm, key)
|
| 68 |
+
|
| 69 |
+
def _to_wire(self, file, compress=None, origin=None, canonicalize=False):
|
| 70 |
+
header = struct.pack("!HBB", self.flags, self.protocol, self.algorithm)
|
| 71 |
+
file.write(header)
|
| 72 |
+
file.write(self.key)
|
| 73 |
+
|
| 74 |
+
@classmethod
|
| 75 |
+
def from_wire_parser(cls, rdclass, rdtype, parser, origin=None):
|
| 76 |
+
header = parser.get_struct("!HBB")
|
| 77 |
+
key = parser.get_remaining()
|
| 78 |
+
return cls(rdclass, rdtype, header[0], header[1], header[2], key)
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
### BEGIN generated Flag constants
|
| 82 |
+
|
| 83 |
+
SEP = Flag.SEP
|
| 84 |
+
REVOKE = Flag.REVOKE
|
| 85 |
+
ZONE = Flag.ZONE
|
| 86 |
+
|
| 87 |
+
### END generated Flag constants
|
tool_server/.venv/lib/python3.12/site-packages/dns/rdtypes/dsbase.py
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license
|
| 2 |
+
|
| 3 |
+
# Copyright (C) 2010, 2011 Nominum, Inc.
|
| 4 |
+
#
|
| 5 |
+
# Permission to use, copy, modify, and distribute this software and its
|
| 6 |
+
# documentation for any purpose with or without fee is hereby granted,
|
| 7 |
+
# provided that the above copyright notice and this permission notice
|
| 8 |
+
# appear in all copies.
|
| 9 |
+
#
|
| 10 |
+
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
|
| 11 |
+
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
| 12 |
+
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
| 13 |
+
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
| 14 |
+
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
| 15 |
+
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
| 16 |
+
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
| 17 |
+
|
| 18 |
+
import binascii
|
| 19 |
+
import struct
|
| 20 |
+
|
| 21 |
+
import dns.dnssectypes
|
| 22 |
+
import dns.immutable
|
| 23 |
+
import dns.rdata
|
| 24 |
+
import dns.rdatatype
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
@dns.immutable.immutable
|
| 28 |
+
class DSBase(dns.rdata.Rdata):
|
| 29 |
+
"""Base class for rdata that is like a DS record"""
|
| 30 |
+
|
| 31 |
+
__slots__ = ["key_tag", "algorithm", "digest_type", "digest"]
|
| 32 |
+
|
| 33 |
+
# Digest types registry:
|
| 34 |
+
# https://www.iana.org/assignments/ds-rr-types/ds-rr-types.xhtml
|
| 35 |
+
_digest_length_by_type = {
|
| 36 |
+
1: 20, # SHA-1, RFC 3658 Sec. 2.4
|
| 37 |
+
2: 32, # SHA-256, RFC 4509 Sec. 2.2
|
| 38 |
+
3: 32, # GOST R 34.11-94, RFC 5933 Sec. 4 in conjunction with RFC 4490 Sec. 2.1
|
| 39 |
+
4: 48, # SHA-384, RFC 6605 Sec. 2
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
def __init__(self, rdclass, rdtype, key_tag, algorithm, digest_type, digest):
|
| 43 |
+
super().__init__(rdclass, rdtype)
|
| 44 |
+
self.key_tag = self._as_uint16(key_tag)
|
| 45 |
+
self.algorithm = dns.dnssectypes.Algorithm.make(algorithm)
|
| 46 |
+
self.digest_type = dns.dnssectypes.DSDigest.make(self._as_uint8(digest_type))
|
| 47 |
+
self.digest = self._as_bytes(digest)
|
| 48 |
+
try:
|
| 49 |
+
if len(self.digest) != self._digest_length_by_type[self.digest_type]:
|
| 50 |
+
raise ValueError("digest length inconsistent with digest type")
|
| 51 |
+
except KeyError:
|
| 52 |
+
if self.digest_type == 0: # reserved, RFC 3658 Sec. 2.4
|
| 53 |
+
raise ValueError("digest type 0 is reserved")
|
| 54 |
+
|
| 55 |
+
def to_text(self, origin=None, relativize=True, **kw):
|
| 56 |
+
kw = kw.copy()
|
| 57 |
+
chunksize = kw.pop("chunksize", 128)
|
| 58 |
+
return "%d %d %d %s" % (
|
| 59 |
+
self.key_tag,
|
| 60 |
+
self.algorithm,
|
| 61 |
+
self.digest_type,
|
| 62 |
+
dns.rdata._hexify(self.digest, chunksize=chunksize, **kw),
|
| 63 |
+
)
|
| 64 |
+
|
| 65 |
+
@classmethod
|
| 66 |
+
def from_text(
|
| 67 |
+
cls, rdclass, rdtype, tok, origin=None, relativize=True, relativize_to=None
|
| 68 |
+
):
|
| 69 |
+
key_tag = tok.get_uint16()
|
| 70 |
+
algorithm = tok.get_string()
|
| 71 |
+
digest_type = tok.get_uint8()
|
| 72 |
+
digest = tok.concatenate_remaining_identifiers().encode()
|
| 73 |
+
digest = binascii.unhexlify(digest)
|
| 74 |
+
return cls(rdclass, rdtype, key_tag, algorithm, digest_type, digest)
|
| 75 |
+
|
| 76 |
+
def _to_wire(self, file, compress=None, origin=None, canonicalize=False):
|
| 77 |
+
header = struct.pack("!HBB", self.key_tag, self.algorithm, self.digest_type)
|
| 78 |
+
file.write(header)
|
| 79 |
+
file.write(self.digest)
|
| 80 |
+
|
| 81 |
+
@classmethod
|
| 82 |
+
def from_wire_parser(cls, rdclass, rdtype, parser, origin=None):
|
| 83 |
+
header = parser.get_struct("!HBB")
|
| 84 |
+
digest = parser.get_remaining()
|
| 85 |
+
return cls(rdclass, rdtype, header[0], header[1], header[2], digest)
|
tool_server/.venv/lib/python3.12/site-packages/dns/rdtypes/euibase.py
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (C) 2015 Red Hat, Inc.
|
| 2 |
+
# Author: Petr Spacek <pspacek@redhat.com>
|
| 3 |
+
#
|
| 4 |
+
# Permission to use, copy, modify, and distribute this software and its
|
| 5 |
+
# documentation for any purpose with or without fee is hereby granted,
|
| 6 |
+
# provided that the above copyright notice and this permission notice
|
| 7 |
+
# appear in all copies.
|
| 8 |
+
#
|
| 9 |
+
# THE SOFTWARE IS PROVIDED 'AS IS' AND RED HAT DISCLAIMS ALL WARRANTIES
|
| 10 |
+
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
| 11 |
+
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
| 12 |
+
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
| 13 |
+
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
| 14 |
+
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
| 15 |
+
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
| 16 |
+
|
| 17 |
+
import binascii
|
| 18 |
+
|
| 19 |
+
import dns.immutable
|
| 20 |
+
import dns.rdata
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
@dns.immutable.immutable
|
| 24 |
+
class EUIBase(dns.rdata.Rdata):
|
| 25 |
+
"""EUIxx record"""
|
| 26 |
+
|
| 27 |
+
# see: rfc7043.txt
|
| 28 |
+
|
| 29 |
+
__slots__ = ["eui"]
|
| 30 |
+
# define these in subclasses
|
| 31 |
+
# byte_len = 6 # 0123456789ab (in hex)
|
| 32 |
+
# text_len = byte_len * 3 - 1 # 01-23-45-67-89-ab
|
| 33 |
+
|
| 34 |
+
def __init__(self, rdclass, rdtype, eui):
|
| 35 |
+
super().__init__(rdclass, rdtype)
|
| 36 |
+
self.eui = self._as_bytes(eui)
|
| 37 |
+
if len(self.eui) != self.byte_len:
|
| 38 |
+
raise dns.exception.FormError(
|
| 39 |
+
f"EUI{self.byte_len * 8} rdata has to have {self.byte_len} bytes"
|
| 40 |
+
)
|
| 41 |
+
|
| 42 |
+
def to_text(self, origin=None, relativize=True, **kw):
|
| 43 |
+
return dns.rdata._hexify(self.eui, chunksize=2, separator=b"-", **kw)
|
| 44 |
+
|
| 45 |
+
@classmethod
|
| 46 |
+
def from_text(
|
| 47 |
+
cls, rdclass, rdtype, tok, origin=None, relativize=True, relativize_to=None
|
| 48 |
+
):
|
| 49 |
+
text = tok.get_string()
|
| 50 |
+
if len(text) != cls.text_len:
|
| 51 |
+
raise dns.exception.SyntaxError(
|
| 52 |
+
f"Input text must have {cls.text_len} characters"
|
| 53 |
+
)
|
| 54 |
+
for i in range(2, cls.byte_len * 3 - 1, 3):
|
| 55 |
+
if text[i] != "-":
|
| 56 |
+
raise dns.exception.SyntaxError(f"Dash expected at position {i}")
|
| 57 |
+
text = text.replace("-", "")
|
| 58 |
+
try:
|
| 59 |
+
data = binascii.unhexlify(text.encode())
|
| 60 |
+
except (ValueError, TypeError) as ex:
|
| 61 |
+
raise dns.exception.SyntaxError(f"Hex decoding error: {str(ex)}")
|
| 62 |
+
return cls(rdclass, rdtype, data)
|
| 63 |
+
|
| 64 |
+
def _to_wire(self, file, compress=None, origin=None, canonicalize=False):
|
| 65 |
+
file.write(self.eui)
|
| 66 |
+
|
| 67 |
+
@classmethod
|
| 68 |
+
def from_wire_parser(cls, rdclass, rdtype, parser, origin=None):
|
| 69 |
+
eui = parser.get_bytes(cls.byte_len)
|
| 70 |
+
return cls(rdclass, rdtype, eui)
|
tool_server/.venv/lib/python3.12/site-packages/dns/rdtypes/mxbase.py
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license
|
| 2 |
+
|
| 3 |
+
# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc.
|
| 4 |
+
#
|
| 5 |
+
# Permission to use, copy, modify, and distribute this software and its
|
| 6 |
+
# documentation for any purpose with or without fee is hereby granted,
|
| 7 |
+
# provided that the above copyright notice and this permission notice
|
| 8 |
+
# appear in all copies.
|
| 9 |
+
#
|
| 10 |
+
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
|
| 11 |
+
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
| 12 |
+
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
| 13 |
+
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
| 14 |
+
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
| 15 |
+
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
| 16 |
+
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
| 17 |
+
|
| 18 |
+
"""MX-like base classes."""
|
| 19 |
+
|
| 20 |
+
import struct
|
| 21 |
+
|
| 22 |
+
import dns.exception
|
| 23 |
+
import dns.immutable
|
| 24 |
+
import dns.name
|
| 25 |
+
import dns.rdata
|
| 26 |
+
import dns.rdtypes.util
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
@dns.immutable.immutable
|
| 30 |
+
class MXBase(dns.rdata.Rdata):
|
| 31 |
+
"""Base class for rdata that is like an MX record."""
|
| 32 |
+
|
| 33 |
+
__slots__ = ["preference", "exchange"]
|
| 34 |
+
|
| 35 |
+
def __init__(self, rdclass, rdtype, preference, exchange):
|
| 36 |
+
super().__init__(rdclass, rdtype)
|
| 37 |
+
self.preference = self._as_uint16(preference)
|
| 38 |
+
self.exchange = self._as_name(exchange)
|
| 39 |
+
|
| 40 |
+
def to_text(self, origin=None, relativize=True, **kw):
|
| 41 |
+
exchange = self.exchange.choose_relativity(origin, relativize)
|
| 42 |
+
return "%d %s" % (self.preference, exchange)
|
| 43 |
+
|
| 44 |
+
@classmethod
|
| 45 |
+
def from_text(
|
| 46 |
+
cls, rdclass, rdtype, tok, origin=None, relativize=True, relativize_to=None
|
| 47 |
+
):
|
| 48 |
+
preference = tok.get_uint16()
|
| 49 |
+
exchange = tok.get_name(origin, relativize, relativize_to)
|
| 50 |
+
return cls(rdclass, rdtype, preference, exchange)
|
| 51 |
+
|
| 52 |
+
def _to_wire(self, file, compress=None, origin=None, canonicalize=False):
|
| 53 |
+
pref = struct.pack("!H", self.preference)
|
| 54 |
+
file.write(pref)
|
| 55 |
+
self.exchange.to_wire(file, compress, origin, canonicalize)
|
| 56 |
+
|
| 57 |
+
@classmethod
|
| 58 |
+
def from_wire_parser(cls, rdclass, rdtype, parser, origin=None):
|
| 59 |
+
preference = parser.get_uint16()
|
| 60 |
+
exchange = parser.get_name(origin)
|
| 61 |
+
return cls(rdclass, rdtype, preference, exchange)
|
| 62 |
+
|
| 63 |
+
def _processing_priority(self):
|
| 64 |
+
return self.preference
|
| 65 |
+
|
| 66 |
+
@classmethod
|
| 67 |
+
def _processing_order(cls, iterable):
|
| 68 |
+
return dns.rdtypes.util.priority_processing_order(iterable)
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
@dns.immutable.immutable
|
| 72 |
+
class UncompressedMX(MXBase):
|
| 73 |
+
"""Base class for rdata that is like an MX record, but whose name
|
| 74 |
+
is not compressed when converted to DNS wire format, and whose
|
| 75 |
+
digestable form is not downcased."""
|
| 76 |
+
|
| 77 |
+
def _to_wire(self, file, compress=None, origin=None, canonicalize=False):
|
| 78 |
+
super()._to_wire(file, None, origin, False)
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
@dns.immutable.immutable
|
| 82 |
+
class UncompressedDowncasingMX(MXBase):
|
| 83 |
+
"""Base class for rdata that is like an MX record, but whose name
|
| 84 |
+
is not compressed when convert to DNS wire format."""
|
| 85 |
+
|
| 86 |
+
def _to_wire(self, file, compress=None, origin=None, canonicalize=False):
|
| 87 |
+
super()._to_wire(file, None, origin, canonicalize)
|
tool_server/.venv/lib/python3.12/site-packages/dns/rdtypes/nsbase.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license
|
| 2 |
+
|
| 3 |
+
# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc.
|
| 4 |
+
#
|
| 5 |
+
# Permission to use, copy, modify, and distribute this software and its
|
| 6 |
+
# documentation for any purpose with or without fee is hereby granted,
|
| 7 |
+
# provided that the above copyright notice and this permission notice
|
| 8 |
+
# appear in all copies.
|
| 9 |
+
#
|
| 10 |
+
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
|
| 11 |
+
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
| 12 |
+
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
| 13 |
+
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
| 14 |
+
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
| 15 |
+
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
| 16 |
+
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
| 17 |
+
|
| 18 |
+
"""NS-like base classes."""
|
| 19 |
+
|
| 20 |
+
import dns.exception
|
| 21 |
+
import dns.immutable
|
| 22 |
+
import dns.name
|
| 23 |
+
import dns.rdata
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
@dns.immutable.immutable
|
| 27 |
+
class NSBase(dns.rdata.Rdata):
|
| 28 |
+
"""Base class for rdata that is like an NS record."""
|
| 29 |
+
|
| 30 |
+
__slots__ = ["target"]
|
| 31 |
+
|
| 32 |
+
def __init__(self, rdclass, rdtype, target):
|
| 33 |
+
super().__init__(rdclass, rdtype)
|
| 34 |
+
self.target = self._as_name(target)
|
| 35 |
+
|
| 36 |
+
def to_text(self, origin=None, relativize=True, **kw):
|
| 37 |
+
target = self.target.choose_relativity(origin, relativize)
|
| 38 |
+
return str(target)
|
| 39 |
+
|
| 40 |
+
@classmethod
|
| 41 |
+
def from_text(
|
| 42 |
+
cls, rdclass, rdtype, tok, origin=None, relativize=True, relativize_to=None
|
| 43 |
+
):
|
| 44 |
+
target = tok.get_name(origin, relativize, relativize_to)
|
| 45 |
+
return cls(rdclass, rdtype, target)
|
| 46 |
+
|
| 47 |
+
def _to_wire(self, file, compress=None, origin=None, canonicalize=False):
|
| 48 |
+
self.target.to_wire(file, compress, origin, canonicalize)
|
| 49 |
+
|
| 50 |
+
@classmethod
|
| 51 |
+
def from_wire_parser(cls, rdclass, rdtype, parser, origin=None):
|
| 52 |
+
target = parser.get_name(origin)
|
| 53 |
+
return cls(rdclass, rdtype, target)
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
@dns.immutable.immutable
|
| 57 |
+
class UncompressedNS(NSBase):
|
| 58 |
+
"""Base class for rdata that is like an NS record, but whose name
|
| 59 |
+
is not compressed when convert to DNS wire format, and whose
|
| 60 |
+
digestable form is not downcased."""
|
| 61 |
+
|
| 62 |
+
def _to_wire(self, file, compress=None, origin=None, canonicalize=False):
|
| 63 |
+
self.target.to_wire(file, None, origin, False)
|
tool_server/.venv/lib/python3.12/site-packages/dns/rdtypes/svcbbase.py
ADDED
|
@@ -0,0 +1,585 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license
|
| 2 |
+
|
| 3 |
+
import base64
|
| 4 |
+
import enum
|
| 5 |
+
import struct
|
| 6 |
+
|
| 7 |
+
import dns.enum
|
| 8 |
+
import dns.exception
|
| 9 |
+
import dns.immutable
|
| 10 |
+
import dns.ipv4
|
| 11 |
+
import dns.ipv6
|
| 12 |
+
import dns.name
|
| 13 |
+
import dns.rdata
|
| 14 |
+
import dns.rdtypes.util
|
| 15 |
+
import dns.renderer
|
| 16 |
+
import dns.tokenizer
|
| 17 |
+
import dns.wire
|
| 18 |
+
|
| 19 |
+
# Until there is an RFC, this module is experimental and may be changed in
|
| 20 |
+
# incompatible ways.
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
class UnknownParamKey(dns.exception.DNSException):
|
| 24 |
+
"""Unknown SVCB ParamKey"""
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
class ParamKey(dns.enum.IntEnum):
|
| 28 |
+
"""SVCB ParamKey"""
|
| 29 |
+
|
| 30 |
+
MANDATORY = 0
|
| 31 |
+
ALPN = 1
|
| 32 |
+
NO_DEFAULT_ALPN = 2
|
| 33 |
+
PORT = 3
|
| 34 |
+
IPV4HINT = 4
|
| 35 |
+
ECH = 5
|
| 36 |
+
IPV6HINT = 6
|
| 37 |
+
DOHPATH = 7
|
| 38 |
+
OHTTP = 8
|
| 39 |
+
|
| 40 |
+
@classmethod
|
| 41 |
+
def _maximum(cls):
|
| 42 |
+
return 65535
|
| 43 |
+
|
| 44 |
+
@classmethod
|
| 45 |
+
def _short_name(cls):
|
| 46 |
+
return "SVCBParamKey"
|
| 47 |
+
|
| 48 |
+
@classmethod
|
| 49 |
+
def _prefix(cls):
|
| 50 |
+
return "KEY"
|
| 51 |
+
|
| 52 |
+
@classmethod
|
| 53 |
+
def _unknown_exception_class(cls):
|
| 54 |
+
return UnknownParamKey
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
class Emptiness(enum.IntEnum):
|
| 58 |
+
NEVER = 0
|
| 59 |
+
ALWAYS = 1
|
| 60 |
+
ALLOWED = 2
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
def _validate_key(key):
|
| 64 |
+
force_generic = False
|
| 65 |
+
if isinstance(key, bytes):
|
| 66 |
+
# We decode to latin-1 so we get 0-255 as valid and do NOT interpret
|
| 67 |
+
# UTF-8 sequences
|
| 68 |
+
key = key.decode("latin-1")
|
| 69 |
+
if isinstance(key, str):
|
| 70 |
+
if key.lower().startswith("key"):
|
| 71 |
+
force_generic = True
|
| 72 |
+
if key[3:].startswith("0") and len(key) != 4:
|
| 73 |
+
# key has leading zeros
|
| 74 |
+
raise ValueError("leading zeros in key")
|
| 75 |
+
key = key.replace("-", "_")
|
| 76 |
+
return (ParamKey.make(key), force_generic)
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
def key_to_text(key):
|
| 80 |
+
return ParamKey.to_text(key).replace("_", "-").lower()
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
# Like rdata escapify, but escapes ',' too.
|
| 84 |
+
|
| 85 |
+
_escaped = b'",\\'
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def _escapify(qstring):
|
| 89 |
+
text = ""
|
| 90 |
+
for c in qstring:
|
| 91 |
+
if c in _escaped:
|
| 92 |
+
text += "\\" + chr(c)
|
| 93 |
+
elif c >= 0x20 and c < 0x7F:
|
| 94 |
+
text += chr(c)
|
| 95 |
+
else:
|
| 96 |
+
text += "\\%03d" % c
|
| 97 |
+
return text
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
def _unescape(value):
|
| 101 |
+
if value == "":
|
| 102 |
+
return value
|
| 103 |
+
unescaped = b""
|
| 104 |
+
l = len(value)
|
| 105 |
+
i = 0
|
| 106 |
+
while i < l:
|
| 107 |
+
c = value[i]
|
| 108 |
+
i += 1
|
| 109 |
+
if c == "\\":
|
| 110 |
+
if i >= l: # pragma: no cover (can't happen via tokenizer get())
|
| 111 |
+
raise dns.exception.UnexpectedEnd
|
| 112 |
+
c = value[i]
|
| 113 |
+
i += 1
|
| 114 |
+
if c.isdigit():
|
| 115 |
+
if i >= l:
|
| 116 |
+
raise dns.exception.UnexpectedEnd
|
| 117 |
+
c2 = value[i]
|
| 118 |
+
i += 1
|
| 119 |
+
if i >= l:
|
| 120 |
+
raise dns.exception.UnexpectedEnd
|
| 121 |
+
c3 = value[i]
|
| 122 |
+
i += 1
|
| 123 |
+
if not (c2.isdigit() and c3.isdigit()):
|
| 124 |
+
raise dns.exception.SyntaxError
|
| 125 |
+
codepoint = int(c) * 100 + int(c2) * 10 + int(c3)
|
| 126 |
+
if codepoint > 255:
|
| 127 |
+
raise dns.exception.SyntaxError
|
| 128 |
+
unescaped += b"%c" % (codepoint)
|
| 129 |
+
continue
|
| 130 |
+
unescaped += c.encode()
|
| 131 |
+
return unescaped
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
def _split(value):
|
| 135 |
+
l = len(value)
|
| 136 |
+
i = 0
|
| 137 |
+
items = []
|
| 138 |
+
unescaped = b""
|
| 139 |
+
while i < l:
|
| 140 |
+
c = value[i]
|
| 141 |
+
i += 1
|
| 142 |
+
if c == ord("\\"):
|
| 143 |
+
if i >= l: # pragma: no cover (can't happen via tokenizer get())
|
| 144 |
+
raise dns.exception.UnexpectedEnd
|
| 145 |
+
c = value[i]
|
| 146 |
+
i += 1
|
| 147 |
+
unescaped += b"%c" % (c)
|
| 148 |
+
elif c == ord(","):
|
| 149 |
+
items.append(unescaped)
|
| 150 |
+
unescaped = b""
|
| 151 |
+
else:
|
| 152 |
+
unescaped += b"%c" % (c)
|
| 153 |
+
items.append(unescaped)
|
| 154 |
+
return items
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
@dns.immutable.immutable
|
| 158 |
+
class Param:
|
| 159 |
+
"""Abstract base class for SVCB parameters"""
|
| 160 |
+
|
| 161 |
+
@classmethod
|
| 162 |
+
def emptiness(cls):
|
| 163 |
+
return Emptiness.NEVER
|
| 164 |
+
|
| 165 |
+
|
| 166 |
+
@dns.immutable.immutable
|
| 167 |
+
class GenericParam(Param):
|
| 168 |
+
"""Generic SVCB parameter"""
|
| 169 |
+
|
| 170 |
+
def __init__(self, value):
|
| 171 |
+
self.value = dns.rdata.Rdata._as_bytes(value, True)
|
| 172 |
+
|
| 173 |
+
@classmethod
|
| 174 |
+
def emptiness(cls):
|
| 175 |
+
return Emptiness.ALLOWED
|
| 176 |
+
|
| 177 |
+
@classmethod
|
| 178 |
+
def from_value(cls, value):
|
| 179 |
+
if value is None or len(value) == 0:
|
| 180 |
+
return None
|
| 181 |
+
else:
|
| 182 |
+
return cls(_unescape(value))
|
| 183 |
+
|
| 184 |
+
def to_text(self):
|
| 185 |
+
return '"' + dns.rdata._escapify(self.value) + '"'
|
| 186 |
+
|
| 187 |
+
@classmethod
|
| 188 |
+
def from_wire_parser(cls, parser, origin=None): # pylint: disable=W0613
|
| 189 |
+
value = parser.get_bytes(parser.remaining())
|
| 190 |
+
if len(value) == 0:
|
| 191 |
+
return None
|
| 192 |
+
else:
|
| 193 |
+
return cls(value)
|
| 194 |
+
|
| 195 |
+
def to_wire(self, file, origin=None): # pylint: disable=W0613
|
| 196 |
+
file.write(self.value)
|
| 197 |
+
|
| 198 |
+
|
| 199 |
+
@dns.immutable.immutable
|
| 200 |
+
class MandatoryParam(Param):
|
| 201 |
+
def __init__(self, keys):
|
| 202 |
+
# check for duplicates
|
| 203 |
+
keys = sorted([_validate_key(key)[0] for key in keys])
|
| 204 |
+
prior_k = None
|
| 205 |
+
for k in keys:
|
| 206 |
+
if k == prior_k:
|
| 207 |
+
raise ValueError(f"duplicate key {k:d}")
|
| 208 |
+
prior_k = k
|
| 209 |
+
if k == ParamKey.MANDATORY:
|
| 210 |
+
raise ValueError("listed the mandatory key as mandatory")
|
| 211 |
+
self.keys = tuple(keys)
|
| 212 |
+
|
| 213 |
+
@classmethod
|
| 214 |
+
def from_value(cls, value):
|
| 215 |
+
keys = [k.encode() for k in value.split(",")]
|
| 216 |
+
return cls(keys)
|
| 217 |
+
|
| 218 |
+
def to_text(self):
|
| 219 |
+
return '"' + ",".join([key_to_text(key) for key in self.keys]) + '"'
|
| 220 |
+
|
| 221 |
+
@classmethod
|
| 222 |
+
def from_wire_parser(cls, parser, origin=None): # pylint: disable=W0613
|
| 223 |
+
keys = []
|
| 224 |
+
last_key = -1
|
| 225 |
+
while parser.remaining() > 0:
|
| 226 |
+
key = parser.get_uint16()
|
| 227 |
+
if key < last_key:
|
| 228 |
+
raise dns.exception.FormError("manadatory keys not ascending")
|
| 229 |
+
last_key = key
|
| 230 |
+
keys.append(key)
|
| 231 |
+
return cls(keys)
|
| 232 |
+
|
| 233 |
+
def to_wire(self, file, origin=None): # pylint: disable=W0613
|
| 234 |
+
for key in self.keys:
|
| 235 |
+
file.write(struct.pack("!H", key))
|
| 236 |
+
|
| 237 |
+
|
| 238 |
+
@dns.immutable.immutable
|
| 239 |
+
class ALPNParam(Param):
|
| 240 |
+
def __init__(self, ids):
|
| 241 |
+
self.ids = dns.rdata.Rdata._as_tuple(
|
| 242 |
+
ids, lambda x: dns.rdata.Rdata._as_bytes(x, True, 255, False)
|
| 243 |
+
)
|
| 244 |
+
|
| 245 |
+
@classmethod
|
| 246 |
+
def from_value(cls, value):
|
| 247 |
+
return cls(_split(_unescape(value)))
|
| 248 |
+
|
| 249 |
+
def to_text(self):
|
| 250 |
+
value = ",".join([_escapify(id) for id in self.ids])
|
| 251 |
+
return '"' + dns.rdata._escapify(value.encode()) + '"'
|
| 252 |
+
|
| 253 |
+
@classmethod
|
| 254 |
+
def from_wire_parser(cls, parser, origin=None): # pylint: disable=W0613
|
| 255 |
+
ids = []
|
| 256 |
+
while parser.remaining() > 0:
|
| 257 |
+
id = parser.get_counted_bytes()
|
| 258 |
+
ids.append(id)
|
| 259 |
+
return cls(ids)
|
| 260 |
+
|
| 261 |
+
def to_wire(self, file, origin=None): # pylint: disable=W0613
|
| 262 |
+
for id in self.ids:
|
| 263 |
+
file.write(struct.pack("!B", len(id)))
|
| 264 |
+
file.write(id)
|
| 265 |
+
|
| 266 |
+
|
| 267 |
+
@dns.immutable.immutable
|
| 268 |
+
class NoDefaultALPNParam(Param):
|
| 269 |
+
# We don't ever expect to instantiate this class, but we need
|
| 270 |
+
# a from_value() and a from_wire_parser(), so we just return None
|
| 271 |
+
# from the class methods when things are OK.
|
| 272 |
+
|
| 273 |
+
@classmethod
|
| 274 |
+
def emptiness(cls):
|
| 275 |
+
return Emptiness.ALWAYS
|
| 276 |
+
|
| 277 |
+
@classmethod
|
| 278 |
+
def from_value(cls, value):
|
| 279 |
+
if value is None or value == "":
|
| 280 |
+
return None
|
| 281 |
+
else:
|
| 282 |
+
raise ValueError("no-default-alpn with non-empty value")
|
| 283 |
+
|
| 284 |
+
def to_text(self):
|
| 285 |
+
raise NotImplementedError # pragma: no cover
|
| 286 |
+
|
| 287 |
+
@classmethod
|
| 288 |
+
def from_wire_parser(cls, parser, origin=None): # pylint: disable=W0613
|
| 289 |
+
if parser.remaining() != 0:
|
| 290 |
+
raise dns.exception.FormError
|
| 291 |
+
return None
|
| 292 |
+
|
| 293 |
+
def to_wire(self, file, origin=None): # pylint: disable=W0613
|
| 294 |
+
raise NotImplementedError # pragma: no cover
|
| 295 |
+
|
| 296 |
+
|
| 297 |
+
@dns.immutable.immutable
|
| 298 |
+
class PortParam(Param):
|
| 299 |
+
def __init__(self, port):
|
| 300 |
+
self.port = dns.rdata.Rdata._as_uint16(port)
|
| 301 |
+
|
| 302 |
+
@classmethod
|
| 303 |
+
def from_value(cls, value):
|
| 304 |
+
value = int(value)
|
| 305 |
+
return cls(value)
|
| 306 |
+
|
| 307 |
+
def to_text(self):
|
| 308 |
+
return f'"{self.port}"'
|
| 309 |
+
|
| 310 |
+
@classmethod
|
| 311 |
+
def from_wire_parser(cls, parser, origin=None): # pylint: disable=W0613
|
| 312 |
+
port = parser.get_uint16()
|
| 313 |
+
return cls(port)
|
| 314 |
+
|
| 315 |
+
def to_wire(self, file, origin=None): # pylint: disable=W0613
|
| 316 |
+
file.write(struct.pack("!H", self.port))
|
| 317 |
+
|
| 318 |
+
|
| 319 |
+
@dns.immutable.immutable
|
| 320 |
+
class IPv4HintParam(Param):
|
| 321 |
+
def __init__(self, addresses):
|
| 322 |
+
self.addresses = dns.rdata.Rdata._as_tuple(
|
| 323 |
+
addresses, dns.rdata.Rdata._as_ipv4_address
|
| 324 |
+
)
|
| 325 |
+
|
| 326 |
+
@classmethod
|
| 327 |
+
def from_value(cls, value):
|
| 328 |
+
addresses = value.split(",")
|
| 329 |
+
return cls(addresses)
|
| 330 |
+
|
| 331 |
+
def to_text(self):
|
| 332 |
+
return '"' + ",".join(self.addresses) + '"'
|
| 333 |
+
|
| 334 |
+
@classmethod
|
| 335 |
+
def from_wire_parser(cls, parser, origin=None): # pylint: disable=W0613
|
| 336 |
+
addresses = []
|
| 337 |
+
while parser.remaining() > 0:
|
| 338 |
+
ip = parser.get_bytes(4)
|
| 339 |
+
addresses.append(dns.ipv4.inet_ntoa(ip))
|
| 340 |
+
return cls(addresses)
|
| 341 |
+
|
| 342 |
+
def to_wire(self, file, origin=None): # pylint: disable=W0613
|
| 343 |
+
for address in self.addresses:
|
| 344 |
+
file.write(dns.ipv4.inet_aton(address))
|
| 345 |
+
|
| 346 |
+
|
| 347 |
+
@dns.immutable.immutable
|
| 348 |
+
class IPv6HintParam(Param):
|
| 349 |
+
def __init__(self, addresses):
|
| 350 |
+
self.addresses = dns.rdata.Rdata._as_tuple(
|
| 351 |
+
addresses, dns.rdata.Rdata._as_ipv6_address
|
| 352 |
+
)
|
| 353 |
+
|
| 354 |
+
@classmethod
|
| 355 |
+
def from_value(cls, value):
|
| 356 |
+
addresses = value.split(",")
|
| 357 |
+
return cls(addresses)
|
| 358 |
+
|
| 359 |
+
def to_text(self):
|
| 360 |
+
return '"' + ",".join(self.addresses) + '"'
|
| 361 |
+
|
| 362 |
+
@classmethod
|
| 363 |
+
def from_wire_parser(cls, parser, origin=None): # pylint: disable=W0613
|
| 364 |
+
addresses = []
|
| 365 |
+
while parser.remaining() > 0:
|
| 366 |
+
ip = parser.get_bytes(16)
|
| 367 |
+
addresses.append(dns.ipv6.inet_ntoa(ip))
|
| 368 |
+
return cls(addresses)
|
| 369 |
+
|
| 370 |
+
def to_wire(self, file, origin=None): # pylint: disable=W0613
|
| 371 |
+
for address in self.addresses:
|
| 372 |
+
file.write(dns.ipv6.inet_aton(address))
|
| 373 |
+
|
| 374 |
+
|
| 375 |
+
@dns.immutable.immutable
|
| 376 |
+
class ECHParam(Param):
|
| 377 |
+
def __init__(self, ech):
|
| 378 |
+
self.ech = dns.rdata.Rdata._as_bytes(ech, True)
|
| 379 |
+
|
| 380 |
+
@classmethod
|
| 381 |
+
def from_value(cls, value):
|
| 382 |
+
if "\\" in value:
|
| 383 |
+
raise ValueError("escape in ECH value")
|
| 384 |
+
value = base64.b64decode(value.encode())
|
| 385 |
+
return cls(value)
|
| 386 |
+
|
| 387 |
+
def to_text(self):
|
| 388 |
+
b64 = base64.b64encode(self.ech).decode("ascii")
|
| 389 |
+
return f'"{b64}"'
|
| 390 |
+
|
| 391 |
+
@classmethod
|
| 392 |
+
def from_wire_parser(cls, parser, origin=None): # pylint: disable=W0613
|
| 393 |
+
value = parser.get_bytes(parser.remaining())
|
| 394 |
+
return cls(value)
|
| 395 |
+
|
| 396 |
+
def to_wire(self, file, origin=None): # pylint: disable=W0613
|
| 397 |
+
file.write(self.ech)
|
| 398 |
+
|
| 399 |
+
|
| 400 |
+
@dns.immutable.immutable
|
| 401 |
+
class OHTTPParam(Param):
|
| 402 |
+
# We don't ever expect to instantiate this class, but we need
|
| 403 |
+
# a from_value() and a from_wire_parser(), so we just return None
|
| 404 |
+
# from the class methods when things are OK.
|
| 405 |
+
|
| 406 |
+
@classmethod
|
| 407 |
+
def emptiness(cls):
|
| 408 |
+
return Emptiness.ALWAYS
|
| 409 |
+
|
| 410 |
+
@classmethod
|
| 411 |
+
def from_value(cls, value):
|
| 412 |
+
if value is None or value == "":
|
| 413 |
+
return None
|
| 414 |
+
else:
|
| 415 |
+
raise ValueError("ohttp with non-empty value")
|
| 416 |
+
|
| 417 |
+
def to_text(self):
|
| 418 |
+
raise NotImplementedError # pragma: no cover
|
| 419 |
+
|
| 420 |
+
@classmethod
|
| 421 |
+
def from_wire_parser(cls, parser, origin=None): # pylint: disable=W0613
|
| 422 |
+
if parser.remaining() != 0:
|
| 423 |
+
raise dns.exception.FormError
|
| 424 |
+
return None
|
| 425 |
+
|
| 426 |
+
def to_wire(self, file, origin=None): # pylint: disable=W0613
|
| 427 |
+
raise NotImplementedError # pragma: no cover
|
| 428 |
+
|
| 429 |
+
|
| 430 |
+
_class_for_key = {
|
| 431 |
+
ParamKey.MANDATORY: MandatoryParam,
|
| 432 |
+
ParamKey.ALPN: ALPNParam,
|
| 433 |
+
ParamKey.NO_DEFAULT_ALPN: NoDefaultALPNParam,
|
| 434 |
+
ParamKey.PORT: PortParam,
|
| 435 |
+
ParamKey.IPV4HINT: IPv4HintParam,
|
| 436 |
+
ParamKey.ECH: ECHParam,
|
| 437 |
+
ParamKey.IPV6HINT: IPv6HintParam,
|
| 438 |
+
ParamKey.OHTTP: OHTTPParam,
|
| 439 |
+
}
|
| 440 |
+
|
| 441 |
+
|
| 442 |
+
def _validate_and_define(params, key, value):
|
| 443 |
+
(key, force_generic) = _validate_key(_unescape(key))
|
| 444 |
+
if key in params:
|
| 445 |
+
raise SyntaxError(f'duplicate key "{key:d}"')
|
| 446 |
+
cls = _class_for_key.get(key, GenericParam)
|
| 447 |
+
emptiness = cls.emptiness()
|
| 448 |
+
if value is None:
|
| 449 |
+
if emptiness == Emptiness.NEVER:
|
| 450 |
+
raise SyntaxError("value cannot be empty")
|
| 451 |
+
value = cls.from_value(value)
|
| 452 |
+
else:
|
| 453 |
+
if force_generic:
|
| 454 |
+
value = cls.from_wire_parser(dns.wire.Parser(_unescape(value)))
|
| 455 |
+
else:
|
| 456 |
+
value = cls.from_value(value)
|
| 457 |
+
params[key] = value
|
| 458 |
+
|
| 459 |
+
|
| 460 |
+
@dns.immutable.immutable
|
| 461 |
+
class SVCBBase(dns.rdata.Rdata):
|
| 462 |
+
"""Base class for SVCB-like records"""
|
| 463 |
+
|
| 464 |
+
# see: draft-ietf-dnsop-svcb-https-11
|
| 465 |
+
|
| 466 |
+
__slots__ = ["priority", "target", "params"]
|
| 467 |
+
|
| 468 |
+
def __init__(self, rdclass, rdtype, priority, target, params):
|
| 469 |
+
super().__init__(rdclass, rdtype)
|
| 470 |
+
self.priority = self._as_uint16(priority)
|
| 471 |
+
self.target = self._as_name(target)
|
| 472 |
+
for k, v in params.items():
|
| 473 |
+
k = ParamKey.make(k)
|
| 474 |
+
if not isinstance(v, Param) and v is not None:
|
| 475 |
+
raise ValueError(f"{k:d} not a Param")
|
| 476 |
+
self.params = dns.immutable.Dict(params)
|
| 477 |
+
# Make sure any parameter listed as mandatory is present in the
|
| 478 |
+
# record.
|
| 479 |
+
mandatory = params.get(ParamKey.MANDATORY)
|
| 480 |
+
if mandatory:
|
| 481 |
+
for key in mandatory.keys:
|
| 482 |
+
# Note we have to say "not in" as we have None as a value
|
| 483 |
+
# so a get() and a not None test would be wrong.
|
| 484 |
+
if key not in params:
|
| 485 |
+
raise ValueError(f"key {key:d} declared mandatory but not present")
|
| 486 |
+
# The no-default-alpn parameter requires the alpn parameter.
|
| 487 |
+
if ParamKey.NO_DEFAULT_ALPN in params:
|
| 488 |
+
if ParamKey.ALPN not in params:
|
| 489 |
+
raise ValueError("no-default-alpn present, but alpn missing")
|
| 490 |
+
|
| 491 |
+
def to_text(self, origin=None, relativize=True, **kw):
|
| 492 |
+
target = self.target.choose_relativity(origin, relativize)
|
| 493 |
+
params = []
|
| 494 |
+
for key in sorted(self.params.keys()):
|
| 495 |
+
value = self.params[key]
|
| 496 |
+
if value is None:
|
| 497 |
+
params.append(key_to_text(key))
|
| 498 |
+
else:
|
| 499 |
+
kv = key_to_text(key) + "=" + value.to_text()
|
| 500 |
+
params.append(kv)
|
| 501 |
+
if len(params) > 0:
|
| 502 |
+
space = " "
|
| 503 |
+
else:
|
| 504 |
+
space = ""
|
| 505 |
+
return "%d %s%s%s" % (self.priority, target, space, " ".join(params))
|
| 506 |
+
|
| 507 |
+
@classmethod
|
| 508 |
+
def from_text(
|
| 509 |
+
cls, rdclass, rdtype, tok, origin=None, relativize=True, relativize_to=None
|
| 510 |
+
):
|
| 511 |
+
priority = tok.get_uint16()
|
| 512 |
+
target = tok.get_name(origin, relativize, relativize_to)
|
| 513 |
+
if priority == 0:
|
| 514 |
+
token = tok.get()
|
| 515 |
+
if not token.is_eol_or_eof():
|
| 516 |
+
raise SyntaxError("parameters in AliasMode")
|
| 517 |
+
tok.unget(token)
|
| 518 |
+
params = {}
|
| 519 |
+
while True:
|
| 520 |
+
token = tok.get()
|
| 521 |
+
if token.is_eol_or_eof():
|
| 522 |
+
tok.unget(token)
|
| 523 |
+
break
|
| 524 |
+
if token.ttype != dns.tokenizer.IDENTIFIER:
|
| 525 |
+
raise SyntaxError("parameter is not an identifier")
|
| 526 |
+
equals = token.value.find("=")
|
| 527 |
+
if equals == len(token.value) - 1:
|
| 528 |
+
# 'key=', so next token should be a quoted string without
|
| 529 |
+
# any intervening whitespace.
|
| 530 |
+
key = token.value[:-1]
|
| 531 |
+
token = tok.get(want_leading=True)
|
| 532 |
+
if token.ttype != dns.tokenizer.QUOTED_STRING:
|
| 533 |
+
raise SyntaxError("whitespace after =")
|
| 534 |
+
value = token.value
|
| 535 |
+
elif equals > 0:
|
| 536 |
+
# key=value
|
| 537 |
+
key = token.value[:equals]
|
| 538 |
+
value = token.value[equals + 1 :]
|
| 539 |
+
elif equals == 0:
|
| 540 |
+
# =key
|
| 541 |
+
raise SyntaxError('parameter cannot start with "="')
|
| 542 |
+
else:
|
| 543 |
+
# key
|
| 544 |
+
key = token.value
|
| 545 |
+
value = None
|
| 546 |
+
_validate_and_define(params, key, value)
|
| 547 |
+
return cls(rdclass, rdtype, priority, target, params)
|
| 548 |
+
|
| 549 |
+
def _to_wire(self, file, compress=None, origin=None, canonicalize=False):
|
| 550 |
+
file.write(struct.pack("!H", self.priority))
|
| 551 |
+
self.target.to_wire(file, None, origin, False)
|
| 552 |
+
for key in sorted(self.params):
|
| 553 |
+
file.write(struct.pack("!H", key))
|
| 554 |
+
value = self.params[key]
|
| 555 |
+
with dns.renderer.prefixed_length(file, 2):
|
| 556 |
+
# Note that we're still writing a length of zero if the value is None
|
| 557 |
+
if value is not None:
|
| 558 |
+
value.to_wire(file, origin)
|
| 559 |
+
|
| 560 |
+
@classmethod
|
| 561 |
+
def from_wire_parser(cls, rdclass, rdtype, parser, origin=None):
|
| 562 |
+
priority = parser.get_uint16()
|
| 563 |
+
target = parser.get_name(origin)
|
| 564 |
+
if priority == 0 and parser.remaining() != 0:
|
| 565 |
+
raise dns.exception.FormError("parameters in AliasMode")
|
| 566 |
+
params = {}
|
| 567 |
+
prior_key = -1
|
| 568 |
+
while parser.remaining() > 0:
|
| 569 |
+
key = parser.get_uint16()
|
| 570 |
+
if key < prior_key:
|
| 571 |
+
raise dns.exception.FormError("keys not in order")
|
| 572 |
+
prior_key = key
|
| 573 |
+
vlen = parser.get_uint16()
|
| 574 |
+
pcls = _class_for_key.get(key, GenericParam)
|
| 575 |
+
with parser.restrict_to(vlen):
|
| 576 |
+
value = pcls.from_wire_parser(parser, origin)
|
| 577 |
+
params[key] = value
|
| 578 |
+
return cls(rdclass, rdtype, priority, target, params)
|
| 579 |
+
|
| 580 |
+
def _processing_priority(self):
|
| 581 |
+
return self.priority
|
| 582 |
+
|
| 583 |
+
@classmethod
|
| 584 |
+
def _processing_order(cls, iterable):
|
| 585 |
+
return dns.rdtypes.util.priority_processing_order(iterable)
|
tool_server/.venv/lib/python3.12/site-packages/dns/rdtypes/tlsabase.py
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license
|
| 2 |
+
|
| 3 |
+
# Copyright (C) 2005-2007, 2009-2011 Nominum, Inc.
|
| 4 |
+
#
|
| 5 |
+
# Permission to use, copy, modify, and distribute this software and its
|
| 6 |
+
# documentation for any purpose with or without fee is hereby granted,
|
| 7 |
+
# provided that the above copyright notice and this permission notice
|
| 8 |
+
# appear in all copies.
|
| 9 |
+
#
|
| 10 |
+
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
|
| 11 |
+
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
| 12 |
+
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
| 13 |
+
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
| 14 |
+
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
| 15 |
+
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
| 16 |
+
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
| 17 |
+
|
| 18 |
+
import binascii
|
| 19 |
+
import struct
|
| 20 |
+
|
| 21 |
+
import dns.immutable
|
| 22 |
+
import dns.rdata
|
| 23 |
+
import dns.rdatatype
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
@dns.immutable.immutable
|
| 27 |
+
class TLSABase(dns.rdata.Rdata):
|
| 28 |
+
"""Base class for TLSA and SMIMEA records"""
|
| 29 |
+
|
| 30 |
+
# see: RFC 6698
|
| 31 |
+
|
| 32 |
+
__slots__ = ["usage", "selector", "mtype", "cert"]
|
| 33 |
+
|
| 34 |
+
def __init__(self, rdclass, rdtype, usage, selector, mtype, cert):
|
| 35 |
+
super().__init__(rdclass, rdtype)
|
| 36 |
+
self.usage = self._as_uint8(usage)
|
| 37 |
+
self.selector = self._as_uint8(selector)
|
| 38 |
+
self.mtype = self._as_uint8(mtype)
|
| 39 |
+
self.cert = self._as_bytes(cert)
|
| 40 |
+
|
| 41 |
+
def to_text(self, origin=None, relativize=True, **kw):
|
| 42 |
+
kw = kw.copy()
|
| 43 |
+
chunksize = kw.pop("chunksize", 128)
|
| 44 |
+
return "%d %d %d %s" % (
|
| 45 |
+
self.usage,
|
| 46 |
+
self.selector,
|
| 47 |
+
self.mtype,
|
| 48 |
+
dns.rdata._hexify(self.cert, chunksize=chunksize, **kw),
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
@classmethod
|
| 52 |
+
def from_text(
|
| 53 |
+
cls, rdclass, rdtype, tok, origin=None, relativize=True, relativize_to=None
|
| 54 |
+
):
|
| 55 |
+
usage = tok.get_uint8()
|
| 56 |
+
selector = tok.get_uint8()
|
| 57 |
+
mtype = tok.get_uint8()
|
| 58 |
+
cert = tok.concatenate_remaining_identifiers().encode()
|
| 59 |
+
cert = binascii.unhexlify(cert)
|
| 60 |
+
return cls(rdclass, rdtype, usage, selector, mtype, cert)
|
| 61 |
+
|
| 62 |
+
def _to_wire(self, file, compress=None, origin=None, canonicalize=False):
|
| 63 |
+
header = struct.pack("!BBB", self.usage, self.selector, self.mtype)
|
| 64 |
+
file.write(header)
|
| 65 |
+
file.write(self.cert)
|
| 66 |
+
|
| 67 |
+
@classmethod
|
| 68 |
+
def from_wire_parser(cls, rdclass, rdtype, parser, origin=None):
|
| 69 |
+
header = parser.get_struct("BBB")
|
| 70 |
+
cert = parser.get_remaining()
|
| 71 |
+
return cls(rdclass, rdtype, header[0], header[1], header[2], cert)
|