HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/__pycache__/rsax931.cpython-310.pyc
o

�N�g�#�@s�dZddlZddlZddlZddlZddlZddlmZmZm	Z	m
Z
mZmZddl
ZddlZdZdZdZdd�Zd	d
�Zdd�Ze�Zd
ZGdd�d�ZGdd�d�ZdS)zE
Create and verify ANSI X9.31 RSA signatures using OpenSSL libcrypto
�N)�c_char_p�c_int�c_void_p�cdll�create_string_buffer�pointer���cCs�tj�d�r&d}tjD]}t�tj�|d��}|r|dnd}|r#nq�n&tjj�	�r�t�d�}|p7t�d�}tj
}tj�|�rGtj�|�}tj�
|�}tj�|�dkr[tj�
|�}|pdt�|�d��}t�d	d
�}|pvt�tj�|d��}|p�t�tj�|d��}|p�t�d
�}t��d�d�dd�ddgkr�|p�t�d�}ttt|���}ntt��d�d�d�dkr�|p�dg}|r�|dnd}n�ttdd�r�tjj��r�t�tj�tj�
tj
�d��}|r�|dnd}n`tj�d�}|�sLtjj���rt�d�}|�pt�d�}|�pt�d�}|�r|dnd}n1tjj���rLtj�d��s0tj�d��r>t�d�}|�p<t�d�}nt�d�}|�rJ|dnd}|�sStd ��|S)!z@
    Find the path (or return the short name) of libcrypto.
    �winNzlibcrypto*.dllrz/opt/salt/lib/libcrypto.dylibzlib/libcrypto.dylib�binz/lib/libcrypto.dylibZHOMEBREW_PREFIXz
/usr/localzopt/openssl/lib/libcrypto.dylibz!opt/openssl@*/lib/libcrypto.dylibz/opt/local/lib/libcrypto.dylib�.��10Z15z/usr/lib/libcrypto.*.dylib�z/usr/lib/libcrypto.dylib�frozenFz
libcrypto.so*Zcryptoz%/opt/saltstack/salt/run/libcrypto.so*z/opt/local/lib/libcrypto.so*z/opt/tools/lib/libcrypto.so*z/opt/saltstack/salt/runz
/opt/salt/libz/opt/salt/lib/libcrypto.so*z/opt/freeware/lib/libcrypto.so*zCannot locate OpenSSL libcrypto)�sys�platform�
startswith�path�glob�os�join�salt�utilsZ	is_darwin�
executable�islink�realpath�dirname�basename�getenv�mac_ver�split�list�reversed�sorted�int�getattrZ
is_smartos�ctypes�utilZfind_libraryZis_sunosZis_aix�isdir�OSError)�librZpy_bin�targetZbrew_prefix�r.�F/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/rsax931.py�_find_libcryptosl
��

��"

�

r0cCst�t��S)z$
    Attempt to load libcrypto.
    )r�LoadLibraryr0r.r.r.r/�_load_libcryptonsr2cCs�t�}z|j}t|�r|�}|dkr|��Wnty(|��|��Ynwd|j_t	|j_
t	f|j_t	|j_
ttf|j_t	|j_
t	f|j_t	t	t	t	f|j_t	|j_
t	t	t	t	f|j_t	|j_
tttt	tf|j_tttt	tf|j_|S)z>
    Set up libcrypto argtypes and initialize the library
    ir.)r2ZOpenSSL_version_num�callableZOPENSSL_init_crypto�AttributeErrorZOPENSSL_no_configZ!OPENSSL_add_all_algorithms_noconf�RSA_new�argtypesr�restype�RSA_free�RSA_sizeZargtyperr�BIO_new_mem_buf�BIO_free�PEM_read_bio_RSAPrivateKey�PEM_read_bio_RSA_PUBKEY�RSA_private_encrypt�RSA_public_decrypt)�	libcryptoZopenssl_version_numr.r.r/�_init_libcryptousN��

���rA�c@�(eZdZdZdd�Zdd�Zdd�ZdS)	�
RSAX931SignerzB
    Create ANSI X9.31 RSA signatures using OpenSSL libcrypto
    cCsTtjj�|d�}t�|t|��|_tt�	��|_
t�|jt|j
�dd�s(t
d��dS)zo
        Init an RSAX931Signer instance

        :param str keydata: The RSA private key in PEM format
        �asciiNzinvalid RSA private key)rr�stringutils�to_bytesr@r:�len�_biorr5�_rsar<r�
ValueError)�selfZkeydatar.r.r/�__init__�s��zRSAX931Signer.__init__cC�t�|j�t�|j�dS�N�r@r;rIr8rJ�rLr.r.r/�__del__��zRSAX931Signer.__del__cC�Rtt�|j��}tjj�|�}t�t	|�|||jt
�}|dkr#td��|d|�S)z�
        Sign a message (digest) using the private key

        :param str msg: The message (digest) to sign
        :rtype: str
        :return: The signature, or an empty string if the encryption failed
        rzUnable to encrypt message)rr@r9rJrrrFrGr>rH�RSA_X931_PADDINGrK)rL�msg�buf�sizer.r.r/�sign�s	�zRSAX931Signer.signN)�__name__�
__module__�__qualname__�__doc__rMrRrYr.r.r.r/rD�s
rDc@rC)	�RSAX931VerifierzB
    Verify ANSI X9.31 RSA signatures using OpenSSL libcrypto
    cCs`tjj�|d�}|�dd�}t�|t|��|_t	t�
��|_t�|jt
|j�dd�s.td��dS)zp
        Init an RSAX931Verifier instance

        :param str pubdata: The RSA public key in PEM format
        rEsRSA �Nzinvalid RSA public key)rrrFrG�replacer@r:rHrIrr5rJr=rrK)rLZpubdatar.r.r/rM�s��zRSAX931Verifier.__init__cCrNrOrPrQr.r.r/rR�rSzRSAX931Verifier.__del__cCrT)a-
        Recover the message (digest) from the signature using the public key

        :param str signed: The signature created with the private key
        :rtype: str
        :return: The message (digest) recovered from the signature, or an empty
            string if the decryption failed
        rzUnable to decrypt message)rr@r9rJrrrFrGr?rHrUrK)rLZsignedrWrXr.r.r/�verify�s
�zRSAX931Verifier.verifyN)rZr[r\r]rMrRrar.r.r.r/r^�s
r^)r]Zctypes.utilr(rrrrrrrrrrZsalt.utils.platformrZsalt.utils.stringutilsZOPENSSL_INIT_ADD_ALL_CIPHERSZOPENSSL_INIT_ADD_ALL_DIGESTSZOPENSSL_INIT_NO_LOAD_CONFIGr0r2rAr@rUrDr^r.r.r.r/�<module>s& Y3-