Skip to main content

browser_protocol/security/
mod.rs

1use serde::{Serialize, Deserialize};
2use serde_json::Value as JsonValue;
3
4/// An internal certificate ID value.
5
6pub type CertificateId = i64;
7
8/// A description of mixed content (HTTP resources on HTTPS pages), as defined by
9/// https://www.w3.org/TR/mixed-content/#categories
10
11#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
12pub enum MixedContentType {
13    #[default]
14    Blockable,
15    OptionallyBlockable,
16    None,
17}
18
19/// The security level of a page or resource.
20
21#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
22pub enum SecurityState {
23    #[default]
24    Unknown,
25    Neutral,
26    Insecure,
27    Secure,
28    Info,
29    InsecureBroken,
30}
31
32/// Details about the security state of the page certificate.
33
34#[derive(Debug, Clone, Serialize, Deserialize, Default)]
35#[serde(rename_all = "camelCase")]
36pub struct CertificateSecurityState {
37    /// Protocol name (e.g. "TLS 1.2" or "QUIC").
38
39    pub protocol: String,
40    /// Key Exchange used by the connection, or the empty string if not applicable.
41
42    pub keyExchange: String,
43    /// (EC)DH group used by the connection, if applicable.
44
45    #[serde(skip_serializing_if = "Option::is_none")]
46    pub keyExchangeGroup: Option<String>,
47    /// Cipher name.
48
49    pub cipher: String,
50    /// TLS MAC. Note that AEAD ciphers do not have separate MACs.
51
52    #[serde(skip_serializing_if = "Option::is_none")]
53    pub mac: Option<String>,
54    /// Page certificate.
55
56    pub certificate: Vec<String>,
57    /// Certificate subject name.
58
59    pub subjectName: String,
60    /// Name of the issuing CA.
61
62    pub issuer: String,
63    /// Certificate valid from date.
64
65    pub validFrom: crate::network::TimeSinceEpoch,
66    /// Certificate valid to (expiration) date
67
68    pub validTo: crate::network::TimeSinceEpoch,
69    /// The highest priority network error code, if the certificate has an error.
70
71    #[serde(skip_serializing_if = "Option::is_none")]
72    pub certificateNetworkError: Option<String>,
73    /// True if the certificate uses a weak signature algorithm.
74
75    pub certificateHasWeakSignature: bool,
76    /// True if the certificate has a SHA1 signature in the chain.
77
78    pub certificateHasSha1Signature: bool,
79    /// True if modern SSL
80
81    pub modernSSL: bool,
82    /// True if the connection is using an obsolete SSL protocol.
83
84    pub obsoleteSslProtocol: bool,
85    /// True if the connection is using an obsolete SSL key exchange.
86
87    pub obsoleteSslKeyExchange: bool,
88    /// True if the connection is using an obsolete SSL cipher.
89
90    pub obsoleteSslCipher: bool,
91    /// True if the connection is using an obsolete SSL signature.
92
93    pub obsoleteSslSignature: bool,
94}
95
96
97#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
98pub enum SafetyTipStatus {
99    #[default]
100    BadReputation,
101    Lookalike,
102}
103
104
105#[derive(Debug, Clone, Serialize, Deserialize, Default)]
106#[serde(rename_all = "camelCase")]
107pub struct SafetyTipInfo {
108    /// Describes whether the page triggers any safety tips or reputation warnings. Default is unknown.
109
110    pub safetyTipStatus: SafetyTipStatus,
111    /// The URL the safety tip suggested ("Did you mean?"). Only filled in for lookalike matches.
112
113    #[serde(skip_serializing_if = "Option::is_none")]
114    pub safeUrl: Option<String>,
115}
116
117/// Security state information about the page.
118
119#[derive(Debug, Clone, Serialize, Deserialize, Default)]
120#[serde(rename_all = "camelCase")]
121pub struct VisibleSecurityState {
122    /// The security level of the page.
123
124    pub securityState: SecurityState,
125    /// Security state details about the page certificate.
126
127    #[serde(skip_serializing_if = "Option::is_none")]
128    pub certificateSecurityState: Option<CertificateSecurityState>,
129    /// The type of Safety Tip triggered on the page. Note that this field will be set even if the Safety Tip UI was not actually shown.
130
131    #[serde(skip_serializing_if = "Option::is_none")]
132    pub safetyTipInfo: Option<SafetyTipInfo>,
133    /// Array of security state issues ids.
134
135    pub securityStateIssueIds: Vec<String>,
136}
137
138/// An explanation of an factor contributing to the security state.
139
140#[derive(Debug, Clone, Serialize, Deserialize, Default)]
141#[serde(rename_all = "camelCase")]
142pub struct SecurityStateExplanation {
143    /// Security state representing the severity of the factor being explained.
144
145    pub securityState: SecurityState,
146    /// Title describing the type of factor.
147
148    pub title: String,
149    /// Short phrase describing the type of factor.
150
151    pub summary: String,
152    /// Full text explanation of the factor.
153
154    pub description: String,
155    /// The type of mixed content described by the explanation.
156
157    pub mixedContentType: MixedContentType,
158    /// Page certificate.
159
160    pub certificate: Vec<String>,
161    /// Recommendations to fix any issues.
162
163    #[serde(skip_serializing_if = "Option::is_none")]
164    pub recommendations: Option<Vec<String>>,
165}
166
167/// Information about insecure content on the page.
168
169#[derive(Debug, Clone, Serialize, Deserialize, Default)]
170#[serde(rename_all = "camelCase")]
171pub struct InsecureContentStatus {
172    /// Always false.
173
174    pub ranMixedContent: bool,
175    /// Always false.
176
177    pub displayedMixedContent: bool,
178    /// Always false.
179
180    pub containedMixedForm: bool,
181    /// Always false.
182
183    pub ranContentWithCertErrors: bool,
184    /// Always false.
185
186    pub displayedContentWithCertErrors: bool,
187    /// Always set to unknown.
188
189    pub ranInsecureContentStyle: SecurityState,
190    /// Always set to unknown.
191
192    pub displayedInsecureContentStyle: SecurityState,
193}
194
195/// The action to take when a certificate error occurs. continue will continue processing the
196/// request and cancel will cancel the request.
197
198#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
199pub enum CertificateErrorAction {
200    #[default]
201    Continue,
202    Cancel,
203}
204
205#[derive(Debug, Clone, Serialize, Deserialize, Default)]
206pub struct DisableParams {}
207
208impl DisableParams { pub const METHOD: &'static str = "Security.disable"; }
209
210impl crate::CdpCommand for DisableParams {
211    const METHOD: &'static str = "Security.disable";
212    type Response = crate::EmptyReturns;
213}
214
215#[derive(Debug, Clone, Serialize, Deserialize, Default)]
216pub struct EnableParams {}
217
218impl EnableParams { pub const METHOD: &'static str = "Security.enable"; }
219
220impl crate::CdpCommand for EnableParams {
221    const METHOD: &'static str = "Security.enable";
222    type Response = crate::EmptyReturns;
223}
224
225/// Enable/disable whether all certificate errors should be ignored.
226
227#[derive(Debug, Clone, Serialize, Deserialize, Default)]
228#[serde(rename_all = "camelCase")]
229pub struct SetIgnoreCertificateErrorsParams {
230    /// If true, all certificate errors will be ignored.
231
232    pub ignore: bool,
233}
234
235impl SetIgnoreCertificateErrorsParams { pub const METHOD: &'static str = "Security.setIgnoreCertificateErrors"; }
236
237impl crate::CdpCommand for SetIgnoreCertificateErrorsParams {
238    const METHOD: &'static str = "Security.setIgnoreCertificateErrors";
239    type Response = crate::EmptyReturns;
240}
241
242/// Handles a certificate error that fired a certificateError event.
243
244#[derive(Debug, Clone, Serialize, Deserialize, Default)]
245#[serde(rename_all = "camelCase")]
246pub struct HandleCertificateErrorParams {
247    /// The ID of the event.
248
249    pub eventId: u64,
250    /// The action to take on the certificate error.
251
252    pub action: CertificateErrorAction,
253}
254
255impl HandleCertificateErrorParams { pub const METHOD: &'static str = "Security.handleCertificateError"; }
256
257impl crate::CdpCommand for HandleCertificateErrorParams {
258    const METHOD: &'static str = "Security.handleCertificateError";
259    type Response = crate::EmptyReturns;
260}
261
262/// Enable/disable overriding certificate errors. If enabled, all certificate error events need to
263/// be handled by the DevTools client and should be answered with 'handleCertificateError' commands.
264
265#[derive(Debug, Clone, Serialize, Deserialize, Default)]
266#[serde(rename_all = "camelCase")]
267pub struct SetOverrideCertificateErrorsParams {
268    /// If true, certificate errors will be overridden.
269
270    #[serde(rename = "override")]
271    pub override_: bool,
272}
273
274impl SetOverrideCertificateErrorsParams { pub const METHOD: &'static str = "Security.setOverrideCertificateErrors"; }
275
276impl crate::CdpCommand for SetOverrideCertificateErrorsParams {
277    const METHOD: &'static str = "Security.setOverrideCertificateErrors";
278    type Response = crate::EmptyReturns;
279}