File: //usr/lib/python3/dist-packages/certbot/__pycache__/crypto_util.cpython-39.pyc
a
�`�R � @ s$ d Z ddlZddlZddlZddlZddlmZ ddlmZm Z ddl
mZ ddlm
Z
ddlmZmZ ddlmZ dd lmZ dd
lmZmZmZ ddlmZ ddlmZ ddlZddlZddlZdd
l m!Z" ddl#m$Z$ ddl%m&Z& ddl%m'Z' ddl%m(Z( ddl)m*Z* e�+e,�Z-dOdd�Z.dd� Z/dd� Z0dd� Z1dd� Z2dPd!d"�Z3d#d$� Z4d%d&� Z5d'd(� Z6d)d*� Z7d+d,� Z8d-d.� Z9d/d0� Z:ej;fd1d2�Z<ej;fd3d4�Z=ej;fd5d6�Z>d7d8� Z?d9d:� Z@ej;fd;d<�ZAej;fd=d>�ZBd?d@� ZCdAdB� ZDdCdD� ZEdEdF� ZFe�GdGejH�ZIdHdI� ZJdJdK� ZKdQdMdN�ZLdS )Rz�Certbot client crypto utility functions.
.. todo:: Make the transition to use PSS rather than PKCS1_v1_5 when the server
is capable of handling the signatures.
� N)�x509)�InvalidSignature�UnsupportedAlgorithm)�default_backend)�ec)�ECDSA�EllipticCurvePublicKey)�PKCS1v15)�RSAPublicKey)�Encoding�NoEncryption�
PrivateFormat)�crypto)�SSL)�crypto_util)�IO)�errors)�
interfaces)�util)�os�rsa� secp256r1�key-certbot.pemc
C s� zt | |pd|d�}W n6 tyL } ztjddd� |�W Y d}~n
d}~0 0 tj�tj�}t �
|d|j� t �t
j�||�dd �\}} |� |�|� W d � n1 s�0 Y |d
kr�t�d| | � nt�d| | � t �| |�S )
ai Initializes and saves a privkey.
Inits key and saves it in PEM format on the filesystem.
.. note:: keyname is the attempted filename, it may be different if a file
already exists at the path.
:param int key_size: key size in bits if key size is rsa.
:param str key_dir: Key save directory.
:param str key_type: Key Type [rsa, ecdsa]
:param str elliptic_curve: Name of the elliptic curve if key type is ecdsa.
:param str keyname: Filename of key
:returns: Key
:rtype: :class:`certbot.util.Key`
:raises ValueError: If unable to generate the key given key_size.
r )�bits�elliptic_curve�key_type� T��exc_infoNi� i� �wbr z Generating RSA key (%d bits): %sz"Generating ECDSA key (%d bits): %s)�make_key�
ValueError�logger�error�zope� component�
getUtilityr �IConfigr �make_or_verify_dir�strict_permissions�unique_filer �path�join�write�debugZKey)
Zkey_sizeZkey_dirr r ZkeynameZkey_pem�err�configZkey_f�key_path� r2 �5/usr/lib/python3/dist-packages/certbot/crypto_util.py�
init_save_key'