Spade
Mini Shell
| Directory:~$ /lib/python2.7/site-packages/josepy/ |
| [Home] [System Details] [Kill Me] |
�
�t0^c@s
dZddlZddlZddlZddlZddlZddlmZmZm Z m
Z
mZmZde
fd��YZde jfd��YZde jfd ��YZd
e jfd��YZde
fd
��YZedkreej��ndS(sJSON Web
Signature.i����N(tb64terrorst json_utiltjwatjwktutilt MediaTypecBs2eZdZdZed��Zed��ZRS(s
MediaType field
encoder/decoder.sapplication/cCs9d|kr5d|kr*tjd��n|j|S|S(sDecoder.t/t;sUnexpected
semi-colon(RtDeserializationErrortPREFIX(tclstvalue((s./usr/lib/python2.7/site-packages/josepy/jws.pytdecodes
cCs9d|kr5|j|j�s$t�|t|j�S|S(sEncoder.R(t
startswithR
tAssertionErrortlen(RR((s./usr/lib/python2.7/site-packages/josepy/jws.pytencodes(t__name__t
__module__t__doc__R
tclassmethodR
R(((s./usr/lib/python2.7/site-packages/josepy/jws.pyRs
tHeadercBs�eZdZejddejjde�Z ejdde�Z
ejddejjde�Zejdde�Z
ejdde�Zejdded d�Zejd
dejde�Zejddejde�Zejdd
ejdejde�Zejdd
ejdejde�Zejdded d�Zd�Zd�Zd�Zejd��Zejd��Zejd��ZRS(s6JOSE
Header.
.. warning:: This class supports **only** Registered Header
Parameter Names (as defined in section 4.1 of the
protocol). If you need Public Header Parameter Names (4.2)
or Private Header Parameter Names (4.3), you must subclass
and override :meth:`from_json` and :meth:`to_partial_json`
appropriately.
.. warning:: This class does not support any extensions through
the "crit" (Critical) Header Parameter (4.1.11) and as a
conforming implementation, :meth:`from_json` treats its
occurrence as an error. Please subclass if you seek for
a different behaviour.
:ivar x5tS256: "x5t#S256"
:ivar str typ: MIME Media Type, inc. :const:`MediaType.PREFIX`.
:ivar str cty: Content-Type, inc. :const:`MediaType.PREFIX`.
talgtdecodert omitemptytjkuRtkidtx5utx5ctdefaulttx5tsx5t#S256ttyptencodertctytcritcs&t�fd�tj�j�D��S(s4Fields
that would not be omitted in the JSON
object.c3sB|]8\}}|jt�|��s|t�|�fVqdS(N(tomittgetattr(t.0tnametfield(tself(s./usr/lib/python2.7/site-packages/josepy/jws.pys <genexpr>Ns (tdicttsixt iteritemst_fields(R)((R)s./usr/lib/python2.7/site-packages/josepy/jws.pytnot_omittedLscCs�t|t|��s3tdjt|����n|j�}|j�}t|�j|�rotd��n|j|�t|�|�S(NsHeader
cannot be added to: {0}s+Addition of overlapping headers not defined(t
isinstancettypet TypeErrortformatR.tsettintersectiontupdate(R)tothertnot_omitted_selftnot_omitted_other((s./usr/lib/python2.7/site-packages/josepy/jws.pyt__add__Rs
cCs(|jdkr!tjd��n|jS(s�Find
key based on header.
.. todo:: Supports only "jwk" header parameter lookup.
:returns: (Public) key found in the header.
:rtype: .JWK
:raises josepy.errors.Error: if key could not be found
sNo key
foundN(RtNoneRtError(R)((s./usr/lib/python2.7/site-packages/josepy/jws.pytfind_key`scCstjd��dS(Ns("crit"
is not supported, please
subclass(RR (tunused_value((s./usr/lib/python2.7/site-packages/josepy/jws.pyR#oscCs8g|D]-}tjtjjtjj|j��^qS(N(tbase64t b64encodetOpenSSLtcryptotdump_certificatet
FILETYPE_ASN1twrapped(Rtcert((s./usr/lib/python2.7/site-packages/josepy/jws.pyRwscCsGytd�|D��SWn(tjjk
rB}tj|��nXdS(Ncss<|]2}tjtjjtjjtj|���VqdS(N(RtComparableX509R@RAtload_certificateRCR>t b64decode(R&RE((s./usr/lib/python2.7/site-packages/josepy/jws.pys <genexpr>s(ttupleR@RAR;RR (Rterror((s./usr/lib/python2.7/site-packages/josepy/jws.pyR|s
(((RRRRtFieldRtJWASignaturet from_jsontTrueRRRtJWKRRRtdecode_b64joseRtx5tS256RRR
R
R"R#R.R9R<RR!(((s./usr/lib/python2.7/site-packages/josepy/jws.pyR&s.! t SignaturecBseZdZeZdZejddedd�Z ejddede�dej
�Zejddejd ej
�Ze jd
��Z e jd��Z d�Zed
��Zed��Zdd�Zeee�d��Zd�Zed��ZRS(sJWS
Signature.
:ivar combined: Combined Header (protected and unprotected,
:class:`Header`).
:ivar unicode protected: JWS protected header (Jose Base-64 decoded).
:ivar header: JWS Unprotected Header (:class:`Header`).
:ivar str signature: The signature.
tcombinedt protectedRRttheaderRt signatureR!cCstj|jd��S(Nsutf-8(Rtencode_b64joseR(R((s./usr/lib/python2.7/site-packages/josepy/jws.pyRT�scCstj|�jd�S(Nsutf-8(RRPR
(R((s./usr/lib/python2.7/site-packages/josepy/jws.pyRT�scKsPd|kr|j|�}ntt|�j|�|jjdk sLt�dS(NRS(t_with_combinedtsuperRRt__init__RSRR:R(R)tkwargs((s./usr/lib/python2.7/site-packages/josepy/jws.pyR[�scCs}d|kst�|jd|jdj�}|jd|jdj�}|ri||jj|�}n|}||d<|S(NRSRVRT(RtgetR-Rt
header_clst
json_loads(RR\RVRTRS((s./usr/lib/python2.7/site-packages/josepy/jws.pyRY�s
cCs'tj|jd��dtj|�S(Nsutf-8t.(RR?R(RRTtpayload((s./usr/lib/python2.7/site-packages/josepy/jws.pyt_msg�sc CsX|dkr|jj�n|}|jjjd|jd|jd|j|j|��S(sEVerify.
:param JWK key: Key used for verification.
tkeytsigtmsgN( R:RSR<RtverifyRcRWRbRT(R)RaRc((s./usr/lib/python2.7/site-packages/josepy/jws.pyRf�s!cKs#t||j�st�|}||d<|rA|j�|d<nt|�j|jj�sbt�|j|jj�s}t�i}x0|D](} | |kr�|j| �|| <q�q�W|r�|j|�j �}
nd}
|j|�} |j
|j|j|
|��}|d|
d| d|�S(s;Sign.
:param JWK key: Key for signature.
RRRURTRVRW(
R/tktyRt
public_keyR3tissubsetR^R-tpopt
json_dumpstsignRcRb(RRaRcRtinclude_jwktprotectR\t
header_paramstprotected_paramsRVRTRW((s./usr/lib/python2.7/site-packages/josepy/jws.pyRl�s"
!
!cCs3tt|�j�}|dj�s/|d=n|S(NRV(RZRRtfields_to_partial_jsonR.(R)tfields((s./usr/lib/python2.7/site-packages/josepy/jws.pyRq�s
cCsStt|�j|�}|j|�}d|dj�krOtjd��n|S(NRRSsalg
not
present(RZRRtfields_from_jsonRYR.RR (RtjobjRrtfields_with_combined((s./usr/lib/python2.7/site-packages/josepy/jws.pyRs�s
(scombinedN(RRRRR^t __slots__RRKRNRTRMRVRPRXRWR!RR[RRYRbR:Rft frozensetRlRqRs(((s./usr/lib/python2.7/site-packages/josepy/jws.pyRR�s* tJWScBsweZdZd
ZeZdd�Zed��Z e
d��Zd�Zed��Z
ed�Zed ��ZRS(sgJSON Web
Signature.
:ivar str payload: JWS Payload.
:ivar str signature: JWS Signatures.
Rat
signaturescs
t��fd��jD��S(sVerify.c3s$|]}|j�j��VqdS(N(RfRa(R&Rd(RcR)(s./usr/lib/python2.7/site-packages/josepy/jws.pys <genexpr>s(tallRy(R)Rc((RcR)s./usr/lib/python2.7/site-packages/josepy/jws.pyRfscKs(|d|d|jjd||�f�S(sSign.RaRy(t
signature_clsRl(RRaR\((s./usr/lib/python2.7/site-packages/josepy/jws.pyRlscCs&t|j�dkst�|jdS(sPGet
a singleton signature.
:rtype: :class:`JWS.signature_cls`
ii(RRyR(R)((s./usr/lib/python2.7/site-packages/josepy/jws.pyRW
scCs�t|j�dkst�d|jjj�ks9t�tj|jjj d��dtj|j
�dtj|jj�S(s7Compact serialization.
:rtype: bytes
iRsutf-8R`(RRyRRWRVR.RR?RTRRa(R)((s./usr/lib/python2.7/site-packages/josepy/jws.pyt
to_compacts3cCs�y|jd�\}}}Wn tk
r>tjd��nX|jdtj|�jd�dtj|��}|dtj|�d|f�S(sACompact
deserialization.
:param bytes compact:
R`sOCompact JWS serialization should comprise of exactly 3
dot-separated componentsRTsutf-8RWRaRy(tsplitt
ValueErrorRR R{RRHR
(RtcompactRTRaRWRd((s./usr/lib/python2.7/site-packages/josepy/jws.pytfrom_compact)s
cCsv|jst�tj|j�}|r]t|j�dkr]|jdj�}||d<|Si|d6|jd6SdS(NiiRaRy(RyRRRXRaRtto_partial_json(R)tflatRatret((s./usr/lib/python2.7/site-packages/josepy/jws.pyR�<s
c s�d|kr*d|kr*tjd��nzd|krj�dtj|jd��d�jj|�f�S�dtj|d�dt�fd�|dD���SdS(NRWRysFlat
mixed with
non-flatRac3s!|]}�jj|�VqdS(N(R{RM(R&Rd(R(s./usr/lib/python2.7/site-packages/josepy/jws.pys <genexpr>Ss(RR RRPRjR{RMRI(RRt((Rs./usr/lib/python2.7/site-packages/josepy/jws.pyRMJs(spayloads
signaturesN(RRRRvRRR{R:RfRRltpropertyRWR|R�RNR�RM(((s./usr/lib/python2.7/site-packages/josepy/jws.pyRx�s
tCLIcBskeZdZed��Zed��Zed��Zed��Zed��Zedd��Z
RS(sJWS CLI.c
Cs�|jjj|jj��}|jj�|jdkrFg|_n|jrb|jj d�nt
jdtj
j�j�d|d|jdt|j��}|jr�tj|j�jd��ntj|j��dS(sSign.RRaRcRnsutf-8N(RRgtloadRctreadtcloseRnR:RtappendRxRltsyststdinRR3R+tprint_R|R
tjson_dumps_pretty(RtargsRcRd((s./usr/lib/python2.7/site-packages/josepy/jws.pyRlZs
- cCs�|jr*tjtjj�j��}nCytjtjj��}Wn$tj k
rl}t
j|�dSX|jdk r�|jdk s�t�|jj|jj��j�}|jj�nd}tjj|j�|jd|�S(sVerify.i����RcN(RRxR�R�R�R�RR_RR;R+R�RcR:RgRR�RhR�tstdouttwriteRaRf(RR�RdRJRc((s./usr/lib/python2.7/site-packages/josepy/jws.pyRfls !
!cCstjj|�S(N(RRLRM(Rtarg((s./usr/lib/python2.7/site-packages/josepy/jws.pyt _alg_type�scCs|tjjkst�|S(N(RRR^R-R(RR�((s./usr/lib/python2.7/site-packages/josepy/jws.pyt_header_type�scCs&|tjjkst�tjj|S(N(RROtTYPESR(RR�((s./usr/lib/python2.7/site-packages/josepy/jws.pyt _kty_type�scCsN|dkrtjd}ntj�}|jddd�|j�}|jd�}|jd|j �|jddd tj
d
�dt�|jdd
d |jdt
j�|jddddd |j�|jd�}|jd|j�|jddd tj
d
�dt�|jdd |jdt�|j|�}|j|�S(s Parse
arguments and sign/verify.is --compacttactiont
store_trueRltfuncs-ks--keyR0trbtrequireds-as--algRs-ps --protectR�Rfs--ktyN(R:R�targvtargparsetArgumentParsertadd_argumenttadd_subparserst
add_parsertset_defaultsRltFileTypeRNR�RtRS256R�RftFalseR�t
parse_argsR�(RR�tparsert
subparserstparser_signt
parser_verifytparsed((s./usr/lib/python2.7/site-packages/josepy/jws.pytrun�s*N(RRRRRlRfR�R�R�R:R�(((s./usr/lib/python2.7/site-packages/josepy/jws.pyR�Wst__main__(RR�R>R�R@R+tjosepyRRRRRRtobjectRtJSONObjectWithFieldsRRRRxR�RtexitR�(((s./usr/lib/python2.7/site-packages/josepy/jws.pyt<module>s.`r_V