U
    gB                     @  s  d dl mZ ddlmZmZ d dlmZ d dlZd dlZddl	m
Z
 G dd deZG d	d
 d
ejZG dd dejZeG dd dZG dd dejZeG dd dZeG dd dZeG dd dZeG dd dZG dd dejZddddZdddd Zd!dd"d#d$Zd%ddd&d'd(Zd!dd)d*d+Zed,eG d-d. d.Zed/eG d0d1 d1Zed2eG d3d4 d4ZdS )5    )annotations   )event_classT_JSON_DICT)	dataclassN)networkc                      sB   e Zd ZdZddddZedd dddZ fd	d
Z  ZS )CertificateIdz+
    An internal certificate ID value.
    intreturnc                 C  s   | S N selfr   r   S/tmp/pip-unpacked-wheel-3ysq0mf8/selenium/webdriver/common/devtools/v85/security.pyto_json   s    zCertificateId.to_jsonjsonr   c                 C  s   | |S r   r   clsr   r   r   r   	from_json   s    zCertificateId.from_jsonc                   s   d t  S )NzCertificateId({}))formatsuper__repr__r   	__class__r   r   r      s    zCertificateId.__repr__)	__name__
__module____qualname____doc__r   classmethodr   r   __classcell__r   r   r   r   r      s
   r   c                   @  s0   e Zd ZdZdZdZdZdd Zedd Z	d	S )
MixedContentTypez
    A description of mixed content (HTTP resources on HTTPS pages), as defined by
    https://www.w3.org/TR/mixed-content/#categories
    Z	blockablezoptionally-blockablenonec                 C  s   | j S r   valuer   r   r   r   r   '   s    zMixedContentType.to_jsonc                 C  s   | |S r   r   r   r   r   r   r   *   s    zMixedContentType.from_jsonN)
r   r   r   r   Z	BLOCKABLEZOPTIONALLY_BLOCKABLENONEr   r    r   r   r   r   r   r"      s   r"   c                   @  s<   e Zd ZdZdZdZdZdZdZdZ	dd	 Z
ed
d ZdS )SecurityStatez3
    The security level of a page or resource.
    unknownZneutralZinsecuresecureinfozinsecure-brokenc                 C  s   | j S r   r$   r   r   r   r   r   :   s    zSecurityState.to_jsonc                 C  s   | |S r   r   r   r   r   r   r   =   s    zSecurityState.from_jsonN)r   r   r   r   UNKNOWNZNEUTRALZINSECUREZSECUREINFOZINSECURE_BROKENr   r    r   r   r   r   r   r'   /   s   r'   c                   @  s   e Zd ZU dZded< ded< ded< ded< ded< ded	< d
ed< d
ed< ded< ded< ded< ded< ded< ded< ded< dZded< dZded< dZded< dd Ze	dd Z
dS )CertificateSecurityStatezC
    Details about the security state of the page certificate.
    strprotocolkey_exchangeciphertyping.List[str]certificatesubject_nameissuerznetwork.TimeSinceEpoch
valid_fromvalid_toboolcertificate_has_weak_signaturecertificate_has_sha1_signature
modern_sslobsolete_ssl_protocolobsolete_ssl_key_exchangeobsolete_ssl_cipherobsolete_ssl_signatureNtyping.Optional[str]key_exchange_groupmaccertificate_network_errorc                 C  s   t  }| j|d< | j|d< | j|d< dd | jD |d< | j|d< | j|d< | j |d	< | j	 |d
< | j
|d< | j|d< | j|d< | j|d< | j|d< | j|d< | j|d< | jd k	r| j|d< | jd k	r| j|d< | jd k	r| j|d< |S )Nr/   keyExchanger1   c                 S  s   g | ]}|qS r   r   .0ir   r   r   
<listcomp>   s     z4CertificateSecurityState.to_json.<locals>.<listcomp>r3   subjectNamer5   	validFromvalidTocertificateHasWeakSignaturecertificateHasSha1Signature	modernSSLobsoleteSslProtocolobsoleteSslKeyExchangeobsoleteSslCipherobsoleteSslSignaturekeyExchangeGrouprB   certificateNetworkError)dictr/   r0   r1   r3   r4   r5   r6   r   r7   r9   r:   r;   r<   r=   r>   r?   rA   rB   rC   r   r   r   r   r   r   }   s.    

















z CertificateSecurityState.to_jsonc                 C  s   | t |d t |d t |d dd |d D t |d t |d tj|d	 tj|d
 t|d t|d t|d t|d t|d t|d t|d d|krt |d nd d|krt |d nd d|krt |d nd dS )Nr/   rD   r1   c                 S  s   g | ]}t |qS r   r.   rE   r   r   r   rH      s     z6CertificateSecurityState.from_json.<locals>.<listcomp>r3   rI   r5   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rB   rT   )r/   r0   r1   r3   r4   r5   r6   r7   r9   r:   r;   r<   r=   r>   r?   rA   rB   rC   )r.   r   ZTimeSinceEpochr   r8   r   r   r   r   r      s(    











z"CertificateSecurityState.from_json)r   r   r   r   __annotations__rA   rB   rC   r   r    r   r   r   r   r   r-   B   s,   
r-   c                   @  s(   e Zd ZdZdZdd Zedd ZdS )SafetyTipStatusZbadReputationZ	lookalikec                 C  s   | j S r   r$   r   r   r   r   r      s    zSafetyTipStatus.to_jsonc                 C  s   | |S r   r   r   r   r   r   r      s    zSafetyTipStatus.from_jsonN)r   r   r   ZBAD_REPUTATIONZ	LOOKALIKEr   r    r   r   r   r   r   rY      s
   rY   c                   @  s6   e Zd ZU ded< dZded< dd Zedd	 ZdS )
SafetyTipInforY   safety_tip_statusNr@   safe_urlc                 C  s,   t  }| j |d< | jd k	r(| j|d< |S )NsafetyTipStatussafeUrl)rU   r[   r   r\   rV   r   r   r   r      s
    

zSafetyTipInfo.to_jsonc                 C  s*   | t |d d|kr"t|d nd dS )Nr]   r^   )r[   r\   )rY   r   r.   r   r   r   r   r      s    zSafetyTipInfo.from_json)r   r   r   rX   r\   r   r    r   r   r   r   r   rZ      s
   
rZ   c                   @  sN   e Zd ZU dZded< ded< dZded< dZd	ed
< dd Zedd Z	dS )VisibleSecurityStatez4
    Security state information about the page.
    r'   security_stater2   security_state_issue_idsNz)typing.Optional[CertificateSecurityState]certificate_security_stateztyping.Optional[SafetyTipInfo]safety_tip_infoc                 C  s\   t  }| j |d< dd | jD |d< | jd k	r@| j |d< | jd k	rX| j |d< |S )NsecurityStatec                 S  s   g | ]}|qS r   r   rE   r   r   r   rH      s     z0VisibleSecurityState.to_json.<locals>.<listcomp>securityStateIssueIdscertificateSecurityStatesafetyTipInfo)rU   r`   r   ra   rb   rc   rV   r   r   r   r      s    

zVisibleSecurityState.to_jsonc                 C  sT   | t |d dd |d D d|kr4t|d nd d|krLt|d nd dS )Nrd   c                 S  s   g | ]}t |qS r   rW   rE   r   r   r   rH      s     z2VisibleSecurityState.from_json.<locals>.<listcomp>re   rf   rg   )r`   ra   rb   rc   )r'   r   r-   rZ   r   r   r   r   r      s    zVisibleSecurityState.from_json)
r   r   r   r   rX   rb   rc   r   r    r   r   r   r   r   r_      s   

r_   c                   @  sb   e Zd ZU dZded< ded< ded< ded< ded	< d
ed< dZded< dd Zedd ZdS )SecurityStateExplanationzI
    An explanation of an factor contributing to the security state.
    r'   r`   r.   titlesummarydescriptionr"   mixed_content_typer2   r3   Nz!typing.Optional[typing.List[str]]recommendationsc                 C  sv   t  }| j |d< | j|d< | j|d< | j|d< | j |d< dd | jD |d< | jd k	rrd	d | jD |d
< |S )Nrd   ri   rj   rk   mixedContentTypec                 S  s   g | ]}|qS r   r   rE   r   r   r   rH     s     z4SecurityStateExplanation.to_json.<locals>.<listcomp>r3   c                 S  s   g | ]}|qS r   r   rE   r   r   r   rH     s     rm   )	rU   r`   r   ri   rj   rk   rl   r3   rm   rV   r   r   r   r     s    



z SecurityStateExplanation.to_jsonc              
   C  sj   | t |d t|d t|d t|d t|d dd |d D d	|krbd
d |d	 D nd dS )Nrd   ri   rj   rk   rn   c                 S  s   g | ]}t |qS r   rW   rE   r   r   r   rH   $  s     z6SecurityStateExplanation.from_json.<locals>.<listcomp>r3   rm   c                 S  s   g | ]}t |qS r   rW   rE   r   r   r   rH   %  s     )r`   ri   rj   rk   rl   r3   rm   )r'   r   r.   r"   r   r   r   r   r     s    


z"SecurityStateExplanation.from_json)	r   r   r   r   rX   rm   r   r    r   r   r   r   r   rh      s   
rh   c                   @  s^   e Zd ZU dZded< ded< ded< ded< ded< ded	< ded
< dd Zedd ZdS )InsecureContentStatusz9
    Information about insecure content on the page.
    r8   ran_mixed_contentdisplayed_mixed_contentcontained_mixed_formran_content_with_cert_errors"displayed_content_with_cert_errorsr'   ran_insecure_content_style displayed_insecure_content_stylec                 C  sX   t  }| j|d< | j|d< | j|d< | j|d< | j|d< | j |d< | j |d< |S )NranMixedContentdisplayedMixedContentcontainedMixedFormranContentWithCertErrorsdisplayedContentWithCertErrorsranInsecureContentStyledisplayedInsecureContentStyle)	rU   rp   rq   rr   rs   rt   ru   r   rv   rV   r   r   r   r   C  s    




zInsecureContentStatus.to_jsonc                 C  sR   | t |d t |d t |d t |d t |d t|d t|d dS )	Nrw   rx   ry   rz   r{   r|   r}   )rp   rq   rr   rs   rt   ru   rv   )r8   r'   r   r   r   r   r   r   N  s    




zInsecureContentStatus.from_jsonN)r   r   r   r   rX   r   r    r   r   r   r   r   ro   )  s   
ro   c                   @  s,   e Zd ZdZdZdZdd Zedd ZdS )	CertificateErrorActionz
    The action to take when a certificate error occurs. continue will continue processing the
    request and cancel will cancel the request.
    continuecancelc                 C  s   | j S r   r$   r   r   r   r   r   c  s    zCertificateErrorAction.to_jsonc                 C  s   | |S r   r   r   r   r   r   r   f  s    z CertificateErrorAction.from_jsonN)	r   r   r   r   CONTINUEZCANCELr   r    r   r   r   r   r   r~   [  s   r~   z0typing.Generator[T_JSON_DICT, T_JSON_DICT, None]r
   c                  c  s   ddi} | V }dS )z3
    Disables tracking security state changes.
    methodzSecurity.disableNr   cmd_dictr   r   r   r   disablek  s     r   c                  c  s   ddi} | V }dS )z2
    Enables tracking security state changes.
    r   zSecurity.enableNr   r   r   r   r   enableu  s     r   r8   )ignorer   c                 c  s"   t  }| |d< d|d}|V }dS )z
    Enable/disable whether all certificate errors should be ignored.

    **EXPERIMENTAL**

    :param ignore: If true, all certificate errors will be ignored.
    r   z#Security.setIgnoreCertificateErrorsr   paramsNrU   )r   r   r   r   r   r   r   set_ignore_certificate_errors  s    
r   r	   )event_idactionr   c                 c  s.   t  }| |d< | |d< d|d}|V }dS )z
    Handles a certificate error that fired a certificateError event.

    :param event_id: The ID of the event.
    :param action: The action to take on the certificate error.
    eventIdr   zSecurity.handleCertificateErrorr   N)rU   r   )r   r   r   r   r   r   r   r   handle_certificate_error  s    
r   )overrider   c                 c  s"   t  }| |d< d|d}|V }dS )a  
    Enable/disable overriding certificate errors. If enabled, all certificate error events need to
    be handled by the DevTools client and should be answered with ``handleCertificateError`` commands.

    :param override: If true, certificate errors will be overridden.
    r   z%Security.setOverrideCertificateErrorsr   Nr   )r   r   r   r   r   r   r   set_override_certificate_errors  s    	r   zSecurity.certificateErrorc                   @  s>   e Zd ZU dZded< ded< ded< edd dd	d
ZdS )CertificateErroraL  
    There is a certificate error. If overriding certificate errors is enabled, then it should be
    handled with the ``handleCertificateError`` command. Note: this event does not fire if the
    certificate error has been allowed internally. Only one client per target should override
    certificate errors at the same time.
    r	   r   r.   
error_typerequest_urlr   r   c                 C  s&   | t |d t|d t|d dS )Nr   Z	errorTypeZ
requestURL)r   r   r   )r	   r.   r   r   r   r   r     s
    


zCertificateError.from_jsonNr   r   r   r   rX   r    r   r   r   r   r   r     s   
r   z$Security.visibleSecurityStateChangedc                   @  s.   e Zd ZU dZded< edd dddZdS )	VisibleSecurityStateChangedzG
    **EXPERIMENTAL**

    The security state of the page changed.
    r_   visible_security_stater   r   c                 C  s   | t |d dS )NZvisibleSecurityState)r   )r_   r   r   r   r   r   r     s    z%VisibleSecurityStateChanged.from_jsonNr   r   r   r   r   r     s   
r   zSecurity.securityStateChangedc                   @  sN   e Zd ZU dZded< ded< ded< ded	< d
ed< edd dddZdS )SecurityStateChangedz1
    The security state of the page changed.
    r'   r`   r8   scheme_is_cryptographicz%typing.List[SecurityStateExplanation]explanationsro   insecure_content_statusr@   rj   r   r   c                 C  sP   | t |d t|d dd |d D t|d d|krHt|d nd dS )	Nrd   ZschemeIsCryptographicc                 S  s   g | ]}t |qS r   )rh   r   rE   r   r   r   rH     s     z2SecurityStateChanged.from_json.<locals>.<listcomp>r   ZinsecureContentStatusrj   )r`   r   r   r   rj   )r'   r   r8   ro   r.   r   r   r   r   r     s    
zSecurityStateChanged.from_jsonNr   r   r   r   r   r     s   
r   )
__future__r   utilr   r   Zdataclassesr   enumtyping r   r	   r   Enumr"   r'   r-   rY   rZ   r_   rh   ro   r~   r   r   r   r   r   r   r   r   r   r   r   r   <module>   sD   k$21

