Skip to content

Commit

Permalink
[CDP] Add "security" domain (#7294)
Browse files Browse the repository at this point in the history
Added DevTools Security domain
  • Loading branch information
adiohana authored and shs96c committed Jun 20, 2019
1 parent 6c6d811 commit b5ac3a3
Show file tree
Hide file tree
Showing 17 changed files with 402 additions and 16 deletions.
10 changes: 10 additions & 0 deletions common/src/web/devToolsSecurityTest
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<html>
<head>
</head>

<body>

<p>Security Test</p>

</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public void setColumnNumber(Integer columnNumber) {
this.columnNumber = columnNumber;
}

public static CallFrame parseCallFrame(JsonInput input) {
private static CallFrame fromJson(JsonInput input) {
String functionName = null;
String scriptId = null;
String callFrameUrl = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void setLineNumber(Double lineNumber) {
this.lineNumber = lineNumber;
}

public static Initiator parseInitiator(JsonInput input) {
private static Initiator fromJson(JsonInput input) {

InitiatorType initiatorType = null;
StackTrace stack = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private RequestIntercepted(InterceptionId interceptionId,
this.requestId = requestId;
}

public static RequestIntercepted fromJson(JsonInput input) {
private static RequestIntercepted fromJson(JsonInput input) {
InterceptionId interceptionId = new InterceptionId(input.nextString());
Request request = null;
String frameId = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ private static RequestWillBeSent fromJson(JsonInput input) {
break;

case "initiator":
initiator = Initiator.parseInitiator(input);
initiator = input.read(Initiator.class);
break;

case "redirectResponse":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ public void setSecurityDetails(SecurityDetails securityDetails) {
this.securityDetails = securityDetails;
}

public static Response fromJson(JsonInput input) {
private static Response fromJson(JsonInput input) {
Response response;
input.beginObject();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private ResponseReceived(RequestId requestId,

}

public static ResponseReceived fromJson(JsonInput input) {
private static ResponseReceived fromJson(JsonInput input) {
RequestId requestId = new RequestId(input.nextString());
LoaderId loaderId = null;
MonotonicTime timestamp = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ private static StackTrace fromJson(JsonInput input) {
input.beginArray();
callFrames = new ArrayList<>();
while (input.hasNext()) {
callFrames.add(CallFrame.parseCallFrame(input));
callFrames.add(input.read(CallFrame.class));
}
input.endArray();
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private static WebSocketCreated fromJson(JsonInput input) {
url = input.nextString();
break;
case "initiator":
initiator = Initiator.parseInitiator(input);
initiator = input.read(Initiator.class);
break;
default:
input.skipValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static ProfileNode fromJson(JsonInput input) {
id = input.read(Integer.class);
break;
case "callFrame":
callFrame = CallFrame.parseCallFrame(input);
callFrame = input.read(CallFrame.class);
break;
case "hitCount":
hitCount = input.read(Integer.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.openqa.selenium.devtools.security;

import static org.openqa.selenium.devtools.ConverterFunctions.map;

import com.google.common.collect.ImmutableMap;

import org.openqa.selenium.devtools.Command;
import org.openqa.selenium.devtools.Event;
import org.openqa.selenium.devtools.security.model.SecurityStateChanged;

public class Security {

private final static String DOMAIN_NAME = "Security";

/**
* Disables tracking security state changes.
*/
public static Command<Void> disable() {
return new Command<>(DOMAIN_NAME + ".disable", ImmutableMap.of());
}

/**
* Enables tracking security state changes.
*/
public static Command<Void> enable() {
return new Command<>(DOMAIN_NAME + ".enable", ImmutableMap.of());
}

/**
* Enable/disable whether all certificate errors should be ignored. (EXPERIMENTAL)
*/
public static Command<Void> setIgnoreCertificateErrors(boolean ignore) {
return new Command<>(DOMAIN_NAME + ".setIgnoreCertificateErrors",
ImmutableMap.of("ignore", ignore));
}

/**
* The security state of the page changed.
*/
public static Event<SecurityStateChanged> securityStateChanged() {
return new Event<>(DOMAIN_NAME + ".securityStateChanged",
map("securityState", SecurityStateChanged.class));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.openqa.selenium.devtools.security.model;

import static java.util.Objects.requireNonNull;

import com.google.common.reflect.TypeToken;

import org.openqa.selenium.devtools.network.model.SecurityState;
import org.openqa.selenium.json.JsonInput;

import java.util.List;

public class SecurityStateChanged {

/**
* Security state
*/
private SecurityState securityState;

/**
* True if the page was loaded over cryptographic transport such as HTTPS.
*/
private boolean schemeIsCryptographic;

/**
* List of explanations for the security state.
* If the overall security state is insecure or warning, at least one corresponding
* explanation should be included.
*/
private List<SecurityStateExplanation> securityStateExplanations;

/**
* Overrides user-visible description of the state.
*/
private String summary;

private SecurityStateChanged(SecurityState securityState, boolean schemeIsCryptographic,
List<SecurityStateExplanation> securityStateExplanations,
String summary) {
this.securityState =
requireNonNull(securityState, "'securityState' is required for SecurityStateChanged");
this.schemeIsCryptographic = schemeIsCryptographic;
this.securityStateExplanations = securityStateExplanations;
this.summary = summary;
}

private static SecurityStateChanged fromJson(JsonInput input) {
SecurityState securityState = SecurityState.valueOf(input.nextString());
boolean schemeIsCryptographic = false;
List<SecurityStateExplanation> securityStateExplanations = null;
String summary = null;
while (input.hasNext()) {
switch (input.nextName()) {
case "schemeIsCryptographic":
schemeIsCryptographic = input.nextBoolean();
break;
case "securityStateExplanations":
securityStateExplanations = input.read(new TypeToken<List<SecurityStateExplanation>>() {
}.getType());
break;
case "summary":
summary = input.nextString();
break;
default:
input.skipValue();
break;
}
}
return new SecurityStateChanged(securityState, schemeIsCryptographic, securityStateExplanations,
summary);
}

public SecurityState getSecurityState() {
return securityState;
}

public boolean isSchemeIsCryptographic() {
return schemeIsCryptographic;
}

public List<SecurityStateExplanation> getSecurityStateExplanations() {
return securityStateExplanations;
}

public String getSummary() {
return summary;
}

}
Loading

0 comments on commit b5ac3a3

Please sign in to comment.