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/modules/__pycache__/gpg.cpython-310.pyc
o

�N�g��	@s$dZddlZddlZddlZddlZddlZddlZddlZddl	Zddl
mZe�e
�ZdZddddd	d
ddd�Zd
dddddd�Zdddddd
d�Zdddddd�ZdZzddlZdZWneyidZYnwdd �Zd!d"�ZdQd#d$�Zd%d&�Zd'd(�ZdRd)d*�ZdSd+d,�ZdQd-d.�ZdRd/d0�Z dRd1d2�Z!dRd3d4�Z"e	5	6	7	8							dTd9d:��Z#						dUd;d<�Z$dVd=d>�Z%dVd?d@�Z&edVdAdB��Z'							dWdCdD�Z(edVdEdF��Z)dVdGdH�Z*							dXdIdJ�Z+	dYdKdL�Z,										dZdMdN�Z-							d[dOdP�Z.dS)\ai
Manage a GPG keychains, add keys, create keys, retrieve keys from keyservers.
Sign, encrypt and sign plus encrypt text and files.

.. versionadded:: 2015.5.0

.. note::

    The ``python-gnupg`` library and ``gpg`` binary are required to be
    installed.
    Be aware that the alternate ``gnupg`` and ``pretty-bad-protocol``
    libraries are not supported.

�N)�SaltInvocationError�gpgZExpiredZUnknownzNot Trustedz
Fully TrustedzMarginally TrustedzUltimately TrustedZRevoked)�e�q�n�f�m�u�r�-�1�2�3�4�5�6�Zexpired�unknownZnot_trustedZ
marginallyZfullyZ
ultimatelyZ
Marginally)rr
rrrrZ	UndefinedZNeverZMarginalZFullyZUltimate)�0rr
rrzkeys.openpgp.orgTFcCstjj�d�S)z,
    Returns the path to the gpg binary
    r)�salt�utils�path�which�rr�D/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/gpg.py�_gpgOsrcCst�sdStr	tSdS)z=
    Makes sure that python-gnupg and gpg are available.
    )FzIThe gpg execution module cannot be loaded: gpg binary is not in the path.)FzTThe gpg execution module cannot be loaded; the gnupg python module is not installed.)r�HAS_GPG_BINDINGS�__virtualname__rrrr�__virtual__Ws���rcCsF|stdd�}td|�}|s!|dkrt�}|Std|�d���|S)z-
    Wrapper for user.info Salt function
    z
config.option�userz	user.inforzUser z does not exist)�__salt__�_get_user_infor)r�userinforrrr!ls�r!cCs<|dkrtj�tdd�d�}|Stj�t|�dd�}|S)z=
    Return default GnuPG home directory path for a user
    r�
config.get�
config_dir�gpgkeys�homez.gnupg)�osr�joinr r!)r�	gnupghomerrr�_get_user_gnupghome�s
�r*cst����fdd��}|S)Nc
s�|�d�}|�d�}|st|�}t|�}t�}|d|dkrCtj�|�rCtd|d�}|gtd|�D]}td||d|�q6t|�D]
}|�d	�rQ||=qG�|i|��}	|d|dkr}td|d�}|gtd|�D]
}td|||�qr|	S)
z<
        Wrap gpg function calls to fix permissions
        rr)�uidzfile.gid_to_group�gidz	file.findz
file.chown�name�__)	�getr*r!r'r�existsr �list�
startswith)
�args�kwargsrr)r"Zrun_user�groupr�key�ret��funcrr�func_wrapper�s(


�z(_restore_ownership.<locals>.func_wrapper)�	functools�wraps)r9r:rr8r�_restore_ownership�s"r=cCs|st|�}tj|d�}|S)z
    Create the GPG object
    )r))r*�gnupgZGPG)rr)rrrr�_create_gpg�sr?cCst||�}|�|�}|S)z*
    Helper function for Listing keys
    )r?�	list_keys)rr)�secretr�_keysrrr�
_list_keys�s

rCcCs*t|�}|r|�||�}|S|�|�}|S)z;
    Helper function for searching keys from keyserver
    )r?�search_keys)�text�	keyserverrrrBrrr�_search_keys�s
�rGc		Cs�|st}g}t|||�D]L}|d|dd�}|�dd�}|�dd�}|�dd�}|r:t�dt�t|d���|d<|rKt�dt�t|d���|d	<|rS|d|d
<|�|�q|S)a�
    Search keys from keyserver

    text
        Text to search the keyserver for, e.g. email address, keyID or fingerprint.

    keyserver
        Keyserver to use for searching for GPG keys, defaults to keys.openpgp.org.

    user
        Which user's keychain to access, defaults to user Salt is running as.
        Passing the user as ``salt`` will set the GnuPG home directory to the
        ``/etc/salt/gpgkeys``.

    CLI Example:

    .. code-block:: bash

        salt '*' gpg.search_keys user@example.com

        salt '*' gpg.search_keys user@example.com keyserver=keyserver.ubuntu.com

        salt '*' gpg.search_keys user@example.com keyserver=keyserver.ubuntu.com user=username

    �keyid�uids)rHrI�expiresN�date�length�%Y-%m-%d�created�	keyLength)�_DEFAULT_KEY_SERVERrGr/�time�strftime�	localtime�float�append)	rErFrrB�_key�tmprJrKrLrrrrD�s(��rDc
	Cs�g}t||�D]o}|d|d|dd�}|�dd�}|�dd�}|�dd�}|�d	d�}|�d
d�}	|rDt�dt�t|d���|d<|rUt�dt�t|d���|d<|r]|d|d
<|rgt|d	|d<|	rqt|d
|d
<|�|�q|S)a�
    List keys in GPG keychain

    user
        Which user's keychain to access, defaults to user Salt is running as.
        Passing the user as ``salt`` will set the GnuPG home directory to the
        ``/etc/salt/gpgkeys``.

    gnupghome
        Specify the location where GPG keyring and related files are stored.

    CLI Example:

    .. code-block:: bash

        salt '*' gpg.list_keys

    rH�fingerprintrI�rHrXrIrJNrKrL�
ownertrust�trustrMrNrO�
ownerTrust�rCr/rQrRrSrT�LETTER_TRUST_DICTrU�
rr)rBrVrWrJrKrL�owner_trustr[rrrr@s6���r@c
	Cs�g}t||dd�D]o}|d|d|dd�}|�dd�}|�d	d�}|�d
d�}|�dd�}|�dd�}	|rFt�d
t�t|d���|d<|rWt�d
t�t|d	���|d<|r_|d
|d<|rit|d|d<|	rst|d|d<|�|�q	|S)a�
    List secret keys in GPG keychain

    user
        Which user's keychain to access, defaults to user Salt is running as.
        Passing the user as ``salt`` will set the GnuPG home directory to the
        ``/etc/salt/gpgkeys``.

    gnupghome
        Specify the location where GPG keyring and related files are stored.

    CLI Example:

    .. code-block:: bash

        salt '*' gpg.list_secret_keys

    T�rArHrXrIrYrJNrKrLrZr[rMrNrOr\r]r_rrr�list_secret_keys;s6���rb�RSA��Autogenerated Key�Generated by SaltStackcCsdddd�}||||d�}t|	|
�}
|r||d<|r||d<|r$||d<|r*||d<|rCtd	d
�}|s>d|d<d
|d<|S||d<nd|d<|
jdi|��}d|vrl|��}|�d�|�|�d�d�d�|�d}|
�|�}|j	r|j	|d<d|d<|Sd|d<d|d<|S)a
    Create a key in the GPG keychain

    .. note::

        GPG key generation requires *a lot* of entropy and randomness.
        Difficult to do over a remote connection, consider having
        another process available which is generating randomness for
        the machine.  Also especially difficult on virtual machines,
        consider the `rng-tools
        <http://www.gnu.org/software/hurd/user/tlecarrour/rng-tools.html>`_
        package.

        The create_key process takes awhile so increasing the timeout
        may be necessary, e.g. -t 15.

    key_type
        The type of the primary key to generate. It must be capable of signing.
        'RSA' or 'DSA'.

    key_length
        The length of the primary key in bits.

    name_real
        The real name of the user identity which is represented by the key.

    name_comment
        A comment to attach to the user id.

    name_email
        An email address for the user.

    subkey_type
        The type of the secondary key to generate.

    subkey_length
        The length of the secondary key in bits.

    expire_date
        The expiration date for the primary and any secondary key.
        You can specify an ISO date, A number of days/weeks/months/years,
        an epoch value, or 0 for a non-expiring key.

    use_passphrase
        Whether to use a passphrase with the signing key. Passphrase is received
        from Pillar.

    user
        Which user's keychain to access, defaults to user Salt is running as.
        Passing the user as ``salt`` will set the GnuPG home directory to the
        ``/etc/salt/gpgkeys``.

    gnupghome
        Specify the location where GPG keyring and related files are stored.

    CLI Example:

    .. code-block:: bash

        salt -t 15 '*' gpg.create_key

    T�)�resrX�message)�key_type�
key_length�	name_real�name_comment�
name_email�subkey_type�
subkey_length�expire_date�
pillar.get�gpg_passphraseFrh�'gpg_passphrase not available in pillar.ri�
passphraseZ
no_protectionzNo-Protection: Truez%commitz%no-protection�
rXz$GPG key pair successfully generated.z Unable to generate GPG key pair.Nr)
r?r Z
gen_key_input�
splitlines�remove�insert�indexr(Zgen_keyrX)rjrkrlrmrnrorprq�use_passphraserr)r7Z
create_paramsrrsZ
input_dataZ	temp_datar6rrr�
create_keynsJL�




�r|c	s
ddd��|r|rd�d<d�d<�S|s!|s!d�d<d�d<�St||��t|||�}��fd	d
�}|r{|d}t|||�}|r_|sMd�d<d�d<�St||d|��d
kr_d|�d��d<t||d|��d
kru�dd|�d�7<d�d<�Sd�d<d�d<�S)a]
    Get a key from the GPG keychain

    keyid
        The keyid of the key to be deleted.

    fingerprint
        The fingerprint of the key to be deleted.

    delete_secret
        Whether to delete a corresponding secret key prior to deleting the public key.
        Secret keys must be deleted before deleting any corresponding public keys.

    user
        Which user's keychain to access, defaults to user Salt is running as.
        Passing the user as ``salt`` will set the GnuPG home directory to the
        ``/etc/salt/gpgkeys``.

    gnupghome
        Specify the location where GPG keyring and related files are stored.

    use_passphrase
        Whether to use a passphrase with the signing key. Passphrase is received
        from Pillar.

        .. versionadded:: 3003

    CLI Example:

    .. code-block:: bash

        salt '*' gpg.delete_key keyid=3FAD9F1E

        salt '*' gpg.delete_key fingerprint=53C96788253E58416D20BCD352952C84C3252192

        salt '*' gpg.delete_key keyid=3FAD9F1E user=username

        salt '*' gpg.delete_key keyid=3FAD9F1E user=username delete_secret=True

    Trg�rhriFrh�/Only specify one argument, fingerprint or keyidri�'Required argument, fingerprint or keyidcsP|rtdd�}|sd�d<d�d<�S�j|||d�}|S�j||dd�}|S)	NrrrsFrhrtri�ru�Zexpect_passphrase)r Zdelete_keys)rXrAr{rs�out�rr7rr�__delete_key0s�z delete_key.<locals>.__delete_keyrXz;Secret key exists, delete first or pass delete_secret=True.�okzSecret key for z	 deleted
zPublic key for z deletedzKey not available in keychain.)r?�get_key�get_secret_key�str)	rHrXZ
delete_secretrr)r{r6r�Zskeyrr�r�
delete_key�s<
0

�r�c	Cs(i}t||�D]�}|d|ks|d|ks|ddd�|kr�|d|d<|d|d<|d|d<|�dd�}|�dd�}|�dd�}|�d	d�}	|�d
d�}
|r`t�dt�t|d���|d<|rqt�dt�t|d���|d<|ry|d|d
<|	r�t|d	|d<|
r�t|d
|d
<q|s�dS|S)a�
    Get a key from the GPG keychain

    keyid
        The key ID (short or long) of the key to be retrieved.

    fingerprint
        The fingerprint of the key to be retrieved.

    user
        Which user's keychain to access, defaults to user Salt is running as.
        Passing the user as ``salt`` will set the GnuPG home directory to the
        ``/etc/salt/gpgkeys``.

    gnupghome
        Specify the location where GPG keyring and related files are stored.

    CLI Example:

    .. code-block:: bash

        salt '*' gpg.get_key keyid=3FAD9F1E

        salt '*' gpg.get_key fingerprint=53C96788253E58416D20BCD352952C84C3252192

        salt '*' gpg.get_key keyid=3FAD9F1E user=username

    rXrH�NrIrJrKrLrZr[rMrNrOr\F�rCr/rQrRrSrTr^�rHrXrr)rWrVrJrKrLr`r[rrrr�Ws>���r�c	Cs,i}t||dd�D]�}|d|ks!|d|ks!|ddd�|kr�|d|d<|d|d<|d|d<|�dd�}|�d	d�}|�d
d�}|�dd�}	|�dd�}
|rbt�d
t�t|d���|d<|rst�d
t�t|d	���|d<|r{|d
|d<|	r�t|d|d<|
r�t|d|d<q	|s�dS|S)a�
    Get a key from the GPG keychain

    keyid
        The key ID (short or long) of the key to be retrieved.

    fingerprint
        The fingerprint of the key to be retrieved.

    user
        Which user's keychain to access, defaults to user Salt is running as.
        Passing the user as ``salt`` will set the GnuPG home directory to the
        ``/etc/salt/gpgkeys``.

    gnupghome
        Specify the location where GPG keyring and related files are stored.

    CLI Example:

    .. code-block:: bash

        salt '*' gpg.get_secret_key keyid=3FAD9F1E

        salt '*' gpg.get_secret_key fingerprint=53C96788253E58416D20BCD352952C84C3252192

        salt '*' gpg.get_secret_key keyid=3FAD9F1E user=username

    TrarXrHr�NrIrJrKrLrZr[rMrNrOr\Fr�r�rrrr��s>���r�cCs�ddd�}t||�}|s|std��|rCz#tjj�|d��}tjj�|���}Wd�n1s1wYWnt	yBtd��w|�
|�}|jsN|jrTd|d	<|S|j
r]d
|d	<|S|jrjd|d<d
|d	<|S|jsud|d<d
|d	<|S)a�
    Import a key from text or file

    text
        The text containing to import.

    filename
        The filename containing the key to import.

    user
        Which user's keychain to access, defaults to user Salt is running as.
        Passing the user as ``salt`` will set the GnuPG home directory to the
        ``/etc/salt/gpgkeys``.

    gnupghome
        Specify the location where GPG keyring and related files are stored.

    CLI Example:

    .. code-block:: bash

        salt '*' gpg.import_key text='-----BEGIN PGP PUBLIC KEY BLOCK-----\n ... -----END PGP PUBLIC KEY BLOCK-----'
        salt '*' gpg.import_key filename='/path/to/public-key-file'

    Trgr}� filename or text must be passed.�rbNzfilename does not exist.zSuccessfully imported key(s).riz!Key(s) already exist in keychain.FrhzUnable to import key.)r?rrr�files�flopen�stringutilsZ
to_unicode�read�OSErrorZimport_keysZimportedZimported_rsaZ	unchangedZnot_imported�count)rE�filenamerr)r7r�_fpZ
imported_datarrr�
import_key�s8

���
	���r�cCs�ddi}t||�}t|t�r|�d�}|r,|r,tdd�}	|	s#td��|j|||	d�}
n|j||dd	�}
|
rZ|rZtjj	�
|d
��}|�tjj�
|
��Wd�n1sUwY|
rs|so|rid�|�|d
<|S|
|d
<|S|
}|S|s{d|d<|Sd}|S)am
    Export a key from the GPG keychain

    keyids
        The key ID(s) of the key(s) to be exported. Can be specified as a comma
        separated string or a list. Anything which GnuPG itself accepts to identify a key
        for example, the key ID, fingerprint, user ID or email address could be used.

    secret
        Export the secret key identified by the ``keyids`` information passed.

    user
        Which user's keychain to access, defaults to user Salt is running as.
        Passing the user as ``salt`` will set the GnuPG home directory to the
        ``/etc/salt/gpgkeys``.

    gnupghome
        Specify the location where GPG keyring and related files are stored.

    use_passphrase
        Whether to use a passphrase to export the secret key.
        Passphrase is received from Pillar.

        .. versionadded:: 3003

    output
        The filename where the exported key data will be written to, default is standard out.

        .. versionadded:: 3006.0

    bare
        If ``True``, return the (armored) exported key block as a string without the
        standard comment/res dict.

        .. versionadded:: 3006.0

    CLI Example:

    .. code-block:: bash

        salt '*' gpg.export_key keyids=3FAD9F1E

        salt '*' gpg.export_key keyids=3FAD9F1E secret=True

        salt '*' gpg.export_key keyids="['3FAD9F1E','3FBD8F1E']" user=username

    rhT�,rrrsrtr�Fr��wNz(Exported key data has been written to {}�comment)r?�
isinstancer��splitr rZexport_keysrrr�r��writer�Zto_str�format)ZkeyidsrArr)r{�output�barer7rrs�result�foutrrr�
export_keys<8


��
�	���r�cCs�digd�}t||�}|st}t|t�r|�d�}|j|g|�R�}|jD]7}d|vrQ|ddkr>|d�d�|d��q%|dd	krP|d�d
�|d��q%d|vr\|d�d�q%|S)
a#
    Receive key(s) from keyserver and add them to keychain

    keyserver
        Keyserver to use for searching for GPG keys, defaults to keys.openpgp.org

    keys
        The keyID(s) to retrieve from the keyserver.  Can be specified as a comma
        separated string or a list.

    user
        Which user's keychain to access, defaults to user Salt is running as.
        Passing the user as ``salt`` will set the GnuPG home directory to the
        ``/etc/salt/gpgkeys``.

    gnupghome
        Specify the location where GPG keyring and related files are stored.

    CLI Example:

    .. code-block:: bash

        salt '*' gpg.receive_keys keys='3FAD9F1E'

        salt '*' gpg.receive_keys keys="['3FAD9F1E','3FBD9F2E']"

        salt '*' gpg.receive_keys keys=3FAD9F1E user=username

    T)rhZchangesrir�r�rrizKey {} added to keychainrXrz!Key {} already exists in keychainZproblemzUnable to add key to keychain)	r?rPr�r�r�Z	recv_keys�resultsrUr�)rF�keysrr)r7rZ	recv_datar�rrr�receive_keysps,



����r�c
Cs�ddd�}gd�}|r|rd|d<d|d<|S|sQ|rGt||d	�}|r9d
|vr4d|d<d|��|d<|S|d
}nd|d<d|�d
�|d<|Sd|d<d|d<|S||vr]d�d�|��S|�dt|�d�}t�dg}|}	|dkr�tj�tdd�d�}
|�d|
g�d}	td|||	dd�}|ddks�d|d<|d|d<|S|dr�t	�
d|d�}t|�d kr�||d
<d!�t|dt|d"�|d<|S||d
<d#�t|d�|d<|S|d|d<|S)$a
    Set the trust level for a key in GPG keychain

    keyid
        The keyid of the key to set the trust level for.

    fingerprint
        The fingerprint of the key to set the trust level for.

    trust_level
        The trust level to set for the specified key, must be one
        of the following:
        expired, unknown, not_trusted, marginally, fully, ultimately

    user
        Which user's keychain to access, defaults to user Salt is running as.
        Passing the user as ``salt`` will set the GnuPG home directory to the
        ``/etc/salt/gpgkeys``.

    CLI Example:

    .. code-block:: bash

        salt '*' gpg.trust_key keyid='3FAD9F1E' trust_level='marginally'
        salt '*' gpg.trust_key fingerprint='53C96788253E58416D20BCD352952C84C3252192' trust_level='not_trusted'
        salt '*' gpg.trust_key keys=3FAD9F1E trust_level='ultimately' user='username'

    Trgr}rFrhr~ri)rrXz Fingerprint not found for keyid zKeyID z not in GPG keychainrzERROR: Valid trust levels - {}r��:rvz--import-ownertrustrr#r$r%z	--homedir�rootzcmd.run_all)�stdinZrunasZpython_shell�retcoder�stderrz\d�z'Changing ownership trust from {} to {}.�zSetting ownership trust to {}.)
r�r�r(�NUM_TRUST_DICTrr'rr �extend�re�findall�len�INV_NUM_TRUST_DICT)
rHrX�trust_levelrr7Z_VALID_TRUST_LEVELSr6r��cmd�_userZhomeDirrhZ_matchrrr�	trust_key�sd
	

��
�
��r�cCs�t||�}|rtdd�}|std��nd}|r#|j|||d�}	|	jS|rotjj�|d��}
|j|
||d�}	Wd�n1s@wY|rltjj�|d��}|�	tjj
�|	j��Wd�|	jS1sgwY|	jStd��)	a�
    Sign message or file

    user
        Which user's keychain to access, defaults to user Salt is running as.
        Passing the user as ``salt`` will set the GnuPG home directory to the
        ``/etc/salt/gpgkeys``.

    keyid
        The keyid of the key to set the trust level for, defaults to
        first key in the secret keyring.

    text
        The text to sign.

    filename
        The filename to sign.

    output
        The filename where the signed file will be written, default is standard out.

    use_passphrase
        Whether to use a passphrase with the signing key. Passphrase is received
        from Pillar.

    gnupghome
        Specify the location where GPG keyring and related files are stored.

    CLI Example:

    .. code-block:: bash

        salt '*' gpg.sign text='Hello there.  How are you?'

        salt '*' gpg.sign filename='/path/to/important.file'

        salt '*' gpg.sign filename='/path/to/important.file' use_passphrase=True

    rrrsrtN)rHrur��wbr�)
r?r r�signrrr�r�Z	sign_filer�r��to_bytes�data)rrHrEr�r�r{r)rrsZsigned_datar�r�rrrr�
s,
0�
��
���r�c
CsXt||�}d}|r ||vr d�|d�|��}t�|�d|d�Sg}	|r+|	�d|g�|r5|j||	d�}
nI|rz|rZtjj	�
|d��}|j|||	d�}
Wd	�n1sTwYn$tjj	�|d��}|j||	d�}
Wd	�n1stwYnt
d
��i}|
jd	ur�d|d<|
j|d
<|
j|d<tt|
j�|d<d|d<|Sd|d<d|d<|S)a<
    Verify a message or file

    text
        The text to verify.

    filename
        The filename to verify.

    user
        Which user's keychain to access, defaults to user Salt is running as.
        Passing the user as ``salt`` will set the GnuPG home directory to the
        ``/etc/salt/gpgkeys``.

    gnupghome
        Specify the location where GPG keyring and related files are stored.

    signature
        Specify the filename of a detached signature.

        .. versionadded:: 2018.3.0

    trustmodel
        Explicitly define the used trust model. One of:
          - pgp
          - classic
          - tofu
          - tofu+pgp
          - direct
          - always
          - auto

        .. versionadded:: 2019.2.0

    CLI Example:

    .. code-block:: bash

        salt '*' gpg.verify text='Hello there.  How are you?'
        salt '*' gpg.verify filename='/path/to/important.file'
        salt '*' gpg.verify filename='/path/to/important.file' use_passphrase=True
        salt '*' gpg.verify filename='/path/to/important.file' trustmodel=direct

    )ZpgpZclassicZtofuztofu+pgpZdirect�always�autoz.Invalid trustmodel defined: {}. Use one of: {}z, Fr}z
--trust-model)�
extra_argsr�Nr�Trh�username�key_idr�zThe signature is verified.riz$The signature could not be verified.)r?r�r(�log�warningr��verifyrrr�ZfopenZverify_filer�rr�r�r��VERIFY_TRUST_LEVELSr�)
rErr�r)Z	signatureZ
trustmodelrZtrustmodels�msgr�Zverifiedr�r7rrrr�PsF
/
�

����


�r�c
	Csddd�}
t||�}|r|rtdd�}|std��nd}|r+|j||||||d�}
n*|rQtjj�|d	��}|j||||||d�}
Wd�n1sKwYntd
��|
j	rq|	sl|red|��|
d<|
S|
j
|
d<|
S|
j
}
|
S|	s�d
|
d<d�|
j�|
d<nd
}
t
�|
j�|
S)a#
    Encrypt a message or file

    user
        Which user's keychain to access, defaults to user Salt is running as.
        Passing the user as ``salt`` will set the GnuPG home directory to the
        ``/etc/salt/gpgkeys``.

    recipients
        The key ID, fingerprint, user ID or email address associated with the recipients
        key can be used.

    text
        The text to encrypt.

    filename
        The filename to encrypt.

    output
        The filename where the signed file will be written, default is standard out.

    sign
        Whether to sign, in addition to encrypt, the data. ``True`` to use
        default key or fingerprint to specify a different key to sign with.

    use_passphrase
        Whether to use a passphrase with the signing key.
        Passphrase is received from Pillar.

    always_trust
        Skip key validation and assume that used keys are fully trusted.

        .. versionadded:: 3006.0

    gnupghome
        Specify the location where GPG keyring and related files are stored.

    bare
        If ``True``, return the (armored) encrypted block as a string without
        the standard comment/res dict.

    CLI Example:

    .. code-block:: bash

        salt '*' gpg.encrypt text='Hello there.  How are you?' recipients=recipient@example.com

        salt '*' gpg.encrypt filename='/path/to/important.file' recipients=recipient@example.com

        salt '*' gpg.encrypt filename='/path/to/important.file' sign=True use_passphrase=True \
                             recipients=recipient@example.com

    Trg�rhr�rrrsrtN)r�ru�always_trustr�r�r�z#Encrypted data has been written to r�Frh�%{}.
Please check the salt-minion log.)r?r r�encryptrrr�r�Zencrypt_filer�r�r��statusr��errorr�)rZ
recipientsrEr�r�r�r{r�r)r�r7rrsr�r�rrrr��s^
A
�����

���
�r�cCsddd�}t||�}|rtdd�}	|	std��nd}	|r%|j||	d�}
n1|rRtjj�|d	��}|r;|j||	|d
�}
n|j||	d�}
Wd�n1sLwYntd��|
j	rr|sm|rfd|��|d
<|S|
j
|d
<|S|
j
}|S|s�d|d<d�|
j�|d
<nd}t
�|
j�|S)a�
    Decrypt a message or file

    user
        Which user's keychain to access, defaults to user Salt is running as.
        Passing the user as ``salt`` will set the GnuPG home directory to the
        ``/etc/salt/gpgkeys``.

    text
        The encrypted text to decrypt.

    filename
        The encrypted filename to decrypt.

    output
        The filename where the decrypted data will be written, default is standard out.

    use_passphrase
        Whether to use a passphrase with the signing key. Passphrase is received
        from Pillar.

    gnupghome
        Specify the location where GPG keyring and related files are stored.

    bare
        If ``True``, return the (armored) decrypted block as a string without the
        standard comment/res dict.

    CLI Example:

    .. code-block:: bash

        salt '*' gpg.decrypt filename='/path/to/important.file.gpg'

        salt '*' gpg.decrypt filename='/path/to/important.file.gpg' use_passphrase=True

    Trgr�rrrsrtNr�r�)rur�r�z#Decrypted data has been written to r�Frhr�)r?r r�decryptrrr�r�Zdecrypt_filer�r�r�r�r�r�r�)rrEr�r�r{r)r�r7rrsr�r�rrrr� sH
.
����
���
�r�)N)NN)NNF)rcrdrerfNNNNFNN)NNFNNT)NNNN)NFNNFNF)NNNNNFN)NNNNNN)
NNNNNNFFNF)NNNNFNF)/�__doc__r;�loggingr'r�rQZsalt.utils.filesrZsalt.utils.pathZsalt.utils.stringutilsZsalt.exceptionsr�	getLogger�__name__r�rr^r�r�r�rPr>r�ImportErrorrrr!r*r=r?rCrGrDr@rbr|r�r�r�r�r�r�r�r�r�r�r�rrrr�<module>s�
��
�
��

'

	

3
33�
�
f
BB8
�]
8b
�G
�Z
�x�