/usr/lib/python2.6/site-packages/keystoneclient/common
NameSizeModeActions
cms.py154100644editdlrm
cms.pyc140780644editdlrm
__init__.py00644editdlrm
__init__.pyc1640644editdlrm
Edit: /usr/lib/python2.6/site-packages/keystoneclient/common/cms.pyc (14078B)
Ñò ddkl}|ioddklan ddkaWqktj oddkaqkXndS(Niÿÿÿÿ(tpatcher(t subprocess(RteventletRtalready_patchedteventlet.greent ImportError(R((sH/tmp/pip-build-cD3xZi/python-keystoneclient/keystoneclient/common/cms.pyt_ensure_subprocess5s cCs |adS(s‘Set subprocess module to use. The subprocess could be eventlet.green.subprocess if using eventlet, or Python's subprocess otherwise. N(R(t _subprocess((sH/tmp/pip-build-cD3xZi/python-keystoneclient/keystoneclient/common/cms.pytset_subprocessEsc CsŽd}d}y6x/|D]'}t|dƒiiƒzWdQXqWWn?tj o3}tdƒh|d6|id6}ti}nX||fS(NiÿÿÿÿtrsVHit OSError in _process_communicate_handle_oserror() Likely due to %(file)s: %(error)stfileterror( tNonetopent__exit__t __enter__tIOErrorRtstrerrorR R (tfilesterrtretcodettry_filete((sH/tmp/pip-build-cD3xZi/python-keystoneclient/keystoneclient/common/cms.pyt_check_files_accessibleNs  cCsÌy|i|ƒ\}}Wnwtj ok}|itijo‚nt|ƒ\}}|io&|iiƒ}||idƒ}nd}n.X|iƒ}|dj o|idƒ}n|||fS(s;Wrapper around process.communicate that checks for OSError.sutf-8tN( t communicatetOSErrorterrnotEPIPER&tstderrtreadtdecodetpollR(tprocesstdataR!toutputR"R%R#tmsg((sH/tmp/pip-build-cD3xZi/python-keystoneclient/keystoneclient/common/cms.pyt#_process_communicate_handle_oserrorbs    cCsW|tjo d}n=|tjo d}n&ttdƒdittfƒƒ‚|S(NsUTF-8thexs"inform" must be one of: %st,(t PKI_ASN1_FORMt PKIZ_CMS_FORMt ValueErrorRtjoin(tinformtencoding((sH/tmp/pip-build-cD3xZi/python-keystoneclient/keystoneclient/common/cms.pyt_encoding_for_form|s    c Cs0tƒt|tiƒot|t|ƒƒ}n|}tidddd|d|dddd d d g d tid tidtidt ƒ}t ||||fƒ\}}}|t i jo6|i dƒoti|ƒ‚q,ti|ƒ‚n6|t ijo%ti|dƒ} || _| ‚n|S(sLVerifies the signature of the contents IAW CMS syntax. :raises subprocess.CalledProcessError: :raises keystoneclient.exceptions.CertificateConfigError: if certificate is not configured properly. topenssltcmss-verifys -certfiles-CAfiles-informRs -nosmimecaps -nodetachs-nocertss-noattrtstdintstdoutR,t close_fdssError reading S/MIME message(Rt isinstancetsixt string_typest bytearrayR=RtPopentPIPEtTrueR4R R t startswithRtCMSErrortCertificateConfigErrorR tCalledProcessErrorR2( t formattedtsigning_cert_file_namet ca_file_nameR;R1R0R2R"R#R%((sH/tmp/pip-build-cD3xZi/python-keystoneclient/keystoneclient/common/cms.pyt cms_verify‰s2        cCs |itƒS(s•Determine if a token a cmsz token Checks if the string has the prefix that indicates it is a Crypto Message Syntax, Z compressed token. (RJt PKIZ_PREFIX(t token_text((sH/tmp/pip-build-cD3xZi/python-keystoneclient/keystoneclient/common/cms.pytis_pkiz¿sicCsMt|||td|ƒ}ti||ƒ}tti|ƒidƒ}|S(Ntmessage_digestsutf-8(t cms_sign_dataR8tzlibtcompressRRtbase64turlsafe_b64encodeR.(ttextROtsigning_key_file_nametcompression_levelRUtsignedt compressedtencoded((sH/tmp/pip-build-cD3xZi/python-keystoneclient/keystoneclient/common/cms.pyt pkiz_signÈs  cCs;|ttƒidƒ}ti|ƒ}ti|ƒ}|S(Nsutf-8(tlenRRtencodeRYturlsafe_b64decodeRWt decompress(t signed_textR[t unencodedt uncompressed((sH/tmp/pip-build-cD3xZi/python-keystoneclient/keystoneclient/common/cms.pytpkiz_uncompressÙscCs"t|ƒ}t|||dtƒS(NR;(RiRQR8(RfRORPRh((sH/tmp/pip-build-cD3xZi/python-keystoneclient/keystoneclient/common/cms.pyt pkiz_verifyàs cCsK|iddƒ}dg}|ti|dƒ7}|idƒdi|ƒS(sConverts a custom formatted token to a PEM-formatted token. See documentation for cms_to_token() for details on the custom formatting. t-t/s-----BEGIN CMS-----i@s-----END CMS----- s (treplacettextwraptwraptappendR:(Rft copy_of_texttlines((sH/tmp/pip-build-cD3xZi/python-keystoneclient/keystoneclient/common/cms.pyt token_to_cmsæs   cCstt|ƒ||ƒS(N(RQRs(ttokenRORP((sH/tmp/pip-build-cD3xZi/python-keystoneclient/keystoneclient/common/cms.pyt verify_tokenós cCs|d tjS(s§Determine if a token appears to be PKI-based. thx to ayoung for sorting this out. base64 decoded hex representation of MII is 3082:: In [3]: binascii.hexlify(base64.b64decode('MII=')) Out[3]: '3082' re: http://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf :: pg4: For tags from 0 to 30 the first octet is the identfier pg10: Hex 30 means sequence, followed by the length of that sequence. pg5: Second octet is the length octet first bit indicates short or long form, next 7 bits encode the number of subsequent octets that make up the content length octets as an unsigned binary int 82 = 10000010 (first bit indicates long form) 0000010 = 2 octets of content length so read the next 2 octets to get the length of the content. In the case of a very large content length there could be a requirement to have more than 2 octets to designate the content length, therefore requiring us to check for MIM, MIQ, etc. :: In [4]: base64.b64encode(binascii.a2b_hex('3083')) Out[4]: 'MIM=' In [5]: base64.b64encode(binascii.a2b_hex('3084')) Out[5]: 'MIQ=' Checking for MI would become invalid at 16 octets of content length 10010000 = 90 In [6]: base64.b64encode(binascii.a2b_hex('3090')) Out[6]: 'MJA=' Checking for just M is insufficient But we will only check for MII: Max length of the content using 2 octets is 3FFF or 16383. It's not practical to support a token of this length or greater in http therefore, we will check for MII only and ignore the case of larger tokens i(tPKI_ASN1_PREFIX(Rt((sH/tmp/pip-build-cD3xZi/python-keystoneclient/keystoneclient/common/cms.pyt is_asn1_tokenùs/tmessagesUse is_asn1_token() instead.tversions1.7.0tremoval_versions2.0.0cCs t|ƒS(s˜Deprecated. This function is deprecated as of the 1.7.0 release in favor of :func:`is_asn1_token` and may be removed in the 2.0.0 release. (Rw(Rt((sH/tmp/pip-build-cD3xZi/python-keystoneclient/keystoneclient/common/cms.pyt is_ans1_token+scCst|||d|ƒS(NRU(RV(t data_to_signROR\RU((sH/tmp/pip-build-cD3xZi/python-keystoneclient/keystoneclient/common/cms.pyt cms_sign_text6s c CsGtƒt|tiƒot|ddƒ}n|}tidddd|d|dd d d d d d|gdtidtidtidtƒ}t ||||fƒ\}}} | t i jp d|joS| t i jot itdƒƒnt itdƒ|ƒti| dƒ‚n|tjo|idƒS|SdS(scUses OpenSSL to sign a document. Produces a Base64 encoding of a DER formatted CMS Document http://en.wikipedia.org/wiki/Cryptographic_Message_Syntax :param data_to_sign: data to sign :param signing_cert_file_name: path to the X509 certificate containing the public key associated with the private key used to sign the data :param signing_key_file_name: path to the private key used to sign the data :param outform: Format for the signed document PKIZ_CMS_FORM or PKI_ASN1_FORM :param message_digest: Digest algorithm to use when signing or resigning R<sutf-8R>R?s-signs-signers-inkeys-outformRs -nosmimecaps -nodetachs-nocertss-noattrs-mdR@RAR,RBtErrorskSigning error: Unable to load certificate - ensure you have configured PKI with "keystone-manage pki_setup"sSigning error: %sN(RRCRDRERFRRGRHRIR4R R RtLOGRRRMR7R.( R|ROR\toutformRUR1R0R2R"R#((sH/tmp/pip-build-cD3xZi/python-keystoneclient/keystoneclient/common/cms.pyRV<s2      cCs"t|||d|ƒ}t|ƒS(NRU(RVt cms_to_token(R[ROR\RUR2((sH/tmp/pip-build-cD3xZi/python-keystoneclient/keystoneclient/common/cms.pytcms_sign_tokenps cCs^d}d}|}|iddƒ}|i|dƒ}|i|dƒ}|iddƒ}|S(sLConverts a CMS-signed token in PEM format to a custom URL-safe format. The conversion consists of replacing '/' char in the PEM-formatted token with the '-' char and doing other such textual replacements to make the result marshallable via HTTP. The return value can thus be used as the value of a HTTP header such as "X-Auth-Token". This ad-hoc conversion is an unfortunate oversight since the returned value now does not conform to any of the standard variants of base64 encoding. It would have been better to use base64url encoding (either on the PEM formatted text or, perhaps even better, on the inner CMS-signed binary value without any PEM formatting). In any case, the same conversion is done in reverse in the other direction (for token verification), so there are no correctness issues here. Note that the non-standard encoding of the token will be preserved so as to not break backward compatibility. The conversion issue is detailed by the code author in a blog post at http://adam.younglogic.com/2014/02/compressed-tokens/. s-----BEGIN CMS-----s-----END CMS-----RlRkR's (Rm(tcms_textt start_delimt end_delimRf((sH/tmp/pip-build-cD3xZi/python-keystoneclient/keystoneclient/common/cms.pyRwstmd5cCs|djodSt|ƒp t|ƒoMti|ƒ}t|tiƒo|idƒ}n|i |ƒ|i ƒS|SdS(s™Hash PKI tokens. return: for asn1 or pkiz tokens, returns the hash of the passed in token otherwise, returns what it was passed in. sutf-8N( RRwRTthashlibtnewRCRDt text_typeRctupdatet hexdigest(ttoken_idtmodethasher((sH/tmp/pip-build-cD3xZi/python-keystoneclient/keystoneclient/common/cms.pytcms_hash_token–s   (/t__doc__RYR*R‡tloggingRnRWt debtcollectorRRDtkeystoneclientRtkeystoneclient.i18nRRRRt getLoggerR RRvRRR8R7tDEFAULT_TOKEN_DIGEST_ALGORITHMtobjectR RRR&R4R=RQRTRaRiRjRsRuRwtremoveR{R}RVR‚RR(((sH/tmp/pip-build-cD3xZi/python-keystoneclient/keystoneclient/common/cms.pytsP            5     2  3