使用browsermob代理,Chrome浏览器证书不受信任



是否可以让chrome忽略使用browsermob代理导致的无效证书

我使用google.com只是为了举例,在实际情况下,我需要提供凭据和登录名,而无效的证书阻止我继续。

请注意,代理运行良好,在我使用所有参数忽略证书颁发之后https://i.stack.imgur.com/dG4Vl.png

import java.io.File;
import org.openqa.selenium.Proxy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.CapabilityType;
import org.testng.annotations.Test;
import net.lightbody.bmp.BrowserMobProxy;
import net.lightbody.bmp.BrowserMobProxyServer;
import net.lightbody.bmp.client.ClientUtil;
import net.lightbody.bmp.core.har.Har;
public class Proxytest4 {
WebDriver driver = null;
BrowserMobProxy proxy = null;
@Test
public void actionLaunchRegistrationPage() throws Exception {
System.setProperty("webdriver.chrome.driver", "/Users/path/chromedriver");
System.setProperty("webdriver.chrome.logfile", "/Users/path/hromedriver_issue.log");
proxy = new BrowserMobProxyServer();
proxy.setTrustAllServers(true);
proxy.start(0);
Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxy);
ChromeOptions options = new ChromeOptions();
options.addArguments("--proxy-server=" + seleniumProxy.getHttpProxy());
options.addArguments("--no-sandbox");
options.addArguments("--start-maximized");
options.addArguments("--disable-extensions");
options.addArguments("disable-gpu");
options.addArguments("window-size=1920,1080");
// options.setAcceptInsecureCerts(true);
options.addArguments("--allow-insecure-localhost");
options.addArguments("--ignore-certificate-errors");
options.addArguments("--allow-running-insecure-content");
// DesiredCapabilities cap = DesiredCapabilities.chrome();
// cap.acceptInsecureCerts();
// cap.setCapability (CapabilityType.ACCEPT_SSL_CERTS, true);
// cap.setCapability (CapabilityType.ACCEPT_INSECURE_CERTS, true);
// cap.setCapability(ChromeOptions.CAPABILITY, options);
// options.setAcceptInsecureCerts(true);
// options.merge(cap);
options.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
options.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS, true);
// driver = new RemoteWebDriver(new URL("http://127.0.0.1:9515"), cap);
driver = new ChromeDriver(options);
// create a new HAR with the label "yahoo.com"
proxy.newHar("https://www.google.com/");
driver.get("https://www.google.com/");
// get the HAR data
Har har = proxy.getHar();
// Writing Har to file
har.getLog().toString();
har.writeTo(new File("/Users/path/HAR.txt"));
// driver.quit();
// browserStackLocal.stop();
proxy.stop();
}
}

修复如下:

1-从以下链接下载browsermob代理证书:https://github.com/lightbody/browsermob-proxy/blob/master/browsermob-core/src/main/resources/sslSupport/ca-certificate-rsa.cer

2-在OS X中打开钥匙链访问实用程序。

  • 选择左侧的系统选项。单击中的锁定图标左上角以启用更改

在此处输入图像描述

  • 在左下角,选择证书选项

在此处输入图像描述

  • 将复制到桌面的证书拖动到证书。在localhost被添加到系统密钥链之后,双击它可以再次打开它。展开"信任"部分和第一个选项,选择"始终信任">

在此处输入图像描述

我认为--disable-web-security是您想要的选项。

最新更新