/var/opt/nydus/ops/oscrypto/__pycache__
Edit: /var/opt/nydus/ops/oscrypto/__pycache__/_tls.cpython-312.pyc (17307B)
NjE d dl mZmZmZmZ d dlZd dlmZ ddlmZm Z m
Z
ddlmZ ddl
mZmZmZ g dZd Zd
Zd Zd Zd
Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d Z"d Z#d Z$d Z%d Z&d Z'd Z(y) )unicode_literalsdivisionabsolute_importprint_functionN)datetime )Certificateint_from_bytestimezone)CIPHER_SUITE_MAP)TLSVerificationErrorTLSDisconnectErrorTLSError)detect_client_auth_request
extract_chainget_dh_params_lengthparse_alertparse_handshake_messagesparse_session_infoparse_tls_recordsraise_client_authraise_dh_paramsraise_disconnectionraise_expired_not_yet_validraise_handshakeraise_hostnameraise_no_issuerraise_protocol_error
raise_revokedraise_self_signedraise_verificationraise_weak_signaturec P g }d}t | D ], \ }}}|dk7 r
t | D ] \ }}|dk( s|} n |s, n |red}|t | k rUt |||dz } |dz }
|
| z }|}||
| }|j t j | |t | k rU|S )a
Extracts the X.509 certificates from the server handshake bytes for use
when debugging
:param server_handshake_bytes:
A byte string of the handshake data received from the server
:return:
A list of asn1crypto.x509.Certificate objects
N )r r lenr
appendr load)
server_handshake_bytesoutputchain_bytesrecord_type_record_datamessage_typemessage_datapointercert_length
cert_startcert_end
cert_bytess
>/opt/nydus/tmp/pip-target-a90h98xg/lib/python/oscrypto/_tls.pyr r # s FK'89O'P#Q'!*B;*O&L,w&* +P (Q K(((WWq[)IJK 1J!K/HG$Z9JMM+**:67
K(( M c n t | D ]' \ }}}|dk7 r
t | D ]
\ }}|dk( s y ) y)a)
Determines if a CertificateRequest message is sent from the server asking
the client for a certificate
:param server_handshake_bytes:
A byte string of the handshake data received from the server
:return:
A boolean - if a client certificate request was found
r$
TF)r r )r* r- r. r/ r0 r1 s r7 r r K sL (99O'P#Q'!*B;*O&L,w& +P (Q r8 c d}d}t | D ], \ }}}|dk7 r
t | D ] \ }}|dk( s|} n |s, n |rt |dd dz }|S )a
Determines the length of the DH params from the ServerKeyExchange
:param server_handshake_bytes:
A byte string of the handshake data received from the server
:return:
None or an integer of the bit size of the DH parameters
Nr$ r )r r r
)r* r+ dh_params_bytesr- r. r/ r0 r1 s r7 r r ` s~ FO'89O'P#Q'!*B;*O&L,w&". +P (Q ! 459Mr8 c t | D ]9 \ }}}|dk7 r
t | dk7 r yt |dd t |dd fc S y)aV
Parses the handshake for protocol alerts
:param server_handshake_bytes:
A byte string of the handshake data received from the server
:return:
None or an 2-element tuple of integers:
0: 1 (warning) or 2 (fatal)
1: The alert description (see https://tools.ietf.org/html/rfc5246#section-7.2)
r= Nr r )r r' r
)r* r- r. r/ s r7 r r s_ (99O'P#Q'!{q {1Q/0.QqAQ2RSS (Q r8 c d}d}d}d}d}d}d}t | D ] \ } }
}| dk7 r
t | D ] \ }}
|dk7 rddddd d
|
dd }t |
d
d }|dkD r|
dd|z }d|z }|
||dz }t | }|dz }|
||dz dk7 }|dz }|
|d }t | D ] \ }}|dk( sd} n t | D ] \ } }
}| dk7 r
t | D ] \ }}
|dk7 rt |
d
d }|dkD r|
dd|z }d|z }t |
||dz }|dz |z }t |
||dz }|+|)|dz |z }|
|d }t | D ] \ }}|dk( sd} n ||d}n
||k7 rd}nd}|||||dS )a
Parse the TLS handshake from the client to the server to extract information
including the cipher suite selected, if compression is enabled, the
session id and if a new or reused session ticket exists.
:param server_handshake_bytes:
A byte string of the handshake data received from the server
:param client_handshake_bytes:
A byte string of the handshake data sent to the server
:return:
A dict with the following keys:
- "protocol": unicode string
- "cipher_suite": unicode string
- "compression": boolean
- "session_id": "new", "reused" or None
- "session_ticket: "new", "reused" or None
NFr$ SSLv3TLSv1zTLSv1.1zTLSv1.2zTLSv1.3)s s s s s r r= " # r new reused)protocolcipher_suitecompression
session_idsession_ticket)r r r
r _parse_hello_extensions)r* client_handshake_bytesrL rM rN rO rP server_session_idclient_session_idr- r. r/ r0 r1 session_id_lengthcipher_suite_startcipher_suite_bytescompression_startextensions_length_startextensions_dataextension_typeextension_datacipher_suite_lengthcompression_lengths r7 r r s * HLKJN'89O'P#Q'!*B;*O&L,w&$$&&& 1Q
!H !/|Br/B C 1$$0B9J4J$K!!#&7!7!-.@ASVWAW!X+,>?L 2Q 6&'89JQ9NOSZZK&7!&;#*+B+CDO2I/2Z.!R'%*N 3[
; +P (QD (99O'P#Q'!*B;*O&L,w& .|Br/B C 1$$0B9J4J$K!!#&7!7"0>PQcfgQg1h"i 2Q 69L L!/=NO`cdOd0e!f !(^-C*;a*?BT*T'"./F/G"H6Mo6^2NN%+)1 7_
1 +P (Q: $$J $55"
%
$" ( r8 c # K d}t | }||k rQ| ||dz dk( ryt | |dz |dz }| ||dz | |dz |dz | |dz |dz |z f |d|z z
}||k rPyyw)a
Creates a generator returning tuples of information about each record
in a byte string of data from a TLS client or server. Stops as soon as it
find a ChangeCipherSpec message since all data from then on is encrypted.
:param data:
A byte string of TLS records
:return:
A generator that yields 3-element tuples:
[0] Byte string of record type
[1] Byte string of protocol version
[2] Byte string of record data
r r r&