
    y                     J   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 dlm	Z	m
Z
 dZ ej                  e j                         G d de             Z G d de      Z G d d	e      Z G d
 de      Z e        e        e       fD  ci c]  } | j&                  |  c} Zyc c} w )    N)_helperserrorszhttps://accounts.google.comc                       e Zd ZdZeej                  d               Zeej                  d               Zej                  d        Z	y)ReauthChallengez!Base class for reauth challenges.c                      y)z"Returns the name of the challenge.N selfs    Lplatform/gsutil/third_party/google-reauth-python/google_reauth/challenges.pynamezReauthChallenge.name"        	    c                      y)zAReturns true if a challenge is supported locally on this machine.Nr   r	   s    r   is_locally_eligiblez#ReauthChallenge.is_locally_eligible(   r   r   c                      y)aU  Performs logic required to obtain credentials and returns it.

        Args:
            metadata: challenge metadata returned in the 'challenges' field in
                the initial reauth request. Includes the 'challengeType' field
                and other challenge-specific fields.

        Returns:
            response that will be send to the reauth service as the content of
            the 'proposalResponse' field in the request body. Usually a dict
            with the keys specific to the challenge. For example,
            {'credential': password} for password challenge.
        Nr   r
   metadatas     r   obtain_challenge_inputz&ReauthChallenge.obtain_challenge_input.   s     	r   N)
__name__
__module____qualname____doc__propertyabcabstractmethodr   r   r   r   r   r   r   r      sa    +      	 r   r   c                   6    e Zd ZdZed        Zed        Zd Zy)PasswordChallengez(Challenge that asks for user's password.c                      y)NPASSWORDr   r	   s    r   r   zPasswordChallenge.nameC   s    r   c                      yNTr   r	   s    r   r   z%PasswordChallenge.is_locally_eligibleG       r   c                 <    t        j                  d      }|sd}d|iS )NzPlease enter your password: 
credential)r   get_user_password)r
   unused_metadatapasswds      r   r   z(PasswordChallenge.obtain_challenge_inputK   s&    ++,IJFf%%r   Nr   r   r   r   r   r   r   r   r   r   r   r   r   @   s0    2   &r   r   c                   6    e Zd ZdZed        Zed        Zd Zy)SecurityKeyChallengez2Challenge that asks for user's security key touch.c                      y)NSECURITY_KEYr   r	   s    r   r   zSecurityKeyChallenge.nameU   s    r   c                      yr!   r   r	   s    r   r   z(SecurityKeyChallenge.is_locally_eligibleY   r"   r   c                    |d   }|d   }|d   }g }|D ]  }|d   j                  d      }t        j                  j                  t	        t        j                  |                  }|d   j                  d      }	t        j                  |	      }	|j                  ||	d        	 t        j                  j                  j                  t              }
|
j                  ||t        j                  j                        }d|iS # t        j                   j"                  $ r}|j$                  t        j                   j"                  j&                  k(  r t        j                  j                  d	       nS|j$                  t        j                   j"                  j(                  k(  r t        j                  j                  d
       n|Y d }~y d }~wt        j                   j*                  $ r" t        j                  j                  d       Y y w xY w)NsecurityKey
challengesapplicationId	keyHandleascii	challenge)keyr5   )print_callbackzIneligible security key.
z0Timed out while waiting for security key touch.
zNo security key found.
)encodepyu2fmodelRegisteredKey	bytearraybase64urlsafe_b64decodeappendconvenienceauthenticatorCreateCompositeAuthenticatorREAUTH_ORIGINAuthenticatesysstderrwriter   U2FErrorcodeDEVICE_INELIGIBLETIMEOUTNoDeviceFoundError)r
   r   skr1   app_idchallenge_datackhr6   r5   apiresponsees                r   r   z+SecurityKeyChallenge.obtain_challenge_input]   s   m$%
O$A;&&w/B++++&222679C+--g6I00;I!!#I"FG 	9##11NNC''7:zz7G7G ( IH!8,,||$$ 	vv..@@@

  !=>5<<00888

  GI   ||.. 	9JJ78	9s    &AD H B$G		?H
HNr)   r   r   r   r+   r+   R   s0    <   r   r+   c                   6    e Zd ZdZed        Zed        Zd Zy)SamlChallengez>Challenge that asks the users to browse to their ID Providers.c                      y)NSAMLr   r	   s    r   r   zSamlChallenge.name   s    r   c                      yr!   r   r	   s    r   r   z!SamlChallenge.is_locally_eligible   r"   r   c                 *    t        j                         )N)r   ReauthSamlLoginRequiredErrorr   s     r   r   z$SamlChallenge.obtain_challenge_input   s     1133r   Nr)   r   r   r   rV   rV   ~   s0    H   4r   rV   )r   r=   rE   pyu2f.convenience.authenticatorr9   pyu2f.errorspyu2f.modelsixgoogle_reauthr   r   rC   add_metaclassABCMetaobjectr   r   r+   rV   r   AVAILABLE_CHALLENGES)r5   s   0r   <module>re      s      
 &   
 * . 3;;f   B& &$)? )X4O 4* 		 NNI  s   B 