�
Ϫ�f�� � � � d Z ddlmZ ddlZddlZddlZddlZddlmZm Z m
Z
ddlmZm
Z
ddlmZ ddlZddlmZ ddlmZ dd lmZ dd
lmZmZ ddlmZmZmZmZmZ ddl m!Z!m"Z"m#Z# dd
l$m%Z%m&Z& ddlm'Z' ddl(m)Z)m*Z* ddl+m,Z, ddl-m.Z. ddl/m0Z0m1Z1 ddl2m3Z3m4Z4 ddl5m6Z6 ddl7m8Z8m9Z9 ejz � ej| � ej~ � d�Z@dddd�ZAej� ZBej� ZC G d� deD� ZE G d� deD� ZF G d � d!eD� ZG G d"� d#eD� ZH G d$� d%e4� ZI G d&� d'eD� ZJd(� ZK G d)� d*� ZLd,d+�ZMy# e:$ r ddl7m;Z8m<Z9 Y ��w xY w)-z0
Handling of RSA, DSA, ECDSA, and Ed25519 keys.
� )�annotationsN)� b64encode�decodebytes�encodebytes)�md5�sha256)�Any)�utils)�InvalidSignature)�default_backend)�hashes�
serialization)�dsa�ec�ed25519�padding�rsa)�Cipher�
algorithms�modes)�load_pem_private_key�load_ssh_public_key)�Literal)�common�sexpy)�int_to_bytes)� randbytes)� iterbytes�nativeString)�
NamedConstant�Names)�_mutuallyExclusiveArguments)�decode_dss_signature�encode_dss_signature)�decode_rfc6979_signature�encode_rfc6979_signature)s ecdsa-sha2-nistp256s ecdsa-sha2-nistp384s ecdsa-sha2-nistp521s nistp256s nistp384s nistp521)s secp256r1s secp384r1s secp521r1c � � e Zd ZdZy)�BadKeyErrorzj
Raised when a key isn't what we expected from it.
XXX: we really need to check for bad keys
N��__name__�
__module__�__qualname__�__doc__� � �8/usr/lib/python3/dist-packages/twisted/conch/ssh/keys.pyr( r( D s � �r/ r( c � � e Zd ZdZy)�BadSignatureAlgorithmErrorzi
Raised when a public key signature algorithm name isn't defined for this
public key format.
Nr) r. r/ r0 r2 r2 L � � �r/ r2 c � � e Zd ZdZy)�EncryptedKeyErrorzb
Raised when an encrypted key is presented to fromString/fromFile without
a password.
Nr) r. r/ r0 r5 r5 S r3 r/ r5 c � � e Zd ZdZy)�BadFingerPrintFormatzS
Raises when unsupported fingerprint formats are presented to fingerprint.
Nr) r. r/ r0 r7 r7 Z s � �r/ r7 c �, � e Zd ZdZ e� Z e� Zy)�FingerprintFormatsa�
Constants representing the supported formats of key fingerprints.
@cvar MD5_HEX: Named constant representing fingerprint format generated
using md5[RFC1321] algorithm in hexadecimal encoding.
@type MD5_HEX: L{twisted.python.constants.NamedConstant}
@cvar SHA256_BASE64: Named constant representing fingerprint format
generated using sha256[RFC4634] algorithm in base64 encoding
@type SHA256_BASE64: L{twisted.python.constants.NamedConstant}
N)r* r+ r, r- r �MD5_HEX�
SHA256_BASE64r. r/ r0 r9 r9 ` s � �
� �o�G�!�O�Mr/ r9 c � � e Zd ZdZy)�PassphraseNormalizationErrorz�
Raised when a passphrase contains Unicode characters that cannot be
normalized using the available Unicode character database.
Nr) r. r/ r0 r= r= q r3 r/ r= c � � t | t � rAt d� | D � � r
t � �t j
d| � j
d� S | S )a�
Normalize a passphrase, which may be Unicode.
If the passphrase is Unicode, this follows the requirements of U{NIST
800-63B, section
5.1.1.2<https://pages.nist.gov/800-63-3/sp800-63b.html#memsecretver>}
for Unicode characters in memorized secrets: it applies the
Normalization Process for Stabilized Strings using NFKC normalization.
The passphrase is then encoded using UTF-8.
@type passphrase: L{bytes} or L{unicode} or L{None}
@param passphrase: The passphrase to normalize.
@return: The normalized passphrase, if any.
@rtype: L{bytes} or L{None}
@raises PassphraseNormalizationError: if the passphrase is Unicode and
cannot be normalized using the available Unicode character database.
c 3 �L K � | ] }t j |� d k( �� � y�w)�CnN)�unicodedata�category)�.0�cs r0 � <genexpr>z'_normalizePassphrase.<locals>.<genexpr>� s � �� �C�1�{�#�#�A�&�$�.�C�s �"$�NFKCzUTF-8)�
isinstance�str�anyr= rA � normalize�encode��
passphrases r0 �_normalizePassphraserN x sM � �& |