import*as i18n from"../i18n/i18n.js";import*as SDK from"../sdk/sdk.js";const UIStrings={theSecurityOfThisPageIsUnknown:"The security of this page is unknown.",thisPageIsNotSecure:"This page is not secure.",thisPageIsSecureValidHttps:"This page is secure (valid HTTPS).",thisPageIsNotSecureBrokenHttps:"This page is not secure (broken HTTPS).",cipherWithMAC:"{PH1} with {PH2}",keyExchangeWithGroup:"{PH1} with {PH2}"},str_=i18n.i18n.registerUIStrings("security/SecurityModel.ts",UIStrings),i18nString=i18n.i18n.getLocalizedString.bind(void 0,str_),i18nLazyString=i18n.i18n.getLazilyComputedLocalizedString.bind(void 0,str_);export class SecurityModel extends SDK.SDKModel.SDKModel{constructor(t){super(t),this._dispatcher=new SecurityDispatcher(this),this._securityAgent=t.securityAgent(),t.registerSecurityDispatcher(this._dispatcher),this._securityAgent.invoke_enable()}resourceTreeModel(){return this.target().model(SDK.ResourceTreeModel.ResourceTreeModel)}networkManager(){return this.target().model(SDK.NetworkManager.NetworkManager)}static SecurityStateComparator(t,e){const i=getOrCreateSecurityStateOrdinalMap();return(t&&i.get(t)||0)-(e&&i.get(e)||0)}}let securityStateToOrdinal=null;const getOrCreateSecurityStateOrdinalMap=()=>{if(!securityStateToOrdinal){securityStateToOrdinal=new Map;const t=[Protocol.Security.SecurityState.Info,Protocol.Security.SecurityState.InsecureBroken,Protocol.Security.SecurityState.Insecure,Protocol.Security.SecurityState.Neutral,Protocol.Security.SecurityState.Secure,Protocol.Security.SecurityState.Unknown];for(let e=0;e<t.length;e++)securityStateToOrdinal.set(t[e],e+1)}return securityStateToOrdinal};SDK.SDKModel.SDKModel.register(SecurityModel,SDK.SDKModel.Capability.Security,!1);export var Events;!function(t){t.SecurityStateChanged="SecurityStateChanged",t.VisibleSecurityStateChanged="VisibleSecurityStateChanged"}(Events||(Events={}));export const SummaryMessages={[Protocol.Security.SecurityState.Unknown]:i18nLazyString(UIStrings.theSecurityOfThisPageIsUnknown),[Protocol.Security.SecurityState.Insecure]:i18nLazyString(UIStrings.thisPageIsNotSecure),[Protocol.Security.SecurityState.Neutral]:i18nLazyString(UIStrings.thisPageIsNotSecure),[Protocol.Security.SecurityState.Secure]:i18nLazyString(UIStrings.thisPageIsSecureValidHttps),[Protocol.Security.SecurityState.InsecureBroken]:i18nLazyString(UIStrings.thisPageIsNotSecureBrokenHttps)};export class PageSecurityState{constructor(t,e,i){this.securityState=t,this.explanations=e,this.summary=i}}export class PageVisibleSecurityState{constructor(t,e,i,r){this.securityState=t,this.certificateSecurityState=e?new CertificateSecurityState(e):null,this.safetyTipInfo=i?new SafetyTipInfo(i):null,this.securityStateIssueIds=r}}export class CertificateSecurityState{constructor(t){this.protocol=t.protocol,this.keyExchange=t.keyExchange,this.keyExchangeGroup=t.keyExchangeGroup||null,this.cipher=t.cipher,this.mac=t.mac||null,this.certificate=t.certificate,this.subjectName=t.subjectName,this.issuer=t.issuer,this.validFrom=t.validFrom,this.validTo=t.validTo,this.certificateNetworkError=t.certificateNetworkError||null,this.certificateHasWeakSignature=t.certificateHasWeakSignature,this.certificateHasSha1Signature=t.certificateHasSha1Signature,this.modernSSL=t.modernSSL,this.obsoleteSslProtocol=t.obsoleteSslProtocol,this.obsoleteSslKeyExchange=t.obsoleteSslKeyExchange,this.obsoleteSslCipher=t.obsoleteSslCipher,this.obsoleteSslSignature=t.obsoleteSslSignature}isCertificateExpiringSoon(){const t=new Date(1e3*this.validTo).getTime();return t<new Date(Date.now()).setHours(48)&&t>Date.now()}getKeyExchangeName(){return this.keyExchangeGroup?this.keyExchange?i18nString(UIStrings.keyExchangeWithGroup,{PH1:this.keyExchange,PH2:this.keyExchangeGroup}):this.keyExchangeGroup:this.keyExchange}getCipherFullName(){return this.mac?i18nString(UIStrings.cipherWithMAC,{PH1:this.cipher,PH2:this.mac}):this.cipher}}class SafetyTipInfo{constructor(t){this.safetyTipStatus=t.safetyTipStatus,this.safeUrl=t.safeUrl||null}}export class SecurityStyleExplanation{constructor(t,e,i,r,s=[],a=Protocol.Security.MixedContentType.None,c=[]){this.securityState=t,this.title=e,this.summary=i,this.description=r,this.certificate=s,this.mixedContentType=a,this.recommendations=c}}class SecurityDispatcher{constructor(t){this._model=t}securityStateChanged({securityState:t,explanations:e,summary:i}){const r=new PageSecurityState(t,e,i||null);this._model.dispatchEventToListeners(Events.SecurityStateChanged,r)}visibleSecurityStateChanged({visibleSecurityState:t}){const e=new PageVisibleSecurityState(t.securityState,t.certificateSecurityState||null,t.safetyTipInfo||null,t.securityStateIssueIds);this._model.dispatchEventToListeners(Events.VisibleSecurityStateChanged,e)}certificateError(t){}}