관리-도구
편집 파일: cisco.cpython-39.pyc
a f�Wc�? � @ s� d Z ddlmZmZ ddlmZ ddlZe�e�Z ddl mZ ddlm Z mZmZmZ ddlmZ ddlmZmZmZmZmZmZ ddlm mZ g d �Zd ZG dd� dej ej!�Z"G d d� de"�Z#G dd� dej$�Z%dS )z1 passlib.handlers.cisco -- Cisco password hashes � )�hexlify� unhexlify)�md5N)�warn)�right_pad_string� to_unicode� repeat_string�to_bytes)�h64)�unicode�u�join_byte_values�join_byte_elems�iter_byte_values� uascii_to_str)� cisco_pix� cisco_asa�cisco_type7s ��������������������������������c @ s6 e Zd ZdZd ZdZdZdZdZe j ZdZdd� Z dS )r a� This class implements the password hash used by older Cisco PIX firewalls, and follows the :ref:`password-hash-api`. It does a single round of hashing, and relies on the username as the salt. This class only allows passwords <= 16 bytes, anything larger will result in a :exc:`~passlib.exc.PasswordSizeError` if passed to :meth:`~cisco_pix.hash`, and be silently rejected if passed to :meth:`~cisco_pix.verify`. The :meth:`~passlib.ifc.PasswordHash.hash`, :meth:`~passlib.ifc.PasswordHash.genhash`, and :meth:`~passlib.ifc.PasswordHash.verify` methods all support the following extra keyword: :param str user: String containing name of user account this password is associated with. This is *required* in order to correctly hash passwords associated with a user account on the Cisco device, as it is used to salt the hash. Conversely, this *must* be omitted or set to ``""`` in order to correctly hash passwords which don't have an associated user account (such as the "enable" password). .. versionadded:: 1.6 .. versionchanged:: 1.7.1 Passwords > 16 bytes are now rejected / throw error instead of being silently truncated, to match Cisco behavior. A number of :ref:`bugs <passlib-asa96-bug>` were fixed which caused prior releases to generate unverifiable hashes in certain cases. � TFc C s� | j }t|t�r|�d�}d}t|�| jkr^| jrVd| j| jf }tj j | j|d��n|t }| j}|r�t|t�r||�d�}|r�t|�dk r�|t |d�7 }|r�t|�dkr�d}nd}t||�}|r�||7 }t|��� }td d � t|�D ��}t�|��d�S )a7 This function implements the "encrypted" hash format used by Cisco PIX & ASA. It's behavior has been confirmed for ASA 9.6, but is presumed correct for PIX & other ASA releases, as it fits with known test vectors, and existing literature. While nearly the same, the PIX & ASA hashes have slight differences, so this function performs differently based on the _is_asa class flag. Noteable changes from PIX to ASA include password size limit increased from 16 -> 32, and other internal changes. �utf-8Nz.Password too long (%s allows at most %d bytes))�msg� � r � c s s"