
    	                     n    d Z ddlZddlZddlZddlmZ ddlmZ ddlmZ  G d dej                        Z
y)z;Convenience class for U2F signing with local security keys.    N)errors)u2f)baseauthenticatorc                   T    e Zd ZdZd Zej                  j                  fdZd Z	d Z
y)LocalAuthenticatorzBAuthenticator wrapper around the native python u2f implementation.c                     || _         y )Norigin)selfr
   s     7lib/third_party/pyu2f/convenience/localauthenticator.py__init__zLocalAuthenticator.__init__   s	    DK    c                 6   	 t        j                  | j                        } |d       |D ]  }|d   }|d   }	 |j                  |||g      }| j                  |j                  j                         j                               }
| j                  |j                         }| j                  |j"                        }|
|||dc S  t        j                  t        j                  j                        # t        j                  $ rJ  |d       t
        j                  j                          t        j                  | j                        }Y ,w xY w# t        j                  $ r3}	|	j                  t        j                  j                  k(  rY d}	~	f d}	~	ww xY w)See base class.r	   z2Please insert your security key and press enter...z Please touch your security key.
	challengekeyN)
clientDatasignatureDataapplicationId	keyHandle)r   GetLocalU2FInterfacer
   r   NoDeviceFoundErrorsixmovesinputAuthenticateU2FErrorcodeDEVICE_INELIGIBLE_base64encodeclient_dataGetJsonencodesignature_data
key_handle)r   app_idchallenge_dataprint_callbackdevicechallenge_itemraw_challenger   resulter!   r$   r%   s                r   r   zLocalAuthenticator.Authenticate   s[   <''t{{;f 67($[1m5!c$$V]SEB &&v'9'9'A'A'C'J'J'LMk))&*?*?@n%%f&7&78j $)!!	 ! ). //&//;;
<<= $$ <IJ	iioo''t{{;f< __ 66V__666

	s/    C2 E2AEEF%'FFFc                      y)r   T )r   s    r   IsAvailablezLocalAuthenticator.IsAvailableE   s    r   c                 H    t        j                  |      j                         S )z5Helper method to base64 encode and return str result.)base64urlsafe_b64encodedecode)r   
bytes_datas     r   r    z LocalAuthenticator._base64encodeI   s    %%j188::r   N)__name__
__module____qualname____doc__r   sysstderrwriter   r0   r    r/   r   r   r   r      s)    J #&**"2"2$=L;r   r   )r9   r   r2   r:   pyu2fr   r   pyu2f.conveniencer   BaseAuthenticatorr   r/   r   r   <module>r@      s0    B 
  
   /2;*<< 2;r   