a
    kÄ#d;‡  ã                #   @   s  d Z ddlZddlmZ ddlmZ ddlmZmZm	Z	 ddl
mZmZmZ ddlmZ ddlmZmZmZ dd	lmZ dd
lmZ ddlmZmZmZmZmZ ddlmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z& ddl'm(Z( ddl)m*Z* ddl+m,Z, ddl-m.Z. ddl/m0Z0 ddl1m2  m3Z3 ej4�r*ddl)m5Z5 dd„ Z6G dd„ deeƒZ7G dd„ deƒZ8dd„ Z9G dd„ deƒZ:ddiZ;G dd „ d eƒZ<d!d"d#œZ=d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFœ"Z>G dGdH„ dHeƒZ?G dIdJ„ dJeƒZ@eee:dKdL� eee:dKdM� dS )Nzò
Common TLS fields & bindings.

This module covers the record layer, along with the ChangeCipherSpec, Alert and
ApplicationData submessages. For the Handshake type, see tls_handshake.py.

See the TLS class documentation for more information.
é    N)Úconf)Úlog_runtime)ÚByteEnumFieldÚPacketListFieldÚStrField)ÚrawÚchbÚorb)Ú
randstring)ÚRawÚPaddingÚbind_layers)ÚTCP)Ú_GenericTLSSessionInheritance)Ú_tls_handshake_clsÚ_TLSHandshakeÚ_tls13_handshake_clsÚTLS13ServerHelloÚTLS13ClientHello)Ú_TLSVersionFieldÚ_tls_versionÚ_TLSIVFieldÚ_TLSMACFieldÚ_TLSPadFieldÚ_TLSPadLenFieldÚ_TLSLengthFieldÚ	_tls_type)Ú
pkcs_i2osp)ÚAEADTagError)ÚCipher_NULL)ÚCipherError)Ú	HMACError)ÚCipher_CHACHA20_POLY1305c                 C   s   | du rdS | |kS )z6Returns if version >= min, or False if version == NoneNF© )ÚversionÚminr#   r#   úN/var/www/html/gsl.tools/lib/python3.9/site-packages/scapy/layers/tls/record.pyÚ_tls_version_check/   s    r'   c                   @   s   e Zd ZdZdZdZdS )Ú_TLSEncryptedContenta~  
    When the content of a TLS record (more precisely, a TLSCiphertext) could
    not be deciphered, we use this class to represent the encrypted data.
    The MAC will still be parsed from the whole message, even though it could
    not been verified. When present (depending on cipher type and protocol
    version), the nonce_explicit, IV and/or padding will also be parsed.
    zEncrypted ContentTN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚnameZmatch_subclassr#   r#   r#   r&   r(   :   s   r(   c                       sJ   e Zd ZdZd‡ fdd„	Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	‡  Z
S )Ú_TLSMsgListFieldz»
    This is the actual content of the TLS record. As a TLS record may pack
    multiple sublayer messages (notably, several handshake messages),
    we inherit from PacketListField.
    Nc                    s&   |s
| j }tt| ƒj||d |d� d S )N)Úlength_from)Ú_get_lengthÚsuperr.   Ú__init__)Úselfr-   Údefaultr/   ©Ú	__class__r#   r&   r2   M   s
    ÿz_TLSMsgListField.__init__c                 C   s   |j d u r|jS |j S ©N)Údeciphered_lenÚlen)r3   Úpktr#   r#   r&   r0   S   s    
z_TLSMsgListField._get_lengthc                 C   sÜ   t }|jdkrft|ƒdkr”t|d ƒ}|jjdkr>|jjdu sJ|jjdkrXt |t ¡}q”t	 |t ¡}n.|jdkrvt
}n|jdkr†t}n|jdkr”t}|t u r¤t |ƒS z|||jd	�W S  tyÖ   tjrÊ‚ t |ƒ Y S 0 dS )
z¢
        Try to parse one of the TLS subprotocols (ccs, alert, handshake or
        application_data). This is used inside a loop managed by .getfield().
        é   é   r   é  Né   é   é   )Útls_session)r   Útyper9   r	   rA   Úadvertised_tls_versionÚtls_versionr   Úgetr   ÚTLSChangeCipherSpecÚTLSAlertÚTLSApplicationDataÚ	Exceptionr   Zdebug_dissector)r3   r:   ÚmÚclsÚmsgtyper#   r#   r&   Úm2iX   s2    

ÿ
þ


z_TLSMsgListField.m2ic           
      C   s\  |   |¡}g }d}|}|dur8|d|… ||d…  }}|dkr¤|jjpJddkrtt|dƒrt|jdkrt|tdd�gfS t|dƒr”|jdkr”|tƒ gfS |tdd	�gfS d
t 	|jj
jj¡v rÆ|t|ƒfS |�rL|}|  ||¡}t|v �r|t }	|	j}|	j`t|ƒdk�r |dt|ƒ … }nd}t|tƒ�r@|jj�s@| |¡ | |¡ qÆ|| |fS dS )a  
        If the decryption of the content did not fail with a CipherError,
        we begin a loop on the clear content in order to get as much messages
        as possible, of the type advertised in the record header. This is
        notably important for several TLS handshake implementations, which
        may for instance pack a server_hello, a certificate, a
        server_key_exchange and a server_hello_done, all in one record.
        Each parsed message may update the TLS context through their method
        .post_dissection_tls_session_update().

        If the decryption failed with a CipherError, presumably because we
        missed the session keys, we signal it by returning a
        _TLSEncryptedContent packet which simply contains the ciphered data.
        ó    Né  i   rB   r@   )Údatar>   )ÚloadFr   )r/   rA   rD   ÚhasattrrB   rH   rF   r   ÚsixÚ
itervaluesÚrcsÚcipherÚreadyr(   rM   r   rQ   Z
underlayerÚpayloadr9   Ú
isinstancer   ÚfrozenÚ"post_dissection_tls_session_updateÚappend)
r3   r:   ÚsÚtmp_lenÚlstÚretZremainZraw_msgÚpÚpadr#   r#   r&   Úgetfield€   sB    
ÿÿ


z_TLSMsgListField.getfieldc                 C   sž   d}t |tƒrŒ|jdu r^t |tƒr*d|_n4t |tƒr<d|_n"t |tƒrNd|_nt |tƒr^d|_|j|_|jjs‚| 	¡ }| 
|¡ qšt|ƒ}nd|_t|ƒ}|S )z’
        Update the context with information from the built packet.
        If no type was given at the record layer, we try to infer it.
        rN   Nr>   r?   r;   r@   )rY   r   rB   rF   rG   r   rH   rA   rZ   Zraw_statefulÚpost_build_tls_session_updater   )r3   r:   ra   Úcurr#   r#   r&   Úi2mµ   s&    






z_TLSMsgListField.i2mc                 C   sœ   d}|D ]}||   ||¡7 }qt|tƒrnt|jjdƒrnt|jd tƒsnt|jd tƒsnt|jd t	ƒsn|| S |j
szd|_
t d|j
¡|dd…  }|| S )zv
        Reconstruct the header because the TLS type may have been updated.
        Then, append the content.
        rN   r=   r   z!Br<   é   )rf   rY   r   r'   rA   rD   Úmsgr   r   rF   rB   ÚstructÚpack)r3   r:   r]   ÚvalÚresra   Úhdrr#   r#   r&   ÚaddfieldÐ   s"    
ÿþýüz_TLSMsgListField.addfield)N)r)   r*   r+   r,   r2   r0   rM   rc   rf   rn   Ú__classcell__r#   r#   r5   r&   r.   F   s   (5r.   c                 C   sD   t | ƒdk rdS ddlm} t| dd… ƒdkoBt| dd… ƒ|v S )zN
    This is a copycat of wireshark's `packet-tls.c` ssl_looks_like_sslv2
    é   Nr   )Ú_sslv2_handshake_typer<   é€   é   )r9   Z scapy.layers.tls.handshake_sslv2rq   Úord)Zdatrq   r#   r#   r&   Ú_ssl_looks_like_sslv2é   s    ru   c                
       sô   e Zd ZdZdgZd Zeddeƒedde	ƒe
ddƒeddƒedg ƒed	dƒed
dƒeddƒgZ‡ fdd„Zed,dd„ƒZdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd d!„ Zd"d#„ Zd$d%„ Zd&d'„ Zd(d)„ Z ‡ fd*d+„Z!‡  Z"S )-ÚTLSa9  
    The generic TLS Record message, based on section 6.2 of RFC 5246.

    When reading a TLS message, we try to parse as much as we can.
    In .pre_dissect(), according to the type of the current cipher algorithm
    (self.tls_session.rcs.cipher.type), we extract the 'iv', 'mac', 'pad' and
    'padlen'. Some of these fields may remain blank: for instance, when using
    a stream cipher, there is no IV nor any padding. The 'len' should always
    hold the length of the ciphered message; for the plaintext version, you
    should rely on the additional 'deciphered_len' attribute.

    XXX Fix 'deciphered_len' which should not be defined when failing with
    AEAD decryption. This is related to the 'decryption_success' below.
    Also, follow this behaviour in record_sslv2.py and record_tls13.py

    Once we have isolated the ciphered message aggregate (which should be one
    or several TLS messages of the same type), we try to decipher it. Either we
    succeed and store the clear data in 'msg', or we graciously fail with a
    CipherError and store the ciphered data in 'msg'.

    Unless the user manually provides the session secrets through the passing
    of a 'tls_session', obviously the ciphered messages will not be deciphered.
    Indeed, the need for a proper context may also present itself when trying
    to parse clear handshake messages.

    For instance, suppose you sniffed the beginning of a DHE-RSA negotiation::

        t1 = TLS(<client_hello>)
        t2 = TLS(<server_hello | certificate | server_key_exchange>)
        t3 = TLS(<server_hello | certificate | server_key_exchange>,
                 tls_session=t1.tls_session)

    (Note that to do things properly, here 't1.tls_session' should actually be
    't1.tls_session.mirror()'. See session.py for explanations.)

    As no context was passed to t2, neither was any client_random. Hence Scapy
    will not be able to verify the signature of the server_key_exchange inside
    t2. However, it should be able to do so for t3, thanks to the tls_session.
    The consequence of not having a complete TLS context is even more obvious
    when trying to parse ciphered content, as we described before.

    Thus, in order to parse TLS-protected communications with Scapy:
    _either Scapy reads every message from one side of the TLS connection and
    builds every message from the other side (as such, it should know the
    secrets needed for the generation of the pre_master_secret), while passing
    the same tls_session context (this is how our automaton.py mostly works);
    _or, if Scapy did not build any TLS message, it has to create a TLS context
    and feed it with secrets retrieved by whatever technique. Note that the
    knowing the private key of the server certificate will not be sufficient
    if a PFS ciphersuite was used. However, if you got a master_secret somehow,
    use it with tls_session.(w|r)cs.derive_keys() and leave the rest to Scapy.

    When building a TLS message with raw_stateful, we expect the tls_session to
    have the right parameters for ciphering. Else, .post_build() might fail.
    r8   rB   Nr$   r9   Úivrh   Úmacrb   Úpadlenc                    s(   |  dd ¡| _tt| ƒj|i |¤Ž d S )Nr8   )rE   r8   r1   rv   r2   )r3   ÚargsÚkargsr5   r#   r&   r2   6  s    zTLS.__init__c                 O   sâ   |durÞt |ƒ}|dkrÒt d|dd… ¡\}}| dd¡}|tvsL|dkrŽ|rd|jdksz|jdkszt|ƒrŠ|rz|jdu rŠddlm	} |S t
S |rÒt|jdƒrÒd	d
„ }	|	|jƒsº|	|jƒrÒ|dkrÒddlm}
 |
S |dk rÞt
S tS )au  
        If the TLS class was called on raw SSLv2 data, we want to return an
        SSLv2 record instance. We acknowledge the risk of SSLv2 packets with a
        msglen of 0x1403, 0x1503, 0x1603 or 0x1703 which will never be casted
        as SSLv2 records but TLS ones instead, but hey, we can't be held
        responsible for low-minded extensibility choices.
        Nrs   ÚBBrA   rp   r   )ÚSSLv2r=   c                 S   s   | ot | jtƒ S r7   )rY   rV   r   )Úxr#   r#   r&   Ú<lambda>V  s    z#TLS.dispatch_hook.<locals>.<lambda>r@   )ÚTLS13rg   )r9   ri   ÚunpackrE   r   rD   rC   ru   Zscapy.layers.tls.record_sslv2r}   r(   r'   rU   ÚprcsZscapy.layers.tls.record_tls13r€   rv   )rK   Z_pktrz   r{   ÚplenZbyte0Zbyte1r]   r}   Z_has_cipherr€   r#   r#   r&   Údispatch_hook:  s8    	ÿþþýÿzTLS.dispatch_hookc              
   C   sº   zJt  d| jjj¡}| jj jd7  _||dd…  }| jjj |||¡W S  tyt } z|jW  Y d}~S d}~0  t	y´ } z*|  
¡  ¡ }t d|¡ |jW  Y d}~S d}~0 0 dS )a†  
        Provided with the record header and AEAD-ciphered data, return the
        sliced and clear tuple (nonce, TLSCompressed.fragment, mac). Note that
        we still return the slicing of the original input in case of decryption
        failure. Also, if the integrity check fails, a warning will be issued,
        but we still return the sliced (unauthenticated) plaintext.
        ú!Qr<   Nrp   ú'TLS: record integrity check failed [%s])ri   rj   rA   rU   Úseq_numrV   Zauth_decryptr    rz   r   Ú
firstlayerÚsummaryr   Úinfo)r3   rm   r]   Úread_seq_numÚadd_dataÚeÚpkt_infor#   r#   r&   Ú_tls_auth_decrypte  s    ÿzTLS._tls_auth_decryptc                 C   s   | j jj |¡S )ab  
        Provided with stream- or block-ciphered data, return the clear version.
        The cipher should have been updated with the right IV early on,
        which should not be at the beginning of the input.
        In case of decryption failure, a CipherError will be raised with
        the slicing of the original input as first argument.
        )rA   rU   rV   Zdecrypt©r3   r]   r#   r#   r&   Ú_tls_decrypt}  s    zTLS._tls_decryptc           	      C   sä   t  d| jjj¡}| jj jd7  _| jjj}|dkr:dS t|ƒ|krJdS | jjj}t  d|dd… ¡d }zX|dkrŠ| 	|| | ¡}n8|dkrº| 
||d	d…  |dd
…  | ¡}ntdƒ‚W n tyÚ   |}Y n0 ||kS )aÊ  
        Provided with the record header, the TLSCompressed.fragment and the
        HMAC, return True if the HMAC is correct. If we could not compute the
        HMAC because the key was missing, there is no sense in verifying
        anything, thus we also return True.

        Meant to be used with a block cipher or a stream cipher.
        It would fail with an AEAD cipher, because rcs.hmac would be None.
        See RFC 5246, section 6.2.3.
        r…   r<   r   TFú!Hrp   é   Nrg   úUnrecognized version.)ri   rj   rA   rU   r‡   Úmac_lenr9   Úhmacr�   ÚdigestÚdigest_sslv3rI   r!   )	r3   rm   rh   rx   r‹   r•   Úalgr$   Úhr#   r#   r&   Ú_tls_hmac_verify‡  s$    

(
zTLS._tls_hmac_verifyc                 C   s   | j jj}| |¡S )ze
        Provided with the TLSCompressed.fragment,
        return the TLSPlaintext.fragment.
        )rA   rU   ÚcompressionÚ
decompress©r3   r]   r™   r#   r#   r&   Ú_tls_decompress¨  s    
zTLS._tls_decompressc              
      s¸  t |ƒdk rtdƒ‚t d|dd… ¡d }|dd… |dd| … ||d d…   }}}d } }}dˆ _d}	ˆ jjjj}
‡ fd	d
„}‡ fdd„}|
dk�rÂt d|dd… ¡d }ˆ jj	rØ||ƒ\}}||||ƒ zV|dk�r"ˆ jjjj
}|d|… ||d…  }}|ˆ jjj_ˆ  |¡}n
ˆ  |¡}W n0 t�y^ } z|jd }W Y d}~njd}~0 0 d}	t|d ƒd }|d| … || d…  }}|ˆ _ˆ jj	�r¨|}n||ƒ\}}||||ƒ n¸|
dk�r*zˆ  |¡}W n0 t�y
 } z|jd }W Y d}~n&d}~0 0 d}	||ƒ\}}||||ƒ nP|
dk�rztj�rdtˆ jjjtƒ�rdd}ˆ  ||¡\}}nˆ  ||¡\}}}d}	ˆ  |¡}|	�r–t |ƒˆ _ndˆ _|| | | }|| | S )a7  
        Decrypt, verify and decompress the message,
        i.e. apply the previous methods according to the reading cipher type.
        If the decryption was successful, 'len' will be the length of the
        TLSPlaintext.fragment. Else, it should be the length of the
        _TLSEncryptedContent.
        rg   z$Invalid record: header is too short.r’   rp   r   NrN   Fc                    sD   ˆ j jj}|dkr2| d| … | | d…  }}n
| d }}||fS )zExtract MAC.r   NrN   )rA   rU   r•   )rP   r^   Úfragrx   ©r3   r#   r&   Úextract_macÄ  s
    
 
z$TLS.pre_dissect.<locals>.extract_macc                    sJ   | dd… t  dt|ƒ¡ }ˆ  |||¡}|sFˆ  ¡  ¡ }t d|¡ dS )zVerify integrity.Nrp   r’   r†   )ri   rj   r9   r›   rˆ   r‰   r   rŠ   )rm   Úcfragrx   ZchdrZ	is_mac_okrŽ   r¡   r#   r&   Ú
verify_macÍ  s    ÿz#TLS.pre_dissect.<locals>.verify_macÚblockr<   é  TéÿÿÿÿÚstreamÚaead)r9   rI   ri   r�   ry   rA   rU   rV   rB   Úencrypt_then_macÚ
block_sizerw   r‘   r    rz   r	   r   Úcrypto_valid_advancedrY   r"   r�   rŸ   r8   )r3   r]   Zmsglenrm   ÚefragÚrrw   rx   rb   Zdecryption_successÚcipher_typer¢   r¤   r$   r«   Úpfragr�   r£   ry   Úmfragr    Zreconstructed_bodyr#   r¡   r&   Úpre_dissect°  sl    0	


 

 
ÿ
zTLS.pre_dissectc                 C   sx   | j jrt| j jdkrt| j jrD| j jdur<| j j| j _d| j _d| j _| j jrt| j jdurl| j j| j _d| j _d| j _|S )a1  
        Commit the pending r/w state if it has been triggered (e.g. by an
        underlying TLSChangeCipherSpec or a SSLv2ClientMasterKey). We update
        nothing if the prcs was not set, as this probably means that we're
        working out-of-context (and we need to keep the default rcs).
        rO   NF)rA   rD   Útriggered_prcs_commitr‚   rU   Útriggered_pwcs_commitÚpwcsÚwcsr�   r#   r#   r&   Úpost_dissect'  s    
ÿzTLS.post_dissectc                 C   s^   |rZzt |d| | jd�}W n4 ty.   ‚ Y n" tyN   tj|d| d�}Y n0 |  |¡ dS )zÅ
        Try to dissect the following data as a TLS message.
        Note that overloading .guess_payload_class() would not be enough,
        as the TLS session to be used would get lost.
        r<   )Ú	_internalÚ_underlayerrA   )r¸   r¹   N)rv   rA   ÚKeyboardInterruptrI   r   Z	raw_layerZadd_payload)r3   r]   ra   r#   r#   r&   Údo_dissect_payload<  s    ÿ
zTLS.do_dissect_payloadc                 C   s   | j jj}| |¡S )ze
        Provided with the TLSPlaintext.fragment,
        return the TLSCompressed.fragment.
        )rA   r¶   rœ   Úcompressrž   r#   r#   r&   Ú_tls_compressN  s    
zTLS._tls_compressc                 C   sb   t  d| jjj¡}| jj jd7  _|t| jdƒ t| jdƒ tt|ƒdƒ }| jjj	 
|||¡S )z¡
        Return the TLSCiphertext.fragment for AEAD ciphers, i.e. the whole
        GenericAEADCipher. Also, the additional data is computed right here.
        r…   r<   rs   )ri   rj   rA   r¶   r‡   r   rB   r$   r9   rV   Zauth_encrypt)r3   r]   Úwrite_seq_numrŒ   r#   r#   r&   Ú_tls_auth_encryptV  s    
ÿ
þýÿzTLS._tls_auth_encryptc                 C   s¢   t  d| jjj¡}| jj jd7  _| jjj}t  d|dd… ¡d }|dkrb| || | ¡}n8|dkr’| ||dd…  |dd…  | ¡}nt	d	ƒ‚|| S )
a�  
        Provided with the record header (concatenation of the TLSCompressed
        type, version and length fields) and the TLSCompressed.fragment,
        return the concatenation of the TLSCompressed.fragment and the HMAC.

        Meant to be used with a block cipher or a stream cipher.
        It would fail with an AEAD cipher, because wcs.hmac would be None.
        See RFC 5246, section 6.2.3.
        r…   r<   r’   rp   r   r“   Nrg   r”   )
ri   rj   rA   r¶   r‡   r–   r�   r—   r˜   rI   )r3   rm   rh   r¾   r™   r$   rš   r#   r#   r&   Ú_tls_hmac_addd  s    

(zTLS._tls_hmac_addc                 C   sL   d}| j jjj}|t|ƒd |  }||kr0d}t|ƒ}||d  }|| S )a©  
        Provided with the concatenation of the TLSCompressed.fragment and the
        HMAC, append the right padding and return it as a whole.
        This is the TLS-style padding: while SSL allowed for random padding,
        TLS (misguidedly) specifies the repetition of the same byte all over,
        and this byte must be equal to len(<entire padding>) - 1.

        Meant to be used with a block cipher only.
        rN   r<   r   )rA   r¶   rV   r«   r9   r   )r3   r]   Úpaddingr«   ry   Zpad_patternr#   r#   r&   Ú_tls_pad{  s    
zTLS._tls_padc                 C   s   | j jj |¡S )zø
        Return the stream- or block-ciphered version of the concatenated input.
        In case of GenericBlockCipher, no IV has been specifically prepended to
        the output, so this might not be the whole TLSCiphertext.fragment yet.
        )rA   r¶   rV   Zencryptr�   r#   r#   r&   Ú_tls_encryptŽ  s    zTLS._tls_encryptc                 C   s®  |dd… |dd…  }}t |ƒ}|dd… t d|¡ }|  |¡}t |ƒ}|dd… t d|¡ }| jjjj}|dkrô| jjsŒ|  	||¡}|  
|¡}| jdkrÔ| jjjj}t|ƒ}	|	| jjj_|  |¡}
|	|
 }
n
|  |¡}
| jjrò|  	||
¡}
n6|dk�r|  	||¡}|  |¡}
n|dk�r*|  |¡}
| j du�rR|dd… t d| j ¡ }n|dd… t dt |
ƒ¡ }| jj�r¢| jjdu�rš| jj| j_d| j_d	| j_||
 | S )
zR
        Apply the previous methods according to the writing cipher type.
        Nrg   rp   r’   r¥   r¦   r¨   r©   F)r9   ri   rj   r½   rA   r¶   rV   rB   rª   rÀ   rÂ   r$   r«   r
   rw   rÃ   r¿   r´   rµ   )r3   r:   Zpayrm   r    r^   r£   r¯   r°   rw   r­   r±   r#   r#   r&   Ú
post_build–  sD    










zTLS.post_buildc                    s:   t t| ƒ ¡ }| jr6|d7 }|d dd„ | jD ƒ¡7 }|S )Nz / c                 s   s   | ]}t |d |jƒV  qdS )Ú_nameN)Úgetattrr-   )Ú.0r~   r#   r#   r&   Ú	<genexpr>å  rN   z TLS.mysummary.<locals>.<genexpr>)r1   rv   Ú	mysummaryrh   Újoinr�   r5   r#   r&   rÉ   á  s
    zTLS.mysummary)N)#r)   r*   r+   r,   Ú	__slots__r-   r   r   r   r   r   r   r.   r   r   r   Úfields_descr2   Úclassmethodr„   r�   r‘   r›   rŸ   r²   r·   r»   r½   r¿   rÀ   rÂ   rÃ   rÄ   rÉ   ro   r#   r#   r5   r&   rv   ó   s:   7

ù	*
!wKrv   r<   Zchange_cipher_specc                   @   s2   e Zd ZdZdZeddeƒgZdd„ Zdd„ Z	d	S )
rF   zº
    Note that, as they are not handshake messages, the ccs messages do not get
    appended to the list of messages whose integrity gets verified through the
    Finished messages.
    zTLS ChangeCipherSpecrL   r<   c                 C   s   d| j _d S ©NT)rA   r³   ©r3   Zmsg_strr#   r#   r&   r[   ù  s    z6TLSChangeCipherSpec.post_dissection_tls_session_updatec                 C   s   d| j _d S rÎ   )rA   r´   rÏ   r#   r#   r&   rd   ü  s    z1TLSChangeCipherSpec.post_build_tls_session_updateN)
r)   r*   r+   r,   r-   r   Ú_tls_changecipherspec_typerÌ   r[   rd   r#   r#   r#   r&   rF   ð  s
   rF   ÚwarningÚfatal)r<   rs   Zclose_notifyZunexpected_messageZbad_record_macZdecryption_failedZrecord_overflowZdecompression_failureZhandshake_failureZno_certificate_RESERVEDZbad_certificateZunsupported_certificateZcertificate_revokedZcertificate_expiredZcertificate_unknownZillegal_parameterZ
unknown_caZaccess_deniedZdecode_errorZdecrypt_errorZexport_restriction_RESERVEDZprotocol_versionZinsufficient_securityZinternal_errorZinappropriate_fallbackZuser_canceledZno_renegotiationZmissing_extensionZunsupported_extensionZcertificate_unobtainableZunrecognized_nameZbad_certificate_status_responseZbad_certificate_hash_valueZunknown_psk_identityZcertificate_requiredZno_application_protocol)"r   é
   r>   r?   r;   é   é(   é)   é*   é+   é,   é-   é.   é/   é0   é1   é2   é3   é<   éF   éG   éP   éV   éZ   éd   ém   én   éo   ép   éq   ér   és   ét   éx   c                   @   s@   e Zd ZdZeddeƒeddeƒgZdd„ Zdd„ Z	d	d
„ Z
dS )rG   z	TLS AlertÚlevelNÚdescrc                 C   s
   |   d¡S )NzAlert %level%: %descr%)Zsprintfr¡   r#   r#   r&   rÉ   "  s    zTLSAlert.mysummaryc                 C   s   d S r7   r#   rÏ   r#   r#   r&   r[   %  s    z+TLSAlert.post_dissection_tls_session_updatec                 C   s   d S r7   r#   rÏ   r#   r#   r&   rd   (  s    z&TLSAlert.post_build_tls_session_update)r)   r*   r+   r-   r   Ú_tls_alert_levelÚ_tls_alert_descriptionrÌ   rÉ   r[   rd   r#   r#   r#   r&   rG     s   

ÿrG   c                   @   s,   e Zd ZdZeddƒgZdd„ Zdd„ ZdS )	rH   zTLS Application DatarP   Ú c                 C   s   d S r7   r#   rÏ   r#   r#   r&   r[   4  s    z5TLSApplicationData.post_dissection_tls_session_updatec                 C   s   d S r7   r#   rÏ   r#   r#   r&   rd   7  s    z0TLSApplicationData.post_build_tls_session_updateN)r)   r*   r+   r-   r   rÌ   r[   rd   r#   r#   r#   r&   rH   0  s   rH   i»  )Zsport)Údport)Ar,   ri   Zscapy.configr   Zscapy.errorr   Zscapy.fieldsr   r   r   Zscapy.compatr   r   r	   Zscapy.utilsr
   Zscapy.packetr   r   r   Zscapy.layers.inetr   Zscapy.layers.tls.sessionr   Zscapy.layers.tls.handshaker   r   r   r   r   Zscapy.layers.tls.basefieldsr   r   r   r   r   r   r   r   Zscapy.layers.tls.crypto.pkcs1r   Z#scapy.layers.tls.crypto.cipher_aeadr   Z%scapy.layers.tls.crypto.cipher_streamr   Zscapy.layers.tls.crypto.commonr    Zscapy.layers.tls.crypto.h_macr!   Zscapy.libs.sixZlibsrS   r¬   r"   r'   r(   r.   ru   rv   rÐ   rF   ró   rô   rG   rH   r#   r#   r#   r&   Ú<module>	   sj   	( $
   }
ï