
    2je                         d Z ddlZddlZddlZddlZddlZddlZddlZdZd Z	d	dZ
edk(  rD eej                        dkD  r eej                  d         ndZ e	       Z e e
ee             yy)
a(  RFC 6238 TOTP generator. Reads base32 secret from the 0600 creds env file
(key AGENT_MS_TOTP_SECRET) and prints the current 6-digit code. The secret is
never printed. Usage: python3 totp_gen.py [step_offset]
  step_offset: integer number of 30s steps to add (default 0). Use -1/+1 to probe skew.
    Nz./home/claude/.config/amd-agent/credentials.envc                  ^   t        t              5 } | D ]o  }|j                         }|j                  d      s%|j	                  dd      d   j                         j                  d      j                  d      c cd d d        S  	 d d d        t        d      # 1 sw Y   t        d      xY w)NzAGENT_MS_TOTP_SECRET==   "'zAGENT_MS_TOTP_SECRET not found)openCREDSstrip
startswithsplitRuntimeError)flines     /tmp/amdwork/totp_gen.pyload_secretr      s    	e K 	KD::<D67zz#q)!,224::3?EEcJJ	K K	KK
 7
88K
 7
88s   'BABBB,c                 
   |t        j                          }t        ||z        |z   }| j                         j                  dd      }|dt	        |       dz  z  z  }t        j                  |      }t        j                  d|      }t        j                  ||t        j                        j                         }	|	d   dz  }
t        j                  d|	|
|
d	z          d
   dz  d|z  z  }t        |      j!                  |      S )N  r      z>Q   z>I   r   i
   )timeintupperreplacelenbase64	b32decodestructpackhmacnewhashlibsha1digestunpackstrzfill)secretwhenstepdigitsoffsetcounterskeymsghocodes               r   totpr7      s    |yy{$$,&(GsB'AQ!	A


1
C
++dG
$Cc7<<(//1A	"AMM$!AE
+A.;fMDt9??6""    __main__r   )r/   )N      r   )__doc__sysosr   r#   r%   r   r!   r	   r   r7   __name__r   argvr   offsecprint r8   r   <module>rE      so   
 4 3 3 389# z!#((ma/#chhqk
QC
-C	$s3
  r8   