a ‚oe:ã@s†UddlmZddlZddlZddlZddlZddlZddlmZddl m Z ddl m Z mZGdd„dejƒZdd „eDƒZe jeje jeje jeje jeje jeje jejiZd ed <ejeefZejeefZe j d e j!d e j"de j#de j$de jde j%de jde j&di Z'ded<dd „e' (¡DƒZ)dddœdd„Z*dddœdd„Z+Gdd „d ƒZ,Gd!d"„d"ƒZ-Gd#d$„d$ƒZ.Gd%d&„d&ƒZ/dS)'é)Ú annotationsN)Úutils)Úx509)ÚNameOIDÚObjectIdentifierc@s<eZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd S)Ú _ASN1Typeééé éééééééééN)Ú__name__Ú __module__Ú __qualname__Ú BitStringZ OctetStringÚ UTF8StringZ NumericStringÚPrintableStringZ T61StringÚ IA5StringZUTCTimeZGeneralizedTimeZ VisibleStringZUniversalStringZ BMPString©rrú7C:\Program Files\Certbot\pkgs\cryptography\x509\name.pyrsrcCsi|] }|j|“qSr)Úvalue©Ú.0ÚirrrÚ !ór!z(typing.Dict[ObjectIdentifier, _ASN1Type]Ú_NAMEOID_DEFAULT_TYPEZCNÚLZSTÚOZOUÚCZSTREETZDCZUIDÚ _OidNameMapÚ_NAMEOID_TO_NAMEcCsi|]\}}||“qSrr)rÚkÚvrrrr!<r"útyping.Union[str, bytes]Ústr)ÚvalÚreturncCsº|sdSt|tƒr&dt |¡ d¡S| dd¡}| dd¡}| dd ¡}| d d ¡}| d d ¡}| dd¡}| dd¡}| dd¡}|ddvršd|}|ddkr¶|dd…d}|S)z>Escape special characters in RFC4514 Distinguished Name value.Úú#Úutf8ú\z\\ú"z\"ú+z\+ú,z\,ú;z\;úz\>úz\00r)r0ú éÿÿÿÿr:Nz\ )Ú isinstanceÚbytesÚbinasciiZhexlifyÚdecodeÚreplace)r-rrrÚ_escape_dn_value?s"           rAcCs|sdSdd„}tj ||¡S)Nr/cSs(| d¡}t|ƒdkr|Stt|dƒƒS)Néé)ÚgroupÚlenÚchrÚint)Úmr-rrrÚsubds  z_unescape_dn_value..sub)Ú_RFC4514NameParserÚ_PAIR_RErI)r-rIrrrÚ_unescape_dn_value\srLc@sžeZdZd!ddœdddddd œd d „Zedd œd d„ƒZedd œdd„ƒZedd œdd„ƒZd"dddœdd„Zdddœdd„Z dd œdd„Z dd œdd „Z dS)#Ú NameAttributeNT)Ú _validaterr+ztyping.Optional[_ASN1Type]ÚboolÚNone)ÚoidrÚ_typerNr.cCsøt|tƒstdƒ‚|tjkrB|tjkr.tdƒ‚t|tƒsTtdƒ‚nt|tƒsTtdƒ‚|tj ksh|tj krºt|tƒsvJ‚t |  d¡ƒ}|dkrž|duržt dƒ‚n|dkrºtjd  |¡dd �|durÐt |tj¡}t|tƒsâtd ƒ‚||_||_||_dS) Nz2oid argument must be an ObjectIdentifier instance.z6oid must be X500_UNIQUE_IDENTIFIER for BitString type.z!value must be bytes for BitStringzvalue argument must be a strr1éTz/Country name must be a 2 character country codezUCountry names should be two characters, but the attribute is {} characters in length.)Ú stacklevelz%_type must be from the _ASN1Type enum)r<rÚ TypeErrorrrrZX500_UNIQUE_IDENTIFIERr=r,Ú COUNTRY_NAMEÚJURISDICTION_COUNTRY_NAMErEÚencodeÚ ValueErrorÚwarningsÚwarnÚformatr#ÚgetrÚ_oidÚ_valuerR)ÚselfrQrrRrNZc_lenrrrÚ__init__psJ ÿ  ÿ   ÿþÿÿý  zNameAttribute.__init__©r.cCs|jS©N)r^©r`rrrrQ¨szNameAttribute.oidcCs|jSrc)r_rdrrrr¬szNameAttribute.valuer,cCst |j|jj¡S)zt The short attribute name (for example "CN") if available, otherwise the OID dotted string. )r(r]rQZ dotted_stringrdrrrÚrfc4514_attribute_name°sz$NameAttribute.rfc4514_attribute_nameútyping.Optional[_OidNameMap]©Úattr_name_overridesr.cCs6|r| |j¡nd}|dur"|j}|›dt|jƒ›�S)z  Format as RFC4514 Distinguished Name string. Use short attribute name if available, otherwise fall back to OID dotted string. Nú=)r]rQrerAr)r`rhZ attr_namerrrÚrfc4514_string¸s ÿzNameAttribute.rfc4514_stringÚobject©Úotherr.cCs&t|tƒstS|j|jko$|j|jkSrc)r<rMÚNotImplementedrQr©r`rmrrrÚ__eq__És zNameAttribute.__eq__rGcCst|j|jfƒSrc)ÚhashrQrrdrrrÚ__hash__ÏszNameAttribute.__hash__cCs d |¡S)Nz/)r\rdrrrÚ__repr__ÒszNameAttribute.__repr__)N)N) rrrraÚpropertyrQrrerjrprrrsrrrrrMosüú8ÿrMc@s„eZdZddœdd„Zdddœdd „Zd d d d œdd„Zdddœdd„Zddœdd„Zddœdd„Zddœdd„Z d dœdd„Z d S)!ÚRelativeDistinguishedNameútyping.Iterable[NameAttribute])Ú attributescCs\t|ƒ}|stdƒ‚tdd„|Dƒƒs.tdƒ‚||_t|ƒ|_t|jƒt|ƒkrXtdƒ‚dS)Nz-a relative distinguished name cannot be emptycss|]}t|tƒVqdSrc©r<rM©rÚxrrrÚ Ûr"z5RelativeDistinguishedName.__init__..z/attributes must be an iterable of NameAttributez$duplicate attributes are not allowed)ÚlistrYÚallrUÚ _attributesÚ frozensetÚ_attribute_setrE©r`rwrrrra×s z"RelativeDistinguishedName.__init__rútyping.List[NameAttribute]©rQr.cs‡fdd„|DƒS)Ncsg|]}|jˆkr|‘qSr©rQrr„rrÚ èr"zDRelativeDistinguishedName.get_attributes_for_oid..r©r`rQrr„rÚget_attributes_for_oidåsz0RelativeDistinguishedName.get_attributes_for_oidNrfr,rgcsd ‡fdd„|jDƒ¡S)z¬ Format as RFC4514 Distinguished Name string. Within each RDN, attributes are joined by '+', although that is rarely used in certificates. r4c3s|]}| ˆ¡VqdSrc©rj©rÚattr©rhrrr{ósÿz;RelativeDistinguishedName.rfc4514_string..©Újoinr~©r`rhrr‹rrjês þz(RelativeDistinguishedName.rfc4514_stringrkrOrlcCst|tƒstS|j|jkSrc)r<rurnr€rorrrrpøs z RelativeDistinguishedName.__eq__rGrbcCs t|jƒSrc)rqr€rdrrrrrþsz"RelativeDistinguishedName.__hash__útyping.Iterator[NameAttribute]cCs t|jƒSrc)Úiterr~rdrrrÚ__iter__sz"RelativeDistinguishedName.__iter__cCs t|jƒSrc)rEr~rdrrrÚ__len__sz!RelativeDistinguishedName.__len__cCsd| ¡›d�S)Nzrˆrdrrrrssz"RelativeDistinguishedName.__repr__)N) rrrrar‡rjrprrr‘r’rsrrrrruÖsÿruc@sîeZdZejdddœdd„ƒZejdddœdd„ƒZdddœd d„Zed1d d dd œdd„ƒZd2dd dœdd„Zdddœdd„Z e ddœdd„ƒZ d3dddœd d!„Z d"d#d$œd%d&„Z d'dœd(d)„Zd*dœd+d,„Zd'dœd-d.„Zd dœd/d0„Zd S)4ÚNamervrP)rwr.cCsdSrcrr�rrrra sz Name.__init__z*typing.Iterable[RelativeDistinguishedName]cCsdSrcrr�rrrraszGtyping.Iterable[typing.Union[NameAttribute, RelativeDistinguishedName]]cCs`t|ƒ}tdd„|Dƒƒr,dd„|Dƒ|_n0tdd„|DƒƒrTt tjt|¡|_ntdƒ‚dS)Ncss|]}t|tƒVqdSrcrxryrrrr{r"z Name.__init__..cSsg|]}tt t|¡gƒ‘qSr)ruÚtypingÚcastrMryrrrr…sÿz!Name.__init__..css|]}t|tƒVqdSrc)r<ruryrrrr{"r"zNattributes must be a list of NameAttribute or a list RelativeDistinguishedName)r|r}r~r•r–ÚListrurUr�rrrrasþ  ÿÿNr,ztyping.Optional[_NameOidMap]©Údatarhr.cCst||p iƒ ¡Src)rJÚparse)Úclsr™rhrrrÚfrom_rfc4514_string,szName.from_rfc4514_stringrfrgcsd ‡fdd„t|jƒDƒ¡S)að Format as RFC4514 Distinguished Name string. For example 'CN=foobar.com,O=Foo Corp,C=US' An X.509 name is a two-level structure: a list of sets of attributes. Each list element is separated by ',' and within each list element, set elements are separated by '+'. The latter is almost never used in real world certificates. According to RFC4514 section 2.1 the RDNSequence must be reversed when converting to string representation. r5c3s|]}| ˆ¡VqdSrcrˆr‰r‹rrr{Asÿz&Name.rfc4514_string..)r�Úreversedr~rŽrr‹rrj4s þzName.rfc4514_stringrr‚rƒcs‡fdd„|DƒS)Ncsg|]}|jˆkr|‘qSrr„rr„rrr…Ir"z/Name.get_attributes_for_oid..rr†rr„rr‡FszName.get_attributes_for_oidz&typing.List[RelativeDistinguishedName]rbcCs|jSrc©r~rdrrrÚrdnsKsz Name.rdnsz typing.Anyr=)Úbackendr.cCs t |¡Src)Ú rust_x509Zencode_name_bytes)r`r rrrÚ public_bytesOszName.public_bytesrkrOrlcCst|tƒstS|j|jkSrc)r<r”rnr~rorrrrpRs z Name.__eq__rGcCstt|jƒƒSrc)rqÚtupler~rdrrrrrXsz Name.__hash__r�ccs |jD]}|D] }|VqqdSrcrž)r`ÚrdnZavarrrr‘]s z Name.__iter__cCstdd„|jDƒƒS)Ncss|]}t|ƒVqdSrc)rE)rr¤rrrr{cr"zName.__len__..)Úsumr~rdrrrr’bsz Name.__len__cCs"d dd„|jDƒ¡}d|›d�S)Nr5css|]}| ¡VqdSrcrˆr‰rrrr{fr"z Name.__repr__..z]|[\da-zA-Z]{2})z7[\x01-\x1f\x21\x24-\x2A\x2D-\x3A\x3D\x3F-\x5B\x5D-\x7F]z3[\x01-\x21\x23-\x2A\x2D-\x3A\x3D\x3F-\x5B\x5D-\x7F]z7[\x01-\x1F\x21\x23-\x2A\x2D-\x3A\x3D\x3F-\x5B\x5D-\x7F]z[\x80-ú]ú|z ( (z!) ( (z)* (z$) )? )? z#([\da-zA-Z]{2})+r,Ú _NameOidMaprPr˜cCs||_d|_||_dS)Nr)Ú_dataÚ_idxÚ_attr_name_overrides)r`r™rhrrrra…sz_RFC4514NameParser.__init__rOrbcCs|jt|jƒkSrc)r­rEr¬rdrrrÚ _has_data‹sz_RFC4514NameParser._has_dataztyping.Optional[str]cCs| ¡r|j|jSdSrc)r¯r¬r­rdrrrÚ_peekŽs z_RFC4514NameParser._peek)Úchr.cCs"| ¡|krt‚|jd7_dS)NrB)r°rYr­)r`r±rrrÚ _read_char“s z_RFC4514NameParser._read_charcCs<|j|j|jd�}|durt‚| ¡}|jt|ƒ7_|S)N)Úpos)Úmatchr¬r­rYrDrE)r`Úpatr´r-rrrÚ_read_re˜s z_RFC4514NameParser._read_rer”cCs8| ¡g}| ¡r,| d¡| | ¡¡q tt|ƒƒS)a' Parses the `data` string and converts it to a Name. According to RFC4514 section 2.1 the RDNSequence must be reversed when converting to string representation. So, when we parse it, we need to reverse again to get the RDNs on the correct order. r5)Ú _parse_rdnr¯r²Úappendr”r�r¦rrrrš s  z_RFC4514NameParser.parserucCs8| ¡g}| ¡dkr0| d¡| | ¡¡q t|ƒS)Nr4)Ú _parse_nar°r²r¸ru)r`Znasrrrr·±s    z_RFC4514NameParser._parse_rdnrMc Cs°z| |j¡}Wn>tyN| |j¡}|j |t |¡¡}|durJt‚Yn 0t|ƒ}| d¡|  ¡dkr’| |j ¡}t   |dd…¡  ¡}n| |j¡}t|ƒ}t||ƒS)Nrir0rB)r¶Ú_OID_RErYÚ _DESCR_REr®r]Ú_NAME_TO_NAMEOIDrr²r°Ú _HEXSTRING_REr>Z unhexlifyr?Ú _STRING_RErLrM)r`Z oid_valueÚnamerQrZ raw_valuerrrr¹¹s"   ÿ     z_RFC4514NameParser._parse_naN)rrrÚreÚcompilerºr»Z_PAIRrKZ_LUTF1Z_SUTF1Z_TUTF1rFÚsysÚ maxunicodeZ_UTFMBZ _LEADCHARZ _STRINGCHARZ _TRAILCHARÚVERBOSEr¾r½rar¯r°r²r¶ršr·r¹rrrrrJjsH   þþüüûû ö rJ)0Z __future__rr>rÀrÂr•rZZ cryptographyrZ"cryptography.hazmat.bindings._rustrr¡Zcryptography.x509.oidrrÚEnumrZ_ASN1_TYPE_TO_ENUMrVrrWZ SERIAL_NUMBERZ DN_QUALIFIERZ EMAIL_ADDRESSrZDOMAIN_COMPONENTr#Ú__annotations__ÚMappingr,r'r«Z COMMON_NAMEZ LOCALITY_NAMEZSTATE_OR_PROVINCE_NAMEZORGANIZATION_NAMEZORGANIZATIONAL_UNIT_NAMEZSTREET_ADDRESSZUSER_IDr(Úitemsr¼rArLrMrur”rJrrrrÚsH  ú ÷ g5_