U mf @s$ddlZddlZddlmZddlmZddlmZmZddl m Z m Z ddl m Z ddlmZGdd d e ZGd d d e ZGd d d eZGdddeZGdddeZGdddeZGdddeZGdddeZGdddeZGdddeZGdddeZGdddeZdS) N)default_backend)hashes)paddingrsa)CryptographyPrivateKeyCryptographyPublicKey) Algorithm)DNSKEYc@sdeZdZUejed<ejZeed<ej ed<e e ddddZ e dd d Z e edd d d ZdS) PublicRSAkey algorithm chosen_hashN) signaturedatareturncCs|j||t|jdS)N)r verifyrPKCS1v15r )selfrrr@/opt/hc_python/lib/python3.8/site-packages/dns/dnssecalgs/rsa.pyrszPublicRSA.verify)rcCs|j}tt|jd}tj|j|dd}|dkrLdt d|}n t d|}|j dkst|j d kr|t d |||j |j d ddS) z,Encode a public key per RFC 3110, section 2.big)length byteorder!H!Biizunsupported RSA key length) r Zpublic_numbersmathceilint bit_lengtheto_bytesstructpackn ValueError)rZpnZ_exp_lenexpZ exp_headerrrrencode_key_bytess  zPublicRSA.encode_key_bytes)r rcCs|||j}td|dd\}|dd}|dkr\td|dd\}|dd}|d|}||d}|tt|dt|dt dS)Nrrrrr ) Z!_ensure_algorithm_key_combinationr r%unpackrZRSAPublicNumbersr! from_bytes public_keyr)clsr Zkeyptrbytes_Zrsa_eZrsa_nrrr from_dnskey#s"      zPublicRSA.from_dnskey)__name__ __module__ __qualname__rZ RSAPublicKey__annotations__key_clsrrZ HashAlgorithmbytesrr* classmethodr r3rrrrr s    r c@sNeZdZUejed<ejZeZdZ d e e e dddZ e edddd Zd S) PrivateRSAr iF)rrrcCs0|j|t|jj}|r,||||S)z1Sign using a private key per RFC 3110, section 3.)r signrr public_clsr r0r)rrrrrrrr<;szPrivateRSA.sign)key_sizercCs|tj|j|tddS)N)Zpublic_exponentr>backendr-)rZgenerate_private_keydefault_public_exponentr)r1r>rrrgenerateBszPrivateRSA.generateN)F)r4r5r6rZ RSAPrivateKeyr7r8r r=r@r9boolr<r:r!rArrrrr;5s  r;c@seZdZejZeZdS) PublicRSAMD5N) r4r5r6rZRSAMD5r rMD5r rrrrrCMsrCc@seZdZeZdS) PrivateRSAMD5N)r4r5r6rCr=rrrrrERsrEc@seZdZejZeZdS) PublicRSASHA1N) r4r5r6rZRSASHA1r rSHA1r rrrrrFVsrFc@seZdZeZdS)PrivateRSASHA1N)r4r5r6rFr=rrrrrH[srHc@seZdZejZeZdS)PublicRSASHA1NSEC3SHA1N) r4r5r6rZRSASHA1NSEC3SHA1r rrGr rrrrrI_srIc@seZdZeZdS)PrivateRSASHA1NSEC3SHA1N)r4r5r6rIr=rrrrrJdsrJc@seZdZejZeZdS)PublicRSASHA256N) r4r5r6rZ RSASHA256r rSHA256r rrrrrKhsrKc@seZdZeZdS)PrivateRSASHA256N)r4r5r6rKr=rrrrrMmsrMc@seZdZejZeZdS)PublicRSASHA512N) r4r5r6rZ RSASHA512r rSHA512r rrrrrNqsrNc@seZdZeZdS)PrivateRSASHA512N)r4r5r6rNr=rrrrrPvsrP)rr%Zcryptography.hazmat.backendsrZcryptography.hazmat.primitivesrZ)cryptography.hazmat.primitives.asymmetricrrZdns.dnssecalgs.cryptographyrrZdns.dnssectypesrZdns.rdtypes.ANY.DNSKEYr r r;rCrErFrHrIrJrKrMrNrPrrrrs&    (