mirror of
https://gitee.com/egzosn/pay-java-parent.git
synced 2026-05-08 12:06:07 +08:00
http配置加入ssl证书输入流
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package com.egzosn.pay.common.http;
|
||||
|
||||
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* HTTP 配置
|
||||
* @author: egan
|
||||
@@ -34,8 +36,9 @@ public class HttpConfigStorage {
|
||||
|
||||
/**
|
||||
* https请求所需的证书(PKCS12)
|
||||
* 证书内容
|
||||
*/
|
||||
private String keystore;
|
||||
private Object keystore;
|
||||
/**
|
||||
* 证书对应的密码
|
||||
*/
|
||||
@@ -144,7 +147,7 @@ public class HttpConfigStorage {
|
||||
*/
|
||||
@Deprecated
|
||||
public String getKeystorePath() {
|
||||
return keystore;
|
||||
return (String) keystore;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -178,17 +181,47 @@ public class HttpConfigStorage {
|
||||
* 获取证书信息
|
||||
* @return 证书信息 根据 {@link #isPath()}进行区别地址与信息串
|
||||
*/
|
||||
public String getKeystore() {
|
||||
return keystore;
|
||||
public InputStream getKeystoreInputStream() throws FileNotFoundException, UnsupportedEncodingException {
|
||||
if (null == keystore){
|
||||
return null;
|
||||
}
|
||||
if(isPath()){
|
||||
return new FileInputStream(new File(getKeystoreStr()));
|
||||
}
|
||||
if(this.keystore instanceof String){
|
||||
return new ByteArrayInputStream(getKeystoreStr().getBytes("ISO-8859-1"));
|
||||
}
|
||||
return (InputStream) keystore;
|
||||
}
|
||||
/**
|
||||
* 获取证书信息
|
||||
* @return 证书信息 根据 {@link #isPath()}进行区别地址与信息串
|
||||
*/
|
||||
public Object getKeystore() {
|
||||
return keystore;
|
||||
}
|
||||
/**
|
||||
* 获取证书信息 证书地址
|
||||
* @return 证书信息 根据 {@link #isPath()}进行区别地址与信息串
|
||||
*/
|
||||
public String getKeystoreStr() {
|
||||
return (String) keystore;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置证书
|
||||
* @param keystore 证书信息
|
||||
* 设置证书字符串信息或证书绝对地址
|
||||
* @param keystore 证书信息字符串信息或证书绝对地址
|
||||
*/
|
||||
public void setKeystore(String keystore) {
|
||||
this.keystore = keystore;
|
||||
}
|
||||
/**
|
||||
* 设置证书字符串信息输入流
|
||||
* @param keystore 证书信息 输入流
|
||||
*/
|
||||
public void setKeystore(InputStream keystore) {
|
||||
this.keystore = keystore;
|
||||
}
|
||||
|
||||
/**
|
||||
* 证书对应的密码
|
||||
|
||||
@@ -103,7 +103,7 @@ public class HttpRequestTemplate {
|
||||
*/
|
||||
public SSLConnectionSocketFactory createSSL( HttpConfigStorage configStorage){
|
||||
|
||||
if (StringUtils.isEmpty(configStorage.getKeystore())){
|
||||
if (null == configStorage.getKeystore()){
|
||||
try {
|
||||
return new SSLConnectionSocketFactory(SSLContext.getDefault());
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
@@ -112,7 +112,7 @@ public class HttpRequestTemplate {
|
||||
}
|
||||
|
||||
//读取本机存放的PKCS12证书文件
|
||||
try(InputStream instream = configStorage.isPath() ? new FileInputStream(new File(configStorage.getKeystore())) : new ByteArrayInputStream(configStorage.getKeystore().getBytes("ISO-8859-1"))){
|
||||
try(InputStream instream = configStorage.getKeystoreInputStream()){
|
||||
//指定读取证书格式为PKCS12
|
||||
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user