Skip to content

Commit f3bd1bf

Browse files
committed
add TLS1.2 override in httpclient classes
1 parent eeda4f8 commit f3bd1bf

File tree

7 files changed

+60
-29
lines changed

7 files changed

+60
-29
lines changed

ipp-v3-java-devkit/src/main/java/com/intuit/ipp/interceptors/HTTPBatchClientConnectionInterceptor.java

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
import java.io.ByteArrayInputStream;
1919
import java.io.ByteArrayOutputStream;
20+
import java.io.File;
21+
import java.io.FileInputStream;
2022
import java.io.IOException;
2123
import java.io.InputStream;
2224
import java.io.UnsupportedEncodingException;
@@ -105,15 +107,14 @@ public void execute(List<IntuitMessage> intuitMessages) throws FMSException {
105107
HttpClientBuilder hcBuilder = HttpClients.custom()
106108
.setRetryHandler(handler)
107109
.setDefaultRequestConfig(setTimeout(intuitRequest.getContext()))
108-
.setDefaultCredentialsProvider(setProxyAuthentication());
110+
.setDefaultCredentialsProvider(setProxyAuthentication())
111+
.setSSLSocketFactory(prepareClientSSL());
109112

110113
entitiesManager.reset();
111114
HttpHost proxy = getProxy();
112115

113116
if (proxy != null) {
114-
hcBuilder.setDefaultCredentialsProvider(setProxyAuthentication())
115-
.setProxy(proxy)
116-
.setSSLSocketFactory(prepareClientSSL());
117+
hcBuilder.setProxy(proxy);
117118
}
118119

119120
CloseableHttpClient client = hcBuilder.build();
@@ -174,12 +175,22 @@ private IntuitMessage getFirst(List<IntuitMessage> intuitMessages) throws FMSExc
174175
*/
175176
public SSLConnectionSocketFactory prepareClientSSL() {
176177
try {
177-
KeyStore trustStore = null;
178-
SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(trustStore, new TrustSelfSignedStrategy()).build();
179-
180-
SSLConnectionSocketFactory sslConnectionFactory =
181-
new SSLConnectionSocketFactory(sslContext.getSocketFactory(),
182-
new NoopHostnameVerifier());
178+
String path = Config.getProperty(Config.PROXY_KEYSTORE_PATH);
179+
String pass = Config.getProperty(Config.PROXY_KEYSTORE_PASSWORD);
180+
KeyStore trustStore = null;
181+
if (path != null && pass != null) {
182+
183+
trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
184+
FileInputStream instream = new FileInputStream(new File(path));
185+
try {
186+
trustStore.load(instream, pass.toCharArray());
187+
} finally {
188+
instream.close();
189+
}
190+
}
191+
SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(trustStore, new TrustSelfSignedStrategy()).build();
192+
String tlsVersion = Config.getProperty(Config.TLS_VERSION);
193+
SSLConnectionSocketFactory sslConnectionFactory = new SSLConnectionSocketFactory(sslContext, new String[]{tlsVersion}, null, new NoopHostnameVerifier());
183194
return sslConnectionFactory;
184195
} catch (Exception ex) {
185196
LOG.error("couldn't create httpClient!! {}", ex.getMessage(), ex);

ipp-v3-java-devkit/src/main/java/com/intuit/ipp/interceptors/HTTPClientConnectionInterceptor.java

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
import java.io.ByteArrayInputStream;
1919
import java.io.ByteArrayOutputStream;
20+
import java.io.File;
21+
import java.io.FileInputStream;
2022
import java.io.IOException;
2123
import java.io.InputStream;
2224
import java.io.UnsupportedEncodingException;
@@ -36,6 +38,7 @@
3638
import org.apache.http.auth.UsernamePasswordCredentials;
3739
import org.apache.http.client.ClientProtocolException;
3840
import org.apache.http.client.CredentialsProvider;
41+
import org.apache.http.client.config.CookieSpecs;
3942
import org.apache.http.client.config.RequestConfig;
4043
import org.apache.http.client.methods.CloseableHttpResponse;
4144
import org.apache.http.client.methods.HttpGet;
@@ -51,7 +54,6 @@
5154
import org.apache.http.impl.client.CloseableHttpClient;
5255
import org.apache.http.impl.client.HttpClientBuilder;
5356
import org.apache.http.impl.client.HttpClients;
54-
import org.apache.http.client.config.CookieSpecs;
5557

5658
import com.intuit.ipp.core.Context;
5759
import com.intuit.ipp.exception.CompressionException;
@@ -95,15 +97,14 @@ public void execute(IntuitMessage intuitMessage) throws FMSException {
9597
HttpClientBuilder hcBuilder = HttpClients.custom()
9698
.setRetryHandler(handler)
9799
.setDefaultRequestConfig(setTimeout(intuitRequest.getContext()))
98-
.setDefaultCredentialsProvider(setProxyAuthentication());
100+
.setDefaultCredentialsProvider(setProxyAuthentication())
101+
.setSSLSocketFactory(prepareClientSSL());
99102

100103
// getting proxy from Config file.
101104
HttpHost proxy = getProxy();
102105

103106
if (proxy != null) {
104-
hcBuilder.setDefaultCredentialsProvider(setProxyAuthentication())
105-
.setProxy(proxy)
106-
.setSSLSocketFactory(prepareClientSSL());
107+
hcBuilder.setProxy(proxy);
107108
}
108109
CloseableHttpClient client = hcBuilder.build();
109110

@@ -267,12 +268,23 @@ private IntuitRetryPolicyHandler getRetryHandler() throws FMSException {
267268

268269
public SSLConnectionSocketFactory prepareClientSSL() {
269270
try {
270-
KeyStore trustStore = null;
271+
String path = Config.getProperty(Config.PROXY_KEYSTORE_PATH);
272+
String pass = Config.getProperty(Config.PROXY_KEYSTORE_PASSWORD);
273+
KeyStore trustStore = null;
274+
if (path != null && pass != null) {
275+
276+
trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
277+
FileInputStream instream = new FileInputStream(new File(path));
278+
try {
279+
trustStore.load(instream, pass.toCharArray());
280+
} finally {
281+
instream.close();
282+
}
283+
}
271284
SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(trustStore, new TrustSelfSignedStrategy()).build();
272-
273-
SSLConnectionSocketFactory sslConnectionFactory =
274-
new SSLConnectionSocketFactory(sslContext.getSocketFactory(),
275-
new NoopHostnameVerifier());
285+
String tlsVersion = Config.getProperty(Config.TLS_VERSION);
286+
SSLConnectionSocketFactory sslConnectionFactory = new SSLConnectionSocketFactory(sslContext, new String[]{tlsVersion}, null, new NoopHostnameVerifier());
287+
276288
return sslConnectionFactory;
277289
} catch (Exception ex) {
278290
LOG.error("couldn't create httpClient!! {}", ex.getMessage(), ex);

ipp-v3-java-devkit/src/main/java/com/intuit/ipp/util/Config.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ public final class Config {
175175
* Set to HTTP_URL_CONNECTION if required. Default is Apache HTTP Client if not set. In XML config you can set as <httpTransport>HTTP_URL_CONNECTION</httpTransport>
176176
*/
177177
public static final String HTTP_TRANSPORT = "httpTransport";
178+
179+
public static final String TLS_VERSION = "tls.version";
178180

179181

180182
public static final String BIGDECIMAL_SCALE_SHIFT = "feature.bigDecimalScaleShift";

ipp-v3-java-devkit/src/main/resources/intuit-default-config.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
<entitlementService>https://quickbooks.api.intuit.com/manage</entitlementService>
77
</baseURL>
88

9+
<tls>
10+
<version>TLSv1.2</version>
11+
</tls>
12+
913
<retry>
1014
<mode>fixed</mode>
1115
<fixed>

oauth2-platform-api/src/main/java/com/intuit/oauth2/http/HttpRequestClient.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,14 @@ public HttpRequestClient(ProxyConfig proxyConfig) {
9898
.setDefaultRequestConfig(config)
9999
.setDefaultHeaders(headers)
100100
.setMaxConnPerRoute(10)
101-
.setDefaultCredentialsProvider(setProxyAuthentication(proxyConfig));
101+
.setDefaultCredentialsProvider(setProxyAuthentication(proxyConfig))
102+
.setSSLSocketFactory(prepareClientSSL());
102103

103104
// getting proxy from Config file.
104105
HttpHost proxy = getProxy(proxyConfig);
105106

106107
if (proxy != null) {
107-
hcBuilder.setDefaultCredentialsProvider(setProxyAuthentication(proxyConfig))
108-
.setProxy(proxy)
109-
.setSSLSocketFactory(prepareClientSSL());
108+
hcBuilder.setProxy(proxy);
110109
}
111110
client = hcBuilder.build();
112111
}
@@ -251,9 +250,8 @@ public SSLConnectionSocketFactory prepareClientSSL() {
251250
KeyStore trustStore = null;
252251
SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(trustStore, new TrustSelfSignedStrategy()).build();
253252

254-
SSLConnectionSocketFactory sslConnectionFactory =
255-
new SSLConnectionSocketFactory(sslContext.getSocketFactory(),
256-
new NoopHostnameVerifier());
253+
String tlsVersion = PropertiesConfig.getInstance().getProperty("TLS_VERSION");
254+
SSLConnectionSocketFactory sslConnectionFactory = new SSLConnectionSocketFactory(sslContext, new String[]{tlsVersion}, null, new NoopHostnameVerifier());
257255
return sslConnectionFactory;
258256
} catch (Exception ex) {
259257
logger.error("couldn't create httpClient!! {}", ex.getMessage(), ex);

oauth2-platform-api/src/main/resources/oauthclient.properties

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ ADDRESS=address
3030
EMAIL=email
3131

3232
#Version
33-
version=4.0.7
33+
version=4.0.8
3434

3535
#MIGRATION SERVICE URL
3636
OAUTH_MIGRATION_URL_PRODUCTION=https://developer.api.intuit.com/v2/oauth2/tokens/migrate
@@ -39,3 +39,5 @@ OAUTH_MIGRATION_URL_SANDBOX=https://developer-sandbox.api.intuit.com/v2/oauth2/t
3939
#REDIRECT URL
4040
REDIRECT_URL=https://developer.intuit.com/v2/OAuth2Playground/RedirectUrl
4141

42+
#TLS Version
43+
TLS_VERSION=TLSv1.2

oauth2-platform-api/src/test/resources/oauthclient.properties

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ ADDRESS=address
3030
EMAIL=email
3131

3232
#Version
33-
version=4.0.7
33+
version=4.0.8
3434

3535
#MIGRATION SERVICE URL
3636
OAUTH_MIGRATION_URL_PRODUCTION=https://developer.api.intuit.com/v2/oauth2/tokens/migrate
@@ -39,3 +39,5 @@ OAUTH_MIGRATION_URL_SANDBOX=https://developer-sandbox.api.intuit.com/v2/oauth2/t
3939
#REDIRECT URL
4040
REDIRECT_URL=https://developer.intuit.com/v2/OAuth2Playground/RedirectUrl
4141

42+
#TLS Version
43+
TLS_VERSION=TLSv1.2

0 commit comments

Comments
 (0)