U mf@s<dZddlZddlZddlZddlZddlZddlZddlmZddlm Z m Z m Z m Z m Z mZmZmZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlmZmZm Z ddlm!Z!m"Z"m#Z#m$Z$ddl%m&Z&ddl'm(Z(dd l)m*Z*dd l+m,Z,dd l-m.Z.m/Z/dd l0m1Z1dd l2m3Z3m4Z4ddl5m6Z6edZ7edZ8e ej9j:ej;jedddZ?eee@fe>dddZAeee>eBe@fe@dddZCee*e&fe@dddZDGdddZEGdddeEZFeFejGejHejIejJhejGejHejIhejKejLejMhejKhZNeFeOeOeOeOZPeNZQdeeejRjSe>fejTjUeee>fe ejRjSe eEeVe,d!d"d#ZWdfeejRjSe>fejTjUeee>fe ejRjSe(d$d%d&ZXe ejRjSeejYjZej[j\ffe3e e e*d'd(d)Z]eej;je@eBfe eee>e@eBfe e@eVe eEe ejRjSe3d6 d7d8Zcdjeej;jfe@e@e*d=d>d?Zfe6jedfe@e@e&d=d@dAZgeejRjSe>fe ee>e_fe@ee@e>fe>dBdCdDZhdkeej;jfe ejRjSejYjZdEdFdGZiejYjZejYjZdHdIdJZjdleejRjSe>fejYjZeee>fe ejRjSejYjZdKdLdMZkejYjZejYjZdHdNdOZldmej9j:ej;je@eBfe eee>e@eBfe e@e eEe ejRjSddP dQdRZmdnejnjoe ej9j:e e ee8e*feVe e@e eee>e@eBfe eee>e@eBfe e@e e1e e=e eEddT dUdVZpdoejnjoej9j:e e=ddWdXdYZqdZd[Zrejstd\rdd]lumvZvdd^lwmxZxdd_lwmyZydd`lwmzZzddalwm{Z{ddblwm|Z|ddcl}m~Z~mZdddlmZmZebZeaZecZefZegZdSZnerZerZerZerZerZd ZejGZGejZejHZHejZejZejIZIejZejZejZejJZJejZejZejZejZejZejZejZdS)pz.Common DNSSEC-related functions and constants.N)datetime)CallableDictListOptionalSetTupleUnioncast) AlgorithmDSDigest NSEC3Hash)AlgorithmKeyMismatchDeniedByPolicyUnsupportedAlgorithmValidationFailure)CDNSKEY)CDS)DNSKEY)DS)NSECBitmap) NSEC3PARAM)RRSIGsigtime_to_posixtime)Flag)GenericPublicKeyzrsa.RSAPublicKeyzec.EllipticCurvePublicKeyzed25519.Ed25519PublicKeyzed448.Ed448PublicKey)GenericPrivateKeyzrsa.RSAPrivateKeyzec.EllipticCurvePrivateKeyzed25519.Ed25519PrivateKeyzed448.Ed448PrivateKey)textreturncCs t|S)zConvert text into a DNSSEC algorithm value. *text*, a ``str``, the text to convert to into an algorithm value. Returns an ``int``. )r from_text)rr!8/opt/hc_python/lib/python3.8/site-packages/dns/dnssec.pyalgorithm_from_textLsr#)valuercCs t|S)zConvert a DNSSEC algorithm value to text *value*, a ``dns.dnssec.Algorithm``. Returns a ``str``, the name of a DNSSEC algorithm. )r Zto_textr$r!r!r"algorithm_to_textWsr&cCsTt|trt|St|tr(t|St|tr:t|St|trH|StddS)z%Convert various format to a timestampzUnsupported timestamp typeN) isinstancerint timestampstrrfloat TypeErrorr%r!r!r" to_timestampbs     r-keyrcCs|}|jtjkr(|dd>|dSd}tt|dD](}||d|d>|d|d7}q7}||d?d@7}|d@Sd S) zReturn the key id (a 16-bit number) for the specified key. *key*, a ``dns.rdtypes.ANY.DNSKEY.DNSKEY`` Returns an ``int`` between 0 and 65535 riN)to_wire algorithmr RSAMD5rangelen)r/rdatatotalir!r!r"key_idps &r>c@sTeZdZddZeedddZeedddZeeddd Z eedd d Z d S) PolicycCsdSNr!)selfr!r!r"__init__szPolicy.__init__)_rcCsdSNFr!rArCr!r!r" ok_to_signszPolicy.ok_to_signcCsdSrDr!rEr!r!r"ok_to_validateszPolicy.ok_to_validatecCsdSrDr!rEr!r!r"ok_to_create_dsszPolicy.ok_to_create_dscCsdSrDr!rEr!r!r"ok_to_validate_dsszPolicy.ok_to_validate_dsN) __name__ __module__ __qualname__rBrboolrFrGr rHrIr!r!r!r"r?s r?cs\eZdZfddZeedddZeedddZeedd d Z eedd d Z Z S) SimpleDenycs&t||_||_||_||_dSr@)superrB _deny_sign_deny_validate_deny_create_ds_deny_validate_ds)rAZ deny_signZ deny_validateZdeny_create_dsZdeny_validate_ds __class__r!r"rBs  zSimpleDeny.__init__r.cCs |j|jkSr@)r7rPrAr/r!r!r"rFszSimpleDeny.ok_to_signcCs |j|jkSr@)r7rQrVr!r!r"rGszSimpleDeny.ok_to_validate)r7rcCs ||jkSr@)rRrAr7r!r!r"rHszSimpleDeny.ok_to_create_dscCs ||jkSr@)rSrWr!r!r"rIszSimpleDeny.ok_to_validate_ds) rJrKrLrBrrMrFrGr rHrI __classcell__r!r!rTr"rNs  rNF)namer/r7originpolicy validatingrc Cs\|dkr t}zt|tr$t|}Wn tk rFtd|YnX|rT|j}n|j}||sft t|t t fs|t d|tj krt}n4|tjkrt}n |tjkrt}n td|t|trtj||}|}|dk st||||j|d|} tdt||j|| } tj !tj"j#tj$j%| dt&| } t't%| S)aCreate a DS record for a DNSSEC key. *name*, a ``dns.name.Name`` or ``str``, the owner name of the DS record. *key*, a ``dns.rdtypes.ANY.DNSKEY.DNSKEY`` or ``dns.rdtypes.ANY.DNSKEY.CDNSKEY``, the key the DS is about. *algorithm*, a ``str`` or ``int`` specifying the hash algorithm. The currently supported hashes are "SHA1", "SHA256", and "SHA384". Case does not matter for these strings. *origin*, a ``dns.name.Name`` or ``None``. If *key* is a relative name, then it will be made absolute using the specified origin. *policy*, a ``dns.dnssec.Policy`` or ``None``. If ``None``, the default policy, ``dns.dnssec.default_policy`` is used; this policy defaults to that of RFC 8624. *validating*, a ``bool``. If ``True``, then policy is checked in validating mode, i.e. "Is it ok to validate using this digest algorithm?". Otherwise the policy is checked in creating mode, i.e. "Is it ok to create a DS with this digest algorithm?". Raises ``UnsupportedAlgorithm`` if the algorithm is unknown. Raises ``DeniedByPolicy`` if the algorithm is denied by policy. Returns a ``dns.rdtypes.ANY.DS.DS`` Nunsupported algorithm "%s"zkey is not a DNSKEY/CDNSKEYrZz!HBBr)(default_policyr'r*r upper ExceptionrrIrHrrr ValueErrorSHA1hashlibsha1SHA256sha256SHA384sha384dnsrYr canonicalizer6AssertionErrorupdatedigeststructpackr>r7r;Z from_wire rdataclassIN rdatatyperr:r ) rYr/r7rZr[r\checkZdshashZwirernZdsrdatadsr!r!r"make_dssJ%            rv)rYr/r7rZrcCs0t||||}t|jtjj|j|j|j|jdS)aCreate a CDS record for a DNSSEC key. *name*, a ``dns.name.Name`` or ``str``, the owner name of the DS record. *key*, a ``dns.rdtypes.ANY.DNSKEY.DNSKEY`` or ``dns.rdtypes.ANY.DNSKEY.CDNSKEY``, the key the DS is about. *algorithm*, a ``str`` or ``int`` specifying the hash algorithm. The currently supported hashes are "SHA1", "SHA256", and "SHA384". Case does not matter for these strings. *origin*, a ``dns.name.Name`` or ``None``. If *key* is a relative name, then it will be made absolute using the specified origin. Raises ``UnsupportedAlgorithm`` if the algorithm is unknown. Returns a ``dns.rdtypes.ANY.DS.CDS`` rdclassrdtypekey_tagr7 digest_typern) rvrrxrjrsrzr7r{rn)rYr/r7rZrur!r!r"make_cdssr|)keysrrsigrcsR|j}t|tjjr0|tjjtj j }n|}|dkr@dSfdd|DS)NcsLg|]D}|jjkrt|jkr|jtj@tjkr|jdkrtt|qS)) r7r>rzflagsrZONEprotocolr r).0rdr~r!r" 2s   z(_find_candidate_keys..) getsignerr'rjnodeNodeZ get_rdatasetrqrrrsr)r}r~r$rdatasetr!rr"_find_candidate_keys(s  r)rrsetrcCs(t|tr|d|dfS|j|fSdS)Nrr4)r'tuplerY)rr!r!r"_get_rrname_rdataset<s r)sigdatar/rcCsFt|j}z||}Wntk r4tdYnX|||dS)Nzinvalid public key)get_algorithm_cls_from_dnskey public_clsZ from_dnskeyrbrverify)rrr/r public_keyr!r!r"_validate_signatureEs  r)rr~r}rZnowr[rc Cs|dkr t}t||}|dkr&td|dkr6t}|j|krHtd|j|krZtdt|||}|D]D}||szqjzt|j ||WdSt tfk rYqjYqjXqjtddS)aValidate an RRset against a single signature rdata, throwing an exception if validation is not successful. *rrset*, the RRset to validate. This can be a ``dns.rrset.RRset`` or a (``dns.name.Name``, ``dns.rdataset.Rdataset``) tuple. *rrsig*, a ``dns.rdata.Rdata``, the signature to validate. *keys*, the key dictionary, used to find the DNSKEY associated with a given name. The dictionary is keyed by a ``dns.name.Name``, and has ``dns.node.Node`` or ``dns.rdataset.Rdataset`` values. *origin*, a ``dns.name.Name`` or ``None``, the origin to use for relative names. *now*, a ``float`` or ``None``, the time, in seconds since the epoch, to use as the current time when validating. If ``None``, the actual current time is used. *policy*, a ``dns.dnssec.Policy`` or ``None``. If ``None``, the default policy, ``dns.dnssec.default_policy`` is used; this policy defaults to that of RFC 8624. Raises ``ValidationFailure`` if the signature is expired, not yet valid, the public key is invalid, the algorithm is unknown, the verification fails, etc. Raises ``UnsupportedAlgorithm`` if the algorithm is recognized by dnspython but not implemented. Nz unknown keyZexpiredz not yet validzverify failure) r_rrtime expiration inception_make_rrsig_signature_datarGr signatureInvalidSignature) rr~r}rZrr[Zcandidate_keysrZ candidate_keyr!r!r"_validate_rrsigNs*(      r)rrrsigsetr}rZrr[rc Cs|dkr t}t|tr(tj|tjj}t|tr<|d}n|j}t|tr^|d}|d}n |j}|}||}||}||krt d|D]J} t| t st dzt || ||||WdSt t fk rYqXqt ddS)aValidate an RRset against a signature RRset, throwing an exception if none of the signatures validate. *rrset*, the RRset to validate. This can be a ``dns.rrset.RRset`` or a (``dns.name.Name``, ``dns.rdataset.Rdataset``) tuple. *rrsigset*, the signature RRset. This can be a ``dns.rrset.RRset`` or a (``dns.name.Name``, ``dns.rdataset.Rdataset``) tuple. *keys*, the key dictionary, used to find the DNSKEY associated with a given name. The dictionary is keyed by a ``dns.name.Name``, and has ``dns.node.Node`` or ``dns.rdataset.Rdataset`` values. *origin*, a ``dns.name.Name``, the origin to use for relative names; defaults to None. *now*, an ``int`` or ``None``, the time, in seconds since the epoch, to use as the current time when validating. If ``None``, the actual current time is used. *policy*, a ``dns.dnssec.Policy`` or ``None``. If ``None``, the default policy, ``dns.dnssec.default_policy`` is used; this policy defaults to that of RFC 8624. Raises ``ValidationFailure`` if the signature is expired, not yet valid, the public key is invalid, the algorithm is unknown, the verification fails, etc. Nrr4zowner names do not matchzexpected an RRSIGzno RRSIGs validated) r_r'r*rjrYr rootrZchoose_relativityrrrr) rrr}rZrr[rrnameZ rrsignameZ rrsigrdatasetr~r!r!r" _validates2'        r) r private_keyrdnskeyrrlifetimerr[rZrc  Csz|dkr t}||stt|trL|dj} |dj} |d} |dj} n|j} |j} |j} |j} |dk rvt |}n t t }|dk rt |}n|dk r||}nt d| dk r| | } t| d}| r|d8}t| tjj| |j|| ||t||dd }tj||| }t|tr&|}n6zt|}||d}Wntk rZtdYnX|||}tt|j|d S) aSign RRset using private key. *rrset*, the RRset to validate. This can be a ``dns.rrset.RRset`` or a (``dns.name.Name``, ``dns.rdataset.Rdataset``) tuple. *private_key*, the private key to use for signing, a ``cryptography.hazmat.primitives.asymmetric`` private key class applicable for DNSSEC. *signer*, a ``dns.name.Name``, the Signer's name. *dnskey*, a ``DNSKEY`` matching ``private_key``. *inception*, a ``datetime``, ``str``, ``int``, ``float`` or ``None``, the signature inception time. If ``None``, the current time is used. If a ``str``, the format is "YYYYMMDDHHMMSS" or alternatively the number of seconds since the UNIX epoch in text form; this is the same the RRSIG rdata's text form. Values of type `int` or `float` are interpreted as seconds since the UNIX epoch. *expiration*, a ``datetime``, ``str``, ``int``, ``float`` or ``None``, the signature expiration time. If ``None``, the expiration time will be the inception time plus the value of the *lifetime* parameter. See the description of *inception* above for how the various parameter types are interpreted. *lifetime*, an ``int`` or ``None``, the signature lifetime in seconds. This parameter is only meaningful if *expiration* is ``None``. *verify*, a ``bool``. If set to ``True``, the signer will verify signatures after they are created; the default is ``False``. *policy*, a ``dns.dnssec.Policy`` or ``None``. If ``None``, the default policy, ``dns.dnssec.default_policy`` is used; this policy defaults to that of RFC 8624. *origin*, a ``dns.name.Name`` or ``None``. If ``None``, the default, then all names in the rrset (including its owner name) must be absolute; otherwise the specified origin will be used to make names absolute when signing. Raises ``DeniedByPolicy`` if the signature is denied by policy. Nr4rz(expiration or lifetime must be specified) rxryZ type_coveredr7labels original_ttlrrrzrrr/zUnsupported key algorithm)r)r_rFrr'rrxryttlrYr-r(rrb derelativizer:is_wildrrjrsr7r>dnssecrrrrr,signr replace)rrrrrrrrr[rZrxryrrZrrsig_inceptionZrrsig_expirationrZrrsig_templaterZ signing_keyZ private_clsrr!r!r"_signsb5             r)rr~rZrcsttrtjtjj|j}|sDdkr:td| }t |\}}d}||j |ddd7}||j |7}|sdkrtd| }t |}|r|j|dkrtd|d|jkrtd n2|j|dkr||jdd}tjd |}| } td |j|j|j} fd d |D} t| D]6} || 7}|| 7}tdt | } || 7}|| 7}qF|S)aCreate signature rdata. *rrset*, the RRset to sign/validate. This can be a ``dns.rrset.RRset`` or a (``dns.name.Name``, ``dns.rdataset.Rdataset``) tuple. *rrsig*, a ``dns.rdata.Rdata``, the signature to validate, or the signature template used when signing. *origin*, a ``dns.name.Name`` or ``None``, the origin to use for relative names. Raises ``UnsupportedAlgorithm`` if the algorithm is recognized by dnspython but not implemented. Nz,relative RR name without an origin specifiedrr^r3z&wild owner name has wrong label lengthr4z#owner name longer than RRSIG labels*z!HHIcsg|]}|qSr!) to_digestable)rr;r^r!r"rsz._make_rrsig_signature_data..z!H)r'r*rjrYr rr is_absoluterrrr6rr:rrsplitrorpryrxrsorted)rr~rZrrrrZname_lensuffixZ rrnamebufZrrfixedZrdatasr;Zrrlenr!r^r"rUsB       rr)rr7rrrcCsDt|}t|tr"|j||dSt|j}||dj||dSdS)aConvert a public key to DNSKEY Rdata *public_key*, a ``PublicKey`` (``GenericPublicKey`` or ``cryptography.hazmat.primitives.asymmetric``) to convert. *algorithm*, a ``str`` or ``int`` specifying the DNSKEY algorithm. *flags*: DNSKEY flags field as an integer. *protocol*: DNSKEY protocol field as an integer. Raises ``ValueError`` if the specified key algorithm parameters are not unsupported, ``TypeError`` if the key type is unsupported, `UnsupportedAlgorithm` if the algorithm is unknown and `AlgorithmKeyMismatch` if the algorithm does not match the key type. Return DNSKEY ``Rdata``. )rrrN)r maker'rZ to_dnskeyget_algorithm_clsr)rr7rrrr!r!r" _make_dnskeys    rcCs0t||||}t|jtjj|j|j|j|jdS)aConvert a public key to CDNSKEY Rdata *public_key*, the public key to convert, a ``cryptography.hazmat.primitives.asymmetric`` public key class applicable for DNSSEC. *algorithm*, a ``str`` or ``int`` specifying the DNSKEY algorithm. *flags*: DNSKEY flags field as an integer. *protocol*: DNSKEY protocol field as an integer. Raises ``ValueError`` if the specified key algorithm parameters are not unsupported, ``TypeError`` if the key type is unsupported, `UnsupportedAlgorithm` if the algorithm is unknown and `AlgorithmKeyMismatch` if the algorithm does not match the key type. Return CDNSKEY ``Rdata``. rxryrrr7r/) rrrxrjrsrrr7r/)rr7rrrr!r!r" _make_cdnskeysr)domainsalt iterationsr7rc Cstdd}zt|tr$t|}Wntk rBtdYnX|tjkrVtd|dkrdd}n4t|trt|ddkrt |}qtdn|}t|t j j st j |}|}|dk stt||}t|D]}t||}qt|d } | |} | S) a Calculate the NSEC3 hash, according to https://tools.ietf.org/html/rfc5155#section-5 *domain*, a ``dns.name.Name`` or ``str``, the name to hash. *salt*, a ``str``, ``bytes``, or ``None``, the hash salt. If a string, it is decoded as a hex string. *iterations*, an ``int``, the number of iterations. *algorithm*, a ``str`` or ``int``, the hash algorithm. The only defined algorithm is SHA1. Returns a ``str``, the encoded NSEC3 hash. Z ABCDEFGHIJKLMNOPQRSTUVWXYZ234567Z 0123456789ABCDEFGHIJKLMNOPQRSTUVz-Wrong hash algorithm (only SHA1 is supported)Nrr3rzInvalid salt lengthzutf-8)r* maketransr'r r`rarbrcr:bytesfromhexrjrYNamer rkr6rlrdrernr9base64 b32encodedecode translate) rrrr7Zb32_conversionZ salt_encodedZdomain_encodedrnrCoutputr!r!r" nsec3_hashs8          r)r algorithmsrZrc Cst|\}}|jtjjtjjtjjfkr0tdt}|D]J}zt |t rVt | }Wn t k rxtd|YnX||q:|jtjjkrg}t|D]}|j|kr||qt|dkrtdtj|j|Sg}|D]}|t||||qtj|j|S)aCreate a DS record from DNSKEY/CDNSKEY/CDS. *rrset*, the RRset to create DS Rdataset for. This can be a ``dns.rrset.RRset`` or a (``dns.name.Name``, ``dns.rdataset.Rdataset``) tuple. *algorithms*, a set of ``str`` or ``int`` specifying the hash algorithms. The currently supported hashes are "SHA1", "SHA256", and "SHA384". Case does not matter for these strings. If the RRset is a CDS, only digest algorithms matching algorithms are accepted. *origin*, a ``dns.name.Name`` or ``None``. If `key` is a relative name, then it will be made absolute using the specified origin. Raises ``UnsupportedAlgorithm`` if any of the algorithms are unknown and ``ValueError`` if the given RRset is not usable. Returns a ``dns.rdataset.Rdataset`` zrrset not a DNSKEY/CDNSKEY/CDSr]rzno acceptable CDS rdata found)rryrjrsrrrrbsetr'r*r r`raraddcds_rdataset_to_ds_rdatasetr{appendr:rfrom_rdata_listrextenddnskey_rdataset_to_cds_rdataset) rrrZrrZ _algorithmsr7resr;r!r!r"make_ds_rdatasets6       r)rrc Cs\|jtjjkrtdg}|D],}|t|jtjj|j|j |j |j dqtj |j|S)zCreate a CDS record from DS. *rdataset*, a ``dns.rdataset.Rdataset``, to create DS Rdataset for. Raises ``ValueError`` if the rdataset is not CDS. Returns a ``dns.rdataset.Rdataset`` zrdataset not a CDSrw)ryrjrsrrbrrxrrzr7r{rnrrrrrr;r!r!r"rUs  r)rYrr7rZrcCsP|jtjjtjjfkrtdg}|D]}|t||||q&tj |j |S)aCreate a CDS record from DNSKEY/CDNSKEY. *name*, a ``dns.name.Name`` or ``str``, the owner name of the CDS record. *rdataset*, a ``dns.rdataset.Rdataset``, to create DS Rdataset for. *algorithm*, a ``str`` or ``int`` specifying the hash algorithm. The currently supported hashes are "SHA1", "SHA256", and "SHA384". Case does not matter for these strings. *origin*, a ``dns.name.Name`` or ``None``. If `key` is a relative name, then it will be made absolute using the specified origin. Raises ``UnsupportedAlgorithm`` if the algorithm is unknown or ``ValueError`` if the rdataset is not DNSKEY/CDNSKEY. Returns a ``dns.rdataset.Rdataset`` zrdataset not a DNSKEY/CDNSKEY) ryrjrsrrrbrr|rrr)rYrr7rZrr;r!r!r"rrs rc CsZ|jtjjkrtdg}|D]*}|t|j|j|j|j |j |j dqtj |j|S)zCreate a CDNSKEY record from DNSKEY. *rdataset*, a ``dns.rdataset.Rdataset``, to create CDNSKEY Rdataset for. Returns a ``dns.rdataset.Rdataset`` zrdataset not a DNSKEYr)ryrjrsrrbrrrxrrr7r/rrrrr!r!r"#dnskey_rdataset_to_cdnskey_rdatasets  r) txnrrkskszsksrrrr[rZrc  Csr|jttjjjtjjjtjjjgkr,|} n|} | D]8\} } tjj || | |||||| d } | |j |j | q4dS)zDefault RRset signer) rrrrrrrr[rZN) ryrrjrs RdataTyperrrrrrrYr)rrrrrrrrr[rZr}rrr~r!r!r"default_rrset_signers*  rT) zonerr} add_dnskey dnskey_ttlrrrnsec3 rrset_signerr[rc  Cs*g} g} |rN|D]*} | djtj@r0| | q| | q| sD|} | sR|} ng}|rbt|}n|}|}|r|dkr||jt j j }|r|j }n||jt j j }|j }|D]\}}||j||q|rtdn>| ptjt|j| | |||| |jd }t|||W5QRSW5QRXdS)a?Sign zone. *zone*, a ``dns.zone.Zone``, the zone to sign. *txn*, a ``dns.transaction.Transaction``, an optional transaction to use for signing. *keys*, a list of (``PrivateKey``, ``DNSKEY``) tuples, to use for signing. KSK/ZSK roles are assigned automatically if the SEP flag is used, otherwise all RRsets are signed by all keys. *add_dnskey*, a ``bool``. If ``True``, the default, all specified DNSKEYs are automatically added to the zone on signing. *dnskey_ttl*, a``int``, specifies the TTL for DNSKEY RRs. If not specified the TTL of the existing DNSKEY RRset used or the TTL of the SOA RRset. *inception*, a ``datetime``, ``str``, ``int``, ``float`` or ``None``, the signature inception time. If ``None``, the current time is used. If a ``str``, the format is "YYYYMMDDHHMMSS" or alternatively the number of seconds since the UNIX epoch in text form; this is the same the RRSIG rdata's text form. Values of type `int` or `float` are interpreted as seconds since the UNIX epoch. *expiration*, a ``datetime``, ``str``, ``int``, ``float`` or ``None``, the signature expiration time. If ``None``, the expiration time will be the inception time plus the value of the *lifetime* parameter. See the description of *inception* above for how the various parameter types are interpreted. *lifetime*, an ``int`` or ``None``, the signature lifetime in seconds. This parameter is only meaningful if *expiration* is ``None``. *nsec3*, a ``NSEC3PARAM`` Rdata, configures signing using NSEC3. Not yet implemented. *rrset_signer*, a ``Callable``, an optional function for signing RRsets. The function requires two arguments: transaction and RRset. If the not specified, ``dns.dnssec.default_rrset_signer`` will be used. Returns ``None``. r4Nz&Signing with NSEC3 not yet implemented)rrrrrrr[rZ)rrZSEPr contextlib nullcontextwriterrrZrjrsrrZSOArNotImplementedError functoolspartialr_sign_zone_nsec)rrr}rrrrrrrr[rrr/cmZ_txnrZsoarCZ _rrset_signerr!r!r" sign_zonesN6       r)rrrrc Cs6dtjjtjjttjjtjjttt dddd}| j }d}d}t | D]}|rh||rhqRn$||tjjr||jkr|}nd}|r||}|r|jD]L} | jtjjkrqq|r| jtjjkrqqtjj|| jf| } ||| q|dk r|||||j|||}qR|r2||||j|j||dS)zNSEC zone signerN)rrY next_securerxrrrc Ssttjjjtjjjg}||}|r|rtdd|jD|B}t t |} tj ||t|tjjj|| d} | | |r||| dS)zNSEC zone signer helpercSsg|] }|jqSr!)ry)rrr!r!r"rVsz:_sign_zone_nsec.._txn_add_nsec..)rxrynextwindowsN)rrjrsrrrget_node rdatasetsrZ from_rdtypeslistr from_rdatar) rrYrrxrrZmandatory_typesrtypesrrr!r!r" _txn_add_nsecGs*   z&_sign_zone_nsec.._txn_add_nsec)N)rj transaction TransactionrYrrrqZ RdataClassr( RRsetSignerZget_soaminimumrZ iterate_namesZ is_subdomainrrsZNSrZrrryrrrrrrx) rrrrZ rrsig_ttlZ delegationZ last_securerYrrrr!r!r"r@sR       rcOs tddS)Nz.DNSSEC validation requires python cryptography) ImportError)argskwargsr!r!r" _need_pycasrr)r)dsa)ec)ed448)rsa)ed25519)rr)rr)NNF)N)NNN)NNN)NNNFNN)N)N)N)NNNNN) NNTNNNNNNN)N)__doc__rrrrdrorrtypingrrrrrrr r Z dns._featuresrjZ dns.exceptionZdns.nameZdns.nodeZ dns.rdataZdns.rdataclassZ dns.rdatasetZ dns.rdatatypeZ dns.rrsetZdns.transactionZdns.zoneZdns.dnssectypesr r r rrrrZdns.rdtypes.ANY.CDNSKEYrZdns.rdtypes.ANY.CDSrZdns.rdtypes.ANY.DNSKEYrZdns.rdtypes.ANY.DSrZdns.rdtypes.ANY.NSECrrZdns.rdtypes.ANY.NSEC3PARAMrZdns.rdtypes.ANY.RRSIGrrZdns.rdtypes.dnskeybaserZ PublicKeyZ PrivateKeyrrrZRRsetrr*r#r(r&r+r-r>r?rNr8ZDSAZ DSANSEC3SHA1ZECCGOSTZNULLrcZGOSTZrfc_8624_policyrZallow_all_policyr_rYrr;ZRdatarMrvr|rZRdatasetrrrrrrrrrrrrrrrrrrrrZonerrrZ _featuresZhaveZcryptography.exceptionsrZ)cryptography.hazmat.primitives.asymmetricrrrrrZdns.dnssecalgsrrZdns.dnssecalgs.baserrvalidateZvalidate_rrsigrZ make_dnskeyZ make_cdnskeyZ _have_pycaZDHZECCZRSASHA1ZRSASHA1NSEC3SHA1Z RSASHA256Z RSASHA512ZECDSAP256SHA256ZECDSAP384SHA384ZED25519ZED448ZINDIRECTZ PRIVATEDNSZ PRIVATEOIDr!r!r!r"s  (           P   %     I  N  |  D  %  '  @  ; !   " !  *  m O