HEX
Server: LiteSpeed
System: Linux php-prod-1.spaceapp.ru 5.15.0-157-generic #167-Ubuntu SMP Wed Sep 17 21:35:53 UTC 2025 x86_64
User: xnsbb3110 (1041)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //usr/local/CyberCP/lib/python3.10/site-packages/asyncssh/__pycache__/pkcs11.cpython-310.pyc
o

�h�,�@s(dZddlmZddlmZmZmZmZmZm	Z	m
Z
mZz(ddlZddlm
Z
mZmZmZddlmZmZddlmZddlmZd	ZWn
eefyQd
ZYnwddlmZdd
lmZmZddlm Z m!Z!m"Z"ddlm#Z#m$Z$ede
e%e&e'dffZ(ee'e&fZ)ee)dfZ*er�ej+eej,eiZ-ej.ej/ej0ej1ej/ej2ej0ej.ej/ej3ej4ej5d�Z6Gdd�de"�Z7Gdd�d�Z8d#d	ddddd�de'dee'de%dee'deedee'deedee7fd d!�Z9dSd#d	ddddd�de'dee'de%dee'deedee'deededfd"d!�Z9dS)$zPKCS#11 smart card handler�)�
TracebackType)�Dict�List�Optional�Sequence�Tuple�Type�Union�castN)�	Attribute�KeyType�	Mechanism�ObjectClass)�
PrivateKey�Token)�encode_rsa_public_key)�encode_ec_public_keyTF�)�
BytesOrStr)�MPInt�String)�SSHCertificate�SSHKey�
SSHKeyPair)�import_certificate_chain�import_public_keyrr�SSHPKCS11Session)sssh-rsasrsa-sha2-256srsa-sha2-512sssh-rsa-sha224@ssh.comsssh-rsa-sha256@ssh.comsssh-rsa-sha384@ssh.comsssh-rsa-sha512@ssh.comsrsa1024-sha1srsa2048-sha256secdsa-sha2-nistp256secdsa-sha2-nistp384secdsa-sha2-nistp521c
sZeZdZdZdZ	ddddededeef�fd	d
�
Z	ddd
�Z
dedefdd�Z�Z
S)�SSHPKCS11KeyPairz3Surrogate for a key accessed via a PKCS#11 provider�pkcs11N�sessionr�privkey�pubkey�certc
s8t�j|j|j|j|j|j|j|dd�||_||_dS)NT)�use_executor)�super�__init__�	algorithm�sig_algorithms�public_data�label�_session�_privkey)�selfrr r!r"��	__class__��B/usr/local/CyberCP/lib/python3.10/site-packages/asyncssh/pkcs11.pyr%Fs
�
zSSHPKCS11KeyPair.__init__�returncCs|j��dS�N)r*�close�r,r/r/r0�__del__PszSSHPKCS11KeyPair.__del__�datacCs�|j}|�d�r|dd�}|jj|t|d�}|jjtjkrAt|�d}t	�
|d|�d�}t	�
||d�d�}t|�t|�}t|�t|�S)z*Sign a block of data with this private keysx509v3-�N)�	mechanism��big)
�
sig_algorithm�
startswithr+�sign�
mechanisms�key_typer�EC�len�int�
from_bytesrr)r,r6r;�sig�length�r�sr/r/r0r=Ss
zSSHPKCS11KeyPair.signr2�r1N)�__name__�
__module__�__qualname__�__doc__�	_key_typerrrrr%r5�bytesr=�
__classcell__r/r/r-r0rAs���

rc	@s�eZdZUdZiZeed<dedede	e
fdd�Zdd	d
�Zde
eded
eddfdd�Zedede	e
ddfdd��Zddd�Zdede	e
de	edeefdd�ZdS)rz>Work around PKCS#11 sessions not supporting simultaneous opens�	_sessions�token_id�token�pincCs||_|j|d�|_d|_dS)N)�user_pinr)�	_token_id�openr*�	_refcount)r,rQrRrSr/r/r0r%ks
zSSHPKCS11Session.__init__r1cCs|S)z6Allow SSHPKCS11Session to be used as a context managerr/r4r/r/r0�	__enter__qszSSHPKCS11Session.__enter__�	_exc_type�
_exc_value�
_tracebackNcCs|��dS)z.Drop one reference to the session when exitingN)r3)r,rYrZr[r/r/r0�__exit__vszSSHPKCS11Session.__exit__cCsV|j|jf}z|j|}Wnty!||||�}||j|<Ynw|jd7_|S)z1Open a new session, or return an already-open oner)�manufacturer_id�serialrP�KeyErrorrW)�clsrRrSrQrr/r/r0rV}s�zSSHPKCS11Session.opencCs4|jd8_|jdkr|j��|j|j=dSdS)z%Drop one reference to an open sessionrrN)rWr*r3rPrUr4r/r/r0r3�s


�zSSHPKCS11Session.close�
load_certs�	key_label�key_idcCst|t�r
t�|�}tjtjtjdi}|dur||tj	<|dur%||tj
<tjtji}|r@dd�|j�
|�D�}dd�|D�}ni}g}|j�
|�D]0}	tt|	�}
t�|
j�}|rzt||
��}|�|j�}
|
rq|�t||
||
��|�t||
|��qJ|jt|�7_|S)z+Return the private keys found on this tokenTNcSs g|]}ttt|tj���qSr/)rr
rNr�VALUE��.0r"r/r/r0�
<listcomp>�s
��z-SSHPKCS11Session.get_keys.<locals>.<listcomp>cSs(i|]}|rdt|j�vr|jj|�qS)�Attest)�str�subject�keyr(rer/r/r0�
<dictcomp>�s��z-SSHPKCS11Session.get_keys.<locals>.<dictcomp>)�
isinstancerirN�fromhexr�CLASSr�PRIVATE_KEY�SIGN�LABEL�	OBJECT_ID�CERTIFICATEr*�get_objectsr
r�encoders�getr?rr(�appendrrWrA)r,rarbrc�	key_attrs�
cert_attrs�certs�certdict�keysrkr �encoderr!r"r/r/r0�get_keys�s>

�


�

��zSSHPKCS11Session.get_keys)r1rrH)rIrJrKrLrP�_SessionMap�__annotations__�_TokenIDrrrir%rXr�
BaseExceptionrr\�classmethodrVr3�boolrrrrr/r/r/r0rfs,


�

��
�
	��)ra�token_label�token_serialrbrc�providerrSrar�r�rbrcr1c	Cszt�|�}g}t|t�r|�d�}|j||d�D]"}	t�|	|��}
|�|
�	|||��Wd�n1s5wYq|S)aLoad PIV keys and X.509 certificates from a PKCS#11 token

           This function loads a list of SSH keypairs with optional X.509
           cerificates from attached PKCS#11 security tokens. The PKCS#11
           provider must be specified, along with a user PIN if the
           tokens are set to require one.

           By default, this function loads both private key handles
           and the X.509 certificates associated with them, allowing for
           X.509 certificate based auth to SSH servers that support it.
           To disable loading of these certificates and perform only
           key-based authentication, load_certs may be set to `False`.

           If token_label and/or token_serial are specified, only tokens
           matching those values will be accessed.

           If key_label and/or key_id are specified, only keys matching
           those values will be loaded. Key IDs can be specified as
           either raw bytes or a string containing hex digits.

               .. note:: If you have an active asyncio event loop at
                         the time you call this function, you may want
                         to consider running it via a call to
                         :meth:`asyncio.AbstractEventLoop.run_in_executor`.
                         While retrieving the keys generally takes only a
                         fraction of a second, calling this function
                         directly could block asyncio event processing
                         until it completes.

           :param provider:
               The path to the PKCS#11 provider's shared library.
           :param pin: (optional)
               The PIN to use when accessing tokens, if needed.
           :param load_certs: (optional)
               Whether or not to load X.509 certificates from the
               security tokens.
           :param token_label: (optional)
               A token label to match against. If set, only security
               tokens with this label will be accessed.
           :param token_serial: (optional)
               A token serial number to match against. If set, only
               security tokens with this serial number  will be accessed.
           :param key_label: (optional)
               A key label to match against. If set, only keys with this
               label will be loaded.
           :param key_id: (optional)
               A key ID to match against. If set, only keys with this ID
               will be loaded.
           :type provider: `str`
           :type pin: `str`
           :type load_certs: `bool`
           :type token_label: `str`
           :type token_serial: `bytes` or `str`
           :type key_label: `str`
           :type key_id: `bytes` or `str`

           :returns: list of class:`SSHKeyPair`

        zutf-8)r�r�N)
r�librmri�encode�
get_tokensrrV�extendr)r�rSrar�r�rbrcr�r}rRrr/r/r0�load_pkcs11_keys�s
C


���r�cCs
td�d�)z,Report that PKCS#11 support is not availablezPKCS#11 support not availableN)�
ValueError)r�rSrar�r�rbrcr/r/r0r�s
	r2):rL�typesr�typingrrrrrrr	r
rrrr
rrr�pkcs11.util.rsar�pkcs11.util.ecr�pkcs11_available�ImportError�ModuleNotFoundError�miscr�packetrr�
public_keyrrrrrr�rNri�	_AttrDictr�r��RSAr@rv�
SHA1_RSA_PKCS�SHA256_RSA_PKCS�SHA512_RSA_PKCS�SHA224_RSA_PKCS�SHA384_RSA_PKCS�ECDSA_SHA256�ECDSA_SHA384�ECDSA_SHA512r>rrr�r/r/r/r0�<module>s�(���%b�������Q�������