a fr@sddlZddlZddlZddlZddlmZzddlmZWneyZddl mZYn0ddl m Z m Z m Z egdZe e e dZGdddeZdd d Zd d Zd dZddZddZddZGdddeZddZdS)N)six)parse_http_list)SHA1SHA256SHA512)zrsa-sha1z rsa-sha256z rsa-sha512z hmac-sha1z hmac-sha256z hmac-sha512)Zsha1Zsha256Zsha512c@s eZdZdS)HttpSigExceptionN)__name__ __module__ __qualname__r r B/usr/lib/python3.9/site-packages/oci/_vendor/httpsig_cffi/utils.pyrsrcCst|}|sdg}g}|D]}|}|dkrX|r6|s>td|d|||fq|dkr|sd|vrv||}n td||d||fq||vrtd||d|||fqd|d }|S) Ndatez(request-target)z@method and path arguments required when using "(request-target)"z %s: %s %shostzmissing required header "%s"z%s: %s ascii)CaseInsensitiveDictlower Exceptionappendjoinencode)Zrequired_headersheadersrmethodpathZ signable_listhZsignabler r r generate_messages*   rcCst|tjs|d}|dd}t|dkr6tdi}t|dkr|d}|rt|rt|}|D]N}d|vrf|dd\}}t|rft|sqf|ddkr|dd }|||<qf|dt|fS) Nr zHInvalid authorization header. (eg. Method key1=value1,key2="value, "2"")=r") isinstancerZ string_typesdecodesplitlen ValueErrorrr)headerZauthvaluesZ auth_valuefieldsitemkeyvaluer r r parse_authorization_header@s&         r-cCsT||dd}|r,dd|D}d||d<tdj|}d|}d |}|S) a Build the Signature template for use with the Authorization header. key_id is the mandatory label indicating to the server which secret to use algorithm is one of the six specified algorithms headers is a list of http headers to be included in the signing string. The signature must be interpolated into the template to get the final Authorization header value. z%s)ZkeyId algorithmZ signaturecSsg|] }|qSr r).0rr r r pz,build_signature_template..rrz{0[0]}="{0[1]}",z Signature {0})rmapformatitems)Zkey_idr.rZ param_mapZkvZ kv_stringZ sig_stringr r r build_signature_templatebs   r7cCsPg}|rLtd|ddd}|d|d}||||dd}q|S)Nz>Ir)structunpackr)dpartsr%bitsr r r lkvxs r>cCs t|dS)Nr)r>)r;r r r sigsr?cCst|jddkS)Nrssh-rsa)r>Zblob)Zkeyobjr r r is_rsasrAcsBeZdZd fdd ZfddZfddZfdd ZZS) rNc s8tt|jfi||r4|ddt|DdS)Ncss|]\}}||fVqdSNr/)r0kvr r r r2z/CaseInsensitiveDict.__init__..)superr__init__updaterZ iteritems)selfr;kwargs __class__r r rGszCaseInsensitiveDict.__init__cstt|||dSrB)rFr __setitem__r)rIr+r,rKr r rMszCaseInsensitiveDict.__setitem__cstt||SrB)rFr __getitem__rrIr+rKr r rNszCaseInsensitiveDict.__getitem__cstt||SrB)rFr __contains__rrOrKr r rPsz CaseInsensitiveDict.__contains__)N)rr r rGrMrNrP __classcell__r r rKr rs  rc Cs|dr|dd}nd}t||d}|dd}|d}t|}t | }d d d t |d d d |dd d DS) z{ Takes an ssh public key and generates the fingerprint. See: http://tools.ietf.org/html/rfc4716 for more info r@rrz\-{4,5}[\w|| ]+\-{4,5}rr:css|]\}}||VqdSrBr )r0abr r r rEr2z"get_fingerprint..Nr) startswithr$rereplacestriprbase64Z b64decodehashlibZmd5Z hexdigestrzip)r+ZregexZfp_plainr r r get_fingerprints   r])NNN)rWr9r[rZZ oci._vendorrZurllib.requestr ImportErrorZurllib2Z%cryptography.hazmat.primitives.hashesrrr frozensetZ ALGORITHMSZHASHESrrrr-r7r>r?rAdictrr]r r r r s(     ""