HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: //usr/lib/python3.6/site-packages/ipaclient/plugins/__pycache__/otptoken_yubikey.cpython-36.pyc
3

�d[e
�
@s"ddlZddlZddlmZmZmZddlmZmZddl	m
Z
mZmZddl
mZddlmZyddlZddlZWn"ek
r�eed�d��YnXejr�eZed	�ed
�ed�ed�ed
�Ze�ZdZedd�Gdd�de��Zedd�Gdd�de��Ze�Gdd�de
��ZdS)�N)�_�api�IntEnum)�NotFound�SkipPluginModule)�Command�Method�Object)�Registry)�
classpropertyzpython-yubico is not installed.)�reasonz
YubiKey Tokens
z
Manage YubiKey tokens.
zt
This code is an extension to the otptoken plugin and provides support for
reading/writing YubiKey tokens directly.
z
EXAMPLES:
zP
 Add a new token:
   ipa otptoken-add-yubikey --owner=jdoe --desc="My YubiKey"
ZotpT)Zno_failc@seZdZdZdS)�_fake_otptokenZotptokenN)�__name__�
__module__�__qualname__�name�rr�&/usr/lib/python3.6/otptoken_yubikey.pyr
;sr
c@seZdZdZdZdS)�_fake_otptoken_add�otptoken_addTN)rrrr�NO_CLIrrrrr@srcs�eZdZed�Zedded�dd�fZeZedd	��Z	e
e	�Zed
d��Z
�fdd
�Z�fdd�Z�fdd�Zdd�Zdd�Z�ZS)�otptoken_add_yubikeyzAdd a new YubiKey OTP token.zslot?�slotzYubiKey slot��)Zcli_nameZlabel�valuescCstjjd�tkS)Nr)rrZ
get_pluginr)�clsrrrZ__NO_CLI_getterSsz$otptoken_add_yubikey.__NO_CLI_gettercCs|jjjjS)N)rrr�api_version)�selfrrrrYsz otptoken_add_yubikey.api_versionc#s@x|jjjj�D]
}|VqWxtt|�j�D]
}|Vq.WdS)N)rrr�args�superr�get_args)r�arg)�	__class__rrr!]s
zotptoken_add_yubikey.get_argsc#sJx&|jjjj�D]}|jd
kr|VqWxtt|�j�D]
}|Vq8WdS)N�type�ipatokenvendor�
ipatokenmodel�ipatokenserial�ipatokenotpalgorithm�ipatokenhotpcounter�ipatokenotpkey�ipatokentotpclockoffset�ipatokentotptimestep�	no_qrcode�qrcode�version)r$r%r&r'r(r)r*r+r,r-r.r/)rrr�optionsrr r�get_options)rZoption)r#rrr1cs 
z otptoken_add_yubikey.get_optionsc#s@x|jjjj�D]
}|VqWxtt|�j�D]
}|Vq.WdS)N)rrrZ
output_paramsr r�get_output_params)rZparam)r#rrr2us
z&otptoken_add_yubikey.get_output_paramscCs|jjjj�S)N)rrr�output)rrrr�_iter_output{sz!otptoken_add_yubikey._iter_outputc!Os�ytj�}Wn�tjjk
rB}ztd|jd��WYdd}~Xndtjjk
rr}zt|j	d��WYdd}~Xn4t
k
r�}ztt|�dd��WYdd}~XnX|j�dks�t
�|jdd�dk�ry*|j�j�}tddhj|��d|d<Wn$tk
�rttd�d��YnXtjd	�}|j�}|j||jd
|jd
���|jdd�|j||dd
�dd�|j�D�}|jjjd|�ddt |j!�t |j"��dd|dd�|��}	x*dD]"}
|
|	jdi�k�r�|	d|
=�q�W|d|	jdi�d<|	S)NzNo YubiKey found: %s)rz:. Please install 'libyubikey' and 'libusb' packages first.rrrrzNo free YubiKey slot!��ipatokenotpdigitsZSERIAL_API_VISIBLET)rc
Ssi|]\}}|dkr||�qS)r/�description�
ipatokenowner�ipatokendisabled�ipatokennotbefore�ipatokennotafterr6)r/r7r8r9r:r;r6r)�.0�k�vrrr�
<dictcomp>�sz0otptoken_add_yubikey.forward.<locals>.<dictcomp>rZhotpZYubiCoZsha1)r$r%r&r'r(r)r*r-�urir*�result)rr)r)r@r*)#�yubicoZfind_yubikey�usbZcoreZUSBErrorr�strerrorZyubikeyZYubiKeyErrorr�
ValueError�strZversion_num�AssertionError�getZstatusZ
valid_configs�sorted�
difference�
IndexErrorr�os�urandomZinit_configZmode_oath_hotpZget_default_ofZ
extended_flagZwrite_config�itemsZBackendZ	rpcclient�forward�unicodeZmodel�serial)rr�kwargsZyk�eZused�keyZcfgr0Zanswerr=rrrrO~sN $




zotptoken_add_yubikey.forward)rr)rrrr�__doc__rZ
takes_optionsZhas_output_params�classmethodZ$_otptoken_add_yubikey__NO_CLI_getterrr�propertyrr!r1r2r4rO�
__classcell__rr)r#rrFs
r)rLZsixZipalibrrrZ
ipalib.errorsrrZipalib.frontendrrr	Zipalib.plugabler
Zipalib.utilrZusb.corerCrB�ImportErrorZPY3rFrPrU�registerZtopicr
rrrrrr�<module>s.