java如何在信任库中存储公共证书
我正在Spring(Java)中开发一个微服务,它需要对外部Web服务进行身份验证,以便执行一些REST API调用
外部Web服务给了我两个文件,一个安全证书(.cer)和一个PEM文件(.PEM)
现在我正在努力理解,如何在信任库中存储给定的证书?所以当我调用他们的API端点时,我不会得到状态码401
我试着使用cacerts,但可能我不完全理解事情是如何运作的
这就是我现在的处境:
public class SSLLoader
{
private static final Logger log = Logger.getLogger(SSLLoader.class);
public SSLLoader() throws Exception
{
loadSSLCerts();
}
private void loadSSLCerts() throws Exception
{
try
{
SslContextUtils.mergeWithSystem(SSLLoader.class.getResourceAsStream("/sa/cacerts"));
log.info("Loaded SSL from sa/cacerts");
}
catch (Throwable t)
{
throw new Exception("Failed to load SSL certs: " + t.getMessage(), t);
}
}
private InputStream fileToStream(String file) throws Exception
{
File initialFile = new File(file);
InputStream resourceAsStream = new FileInputStream(initialFile);
if (null == resourceAsStream)
{
throw new Exception("File cannot be found - " +file);
}
return resourceAsStream;
}
}
共 (0) 个答案