+
    :il  c                  sR  a  0 t $ ^ RIH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HtHtHtHt ^ RIHt ^ RIHt ^ RIHt ^ RIHt ^ R	IHt ^ R
IHtHtHtHtHt ^ RI H!t! ^ RI"H#t#H$t$ ^ RI%H&t& ^ RI'H(t(H)t)H*t* ^ RI+H,t,H-t- ^ RI.H/t/H0t0H1t1H2t2H3t3H4t4H5t5H6t6H7t7H8t8 ^RI9H:t: ]'       d	   ^ RI;H<t<H=t= ]P|                  ! ]?4      t@RtA]2P                  tCR]&P                  R]&P                  R]&P                  R]&P                  R]&P                  R]&P                  R]&P                  R]&P                  R]&P                  /	tMRtNR R ltO]P                  ! R 4      tQR! R" ltRR# R$ ltSR% tTR& R' ltUR( R) ltV ! R* R+4      tW ! R, R-4      tXR. R/ ltYR0 R1 ltZROR2 R3 llt[R4 R5 lt\R6 R7 lt]R8 R9 lt^R: R; lt_R< R= lt`R> R? ltaR@ RA ltbRB RC ltc]P                  ]P                  ,          ]P                  ,          ]P                  ,          ]P                  ,          ]P                  ,          ]P                  ,          ]P                  ,          tlRD]mRE&   RF tn]P                  3RG RH llto]P                  3RI RJ lltp]P                  3RK RL lltq]P                  3RM RN lltrR# )P    )annotationsN)datedatetime)TYPE_CHECKINGAnyMapping	TypeAliascast)uuid4)x509)InvalidSignature)default_backend)hashes)eced25519paddingrsax25519)
PBKDF2HMAC)EncodingPublicFormat)NameOID)BadResponseErrorNotSupportedErrorTlv)SW	ApduError)
	ALGORITHMKEY_TYPEMANAGEMENT_KEY_TYPE	OBJECT_IDSLOTTAG_LRCChuidFascN
PivSessionSlotMetadata)display_serial)CertificatePublicKeyTypesPublicKeyTypesi _ ZCNZLZSTZOZOUZCZSTREETZDCZUIDz
\"+,'<> #=c                    V ^8  d   QhRRRR/# )   valuestrreturnzlist[list[str]] Zformat   "./usr/lib/python3.14/site-packages/ykman/piv.py__annotate__r2   _   s        #  /      c                sH   \        V 4      p. p. pR pRpV'       d   VP                  ^ 4      pVR8X  dg   VP                  ^ 4      pV\        9   d   TpM}VP                  ^ 4      pV\        P	                  Wx,           4      ,          p VP                  4       pRpM6VR9   d0   VP                  V4       R pVR8X  d   VP                  V4       . pK  V'       d   \        R4      hWF,          pK  VP                  V4       VP                  V4       V#   \         d     EK  i ; i)Z r3   Z\z,+Z,zInvalid UTF-8 data)	ZlistZpop_ESCAPEDbytesZfromhexZdecodeZUnicodeDecodeErrorappend
ValueError)	r+   Z	remainingnameentryZbufZhexbufZcZc1Zc2	   &        r1   _parser;   _   s   UIDE
CF
MM!9q!BX~]]1%%--00A F $YLLCCxE"122	LLKKK * s   D D! D!z
\d(\.\d+)+c               r)   r*   r+   r,   r-   z	x509.Namer.   r/   r0   r1   r2   r2      s     , , ,	 ,r3   c                s    \         P                  ! R\        4        \        P                  P                  V 4      #   \         d    \        T 4      u # i ; i)zParse an RFC 4514 string into a x509.Name.

See: https://tools.ietf.org/html/rfc4514.html

:param value: An RFC 4514 string.
:deprecated: Use x509.Name.from_rfc4514_string() instead.
z8Deprecated: use x509.Name.from_rfc4514_string() instead.)warningsZwarnZDeprecationWarningr
   NameZfrom_rfc4514_stringAttributeError_parse_rfc4514_string)r+      &r1   parse_rfc4514_stringrB      sJ     MMB,yy,,U33 ,$U++,s   < AAc               r)   r<   r.   r/   r0   r1   r2   r2      s     ! ! ! !r3   c                s   \        V 4      p. pV F  p. pV F  pR V9  d   \        R4      hVP                  R ^4      w  rgV\        9   d   \        V,          pMA\        P                  V4      '       d   \        P                  ! V4      pM\        RV R24      hVP                  \        P                  ! W4      4       K  	  VP                  ^ \        P                  ! V4      4       K  	  \        P                  ! V4      # )Z=zInvalid RFC 4514 stringzUnsupported attribute: 'Z')r;   r7   Zsplit_NAME_ATTRIBUTES_DOTTED_STRING_REZ	fullmatchr
   ZObjectIdentifierr6   ZNameAttributeZinsertZRelativeDistinguishedNamer>   )	r+   r8   Z
attributesr9   ZpartsZpartZkZvZattrr:   r1   r@   r@      s    %=D79JD$ !:;;::c1%DA$$'*",,Q//,,Q/ #;A3a!@AALL++D45  	!T;;EBC  99Z  r3   c                s   V P                   \        P                  8X  d+   \        P                  ! R V P
                  \        4       4      # V \        P                  8X  d3   \        P                  ! \        P                  ! 4       \        4       4      # V \        P                  8X  d3   \        P                  ! \        P                  ! 4       \        4       4      # V \        P                  8X  d   \        P                  P!                  4       # V \        P"                  8X  d   \$        P&                  P!                  4       # \)        R4      h)i  zInvalid algorithm)	algorithmr   RSAr   Zgenerate_private_keyZbit_lenr   r   ZECCP256r   Z	SECP256R1ZECCP384Z	SECP384R1ED25519r   ZEd25519PrivateKeyZgenerateX25519r   X25519PrivateKeyr7   )key_typerA   r1   
_dummy_keyrK      s    Y]]*''x/?/?ARSS8###&&r||~7HII8###&&r||~7HII8###((11338??"&&//11
(
))r3   c               s$    V ^8  d   QhRRRRRR/# )r*   pinr,   saltr5   r-   r.   r/   r0   r1   r2   r2      s!     
+ 
+s 
+% 
+E 
+r3   c                s    \        \        P                  ! 4       ^VR\        4       4      pVP	                  V P                  R4      4      # )zDerive a management key from the users PIN and a salt.

NOTE: This method of derivation is deprecated! Protect the management key using
PivmanProtectedData instead.

:param pin: The PIN.
:param salt: The salt.
i'  zutf-8)r   r   ZSHA1r   ZderiveZencode)rL   rM   Zkdf   && r1   derive_management_keyrO      s7     V[[]Be_5F
GC::cjj)**r3   c               r)   )r*   rE   r   r-   r5   r.   r/   r0   r1   r2   r2      s     ) ).A )e )r3   c                sB    \         P                  ! V P                  4      # )z_Generate a new random management key.

:param algorithm: The algorithm for the management key.
)osurandomZkey_len)rE   rA   r1   generate_random_management_keyrR      s    
 ::i''((r3   c                  s   ] tR t^t]! ^4      3R R lltR R ltR R lt]R R l4       t	]	P                  R	 R
 l4       t	]R R l4       t]P                  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tR# )
PivmanDatac                   V ^8  d   QhRR/# r*   raw_datar5   r.   r/   r0   r1   r2   PivmanData.__annotate__   s     W W Wr3   c                	sP   \         P                  ! \        V4      P                  4      p^V9   d&   \        P                  ! RV^,          4      ^ ,          MRV n        VP                  ^4      V n        ^V9   d&   \        P                  ! RV^,          4      V n        R# RV n        R# )i   >BN>I)	r   
parse_dictr+   structunpack_flagsgetrM   pin_timestampselfrV   datarN   r1   __init__ZPivmanData.__init__   sq    ~~c(m112<@DLfmmD$t*5a8dHHTN	@DV]]4d<RVr3   c               r)   )r*   maskintr-   boolr.   r/   r0   r1   r2   rW      s     / /c /d /r3   c                	sN    \        V P                  ;'       g    ^ V,          4      # )r    )rf   r]   )ra   rd      &&r1   	_get_flagZPivmanData._get_flag   s    T[[%%A-..r3   c               s$    V ^8  d   QhRRRRRR/# )r*   rd   re   r+   rf   r-   Noner.   r/   r0   r1   r2   rW      s!     ! !c !$ !4 !r3   c                	s    V'       d%   V P                   ;'       g    ^ V,          V n         R# V P                   e   V ;P                   V( ,          un         R# R# )r    N)r]   )ra   rd   r+   s   &&&r1   	_set_flagZPivmanData._set_flag   s<    ;;++!t3DK[[$KKD5 K %r3   c               rT   r*   r-   rf   r.   r/   r0   r1   r2   rW      s     $ $T $r3   c                	s$    V P                  ^4      # )   rh   ra   rA   r1   puk_blockedPivmanData.puk_blocked       ~~d##r3   c               r)   r*   r+   rf   r-   ri   r.   r/   r0   r1   r2   rW      s     $ $ $$ $r3   c                	s*    V P                  ^V4       R# )rl   Nrj   ra   r+   rg   r1   ro   rp          tU#r3   c               rT   rk   r.   r/   r0   r1   r2   rW      s     $ $4 $r3   c                	s$    V P                  ^4      # )r*   rm   rn   rA   r1   mgm_key_protectedPivmanData.mgm_key_protected   rq   r3   c               r)   rr   r.   r/   r0   r1   r2   rW      s     $ $t $ $r3   c                	s*    V P                  ^V4       R# )r*   Nrs   rt   rg   r1   rv   rw      ru   r3   c               rT   rk   r.   r/   r0   r1   r2   rW      s     ; ;4 ;r3   c                	sB    V P                   ;'       g    V P                  # N)has_derived_keyhas_stored_keyrn   rA   r1   has_protected_keyZPivmanData.has_protected_key   s    ##::t':'::r3   c               rT   rk   r.   r/   r0   r1   r2   rW      s     % % %r3   c                	s    V P                   R J# rx   )rM   rn   rA   r1   ry   ZPivmanData.has_derived_key   s    yy$$r3   c               rT   rk   r.   r/   r0   r1   r2   rW      s     & & &r3   c                	s    V P                   # rx   )rv   rn   rA   r1   rz   ZPivmanData.has_stored_key   s    %%%r3   c               rT   r*   r-   r5   r.   r/   r0   r1   r2   rW      s     0 05 0r3   c                	s   R pV P                   '       d3   V\        ^\        P                  ! RV P                   4      4      ,          pV P                  e   V\        ^V P                  4      ,          pV P
                  e3   V\        ^\        P                  ! RV P
                  4      4      ,          pV'       d   \        ^V4      # R # )r3   rX   rY   )r]   r   r[   ZpackrM   r_   ra   rb      & r1   	get_bytesZPivmanData.get_bytes   s    ;;;Cfkk$<==D99 Cdii((D)Cfkk$0B0BCDDD"&s4/C/r3   )r]   r_   rM   N)__name__
__module____qualname____firstlineno__r   rc   rh   rj   Zpropertyro   Zsetterrv   r{   ry   rz   r   __static_attributes__r.   r3   r1   rS   rS      s    ),T W/! $ $ $ $ $ $ $ $ ; ; % % & &0 0r3   rS   c                  s@    ] tR tRt]! ^4      3R R lltR R ltRtR# )PivmanProtectedDatai  c               rT   rU   r.   r/   r0   r1   r2    PivmanProtectedData.__annotate__	  s     " " "r3   c                	s    \         P                  ! \        V4      P                  4      pVP                  ^4      V n        R# )i   N)r   rZ   r+   r^   keyr`   rN   r1   rc   ZPivmanProtectedData.__init__	  s)    ~~c(m11288D>r3   c               rT   r|   r.   r/   r0   r1   r2   r     s     0 05 0r3   c                	s    R pV P                   e   V\        ^V P                   4      ,          pV'       d   \        ^V4      # R # )r3   )r   r   r}   r~   r1   r   ZPivmanProtectedData.get_bytes  s9    88Cdhh''D"&s4/C/r3   )r   N)r   r   r   r   r   rc   r   r   r.   r3   r1   r   r     s    ),T "0 0r3   r   c               r)   )r*   sessionr$   r-   rS   r.   r/   r0   r1   r2   r2     s      Z J r3   c                s   \         P                  R4        \        V P                  \        4      4      #   \
         dJ   pTP                  \        P                  8X  d%   \         P                  R4       \        4       u Rp?# h Rp?ii ; i)zKRead out the Pivman data from a YubiKey.

:param session: The PIV session.
zReading pivman dataNo data, initializing blankN)	loggerdebugrS   
get_objectOBJECT_ID_PIVMAN_DATAr   swr   FILE_NOT_FOUNDr   er~   r1   get_pivman_datar     sg    
 LL&'',,-BCDD 442$$$LL67<s!   5 B	 =B=B	BB	c               r)   )r*   r   r$   r-   r   r.   r/   r0   r1   r2   r2   $  s     
 
z 
6I 
r3   c                sd   \         P                  R4        \        V P                  \        4      4      #   \
         dJ   pTP                  \        P                  8X  d%   \         P                  R4       \        4       u Rp?# h Rp?i\         d    \        R\        \        4       R24      hi ; i)zRead out the Pivman protected data from a YubiKey.

This function requires PIN verification prior to being called.

:param session: The PIV session.
zReading protected pivman datar   Nz Invalid data in protected slot (Z))r   r   r   r   OBJECT_ID_PIVMAN_PROTECTED_DATAr   r   r   r   	Exceptionr7   hexr   r~   r1   get_pivman_protected_datar   $  s     LL01
"7#5#56U#VWW 442$$$LL67&(( 
.s3R/S.TTUV
 	

s'   5 B/ =B=B/BB/B/c               s0    V ^8  d   QhRRRRRRRRR	RR
R/# )r*   r   r$   new_keyr5   rE   r   touchrf   store_on_devicer-   ri   r.   r/   r0   r1   r2   r2   :  sL     =S =S=S=S #=S 	=S
 =S 
=Sr3   c                s~   \        V 4      pVP                  4       pRpV'       g   V'       g   VP                  '       d    \        V 4      pV P                  W!V4       VP                  '       d   \
        P                  R4       RVn	        WEn
        VP                  4       pWh8w  d   V P                  \        V4       Ve   V'       dB   \
        P                  R4       Wn        V P                  \        VP                  4       4       R# VP                  '       dD   \
        P                  R4        RVn        V P                  \        VP                  4       4       R# R# R#   \         d%    \
        P                  RRR7       T'       d   h  ELFi ; i  \         d    \
        P                  RRR7        R# i ; i)	a/  Set a new management key, while keeping PivmanData in sync.

:param session: The PIV session.
:param new_key: The new management key.
:param algorithm: The algorithm for the management key.
:param touch: If set, touch is required.
:param store_on_device: If set, the management key is stored on device.
Nz*Failed to initialize protected pivman dataTZexc_infozClearing salt in pivman dataz$Storing key in protected pivman dataz)Clearing old key in protected pivman dataz#No PIN provided, can't clear key...)r   r   rz   r   r   r   r   set_management_keyry   rM   rv   
put_objectr   r   r   r   )	r   r   rE   r   r   pivmanZpivman_old_bytesZpivman_protZpivman_bytess	   &&&&&    r1   pivman_set_mgm_keyr   :  su    W%F'')K63H3H3H	3G<K y5934  / ##%L'0,?LL?@%O>@U@U@WX___ LLDES"&""3))+  +  	LLEPTLU 	J  SBTRSs*   E$ 3+F $)FFF"F<;F<c               (    V ^8  d   QhRRRRRRRR/# )r*   r   r$   old_pinr,   new_pinr-   ri   r.   r/   r0   r1   r2   r2   z  s.     F Fz FC F# F$ Fr3   c           	     s   V P                  W4       \        V 4      pVP                  '       d   \        P	                  R4       V P                  \        V\        \        VP                  4      4      4       V P                  V4       \        P                  ! ^4      p\        W$4      pV P                  \        P                  V4       WCn	        V P!                  \"        VP%                  4       4       R# R# )zChange the PIN, while keeping PivmanData in sync.

:param session: The PIV session.
:param old_pin: The old PIN.
:param new_pin: The new PIN.
z.Has derived management key, update for new PINN)Z
change_pinr   ry   r   r   ZauthenticaterO   r   r5   rM   Z
verify_pinrP   rQ   r   r   TDESr   r   r   )r   r   r   r   Znew_saltr      &&&   r1   pivman_change_pinr   z  s     w(W%FEF!'4v{{+CD	
 	7#::b>':""#6#;#;WE0&2B2B2DE r3   c               r   )r*   r   r$   pin_attemptsre   puk_attemptsr-   ri   r.   r/   r0   r1   r2   r2     s2     F FF'*F:=F	Fr3   c                s    V P                  W4       \        V 4      pVP                  '       d.   RVn        V P                  \        VP                  4       4       R# R# )zSet the number of PIN and PUK retry attempts, while keeping PivmanData in sync.

:param session: The PIV session.
:param pin_attempts: The PIN attempts.
:param puk_attempts: The PUK attempts.
FN)Zset_pin_attemptsr   ro   r   r   r   )r   r   r   r   s   &&& r1   pivman_set_pin_attemptsr     sO     \8W%F"0&2B2B2DE r3   c               r)   )r*   r   r$   r-   z&Mapping[SLOT, x509.Certificate | None]r.   r/   r0   r1   r2   r2     s      z .T r3   c                s    / p\          Uu. uF  q"\         P                  8w  g   K  VNK  	  ppV F  p V P                  V4      W&   K  	  V# u upi   \         d     K0  \         d	    RY&    KA  i ; i)zRead out and parse stored certificates.

Only certificates which are successfully parsed are returned.

:param session: The PIV session.
N)r    ATTESTATIONZget_certificater   r   )r   certssslotsslots   &    r1   list_certificatesr     s{     E$(BDq1A1A,ADEB	!11$7EK  L C  	 	EK	s'   AAAA2 A2)A21A2c               r)   )r*   r   r$   r-   zMapping[SLOT, SlotMetadata]r.   r/   r0   r1   r2   r2     s     	 	
 	'B 	r3   c                s   / p\          Uu. uF  q"\         P                  8w  g   K  VNK  	  ppV F  p V P                  V4      W&   K  	  V# u upi   \         d,   pTP                  \
        P                  8w  d   h  R p?KS  R p?ii ; irx   )r    r   Zget_slot_metadatar   r   r   ZREFERENCE_DATA_NOT_FOUND)r   keysr   r   r   r   s   &     r1   
_list_keysr     s    D$(BDq1A1A,ADEB	 2248DJ  K C  	ttr222 3	s!   AAAB BBc               s(    V ^8  d   QhRRRRRRRR/# )	r*   r   r$   r   r    
public_keyr(   r-   rf   r.   r/   r0   r1   r2   r2     s0     1 11
1 1 
	1r3   c                s    Rp\         P                  R4       V P                  V\        P                  ! V4      V\
        P                  ! 4       \        P                  ! 4       4      p\        V\        P                  4      '       d=   VP                  VV\        P                  ! 4       \
        P                  ! 4       4       R# \        V\        P                  4      '       d<   VP                  WC\        P                  ! \
        P                  ! 4       4      4       R# \!        R\#        V4       24      h  \$         d_   pTP&                  \(        P*                  \(        P,                  39   d*   \         P                  RTP&                  R 24        Rp?R# h Rp?i\.         d    \         P                  R	4        R# i ; i)
a3  Check that a given public key corresponds to the private key in a slot.

This will create a signature using the private key, so the PIN must be verified
prior to calling this function if the PIN policy requires it.

:param session: The PIV session.
:param slot: The slot.
:param public_key: The public key.
s   testzBTesting private key by creating a test signature, and verifying itzUnknown key type: TzCouldn't create signature: SW=Z04xNFzSignature verification failed)r   r   signr   from_public_keyr   SHA256r   PKCS1v15
isinstancer   ZRSAPublicKeyZverifyr   ZEllipticCurvePublicKeyZECDSAr7   Ztyper   r   r   ZINCORRECT_PARAMETERSZWRONG_PARAMETERS_P1P2r   )r   r   r   Z	test_dataZtest_sigr   r   r1   	check_keyr     sR   #	P	
 <<$$Z0MMO
 j#"2"233  "	 	 
B$=$=>>h288FMMO3LM  1$z2B1CDEE  44B++R-E-EFFLL9!$$sDE 45s8   C D6 AD6 D6 6GAFFG'G Gc               rT   r|   r.   r/   r0   r1   r2   r2     s       r3   c                 s    \        \        RRR^ ^^ ^^ ^4	      \        4       P                  \	        R^^4      RR7      p \        V 4      # )z0Generate a CHUID (Cardholder Unique Identifier).i'  i?B i  r3   )Zfasc_nZguidZexpiration_dateZasymmetric_signature)r"   r#   r	   r5   r   )Zchuids    r1   generate_chuidr     sJ     T4Az1dAFW]]T1a( E <r3   c               rT   r|   r.   r/   r0   r1   r2   r2     s      e r3   c                 s   \        ^R\        P                  ! ^4      ,           4      \        ^R4      ,           \        ^R4      ,           \        ^4      ,           \        ^R4      ,           \        ^R4      ,           \        ^4      ,           \        ^4      ,           \        ^4      ,           \        ^4      ,           \        ^4      ,           \        ^4      ,           \        \        4      ,           # )z+Generate a CCC (Card Capability Container).s     s   !    s   )r   rP   rQ   r!   r.   r3   r1   generate_cccr     s     	D1BJJrNBC
dG
	
dG
	 d)	 dG
		
 dG
	 d)	 d)	 d)	 d)		 d)
	 d)	 g,	r3   c               rT   )r*   r   r$   r.   r/   r0   r1   r2   r2     s     H H* Hr3   c                s   \        V 4      pRV P                  /pV.p V P                  4       pVP                  '       d   VP	                  R4       RVP
                  VP                  3,          pWRR&    V P                  4       pVP                  '       d   RVP
                   R2VR&   MR	VR&     V P                  4       p	V	P                  '       d   VP	                  R4       V	P                  p
V
P$                  VR&   VP&                  '       d   VP	                  R4       VP(                  '       d   VP	                  R4       / pVP	                  V4        V P+                  \,        P.                  4      VR&    V P+                  \,        P8                  4      VR&   \;        V 4      p \=        V 4      p\>         Uu. uF  qV9   g	   W9   g   K  VNK  	  ppV EFw  p/ pVVRV 2&   VV9   d   VV,          P                  VR&   MRVR&   VPA                  VR4      pV'       Ed    VPB                  PE                  4       pVPF                  PE                  4       pTPO                  \P        PR                  ! 4       4      PU                  4       p \V        PX                  ! TP[                  4       4      P$                  pTP\                  p  TP^                  p  TPd                  pTTR &   TTR!&   TTR"&   \i        T4      TR#&   TTR$&   T'       d   TPk                  4       TR%&   T'       d   TPk                  4       TR&&   EKe  EKh  VV9   g   EKr  R'VR&   EKz  	  V#   \         d)    T P                  4       pT^8X  d   RM
\        T4      p ELi ; i  \         d     T P                  4       pTP
                  ^ 8X  d   TP	                  R
4       M#TP                  '       d   TP	                  R4       RTP
                  TP                  3,          pYRR&    ELf  \         d)    TP                  '       d   TP	                  R
4         ELi ; ii ; i  \         d    \         P"                  p
 EL~i ; i  \0         d0   pTP2                  \4        P6                  8X  d   RTR&    Rp?EL,Rp?ii ; i  \0         d0   pTP2                  \4        P6                  8X  d   RTR&    Rp?ELFRp?ii ; i  \         d    / p ELGi ; iu upi   \H         d,   p\J        PM                  RRR7       RT 2TR&    Rp?EK\  Rp?ii ; i  \H         d    Rp ELi ; i  \`         d    TPb                  p ELi ; i  \H         d    \J        PM                  RRR7       Rp ELi ; i  \`         d    TPf                  p ELi ; i  \H         d    \J        PM                  RRR7       Rp ELi ; i)(z^Get human readable information about the PIV configuration.

:param session: The PIV session.
zPIV versionzWARNING: Using default PIN!z%d/%dz
15 or morezPIN tries remainingzConfigured, z attempts remainingZ
BiometricszNot configuredzPUK is blockedzWARNING: Using default PUK!zPUK tries remainingz&WARNING: Using default Management key!zManagement key algorithmz#Management key is derived from PIN.z:Management key is stored on the YubiKey, protected by PIN.CHUIDzNo data availableNZCCCzSlot zPrivate key typeZEMPTYzFailed parsing certificateTr   zMalformed certificate: ZErrorZUnsupportedzFailed reading not_valid_beforezFailed reading not_valid_afterzPublic key typez
Subject DNz	Issuer DNZSerialZFingerprintz
Not beforez	Not afterzFailed to parse certificate)6r   ZversionZget_pin_metadataZdefault_valuer6   Zattempts_remainingZtotal_attemptsr   Zget_pin_attemptsr,   Zget_bio_metadataZ
configuredZget_puk_metadataro   Zget_management_key_metadatarJ   r   r   r8   ry   rz   r   r   r   r   r   r   r   Z
CAPABILITYr   r   r    r^   subjectZrfc4514_stringZissuerr7   r   r   fingerprintr   r   r   r   r   r   serial_numberZnot_valid_before_utcr?   not_valid_beforeZnot_valid_after_utcnot_valid_afterr&   Z	isoformat)r   r   ZinfoZlinesZpin_dataZ	tries_strZtriesZbioZpuk_dataZmetadatarJ   Zobjectsr   r   r   r   r   r   Z	cert_datacertZ
subject_dnZ	issuer_dnr   Zkey_algoZserialZ
not_beforeZ	not_afters   &                          r1   get_piv_infor     s~   
 W%FwD vE@++-!!!LL67x::H<S<STT	
 #,	/&&(>>>s5566IJ  "2D$,668!!!LLAB$$ (0}}D	#$:;QR G	LL3"--ioo>
1 ++I,@,@A
 g&E'" 81T	QZQQE8$&	"+%v4<,0J,?,?I(),3I()yyt$4!\\88:
 KK668	 **6==?;??AK)#33DOO4EFKK ''F"7262K2KJ!5151I1II ,4I'(&0Il#%.Ik""0"8Ih'2Im$*4*>*>*@	,')2)<)<)>	+& U]!>Igi l Lq  @((*$)RKLSZ	@  /	///1H**a/-.''':;++''# I +4&'  	/!!!-.	//,  ,&++,  3442$$$2GG3  1442$$$0GEN1   9  9DI'>qc%B	'"	  )() & 7!%!6!6J7 ">N!
" & 5 $ 4 4I5 !=M 	!s3  AM 55N +N 2!Q Q "Q3 ="R0 +S- >TT(4T.T?UV/NNQAP 4PQ
4Q
Q	Q

QQ0/Q03R->$R((R-0S*;$S%%S*-S>=S>T<T77T<?UUU.*U1-U..U11$VVV73V:6V77V::$W"!W"r   _AllowedHashTypesc                s^    V \         P                  \         P                  39   d   R # V! 4       # rx   )r   rG   rH   )rJ   hash_algorithmrg   r1   _hashr     s%    H$$hoo66r3   c               0    V ^8  d   QhRRRRRRRRR	R
RR/# )r*   r   r$   r   r    rJ   r   builderzx509.CertificateBuilderr   type[_AllowedHashTypes]r-   x509.Certificater.   r/   r0   r1   r2   r2     sL     "B "B"B
"B "B %	"B
 ,"B "Br3   c           	     s   \         P                  R4       \        V4      p\        V\        P
                  4      '       d   Q hVP                  V\        W$4      \        4       4      pV P                  VVVP                  \        W$4      \        P                  ! 4       4      p\        P                  ! \        P                  ! ^0VP                  \         P"                  4      4      4      p\        V^,          P$                  RV,           4      V^&   \        ^0RP'                  V4      4      p	\(        P*                  ! V	\        4       4      # )zSign a Certificate.

:param session: The PIV session.
:param slot: The slot.
:param key_type: The key type.
:param builder: The x509 certificate builder object.
:param hash_algorithm: The hash algorithm, ignored for Curve 25519.
zSigning a certificater   r3   )r   r   rK   r   r   rI   r   r   r   Ztbs_certificate_bytesr   r   r   
parse_listr\   public_bytesr   DERtagjoinr
   Zload_der_x509_certificate)
r   r   rJ   r   r   	dummy_keyr   sigseqders
   &&&&&     r1   sign_certificate_builderr     s     LL()8$I)V%<%<====<<	5#BODUVD
,,""h'C ..D$*;*;HLL*IJ
KCQUS[)CF
dCHHSM
"C))#/@AAr3   c               r   )r*   r   r$   r   r    r   r(   r   z%x509.CertificateSigningRequestBuilderr   r   r-   x509.CertificateSigningRequestr.   r/   r0   r1   r2   r2     sD     /: /:/:
/: /: 3	/:
 ,/: $/:r3   c           	     s   \         P                  R4       \        P                  ! V4      p\	        V4      p\        V\        P                  4      '       d   Q hVP                  V\        WT4      \        4       4      p\        P                  ! \        P                  ! ^0VP                  \        P                   4      4      4      pVP"                  \$        P&                  8X  d   \(        P*                  M\(        P,                  p	VP/                  4       P                  \        P                   V	4      p
VP                  \        P                   V	4      p\        V^ ,          P1                  W4      4      V^ &   V P                  VVV^ ,          \        WT4      \2        P4                  ! 4       4      p\        V^,          P6                  RV,           4      V^&   \        ^0RP9                  V4      4      p\:        P<                  ! V\        4       4      # )zSign a CSR.

:param session: The PIV session.
:param slot: The slot.
:param public_key: The public key.
:param builder: The x509 certificate signing request builder
    object.
:param hash_algorithm: The hash algorithm, ignored for Curve 25519.
zSigning a CSRr   r3   )r   r   r   r   rK   r   r   rI   r   r   r   r   r   r\   r   r   r   rE   r   rF   r   ZPKCS1ZSubjectPublicKeyInfor   Zreplacer   r   r   r   r
   Zload_der_x509_csr)r   r   r   r   r   rJ   r   Zcsrr   Z
pub_formatZdummy_bytesZ	pub_bytesr   r   s   &&&&&         r1   sign_csr_builderr     s{     LL!''
3H8$I)V%<%<====
,,y%"A?CT
UC
..D#*:*:8<<*HI
JC
 . 	.. 
 &&(55hllJOK''jAIQ78CF
,,Ah'C QUS[)CF
dCHHSM
"C!!#'899r3   c               s8    V ^8  d   QhRRRRRRRRR	R
RR
RRRR/# )r*   r   r$   r   r    r   r(   subject_strr,   
valid_fromr   valid_tor   r   r-   r   r.   r/   r0   r1   r2   r2     sb     #V #V#V
#V #V 	#V
 #V #V ,#V #Vr3   c                s   \         P                  R4       \        P                  ! V4      p\        '       d   \        \        V4      p\        V4      p\        P                  ! 4       P                  V4      P                  V4      P                  V4      P                  \        P                  ! 4       4      P                  V4      P!                  V4      p	\#        WWyV4      # )ar  Generate a self-signed certificate using a private key in a slot.

:param session: The PIV session.
:param slot: The slot.
:param public_key: The public key.
:param subject_str: The subject RFC 4514 string.
:param valid_from: The date from when the certificate is valid.
:param valid_to: The date when the certificate expires.
:param hash_algorithm: The hash algorithm.
z$Generating a self-signed certificate)r   r   r   r   r   r   r'   rB   r
   ZCertificateBuilderr   subject_nameZissuer_namer   Zrandom_serial_numberr   r   r   )
r   r   r   r   r   r   r   rJ   r   r   s
   &&&&&&&   r1    generate_self_signed_certificater     s    & LL78''
3H}3Z@
";/G!	J		g		W		t002	3		*	%		"  $G8nUUr3   c               r   )r*   r   r$   r   r    r   r(   r   r,   r   r   r-   r   r.   r/   r0   r1   r2   r2   1  sL     P PP
P P 	P
 ,P $Pr3   c                s    \         P                  R4       \        P                  ! 4       P	                  \        V4      4      p\        WW%V4      # )zGenerate a CSR using a private key in a slot.

:param session: The PIV session.
:param slot: The slot.
:param public_key: The public key.
:param subject_str: The subject RFC 4514 string.
:param hash_algorithm: The hash algorithm.
zGenerating a CSR)r   r   r
   Z CertificateSigningRequestBuilderr   rB   r   )r   r   r   r   r   r   s   &&&&& r1   generate_csrr   1  sC     LL#$335BB[)G G:OOr3   )FF)s__conditional_annotations__Z
__future__r   ZloggingrP   Zrer[   r=   r   r   Ztypingr   r   r   r   r   Zuuidr	   Zcryptographyr
   Zcryptography.exceptionsr   Zcryptography.hazmat.backendsr   Zcryptography.hazmat.primitivesr   Z)cryptography.hazmat.primitives.asymmetricr   r   r   r   r   Z)cryptography.hazmat.primitives.kdf.pbkdf2r   Z,cryptography.hazmat.primitives.serializationr   r   Zcryptography.x509.oidr   Zyubikit.corer   r   r   Zyubikit.core.smartcardr   r   Zyubikit.pivr   r   r   r   r    r!   r"   r#   r$   r%   Zutilr&   Z/cryptography.hazmat.primitives.asymmetric.typesr'   r(   Z	getLoggerr   r   r   ZPRINTEDr   ZCOMMON_NAMEZLOCALITY_NAMEZSTATE_OR_PROVINCE_NAMEZORGANIZATION_NAMEZORGANIZATIONAL_UNIT_NAMEZCOUNTRY_NAMEZSTREET_ADDRESSZDOMAIN_COMPONENTZUSER_IDrC   r4   r;   ZcompilerD   rB   r@   rK   rO   rR   rS   r   r   r   r   r   r   r   r   r   r   r   r   ZSHA224r   ZSHA384ZSHA512ZSHA3_224ZSHA3_256ZSHA3_384ZSHA3_512r   Z__annotations__r   r   r   r   r   )r   s   @r1   <module>r      s@  8 # "  	 	   # ? ?   4 8 1 W W @ O ) A A 0   !
 
		8	$ ! "+"3"3  	'

		'
(
(	"	"'
*
*		g$$'
"
"	7??
   F JJ}- ,&!**
+)40 40n	0 	0 
,=S@F.F (	1h&HX MMmmmm mm oo	
 oo oo oo 9 	 /5mm"BT /5mm/:r /5mm#VV /5mmP Pr3   