File manager - Edit - /opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/win_certutil.cpython-310.pyc
Back
o ;j� � @ sp d Z ddlZddlZddlZddlZddlmZ e�e �Z dZdd� Zddd �Z d d� Zdd d�Zddd�ZdS )z� This module allows you to install certificates into the windows certificate manager. .. code-block:: bash salt '*' certutil.add_store salt://cert.cer 'TrustedPublisher' � N)�CommandExecutionErrorZcertutilc C s t jj�� rtS dS )z Only works on Windows )Fz:Module win_certutil: module only works on Windows systems.)�salt�utils�platformZ is_windows�__virtualname__� r r �M/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/win_certutil.py�__virtual__ s r �basec C sl t d | |�} tj�| �sd| � �}t|��d| � d�}t d |�}t�d|�}|dur4|�� d �� S dS ) a: Get the serial number of a certificate file Args: cert_file (str): The certificate file to find the serial for. Can be a local file or a file on the file server (``salt://``) saltenv (:obj:`str`, optional): The environment on the fileserver to use for the certificate. Default is ``base``. Returns: str: The serial number of the certificate if found, otherwise ``None``. CLI Example: .. code-block:: bash salt '*' certutil.get_cert_serial <certificate name> � cp.cache_file�cert_file not found: zcertutil.exe -silent -verify "�"�cmd.runz:\s*(\w*)\r\n\r\nNr ) �__salt__�os�path�existsr �re�search�groups�strip)� cert_file�saltenv�msg�cmd�out�matchesr r r �get_cert_serial s r c C s( d| � d�}t d |�}t�d|�}|S )aQ Get all of the certificate serials in the specified store store (str): The store to get all the certificate serials from Returns: list: A list of serial numbers found, or an empty list if none found CLI Example: .. code-block:: bash salt '*' certutil.get_stored_cert_serials <store> zcertutil.exe -store "r r z={16}\r\n.*:\s*(\w*)\r\n)r r �findall)�storer r r r r r �get_stored_cert_serialsF s r Fc C sZ t d | |�} tj�| �sd| � �}t|��d|� d| � d�}|r't d |�S t d |�S )a, Add the cert to the given Certificate Store Args: source (str): The source certificate file. This is either the path to a local file or a file from the file server in the form of ``salt://path/to/file`` store (str): The certificate store to add the certificate to retcode (:obj:`bool`, optional): If ``True``, return the retcode instead of stdout. Default is ``False``. saltenv (:obj:`str`, optional): The salt environment to use. This is ignored if the path is local. Default is ``base``. CLI Example: .. code-block:: bash salt '*' certutil.add_store salt://cert.cer TrustedPublisher salt '*' certutil.add_store C:\path\to\local.cer TrustedPublisher r r zcertutil.exe -addstore � "r �cmd.retcoder )r r r r r )�sourcer �retcoder r r r r r � add_store] s r% c C sb t d | |�} tj�| �sd| � �}t|��t| �}d|� d|� d�}|r+t d |�S t d |�S )a7 Delete the cert from the given Certificate Store Args: source (str): The source certificate file. This is either the path to a local file or a file from the file server in the form of ``salt://path/to/file`` store (str): The certificate store to delete the certificate from retcode (:obj:`bool`, optional): If ``True``, return the retcode instead of stdout. Default is ``False`` saltenv (:obj:`str`, optional): The salt environment to use. This is ignored if the path is local. Default is ``base``. CLI Example: .. code-block:: bash salt '*' certutil.del_store salt://cert.cer TrustedPublisher salt '*' certutil.del_store 'C:\path\to\local.cer' TrustedPublisher r r zcertutil.exe -delstore r! r r"