관리-도구
편집 파일: dnssec.cpython-39.pyc
a �����!cu-����������������������@���s����d�dl�mZ�d�dl�mZ�d�dl�mZ�d�dlmZ�d�dlZd�dlZd�dlZd�dl Z d�dl mZ�d�dlZ d�dlZ e�d�ZdZG�d d ��d e jj�Zddd �ZG�dd��de�ZG�dd��d�ZG�dd��d�ZG�dd��d�Zdd��Zdd��ZG�dd��d�ZdS�)�����)�print_function)�absolute_import)�unicode_literals)�EnumN��_�dnf�=���c�������������������@���s���e�Zd�ZdZdd��ZdS�)�DnssecErrorz- Exception used in the dnssec module c�����������������C���s���d��|�jd�ur|�jnd�S�)Nz<DnssecError, value='{}'>z Not specified)�format�value��self��r����./usr/lib/python3.9/site-packages/dnf/dnssec.py�__repr__-���s�����zDnssecError.__repr__N)�__name__� __module__�__qualname__�__doc__r���r���r���r���r���r ���)���s���r ����_openpgpkeyc�����������������C���s����|���dd�}t|�dkr$d}t|��|d�}|d�}t���}|�|�d���t�|� ��dd���� d����}|d�|�d�|�S�) z� Implements RFC 7929, section 3 https://tools.ietf.org/html/rfc7929#section-3 :param email_address: :param tag: :return: �@��������z0Email address must contain exactly one '@' sign.r���zutf-8�����.)�rsplit�lenr ����hashlibZsha256�update�encode�base64Z b16encode�digest�decode�lower)Z email_address�tag�split�msg�local�domain�hashr"���r���r���r����email2location2���s���� �r+���c�������������������@���s(���e�Zd�ZdZdZdZdZdZdZdZ dS�) �Validityz� Output of the verification algorithm. TODO: this type might be simplified in order to less reflect the underlying DNS layer. TODO: more specifically the variants from 3 to 5 should have more understandable names r���r���������������� ���N) r���r���r���r����VALID�REVOKED�PROVEN_NONEXISTENCE�RESULT_NOT_SECURE�BOGUS_RESULT�ERRORr���r���r���r���r,���J���s���r,���c�������������������@���s���e�Zd�ZdZdS�)�NoKeyz� This class represents an absence of a key in the cache. It is an expression of non-existence using the Python's type system. N)r���r���r���r���r���r���r���r���r7���X���s���r7���c�������������������@���s.���e�Zd�ZdZd dd�Zdd��Zedd���ZdS�) �KeyInfozv Wrapper class for email and associated verification key, where both are represented in form of a string. Nc�����������������C���s���||�_�||�_d�S�)N)�email�key)r���r9���r:���r���r���r����__init__e���s����zKeyInfo.__init__c�����������������C���s���d��|�j|�j�d�d�d���S�)NzKeyInfo("{}", "{}...")�ascii����)r���r9���r:���r#���r ���r���r���r���r���i���s����zKeyInfo.__repr__c����������� ������C���s����t��d|��}|du�rt�|�d�}|�d��d�}d}d}tdt|��D�]$}||�dkr\|}||�dkrH|}qHd �||d �|d����� d�}t ||�S�)z� Since dnf uses different format of the key than the one used in DNS RR, I need to convert the former one into the new one. � <(.*@.*)>Nr���r<���� r���z$-----BEGIN PGP PUBLIC KEY BLOCK-----z"-----END PGP PUBLIC KEY BLOCK-----��r���)�re�searchr ����groupr#���r&����ranger����joinr ���r8���) ZuseridZraw_keyZinput_emailr9���r:����start�stop�iZcat_keyr���r���r����from_rpm_key_objectl���s���� zKeyInfo.from_rpm_key_object)NN)r���r���r���r���r;���r����staticmethodrI���r���r���r���r���r8���`���s ��� r8���c�������������������@���s8���e�Zd�ZdZi�Zedd���Zedd���Zedd���ZdS�) �DNSSECKeyVerificationz� The main class when it comes to verification itself. It wraps Unbound context and a cache with already obtained results. c�����������������C���sZ���|�|krt��d��tjS�|�tu�r0t��d��tjS�t��d�|����t��d�|���tjS�dS�)zD Compare the key in case it was found in the cache. zCache hit, valid keyzCache hit, proven non-existencezKey in cache: {}�Input key : {}N)�logger�debugr,���r1���r7���r3���r���r2���)� key_unionZinput_key_stringr���r���r���� _cache_hit����s���� z DNSSECKeyVerification._cache_hitc����������� ��� ���C���s���zddl�}W�n>�tyJ�}�z&td�|��}tj�|��W�Y�d}~n d}~0�0�|���}|�dd�dkrnt � d��|�dd�dkr�t � d ��|���dkr�t � d ��|�d�dkr�t � d��|� t|�j�t|j�\}}|dkr�t � d ��tjS�|j�rt � d�|j���tjS�|j�s t � d��tjS�|j�s>|j|jk�rN|j�sNt � d��tjS�|j�snt � d�|j���tjS�|j� ��d�}t!�"|�}||�j#k�r�tj$S�t � d�|���t � d�|�j#���tj%S�dS�)zz In case the key was not found in the cache, create an Unbound context and contact the DNS system r���NzLConfiguration option 'gpgkey_dns_verification' requires python3-unbound ({})z verbosity:�0z(Unbound context: Failed to set verbosityzqname-minimisation:Zyesz1Unbound context: Failed to set qname minimisationz+Unbound context: Failed to read resolv.confz/var/lib/unbound/root.keyz0Unbound context: Failed to add trust anchor filez%Communication with DNS servers failedz DNSSEC signatures are wrong ({})z!Result is not secured with DNSSECz1Non-existence of this record was proven by DNSSECz&Unknown error in DNS communication: {}zKey from DNS: {}rL���)&�unbound�ImportErrorr���r���r���� exceptions�ErrorZub_ctxZ set_optionrM���rN���Z resolvconfZadd_ta_file�resolver+���r9����RR_TYPE_OPENPGPKEYZRR_CLASS_INr,���r6���ZbogusZ why_bogusr5���Zsecurer4���ZnxdomainZrcodeZ RCODE_NOERRORZhavedatar3���Z rcode_str�dataZas_raw_datar!���Z b64encoder:���r1���r2���) � input_keyrR����er'����ctx�status�resultrX���Zdns_data_b64r���r���r����_cache_miss����sR�����" � z!DNSSECKeyVerification._cache_missc�����������������C���sz���t��d�|�j���tj�|�j�}|dur6t�||�j�S�t� |��}|t jkrZ|�jtj|�j<�n|t jkrrt ��tj|�j<�|S�dS�)zI Public API. Use this method to verify a KeyInfo object. z(Running verification for key with id: {}N)rM���rN���r���r9���rK����_cache�getrP���r:���r^���r,���r1���r3���r7���)rY���rO���r]���r���r���r����verify����s���� zDNSSECKeyVerification.verifyN) r���r���r���r���r_���rJ���rP���r^���ra���r���r���r���r���rK�������s��� 9rK���c�����������������C���s8���t�d�|�j�d�}|tjkr(|t�d��S�|t�d��S�dS�)zE Inform the user about key validity in a human readable way. zDNSSEC extension: Key for user � z is valid.zhas unknown status.N)r���r9���r,���r1���)Zki�v�prefixr���r���r���� nice_user_msg����s���� re���c�����������������C���s���t�d�|��S�)z; Label any given message with DNSSEC extension tag zDNSSEC extension: r���)�mr���r���r����any_msg����s����rg���c�������������������@���s(���e�Zd�ZdZedd���Zedd���ZdS�)�RpmImportedKeysaQ�� Wrapper around keys, that are imported in the RPM database. The keys are stored in packages with name gpg-pubkey, where the version and release is different for each of them. The key content itself is stored as an ASCII armored string in the package description, so it needs to be parsed before it can be used. c������������ ������C���s����t�jj���}�|��dd�}g�}|D�]d}t�j�|d�}t�d|��d�}t�j�|d�}|� d�dd ��}d � |�}|t||�d��g7�}q |S�)N�namez gpg-pubkey�packagerr>���r����descriptionr?���r-������r@���r<���) r���ZrpmZtransactionZTransactionWrapperZdbMatchZ getheaderrA���rB���rC���r&���rE���r8���r ���) Ztransaction_setZpackagesZreturn_list�pkgrj���r9���rk���Z key_linesZkey_strr���r���r����_query_db_for_gpg_keys��s���� z&RpmImportedKeys._query_db_for_gpg_keysc������������������C���s��t����}�t�ttd����|�D�]�}zt�|�}W�nF�tyv�}�z.t� d� |j|j���W�Y�d�}~qW�Y�d�}~n d�}~0�0�|t jkr�t�td� |j����q|t jkr�t�td� |j����q|t jkr�t�td� |j����q|t jk�rt�td� |j����qt�td� |j����qd�S�)Nz1Testing already imported keys for their validity.z%DNSSEC extension error (email={}): {}zGPG Key {} is validz,GPG Key {} does not support DNS verificationz�GPG Key {} could not be verified, because DNSSEC signatures are bogus. Possible causes: wrong configuration of the DNS server, MITM attackz=GPG Key {} has been revoked and should be removed immediatelyzGPG Key {} could not be tested)rh���rn���rM����inforg���r���rK���ra���r ���Zwarningr���r9���r���r,���r1���rN���r3���r5���r2���)�keysr:���r]���rZ���r���r���r����check_imported_keys_validity��s4�����" � � � z,RpmImportedKeys.check_imported_keys_validityN)r���r���r���r���rJ���rn���rq���r���r���r���r���rh�����s ��� rh���)r���)Z __future__r���r���r����enumr���r!���r���ZloggingrA���Zdnf.i18nr���Zdnf.rpmr���Zdnf.exceptionsZ getLoggerrM���rW���rT���rU���r ���r+���r,���r7���r8���rK���re���rg���rh���r���r���r���r����<module>���s*��� &h