gpt4 book ai didi

javax.net.ssl.SSLException : Certificate for <> doesn't match any of the subject alternative names: [] 异常

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:16:09 26 4
gpt4 key购买 nike

当我尝试使用 Postman 访问 URL 时,它工作正常,通过使用我的个人证书。但是当我使用 Rest Assured 测试用例尝试相同时,它抛出上述异常。

配置类

public class Configuration {

protected SSLConfig config = null;
private static final Logger LOG = LoggerFactory.getLogger(Configuration.class);

@SuppressWarnings("deprecation")
@BeforeClass
public void setKeystore()

{
KeyStore keyStore = null;

KeyStore trustStore = null;
try {
String certPassword = System.getProperty("certPassword");
String certPath = System.getProperty("certPath");

String trustStorePassword = System.getProperty("trustStorePassword");
String trustStorePath = System.getProperty("trustStorePath");
Validate.notNull(certPath, "Path to Certificate on the file system cannot be null");
Validate.notEmpty(certPassword, "Password cannot be empty");
Validate.notNull(trustStorePath, "Path to trustStore on the file system cannot be null");
Validate.notEmpty(trustStorePassword, "TrustStore Password cannot be empty");

keyStore = KeyStore.getInstance("JKS");
keyStore.load(new FileInputStream(certPath), certPassword.toCharArray());
trustStore = KeyStore.getInstance("JKS");
trustStore.load(new FileInputStream(trustStorePath), trustStorePassword.toCharArray());

if (keyStore != null) {

org.apache.http.conn.ssl.SSLSocketFactory clientAuthFactory = new org.apache.http.conn.ssl.SSLSocketFactory(
keyStore, certPassword, trustStore);
config = new SSLConfig().with().sslSocketFactory(clientAuthFactory).and().allowAllHostnames();

}
EnvironmentConstants.getEnvironment();

} catch (Exception e) {
LOG.error("Error while loading keystore");
e.printStackTrace();
}
}

@BeforeTest
public Properties loadproperties() {

InputStream input = getClass().getClassLoader().getResourceAsStream("errorMessages.properties");
Properties properties = new Properties();
try {
properties.load(input);
} catch (IOException e) {
e.printStackTrace();
}
return properties;
}

}

最佳答案

这个问题是因为,我们公司配置了新的服务器,但没有在服务器证书中包含DNS。所以我公司在证书中包含服务器名称。现在它正在工作。

关于javax.net.ssl.SSLException : Certificate for <> doesn't match any of the subject alternative names: [] 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45224718/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com