+
    :i2C  c                  s   ^ RI Ht ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIH	t	H
t
 ^ RIHt ^ RIHtHt ^ RIHt ^ RIHt ^ RIHt ^ R	IHtHtHt ^R
IHtHtHtHtHtHtH t H!t! ^RI"H#t#H$t$H%t%H&t& ]PN                  ! ](4      t)^qt*^rt+^st,^tt-^ut.^vt/^wt0^xt1^yt2^zt3^|t4^t5^t6^t7^t8^t9^t:^t;^t<^t=^t>]P~                  ! R4      t@^tA^tB^tC^tD^ tE^tF^tG] ! R R]4      4       tH] ! R R]4      4       tI^tJR R ltKR tL] ! R R4      4       tM] ! R R4      4       tN]]! RRR7       ! R R4      4       4       tO]C3R ltPR tQR tRR  tSR! tTR" tUR# tVR$ tW ! R% R&4      tXR# )'    )annotationsN)	b32decode	b64encode)	dataclass)IntEnumunique)total_ordering)time)Mapping)parse_qsunquoteurlparse)BadResponseErrorNotSupportedErrorTlvVersion_override_version	bytes2int	int2bytesrequire_version)AIDScpKeyParamsSmartCardConnectionSmartCardProtocolz^((\d+)/)?(([^:]+):)?(.+)$c                  s"    ] tR t^Et^t^t^tRtR# )HASH_ALGORITHM N)__name__
__module____qualname____firstlineno__SHA1ZSHA256ZSHA512__static_attributes__r       1/usr/lib/python3.14/site-packages/yubikit/oath.pyr   r   E   s    DFFr!   r   c                  s    ] tR t^Lt^t^ tRtR# )	OATH_TYPEr   N)r   r   r   r   HOTPTOTPr    r   r!   r"   r#   r#   L   s    DDr!   r#   c                   V ^8  d   QhRR/# )   keystrr   Zformat   "r"   __annotate__r,   U   s      s r!   c                s    V P                  4       P                  RR4      p V R\        V 4      ) ^,          ,          ,          p \        V 4      # )z?Parse Base32 encoded key.

:param key: The Base32 encoded key.
Z  Z=)upperreplacelenr   )r(      &r"   parse_b32_keyr2   U   s?    
 ))+

c2
&C33s8)a-  CS>r!   c                s    \         P                  ! V 4      p\        P                  ! \        P
                  ! V\        ,          4      4      VP                  \        4      VP                  \        4      3# N)
r   Z
parse_dictr   Zpatchr   Z
from_bytesTAG_VERSIONgetTAG_NAMETAG_CHALLENGE)responsedata   & r"   _parse_selectr;   _   sP    >>(#D 2 243D EF r!   c                  s    ] tR t^ht$ RtR]R&   R]R&   R]R&   R]R	&   ]tR
]R&   ]t	R
]R&   ]
tR
]R&   RtR]R&   ]R R l4       tR R ltRtR# )CredentialDataz'An object holding OATH credential data.r)   namer#   	oath_typer   hash_algorithmbytessecretintdigitsperiodcounterN
str | Noneissuerc                    V ^8  d   QhRRRR/# )r'   urir)   returnr<   r   r*   r+   r"   r,   CredentialData.__annotate__v   s     
 
C 
N 
r!   c                s    \        VP                  4       4      pVP                  R8w  d   \        R4      hVP                  f   \        R4      h\
        VP                  P                  4       ,          p\        R \        VP                  4      P                  4        4       4      pRp\        VP                  4      R,          pRV9   d   VP                  R^4      w  rVV ! VV\        VP                  RR	4      P                  4       ,          \!        VR
,          4      \#        VP                  R\$        4      4      \#        VP                  R\&        4      4      \#        VP                  R\(        4      4      VP                  RV4      R7      # )zIParse OATH credential data from URI.

:param uri: The URI to parse from.
ZotpauthzInvalid URI schemeNzMissing OATH typec              3  s:   "   T F  w  rW^ ,          3x  K  	  R# 5i)r    Nr   )Z.0ZkZvs   &  r"   Z	<genexpr>Z+CredentialData.parse_uri.<locals>.<genexpr>   s     K,JDAqA$i,Js      NN:Z	algorithmr   rA   rC   rD   rE   rG   )r=   r>   r?   rA   rC   rD   rE   rG   )r   ZstripZscheme
ValueErrorZhostnamer#   r.   Zdictr
   ZqueryZitemsr   Zpathsplitr   r5   r2   rB   DEFAULT_DIGITSDEFAULT_PERIODDEFAULT_IMF)ZclsrI   Zparsedr>   ZparamsrG   r=      &&     r"   	parse_uriZCredentialData.parse_uriu   s/    #))+&==I%122??"011foo3356	KHV\\,B,H,H,JKKv{{#B'$;::c1-LF)&**[&*I*O*O*QR !12vzz(N;<vzz(N;<

9k:;::h/	
 		
r!   c               r&   )r'   rJ   r@   r   r*   r+   r"   r,   rK      s     T T Tr!   c                	sn    \        V P                  V P                  V P                  V P                  4      # r3   )_format_cred_idrG   r=   r>   rD   selfr1   r"   get_idZCredentialData.get_id   s#    t{{DIIt~~t{{SSr!   r   )r   r   r   r   __doc____annotations__rQ   rC   rR   rD   rS   rE   rG   ZclassmethodrU   rY   r    r   r!   r"   r<   r<   h   sa    1
I""M FC  FC GSFJ
 
<T Tr!   r<   c                  s:    ] tR t^t$ RtR]R&   R]R&   R]R&   RtR# )	CodezAn OATH code object.r)   valuerB   
valid_fromvalid_tor   N)r   r   r   r   rZ   r[   r    r   r!   r"   r\   r\      s    JOMr!   r\   FT)ZorderZfrozenc                  st    ] tR t^t$ RtR]R&   R]R&   R]R&   R]R&   R	]R
&   R]R&   R]R&   R tR tR tRt	R# )
CredentialzAn OATH credential object.r)   	device_idr@   idrF   rG   r=   r#   r>   rB   rD   zbool | Nonetouch_requiredc                	s*   V P                   ;'       g    V P                  P                  4       V P                  P                  4       3pVP                   ;'       g    VP                  P                  4       VP                  P                  4       3pW#8  # r3   )rG   r=   Zlower)rX   otherZaZb   &&  r"   __lt__ZCredential.__lt__   sg    kk&&TYY--/1BCll((ejj//15::3C3C3EFur!   c                	s    \        V\        V 4      4      ;'       d;    V P                  VP                  8H  ;'       d    V P                  VP                  8H  # r3   )Z
isinstanceZtypera   rb   )rX   rd      &&r"   __eq__ZCredential.__eq__   sI    ud4j) $ $%//1$ $588#	
r!   c                	sD    \        V P                  V P                  34      # r3   )Zhashra   rb   rW   r1   r"   __hash__ZCredential.__hash__   s    T^^TWW-..r!   r   N)
r   r   r   r   rZ   r[   rf   rh   ri   r    r   r!   r"   r`   r`      s<     %NI
IK

/r!   r`   c                s    R pV\         P                  8X  d   V\        8w  d   VRV,          ,          pV '       d   W@R,           ,          pWA,          pVP                  4       # )r-   z%d/rN   )r#   r%   rR   encode)rG   r=   r>   rD   cred_ids   &&&& r"   rV   rV      sK    GINN"v'?56>!C<OG>>r!   c                s   V P                  4       pV\        P                  8X  ds   \        P	                  V4      pV'       dM   VP                  ^4      pVP                  ^4      VP                  ^4      V'       d   \        V4      3# \        3# RV\        3# RV9   d$   V^ ,          R8w  d   VP                  R^4      w  rRMRpWR^ 3# )r'   NrN   )	decoder#   r%   TOTP_ID_PATTERNmatchZgrouprB   rR   rP   )rk   r>   r9   rn   Z
period_strrG   s   &&    r"   _parse_cred_idro      s    >>DINN"%%d+QJAA#-J  4B  ~--$;47c>::c1-LFDF?r!   c                s    \         P                  ! V 4      P                  4       R ,          p\        V4      P	                  RR4      P                  4       # ):Ni   Ns   =r!   )hashlibZsha256digestr   r/   rl   )saltdr:   r"   _get_device_idrt      s>    t##%c*AQ<c*1133r!   c                sL    \         P                  ! WR 4      P                  4       # )sha1)hmacnewrq   )r(   Zmessagerg   r"   
_hmac_sha1rx      s    88C&)0022r!   c                sR    \         P                  ! R VP                  4       V R^4      # )ru   i  )rp   Zpbkdf2_hmacrj   )rr   Z
passphraserg   r"   _derive_keyry      s$    vz'8'8':D$KKr!   c                s    \         P                  ! VP                  4      p\        V 4      VP                  8  d"   VP                  V 4       VP                  4       p V # r3   )rp   rw   r=   r0   Z
block_sizeZupdaterq   )r(   ZalgoZh   && r"   _hmac_shorten_keyr{      s?    DIIA
3x!,,	hhjJr!   c                s@    W,          p\         P                  ! R V4      # )z>q)structpack)	timestamprD   	time_steprz   r"   _get_challenger      s    #I;;tY''r!   c                sn   V P                   \        P                  8X  d@   WP                  ,          pW0P                  ,          pV^,           V P                  ,          pMTpRpV^ ,          p\	        \        \        VR,          4      R,          ^
V,          ,          4      P                  VR4      VV4      # )rM   l    rL   iZ0)r>   r#   r%   rD   r\   r)   r   Zrjust)
credentialr~   Z	truncatedr   r^   r_   rC      &&&    r"   _format_coder      s    y~~-!2!22	!2!22
MZ%6%66
%q\FYy}%
2b&j@AGGPST r!   c                  s"   ] tR tRtRtR'R R llt]R R l4       t]R R	 l4       t]R
 R l4       t	]R R l4       t
R R ltR R ltR R ltR R ltR R ltR(R R lltR'R R lltR R ltR R ltR  R! ltR'R" R# lltR'R$ R% lltR&tR# ))OathSessioni	  z$A session with the OATH application.Nc               rH   )r'   
connectionr   scp_key_paramszScpKeyParams | Noner   r*   r+   r"   r,   OathSession.__annotate__  s     
 
'
 ,
r!   c                	s   \        V\        4      V n        \        V P                  P	                  \
        P                  4      4      w  V n        V n        V n	        V P                  P                  V P                  4       V'       dC   RV P                  u;8:  d   R8  d   M M\        R4      hV P                  P                  V4       W n        V P                  RJV n        \!        V P                  4      V n        V'       * ;'       d    V P                  R8  V n        \&        P)                  RV P                   RV P                   R24       R# )	   z,SCP for OATH requires YubiKey 5.6.3 or laterNz"OATH session initialized (version=z
, has_key=))r   r    r    )r   i      )r   r    r    )r   INS_SEND_REMAININGprotocolr;   selectr   OATH_version_salt
_challengeZ	configureversionr   init_scp_scp_params_has_keyrt   
_device_id_neo_unlock_workaroundloggerdebug)rX   r   r   s   &&&r"   __init__ZOathSession.__init__  s    
 **6HI5BMM  *6
2tz4? 	-DMM5I5'(VWWMM"">2)t3(4*8&8&U&UT\\I=U#0 ?}}oQ(	
r!   c               r&   )r'   rJ   r   r   r*   r+   r"   r,   r   &  s       r!   c                    V P                   # )z$The version of the OATH application.)r   rW   r1   r"   r   ZOathSession.version%       }}r!   c               r&   )r'   rJ   r)   r   r*   r+   r"   r,   r   +  s      3 r!   c                r   )zJThe device ID.

A random static identifier that is re-generated on reset.
)r   rW   r1   r"   ra   ZOathSession.device_id*  s     r!   c               r&   r'   rJ   boolr   r*   r+   r"   r,   r   3  s       r!   c                r   )z+If True, the YubiKey has an access key set.)r   rW   r1   r"   has_keyZOathSession.has_key2  r   r!   c               r&   r   r   r*   r+   r"   r,   r   8  s     + + +r!   c                s    V P                   RJ# )zDIf True, the OATH application is currently locked via an access key.N)r   rW   r1   r"   lockedZOathSession.locked7  s     d**r!   c               r&   r'   rJ   Noner   r*   r+   r"   r,   r   <  s     5 5t 5r!   c                s   V P                   P                  ^ \        ^^4       \        V P                   P	                  \
        P                  4      4      w  qn        V n        V P                  '       d&   V P                   P                  V P                  4       \        P                  R4       RV n        \        V P                  4      V n        R# )z0Perform a factory reset on the OATH application.z%OATH application data reset performedFN)r   	send_apdu	INS_RESETr;   r   r   r   r   r   r   r   r   infor   rt   r   )rX   _r:   r"   resetZOathSession.reset<  s    9dD9)6t}}7K7KCHH7U)V&:tMM""4#3#34;<(4r!   c               rH   )r'   passwordr)   rJ   r@   r   r*   r+   r"   r,   r   F  s     1 13 15 1r!   c                s.    \        V P                  V4      # )zQDerive an access key from a password.

:param password: The derivation password.
)ry   r   )rX   r   rg   r"   
derive_keyZOathSession.derive_keyF  s    
 4::x00r!   c               rH   r'   r(   r@   rJ   r   r   r*   r+   r"   r,   r   M  s     , ,E ,d ,r!   c                s   \         P                  R4       \        WP                  4      p\        P
                  ! ^4      p\        \        V4      \        \        V4      ,           pV P                  P                  ^ \        ^ ^ V4      p\        W4      p\        P                  ! \        P                  ! \        V4      V4      '       g   \        R4      hRV n        RV n        R# )ziValidate authentication with access key.

This unlocks the session for use.

:param key: The access key.
zUnlocking sessionz5Response from validation does not match verification!NF)r   r   rx   r   osurandomr   TAG_RESPONSEr7   r   r   INS_VALIDATErv   Zcompare_digestunpackr   r   )rX   r(   r8   	challenger9   respZverificationrT   r"   validateZOathSession.validateM  s     	()c??3JJqM	<*S	-JJ}}&&q,1dC!#1""3::lD#A<PP"G  &+#r!   c               rH   r   r   r*   r+   r"   r,   r   a  s      5 T r!   c                s   \         P                  ! ^4      p\        W4      pV P                  P	                  ^ \
        ^ ^ \        \        \        \        P                  \        P                  ,          4      V,           4      \        \        V4      ,           \        \        V4      ,           4       \        P!                  R4       RV n        V P$                  '       dg   \        P'                  R4       \)        V P                  P+                  \,        P.                  4      4      ^,          V n        V P3                  V4       R# R# )zCSet an access key for authentication.

:param key: The access key.
zNew access code setTz/Performing NEO workaround, re-select and unlockN)r   r   rx   r   r   INS_SET_CODEr   TAG_KEYr   r#   r%   r   r   r7   r   r   r   r   r   r   r;   r   r   r   r   r   )rX   r(   r   r8   re   r"   set_keyZOathSession.set_keya  s    
 JJqM	c-GYy~~8K8K'KLsRSmY/0lH-.
	
 	)*&&&LLJK+DMM,@,@,JKANDOMM# 'r!   c               r&   r   r   r*   r+   r"   r,   r   z  s      4 r!   c           	     s    V P                   P                  ^ \        ^ ^ \        \        4      4       \
        P                  R4       RV n        R# )z[Remove the access key.

This removes the need to authentication a session before using it.
zAccess code removedFN)r   r   r   r   r   r   r   r   rW   r1   r"   	unset_keyZOathSession.unset_keyz  s6    
 	<As7|D)*r!   c               $    V ^8  d   QhRRRRRR/# )r'   credential_datar<   rc   r   rJ   r`   r   r*   r+   r"   r,   r     s$     '
 '
-'
?C'
	'
r!   c                s   TpVP                  4       p\        VP                  VP                  4      pVP	                  \
        R4      p\        \        V4      \        \        \        P                  ! RVP                  VP                  ,          VP                  4      V,           4      ,           pV'       d(   V\        P                  ! R\        \        4      ,          pVP                  ^ 8  d7   V\        \         \        P                  ! RVP                  4      4      ,          p\"        P%                  RVP                  : RVP                  : RVP                   RVP&                   RVP                   R	V R
24       V P(                  P+                  ^ \,        ^ ^ V4       \"        P/                  R4       \1        V P2                  VVP4                  VP6                  VP                  VP&                  V4      # )zoAdd an OATH credential.

:param credential_data: The credential data.
:param touch_required: The touch policy.
s    z>BBz>IzImporting credential (type=z, hash=z	, digits=	, period=z, imf=z, touch_required=r   zCredential imported)rY   r{   rA   r?   ZljustHMAC_MINIMUM_KEY_SIZEr   r6   r   r|   r}   r>   rC   TAG_PROPERTYPROP_REQUIRE_TOUCHrE   TAG_IMFr   r   rD   r   r   INS_PUTr   r`   ra   rG   r=   )rX   r   rc   rs   rk   rA   r9   r   r"   put_credentialZOathSession.put_credential  s    ((*"188Q-=-=>3U;8W%KKq{{Q-=-==qxxH6Q)
 

 FKK|5GHHD99q=CT199!=>>D)!++@P@P?S ThhZy
& D,-Q0	

 	7Aq$7)*NNHHFFKKHH
 	
r!   c               s(    V ^8  d   QhRRRRRRRR/# )r'   credential_idr@   r=   r)   rG   rF   rJ   r   r*   r+   r"   r,   r     s,      "*-7A	r!   c                s   \         P                  RV: RV RV R24       \        V P                  R4       \	        V\
        P                  4      w   rE\        W2\
        P                  V4      pV P                  P                  ^ \        ^ ^ \        \        V4      \        \        V4      ,           4       \         P                  R4       V# )zRename a OATH credential.

:param credential_id: The id of the credential.
:param name: The new name of the credential.
:param issuer: The credential issuer.
zRenaming credential 'z' to 'rN   Z'zCredential renamed)r   r   rM   )r   r   r   r   ro   r#   r%   rV   r   r   
INS_RENAMEr   r6   r   )rX   r   r=   rG   r   rD   Znew_ids   &&&&   r"   rename_credentialZOathSession.rename_credential  s     	,],=VF81TFRSTUi0%mY^^D1 y~~vFz1aX}!=Hf@U!U	
 	()r!   c               r&   )r'   rJ   zlist[Credential]r   r*   r+   r"   r,   r     s      "2 r!   c                s   \         P                  R4       . p\        P                  ! V P                  P                  ^ \        ^ ^ 4      4       Fz  p\        P                  ! \        V4      p\        \        V^ ,          ,          4      pVR,          p\        WT4      w  rgpVP                  \        V P                  WVWtVR4      4       K|  	  V# )zList OATH credentials.zListing OATH credentials...rL   N)r   r   r   
parse_listr   r   INS_LISTr   TAG_NAME_LISTr#   	MASK_TYPEro   Zappendr`   ra   )	rX   Zcredstlvr9   r>   rk   rG   r=   rD   s	   &        r"   list_credentialsZOathSession.list_credentials  s    23>>$--"9"9!Xq!"LMC::mS1D!)d1g"56I2hG#1'#E F&LLNNGTfd N r!   c               s$    V ^8  d   QhRRRRRR/# )r'   r   r@   r   rJ   r   r*   r+   r"   r,   r     s!      u  5 r!   c                s   \         P                  RV: 24       \        P                  ! \        V P
                  P                  ^ \        ^ ^ \        \        V4      \        \        V4      ,           4      4      pVR,          # )z~Perform a calculate for an OATH credential.

:param credential_id: The id of the credential.
:param challenge: The challenge.
z%Calculating response for credential: rL   )
r   r   r   r   r   r   r   INS_CALCULATEr6   r7   )rX   r   r   r   s   &&& r"   	calculateZOathSession.calculate  si     	<]<MNOzzMM##Hm,s=)/LL	
 Bxr!   c               rH   )r'   r   r@   rJ   r   r   r*   r+   r"   r,   r     s     * *u * *r!   c           
     s    \         P                  RV: 24       V P                  P                  ^ \        ^ ^ \        \        V4      4       \         P                  R4       R# )zLDelete an OATH credential.

:param credential_id: The id of the credential.
zDeleting crededential: zCredential deletedN)r   r   r   r   
INS_DELETEr   r6   r   )rX   r   rg   r"   delete_credentialZOathSession.delete_credential  sG    
 	.}.?@A:q!S=5QR()r!   c               rH   )r'   r~   
int | NonerJ   z Mapping[Credential, Code | None]r   r*   r+   r"   r,   r     s     ) )#)	))r!   c                s0   \        T;'       g    \        4       4      p\        V\        4      p\        P                  RV 24       / p\        P                  ! V P                  P                  ^ \        ^ ^\        \        V4      4      4      pV'       Ed   \        P                  ! \        VP                  ^ 4      4      pVP                  ^ 4      pVP                  pV\         8X  d   \"        P$                  M\"        P&                  pV\(        8H  p	\+        WX4      w  rp\-        V P.                  WZWW4      pRpV\0        8X  dL   V\        8X  d   \3        WVP4                  4      pM)\        P                  RV 24       V P7                  W4      pWV&   EK	  V# )zCalculate codes for all OATH credentials on the YubiKey.

This excludes credentials which require touch as well as HOTP credentials.

:param timestamp: A timestamp used for the TOTP challenge.
zCalculating all codes for time=NzRecalculating code for period=)rB   r   r   rR   r   r   r   r   r   r   INS_CALCULATE_ALLr7   r   r6   ZpopZtagTAG_HOTPr#   r$   r%   	TAG_TOUCHro   r`   ra   TAG_TRUNCATEDr   r]   calculate_code)rX   r~   r   Zentriesr9   rk   r   Zresp_tagr>   ZtouchrG   r=   rD   r   Zcodes   &&             r"   calculate_allZOathSession.calculate_all  sE    	++TV,	"9n=	6ykBC~~MM##$aCy,I

 djj488A;7G((1+CwwH*2h*>	INNI	)E#1'#E F&#&J D=(^+'
syyID LL#A&!JK..zED"&Jr!   c               r   )r'   r   r`   r~   r   rJ   r\   r   r*   r+   r"   r,   r     s$      =  =$ =1; =	 =r!   c                sT   VP                   V P                   8w  d   \        R4      h\        T;'       g    \        4       4      pVP                  \
        P                  8X  d<   \        P                  RV RVP                   24       \        W!P                  4      pM\        P                  R4       Rp\        P                  ! \        V P                  P                  ^ \         ^ ^\        \"        VP$                  4      \        \&        V4      ,           4      4      p\)        WV4      # )zsCalculate code for an OATH credential.

:param credential: The credential object.
:param timestamp: The timestamp.
z*Credential does not belong to this YubiKeyzCalculating TOTP code for time=r   zCalculating HOTP coder!   )ra   rO   rB   r   r>   r#   r%   r   r   rD   r   r   r   r   r   r   r   r6   rb   r7   r   )rX   r   r~   r   r8   s   &&&  r"   r   ZOathSession.calculate_code  s     4>>1IJJ	++TV,	9>>1LL1) =$++,. 'y2C2CDILL01I::MM##Hjmm,s=)/LL	
 J8<<r!   )r   r   r   r   r   r   r   r   r3   )F)r   r   r   r   rZ   r   Zpropertyr   ra   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r   r!   r"   r   r   	  s    .
2       + +51,(2'
R& &*)V =  =r!   r   )YZ
__future__r   rp   rv   Zloggingr   Zrer|   Zbase64r   r   Zdataclassesr   Zenumr   r   Z	functoolsr   r   Ztypingr	   Zurllib.parser
   r   r   Zcorer   r   r   r   r   r   r   r   Zcore.smartcardr   r   r   r   Z	getLoggerr   r   r6   r   r   r7   r   r   r   r   r4   r   r   r   r   r   r   r   r   r   r   r   r   Zcompilerm   Z	MASK_ALGOr   rR   rQ   rS   ZCHALLENGE_LENr   r   r#   r   r2   r;   r<   r\   r`   rV   ro   rt   rx   ry   r{   r   r   r   r   r!   r"   <module>r      s   "    	 	  ' !   $   4 4	 	 	 V U			8	$ 

	 

	
  **:;		  W     
   ,T ,T ,T^    
t$/ / % /6 5C *4
3L(
"m= m=r!   