|
|
@ -1,5 +1,14 @@
|
|
|
|
package kr.xit.core.spring.config.support;
|
|
|
|
package kr.xit.core.spring.config.support;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.security.cert.CertificateException;
|
|
|
|
|
|
|
|
import java.security.cert.X509Certificate;
|
|
|
|
|
|
|
|
import javax.net.ssl.HostnameVerifier;
|
|
|
|
|
|
|
|
import javax.net.ssl.HttpsURLConnection;
|
|
|
|
|
|
|
|
import javax.net.ssl.SSLContext;
|
|
|
|
|
|
|
|
import javax.net.ssl.SSLSession;
|
|
|
|
|
|
|
|
import javax.net.ssl.TrustManager;
|
|
|
|
|
|
|
|
import javax.net.ssl.X509TrustManager;
|
|
|
|
|
|
|
|
import kr.xit.core.exception.BizRuntimeException;
|
|
|
|
import org.apache.catalina.Context;
|
|
|
|
import org.apache.catalina.Context;
|
|
|
|
import org.apache.catalina.connector.Connector;
|
|
|
|
import org.apache.catalina.connector.Connector;
|
|
|
|
import org.apache.tomcat.util.descriptor.web.SecurityCollection;
|
|
|
|
import org.apache.tomcat.util.descriptor.web.SecurityCollection;
|
|
|
@ -31,7 +40,8 @@ import org.springframework.context.annotation.Configuration;
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* </pre>
|
|
|
|
* </pre>
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@ConditionalOnProperty(value = "server.ssl.enabled", havingValue = "true", matchIfMissing = false)
|
|
|
|
//@ConditionalOnProperty(value = "server.ssl.enabled", havingValue = "true", matchIfMissing = false)
|
|
|
|
|
|
|
|
@ConditionalOnProperty(value = "server.http")
|
|
|
|
@Configuration
|
|
|
|
@Configuration
|
|
|
|
public class HttpsConnectorConfig {
|
|
|
|
public class HttpsConnectorConfig {
|
|
|
|
@Value("${server.port}")
|
|
|
|
@Value("${server.port}")
|
|
|
@ -44,6 +54,11 @@ public class HttpsConnectorConfig {
|
|
|
|
public ServletWebServerFactory servletContainer() {
|
|
|
|
public ServletWebServerFactory servletContainer() {
|
|
|
|
|
|
|
|
|
|
|
|
TomcatServletWebServerFactory tomcat = null;
|
|
|
|
TomcatServletWebServerFactory tomcat = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
ignoreSsl();
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
throw BizRuntimeException.create(e.getMessage());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(SSL_REDIRECT){
|
|
|
|
if(SSL_REDIRECT){
|
|
|
|
tomcat = new TomcatServletWebServerFactory() {
|
|
|
|
tomcat = new TomcatServletWebServerFactory() {
|
|
|
@ -72,4 +87,51 @@ public class HttpsConnectorConfig {
|
|
|
|
if(SSL_REDIRECT) connector.setRedirectPort(SSL_PORT);
|
|
|
|
if(SSL_REDIRECT) connector.setRedirectPort(SSL_PORT);
|
|
|
|
return connector;
|
|
|
|
return connector;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void ignoreSsl() throws Exception {
|
|
|
|
|
|
|
|
HostnameVerifier hv = new HostnameVerifier() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public boolean verify(String urlHostName, SSLSession session) {
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
trustAllHttpsCertificates();
|
|
|
|
|
|
|
|
HttpsURLConnection.setDefaultHostnameVerifier(hv);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static void trustAllHttpsCertificates() throws Exception {
|
|
|
|
|
|
|
|
TrustManager[] trustAllCerts = new TrustManager[1];
|
|
|
|
|
|
|
|
TrustManager tm = new miTM();
|
|
|
|
|
|
|
|
trustAllCerts[0] = tm;
|
|
|
|
|
|
|
|
SSLContext sc = SSLContext.getInstance("SSL");
|
|
|
|
|
|
|
|
sc.init(null, trustAllCerts, null);
|
|
|
|
|
|
|
|
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static class miTM implements TrustManager, X509TrustManager {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void checkClientTrusted(X509Certificate[] chain, String authType)
|
|
|
|
|
|
|
|
throws CertificateException {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public X509Certificate[] getAcceptedIssuers() {
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public boolean isServerTrusted(X509Certificate[] certs) {
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public boolean isClientTrusted(X509Certificate[] certs) {
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void checkServerTrusted(X509Certificate[] certs, String authType) throws CertificateException {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|