HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //lib/python3.6/site-packages/sos/cleaner/mappings/__pycache__/ipv6_map.cpython-36.opt-1.pyc
3

\��h./�@s6ddlZddlmZGdd�de�ZGdd�d�ZdS)�N)�SoSMapc@sHeZdZdZiZddddgZdgZdZdZd	d
�Z	dd�Z
ddd�ZdS)�
SoSIPv6MapatMapping for IPv6 addresses and networks.

    Much like the IP map handles IPv4 addresses, this map is designed to take
    IPv6 strings and obfuscate them consistently to maintain network topology.
    To do this, addresses will be manipulated by the ipaddress library.

    If an IPv6 address is encountered without a netmask, it is assumed to be a
    /64 address.
    z^::1/.*z::/0zfd53:.*z^53..:�534fF�cCs�d|krdSx�|dD]|}tj|�}|d|d}|j||�}|j|j|j<xB|d|dD].}|d|d|}|j||�||j|<q`WqWdS)z�Override the base conf_update() so that we can load the existing
        networks into ObfuscatedIPv6Network() objects for the current run.
        �networksN�
obfuscated�hosts)�	ipaddress�
ip_network�_get_network�obfuscated_address�dataset�original_address�add_obfuscated_host_address)�self�configZnetworkZ_origZ_obfuscated�_net�host�_ob_host�r�/usr/lib/python3.6/ipv6_map.py�conf_update)s
zSoSIPv6Map.conf_updatecCs�d|kr|jd�dnd}|}|s*|d7}ytj|�}|j|�}|j}Wndtk
r�tj|dd�}|j|�}|j|jkr�|j|j|j<tj	|jd�d�}|j
|�}YnX|r�d|kr�|�d|��S|S)	N�/r�z/64F)�strictr���)�splitr	r
rr�
ValueError�network_addrr
rZ
ip_address�obfuscate_host_address)r�item�_prefixZ_ipaddr�_addrrZ	_hostaddrrrr�
sanitize_item9s$



zSoSIPv6Map.sanitize_itemrcCs.|j}||jkr$t|||j�|j|<|j|S)z�Attempt to find an existing ObfuscatedIPv6Network object from which
        to either find an existing obfuscated match, or create a new one. If
        no such object already exists, create it.
        )�
compressedr�ObfuscatedIPv6Network�first_hexes)rZaddressrr"rrrrVs

zSoSIPv6Map._get_networkN)r)�__name__�
__module__�__qualname__�__doc__rZignore_matchesr&Zcompile_regexes�versionrr#rrrrrrs	rc@sneZdZdZiZddd�Zedd��Zedd	��Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
dd�Zdd�ZdS)r%a�An abstraction class that represents a network that is (to be) handled
    by sos.

    Each distinct IPv6 network that we encounter will have a representative
    instance of this class, from which new obfuscated subnets and host
    addresses will be generated.

    This class should be built from an ``ipaddress.IPv6Network`` object. If
    an obfuscation string is not passed, one will be created during init.
    rNcCs�t|tj�std��||_|j|_|jj|_	i|_
|dkrDdg|_n||_|sZ|j�|_
n,t|t�svtdt|�����|jd�d|_
dS)a�Basic setup for the obfuscated network. Minor validation on the addr
        used to create the instance, as well as on an optional ``obfuscation``
        which if set, will serve as the obfuscated_network address.

        :param addr:        The *un*obfuscated network to be handled
        :type addr:         ``ipaddress.IPv6Network``

        :param obfuscation: An optional pre-determined string representation of
                            the obfuscated network address
        :type obfuscation:  ``str``

        :param used_hexes:  A list of already used hexes for the first hextet
                            of a potential global address obfuscation
        :type used_hexes:   ``list``
        z*Invalid network: not an IPv6Network objectNrz;Pre-determined obfuscated network address must be str, not rr)�
isinstancer	ZIPv6Network�	Exception�addrZ	prefixlen�prefixZnetwork_addressr$rrr&�_obfuscate_network_address�_obfuscated_network�str�	TypeError�typer)rr.ZobfuscationZ
used_hexesrrr�__init__qs


zObfuscatedIPv6Network.__init__cCs|j�d|j��S)Nr)r1r/)rrrrr�sz(ObfuscatedIPv6Network.obfuscated_addresscCs|jjS)N)r.r$)rrrrr�sz&ObfuscatedIPv6Network.original_addresscs�fdd�|D�S)a#Generate a set of obfuscated hextets, based on the length of the
        source hextet. If any hextets are compressed, keep that compression.

        E.G. '::1234:bcd' will generate a leading empty '' hextet, followed by
        two 4-character hextets, e.g. '::0005:0006'.

        :param hextets:     The extracted hextets from a source address
        :type hextets:      ``list``

        :returns:           A set of generated hextets for use in an obfuscated
                            address
        :rtype:             ``list``
        csg|]}|r�jd�nd�qS)�r)�
obfuscate_hex)�.0�h)rrr�
<listcomp>�sz:ObfuscatedIPv6Network.generate_hextets.<locals>.<listcomp>r)rZhextetsr)rr�generate_hextets�sz&ObfuscatedIPv6Network.generate_hextetscCs,|jj|d�d}||j|<|d|�d��S)a�Generate a string of size length of hex characters. Due to the need
        of deterministic generation in concurrent cleaner, generation starts
        from zero values and is incremented by one (for a given length).

        :param length:  The number of characters to generate
        :type length:   ``int``

        :returns:       A string of ``length`` hex characters
        :rtype:         ``str``
        rr�0�x)�ob_counters�get)rZlength�valrrrr7�s
z#ObfuscatedIPv6Network.obfuscate_hexcCs4|jjr|j�S|jjr|jS|jjr.|j�S|jS)z�Generate the obfuscated pair for the network address. This is
        determined based on the netmask of the network this class was built
        on top of.
        )r.Z	is_global�_obfuscate_global_addressZ
is_link_localrZ
is_private�_obfuscate_private_address)rrrrr0�sz0ObfuscatedIPv6Network._obfuscate_network_addresscCs�|jjd�dd�}dg}tdd�|D��r�dt|j�d}|�|jd	���}x ||jkrp|�|jd	���}qRW|jj|�|g}|j|�}|j|�dj	|�S)
aGlobal unicast addresses have a 48-bit global routing prefix and a
        16-bit subnet. We set the global routing prefix to a static
        sos-specific identifier that could never be seen in the wild,
        '534f:'

        We then obfuscate the subnet hextet.
        �:rNrcss|]}|VqdS)Nr)r8�crrr�	<genexpr>�szBObfuscatedIPv6Network._obfuscate_global_address.<locals>.<genexpr>�5��)
rr�all�lenr&r7�appendr;�extend�join)r�_hextets�_ob_hexZ_startZextrrrrA�s

z/ObfuscatedIPv6Network._obfuscate_global_addresscCs4|jjd�dd�}dg}|j|j|��dj|�S)aThe first 8 bits will always be 'fd', the next 40 bits are meant
        to be a global ID, followed by 16 bits for the subnet. To keep things
        relatively simply we maintain the first hextet as 'fd53', and then
        obfuscate any remaining hextets.
        rCrNZfd53)rrrLr;rM)rrNrOrrrrB�sz0ObfuscatedIPv6Network._obfuscate_private_addresscsz�fdd�}|j�jkrn�jjd�}|jt|�d�jd�}||�}x|�jj�kr^||�}qFW�j|j|��j|jS)a�Given an unobfuscated address, generate an obfuscated match for it,
        and save it to this network for tracking during the execution of clean.

        Note: another way to do this would be to convert the obfuscated network
        to bytes, and add a random amount to that based on the number of
        addresses that the network can support and from that new bytes count
        craft a new IPv6 address. This has the advantage of absolutely
        guaranteeing the new address is within the network space (whereas the
        method employed below could *theoretically* generate an overlapping
        address), but would in turn remove any ability to compress obfuscated
        addresses to match the general format/syntax of the address it is
        replacing. For the moment, it is assumed that being able to maintain a
        quick mental note of "unobfuscated device ff00::1 is obfuscated device
        53ad::a1b2" is more desireable than "ff00::1 is now obfuscated as
        53ad::1234:abcd:9876:a1b2:".

        :param addr:        The unobfuscated IPv6 address
        :type addr:         ``ipaddress.IPv6Address``

        :returns:           An obfuscated address within this network
        :rtype:             ``str``
        cs"dj�jdj�j|jd���g�S)NrrC)rMr1r;r)r)rrr�_generate_addressszGObfuscatedIPv6Network.obfuscate_host_address.<locals>._generate_addressrCN)r$rr�rstriprJ�lstrip�valuesr)rr.rPZ_nZ_hostrr)rrr�sz,ObfuscatedIPv6Network.obfuscate_host_addresscCs||j|<dS)zjAdds an obfuscated pair to the class for tracking and ongoing
        consistency in obfuscation.
        N)r)rrrrrrrsz1ObfuscatedIPv6Network.add_obfuscated_host_address)rN)r'r(r)r*r>r5�propertyrrr;r7r0rArBrrrrrrr%bs

"'r%)r	Zsos.cleaner.mappingsrrr%rrrr�<module>sR