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__/nacl.cpython-310.pyc
o

�N�gw6�@s�dZddlZddlZddlZddlZddlZddlZddlZddl	Zddl
ZdZz
ddlZ
ddlZ
Wney=dZYnwdZdd�Zdd�Zd	d
�Zdd�Zd
d�Zd!dd�Zdd�Zd"dd�Zdd�Zd"dd�Zdd�Zdd�Zdd�Zdd �ZdS)#z8
Common code shared between the nacl module and runner.
�NzLPyNaCl import error, perhaps missing python PyNaCl package or should update.�naclcCstddurdSt�S)NZ	fips_modeT)Fz%nacl utils not available in FIPS mode)Z__opts__�check_requirements�rr�C/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/nacl.py�__virtual__srcCstdutfS)z0
    Check required libraries are available
    N)�	REQ_ERRORrrrrr"src
Ks�|�d�}|stj�|d�d�d�}|�d�}|s&tj�|d�d�d�}|�dd�d	|d	|d
�}t�d�}z|�td|i��Wnttfyb}z|�|d�|i��WYd	}~nd	}~wwt	|�
��t	|�
��@D]}||||<qo|S)
z
    Return configuration
    �sk_file�optsZpki_dirzmaster/nacl�pk_filezmaster/nacl.pub�box_typeZ	sealedboxN)r�skr�pkr
z.configz
config.get)�get�os�path�join�__virtualname__�update�__salt__�	NameError�KeyError�set�keys)�kwargsrr
�configZ
config_key�e�krrr�_get_config)s,


�
"��rcKs�tdi|��}d}|drtjj�|d�}|d}|sP|rPz&tjj�|d��}tjj�|����	d�}Wd�n1s>wYWnt
yOtd��wt�
|�S)z
    Return sk
    Nrr�rb�
zno key or sk_file foundr)r�salt�utils�stringutils�to_str�files�fopen�
to_unicode�read�rstrip�OSError�	Exception�base64�	b64decode)rr�keyr�keyfrrr�_get_skIs���
r/cKs�tdi|��}d}|drtjj�|d�}|d}|sP|rPz&tjj�|d��}tjj�|����	d�}Wd�n1s>wYWnt
yOtd��wt|�}t
�|�S)z
    Return pk
    Nr
r
rrzno pubkey or pk_file foundr)rr r!r"r#r$r%r&r'r(r)r*�strr+r,)rrZpubkeyr
r.rrr�_get_pk[s ���
r1cKs2d|vr|d}|dur"tjj��}t�|���t�|j���d�S|dur+|�d�}|r�|dur�tj	�
|�s�tjj��}tjj
�|d��}|�t�|����Wd�n1sZwYtjj��r�tjj��}tjj�||�tjjj||ddddd	�nt�|d
�d|��Std|�d
���|dur�|r�td��tj	�
|�r�tj	�
|�r�td|�d|�d
���tj	�
|��rtj	�
|��stjj
�|d��}tjj�|����d�}t�|�}Wd�n1s�wYtj�|�}tjj
�|d��}|�t�|j����Wd�n	1�swYd|��Stjj��}tjj
�|d��}|�t�|����Wd�n	1�s?wYtjj���rgtjj��}tjj�||�tjjj||ddddd	�nt�|d
�tjj
�|d��}|�t�|j����Wd�n	1�s�wYd|�d|��S)aW
    Use PyNaCl to generate a keypair.

    If no `sk_file` is defined return a keypair.

    If only the `sk_file` is defined `pk_file` will use the same name with a postfix `.pub`.

    When the `sk_file` is already existing, but `pk_file` is not. The `pk_file` will be generated
    using the `sk_file`.

    CLI Examples:

    .. code-block:: bash

        salt-call nacl.keygen
        salt-call nacl.keygen sk_file=/etc/salt/pki/master/nacl
        salt-call nacl.keygen sk_file=/etc/salt/pki/master/nacl pk_file=/etc/salt/pki/master/nacl.pub
        salt-call --local nacl.keygen

    sk_file
      Path to where there secret key exists.
      The argrument ``keyfile`` was deprecated
      in favor of ``sk_file``. ``keyfile`` will
      continue to work to ensure backwards
      compatbility, but please use the preferred
      ``sk_file``.
    �keyfileN)rr
z.pub�wbZfull_controlZgrantT)Zreset_permsZ	protectedizsaved sk_file: zsk_file:� already exist.z6sk_file: Must be set inorder to generate a public key.z
 and pk_file:rrzsaved pk_file: zsaved sk_file:z  pk_file: )r�public�
PrivateKeyZgenerater+�	b64encode�encodeZ
public_keyrr�isfiler r!r$r%�write�platformZ
is_windowsZ
win_functionsZget_current_userZwin_daclZ	set_ownerZset_permissions�chmodr*r"r&r'r(r,)rr
rZkpr.Zcur_userrrrr�keygennst�
��

��
���r=cK�rd|vr|d|d<d|d<d|vr|d|d<d|d<tdi|��d}|dkr1t|fi|��St|fi|��S)	a4
    Alias to `{box_type}_encrypt`

    box_type: secretbox, sealedbox(default)

    sk_file
      Path to where there secret key exists.
      The argrument ``keyfile`` was deprecated
      in favor of ``sk_file``. ``keyfile`` will
      continue to work to ensure backwards
      compatbility, but please use the preferred
      ``sk_file``.
    sk
      Secret key contents. The argument ``key``
      was deprecated in favor of ``sk``. ``key``
      will continue to work to ensure backwards
      compatibility, but please use the preferred
      ``sk``.
    r2r�	secretboxrr-rNr)r�secretbox_encrypt�sealedbox_encrypt��datarrrrr�enc�srDcK�ztd|�}Wn3ty;}z'tjj�|d��}tjj�|���}Wd�n1s,wYWYd}~nd}~wwt	|fi|��}|r{t
j�|�rTtd|�d���tjj�|d��}|�
tjj�|��Wd�n1sqwYd|��S|S)a	
    This is a helper function to encrypt a file and return its contents.

    You can provide an optional output file using `out`

    `name` can be a local file or when not using `salt-run` can be a url like `salt://`, `https://` etc.

    CLI Examples:

    .. code-block:: bash

        salt-run nacl.enc_file name=/tmp/id_rsa
        salt-call nacl.enc_file name=salt://crt/mycert out=/tmp/cert
        salt-run nacl.enc_file name=/tmp/id_rsa box_type=secretbox             sk_file=/etc/salt/pki/master/nacl.pub
    �cp.get_file_strrN�file:r4r3�Wrote: )rr*r r!r$r%r"r&r'rDrrr9r:�to_bytes��name�outrrCr�f�drrr�enc_file��"����
rOcKr>)	a4
    Alias to `{box_type}_decrypt`

    box_type: secretbox, sealedbox(default)

    sk_file
      Path to where there secret key exists.
      The argrument ``keyfile`` was deprecated
      in favor of ``sk_file``. ``keyfile`` will
      continue to work to ensure backwards
      compatbility, but please use the preferred
      ``sk_file``.
    sk
      Secret key contents. The argument ``key``
      was deprecated in favor of ``sk``. ``key``
      will continue to work to ensure backwards
      compatibility, but please use the preferred
      ``sk``.
    r2rr?rr-rNr)r�secretbox_decrypt�sealedbox_decryptrBrrr�decsrScKrE)a
    This is a helper function to decrypt a file and return its contents.

    You can provide an optional output file using `out`

    `name` can be a local file or when not using `salt-run` can be a url like `salt://`, `https://` etc.

    CLI Examples:

    .. code-block:: bash

        salt-run nacl.dec_file name=/tmp/id_rsa.nacl
        salt-call nacl.dec_file name=salt://crt/mycert.nacl out=/tmp/id_rsa
        salt-run nacl.dec_file name=/tmp/id_rsa.nacl box_type=secretbox             sk_file=/etc/salt/pki/master/nacl.pub
    rFrNrGr4r3rH)rr*r r!r$r%r"r&r'rSrrr9r:rIrJrrr�dec_file=rPrTcKsDtjj�|�}tdi|��}tj�|�}tj�|�}t	�
|�|��S)a�
    Encrypt data using a public key generated from `nacl.keygen`.
    The encryptd data can be decrypted using `nacl.sealedbox_decrypt` only with the secret key.

    CLI Examples:

    .. code-block:: bash

        salt-run nacl.sealedbox_encrypt datatoenc
        salt-call --local nacl.sealedbox_encrypt datatoenc pk_file=/etc/salt/pki/master/nacl.pub
        salt-call --local nacl.sealedbox_encrypt datatoenc pk='vrwQF7cNiNAVQVAiS3bvcbJUnF0cN6fU9YTZD9mBfzQ='
    Nr)r r!r"rIr1rr5Z	PublicKey�	SealedBoxr+r7�encrypt)rCrr
�keypair�brrrrA^s
rAcKsP|durdStjj�|�}tdi|��}tj�|�}tj�|�}|�	t
�|��S)a�
    Decrypt data using a secret key that was encrypted using a public key with `nacl.sealedbox_encrypt`.

    CLI Examples:

    .. code-block:: bash

        salt-call nacl.sealedbox_decrypt pEXHQM6cuaF7A=
        salt-call --local nacl.sealedbox_decrypt data='pEXHQM6cuaF7A=' sk_file=/etc/salt/pki/master/nacl
        salt-call --local nacl.sealedbox_decrypt data='pEXHQM6cuaF7A=' sk='YmFkcGFzcwo='
    Nr)r r!r"rIr/rr5r6rU�decryptr+r,)rCrrrWrXrrrrRtsrRcKs8tjj�|�}tdi|��}tj�|�}t�	|�
|��S)a�
    Encrypt data using a secret key generated from `nacl.keygen`.
    The same secret key can be used to decrypt the data using `nacl.secretbox_decrypt`.

    CLI Examples:

    .. code-block:: bash

        salt-run nacl.secretbox_encrypt datatoenc
        salt-call --local nacl.secretbox_encrypt datatoenc sk_file=/etc/salt/pki/master/nacl
        salt-call --local nacl.secretbox_encrypt datatoenc sk='YmFkcGFzcwo='
    Nr)r r!r"rIr/r�secret�	SecretBoxr+r7rV)rCrrrXrrrr@�sr@cKsF|durdStjj�|�}tdi|��}tjj|d�}|�t	�
|��S)a�
    Decrypt data that was encrypted using `nacl.secretbox_encrypt` using the secret key
    that was generated from `nacl.keygen`.

    CLI Examples:

    .. code-block:: bash

        salt-call nacl.secretbox_decrypt pEXHQM6cuaF7A=
        salt-call --local nacl.secretbox_decrypt data='pEXHQM6cuaF7A=' sk_file=/etc/salt/pki/master/nacl
        salt-call --local nacl.secretbox_decrypt data='pEXHQM6cuaF7A=' sk='YmFkcGFzcwo='
    N)r-r)r r!r"rIr/rrZr[rYr+r,)rCrr-rXrrrrQ�s
rQ)NN)N)�__doc__r+rZ
salt.syspathsr Zsalt.utils.filesZsalt.utils.platformZsalt.utils.stringutilsZsalt.utils.versionsZsalt.utils.win_daclZsalt.utils.win_functionsrZnacl.publicrZnacl.secret�ImportErrorrrrrr/r1r=rDrOrSrTrArRr@rQrrrr�<module>sB�� 
a
&!
'!