%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python2.7/site-packages/salt/utils/
Upload File :
Create Path :
Current File : //usr/lib/python2.7/site-packages/salt/utils/nacl.pyc

�
���^c@@s�dZddlmZmZmZddlZddlZddlZddlm	Z	ddl
ZddlZddl
ZddlZddlZddlZddlZeje�ZdZyddlZddlZWneefk
r�ZdZnXdZd�Zd�Zd	�Z d
�Z!d�Z"ddd�Z#d
�Z$dd�Z%d�Z&dd�Z'd�Z(d�Z)d�Z*d�Z+dS(u8
Common code shared between the nacl module and runner.
i(tabsolute_importtprint_functiontunicode_literalsN(tsixuNlibnacl import error, perhaps missing python libnacl package or should update.unaclcC@st�S(N(tcheck_requirements(((s3/usr/lib/python2.7/site-packages/salt/utils/nacl.pyt__virtual__"scC@stdktfS(u0
    Check required libraries are available
    N(t	REQ_ERRORtNone(((s3/usr/lib/python2.7/site-packages/salt/utils/nacl.pyR&scK@sidd6d
d6tjj|djd�d�d6d
d6tjj|djd�d	�d
6}djt�}y|jtd|i��Wn6t	t
fk
r�}|j|dj|i��nXx8t|j��t|j��@D]}||||<q�W|S(u
    Return configuration
    u	sealedboxubox_typeuskuoptsupki_dirumaster/naclusk_fileupkumaster/nacl.pubupk_fileu
{0}.configu
config.getN(
Rtostpathtjointgettformatt__virtualname__tupdatet__salt__t	NameErrortKeyErrortsettkeys(tkwargstconfigt
config_keytetk((s3/usr/lib/python2.7/site-packages/salt/utils/nacl.pyt_get_config-s#&!)cK@s�t|�}d}|dr8tjjj|d�}n|d}|r�|r�yItjjj|d��+}tjjj|j	��j
d�}WdQXWq�ttfk
r�t
d��q�Xntj|�S(u
    Return sk
    uskusk_fileurbu
Nuno key or sk_file found(RRtsalttutilststringutilstto_strtfilestfopent
to_unicodetreadtrstriptIOErrortOSErrort	Exceptiontbase64t	b64decode(RRtkeytsk_filetkeyf((s3/usr/lib/python2.7/site-packages/salt/utils/nacl.pyt_get_skEs


.cK@s�t|�}d}|dr8tjjj|d�}n|d}|r�|r�yItjjj|d��+}tjjj|j	��j
d�}WdQXWq�ttfk
r�t
d��q�Xntj|�}tj|�S(u
    Return pk
    upkupk_fileurbu
Nuno pubkey or pk_file found(RRRRRRRRR R!R"R#R$R%Rt	text_typeR&R'(RRtpubkeytpk_fileR*((s3/usr/lib/python2.7/site-packages/salt/utils/nacl.pyt_get_pkWs


.cK@s�d|kr/tjjjdd�|d}n|dkrttjj�}itj	|j
�d6tj	|j�d6S|dkr�dj|�}n|r�|dkr�t
jj|�s�tjj�}tjjj|d�� }|jtj	|j
��WdQXtjjj�rdtjjj�}tjjj||�tjjj||d	d
dtdt�nt
j|d
�dj|�Stdj|���n|dkr�|r�td��nt
jj|�r�t
jj|�r�tdj||���nt
jj|�r�t
jj|�r�tjjj|d��:}tjjj|j��j d�}tj!|�}WdQXtjj|�}tjjj|d�� }|jtj	|j��WdQXdj|�Stjj�}tjjj|d�� }|jtj	|j
��WdQXtjjj�rytjjj�}tjjj||�tjjj||d	d
dtdt�nt
j|d
�tjjj|d�� }|jtj	|j��WdQXdj||�S(uP
    Use libnacl 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
    ukeyfileuNeonuxThe 'keyfile' argument has been deprecated and will be removed in Salt {version}. Please use 'sk_file' argument instead.uskupku{0}.pubuwbNufull_controlugranttreset_permst	protectediusaved sk_file: {0}usk_file:{0} already exist.u6sk_file: Must be set inorder to generate a public key.u*sk_file:{0} and pk_file:{1} already exist.urbu
usaved pk_file: {0}usaved sk_file:{0}  pk_file: {1}("RRtversionst
warn_untilRtlibnacltpublict	SecretKeyR&t	b64encodetsktpkRRR	tisfileRRtwritetplatformt
is_windowst
win_functionstget_current_usertwin_daclt	set_ownertset_permissionstTruetchmodR%RR R!R"R'(R)R.RtkpR*tcur_userR8((s3/usr/lib/python2.7/site-packages/salt/utils/nacl.pytkeygenjsZ
*+
$%$
+cK@s�d|kr3tjjjdd�|d|d<nd|krftjjjdd�|d|d<nt|�d}|d	kr�t||�St||�S(
uT
    Alias to `{box_type}_encrypt`

    box_type: secretbox, sealedbox(default)
    ukeyfileuNeonuxThe 'keyfile' argument has been deprecated and will be removed in Salt {version}. Please use 'sk_file' argument instead.usk_fileukeyuoThe 'key' argument has been deprecated and will be removed in Salt {version}. Please use 'sk' argument instead.uskubox_typeu	secretbox(RRR2R3Rtsecretbox_encrypttsealedbox_encrypt(tdataRtbox_type((s3/usr/lib/python2.7/site-packages/salt/utils/nacl.pytenc�s
cK@s�ytd|�}WnOtk
re}tjjj|d��"}tjjj|j��}WdQXnXt	||�}|r�t
jj|�r�tdj
|���ntjjj|d��#}|jtjjj|��WdQXdj
|�S|S(u	
    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
    ucp.get_file_strurbNufile:{0} already exist.uwbu
Wrote: {0}(RR%RRRRRR R!RLRR	R:RR;tto_bytes(tnametoutRRJRtftd((s3/usr/lib/python2.7/site-packages/salt/utils/nacl.pytenc_file�s%"
cK@s�d|kr=tjjjdd�|d|d<d|d<nd|krztjjjdd�|d|d	<d|d<nt|�d}|dkr�t||�St||�S(
uT
    Alias to `{box_type}_decrypt`

    box_type: secretbox, sealedbox(default)
    ukeyfileuNeonuxThe 'keyfile' argument has been deprecated and will be removed in Salt {version}. Please use 'sk_file' argument instead.usk_fileu	secretboxubox_typeukeyuoThe 'key' argument has been deprecated and will be removed in Salt {version}. Please use 'sk' argument instead.usk(RRR2R3Rtsecretbox_decrypttsealedbox_decrypt(RJRRK((s3/usr/lib/python2.7/site-packages/salt/utils/nacl.pytdec�s 


cK@s�ytd|�}WnOtk
re}tjjj|d��"}tjjj|j��}WdQXnXt	||�}|r�t
jj|�r�tdj
|���ntjjj|d��#}|jtjjj|��WdQXdj
|�S|S(u
    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
    ucp.get_file_strurbNufile:{0} already exist.uwbu
Wrote: {0}(RR%RRRRRR R!RURR	R:RR;RM(RNRORRJRRPRQ((s3/usr/lib/python2.7/site-packages/salt/utils/nacl.pytdec_files%"
cK@sItjjj|�}t|�}tjj|�}tj	|j
|��S(u�
    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='
    (RRRRMR/R4tsealedt	SealedBoxR&R7tencrypt(RJRR9tb((s3/usr/lib/python2.7/site-packages/salt/utils/nacl.pyRI<scK@sk|dkrdStjjj|�}t|�}tjj|�}tj	j
|�}|jtj
|��S(u�
    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='
    N(RRRRRMR+R4R5R6RWRXtdecryptR&R'(RJRR8tkeypairRZ((s3/usr/lib/python2.7/site-packages/salt/utils/nacl.pyRTQscK@sItjjj|�}t|�}tjj|�}tj	|j
|��S(u�
    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='
    (RRRRMR+R4tsecrett	SecretBoxR&R7RY(RJRR8RZ((s3/usr/lib/python2.7/site-packages/salt/utils/nacl.pyRHiscK@s\|dkrdStjjj|�}t|�}tjjd|�}|j	t
j|��S(u�
    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='
    R(N(RRRRRMR+R4R]R^R[R&R'(RJRR(RZ((s3/usr/lib/python2.7/site-packages/salt/utils/nacl.pyRS~s
(,t__doc__t
__future__RRRR&tloggingRtsalt.extRt
salt.syspathsRtsalt.utils.filestsalt.utils.platformtsalt.utils.stringutilstsalt.utils.versionstsalt.utils.win_functionstsalt.utils.win_daclt	getLoggert__name__tlogRRtlibnacl.secretR4tlibnacl.sealedtImportErrorR$RR
RRRR+R/RGRLRRRURVRIRTRHRS(((s3/usr/lib/python2.7/site-packages/salt/utils/nacl.pyt<module>sD
					R	!	"!			

Zerion Mini Shell 1.0