Return-Path: X-Original-To: apmail-camel-commits-archive@www.apache.org Delivered-To: apmail-camel-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id A82221783A for ; Fri, 24 Oct 2014 21:42:58 +0000 (UTC) Received: (qmail 96577 invoked by uid 500); 24 Oct 2014 21:42:58 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 96507 invoked by uid 500); 24 Oct 2014 21:42:58 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 96497 invoked by uid 99); 24 Oct 2014 21:42:58 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 24 Oct 2014 21:42:58 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 2F82F81266E; Fri, 24 Oct 2014 21:42:58 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: dhirajsb@apache.org To: commits@camel.apache.org Date: Fri, 24 Oct 2014 21:43:00 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [3/5] git commit: CAMEL-7954: Updated Camel-box to use SSLContextParameters CAMEL-7954: Updated Camel-box to use SSLContextParameters Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/bfa2388b Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/bfa2388b Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/bfa2388b Branch: refs/heads/camel-2.14.x Commit: bfa2388b3bab07e0110faf7846af2bd44dda99b4 Parents: 90f42ed Author: Dhiraj Bokde Authored: Fri Oct 24 13:32:01 2014 -0700 Committer: Dhiraj Bokde Committed: Fri Oct 24 14:42:28 2014 -0700 ---------------------------------------------------------------------- .../camel/component/box/BoxConfiguration.java | 12 +++++++++++ .../component/box/internal/BoxClientHelper.java | 22 ++++++++++++++++++++ .../component/box/internal/LoginAuthFlowUI.java | 15 +++++++++++++ 3 files changed, 49 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/bfa2388b/components/camel-box/src/main/java/org/apache/camel/component/box/BoxConfiguration.java ---------------------------------------------------------------------- diff --git a/components/camel-box/src/main/java/org/apache/camel/component/box/BoxConfiguration.java b/components/camel-box/src/main/java/org/apache/camel/component/box/BoxConfiguration.java index 0fdac6d..2fabf7f 100644 --- a/components/camel-box/src/main/java/org/apache/camel/component/box/BoxConfiguration.java +++ b/components/camel-box/src/main/java/org/apache/camel/component/box/BoxConfiguration.java @@ -24,6 +24,7 @@ import com.box.boxjavalibv2.authorization.IAuthSecureStorage; import com.box.boxjavalibv2.authorization.OAuthRefreshListener; import org.apache.camel.spi.UriParam; import org.apache.camel.spi.UriParams; +import org.apache.camel.util.jsse.SSLContextParameters; /** * Component configuration for Box component. @@ -67,6 +68,9 @@ public class BoxConfiguration { @UriParam private Map httpParams; + @UriParam + private SSLContextParameters sslContextParameters; + /** * Box.com login timeout in seconds, defaults to 30. */ @@ -169,6 +173,14 @@ public class BoxConfiguration { this.httpParams = httpParams; } + public SSLContextParameters getSslContextParameters() { + return sslContextParameters; + } + + public void setSslContextParameters(SSLContextParameters sslContextParameters) { + this.sslContextParameters = sslContextParameters; + } + public int getLoginTimeout() { return loginTimeout; } http://git-wip-us.apache.org/repos/asf/camel/blob/bfa2388b/components/camel-box/src/main/java/org/apache/camel/component/box/internal/BoxClientHelper.java ---------------------------------------------------------------------- diff --git a/components/camel-box/src/main/java/org/apache/camel/component/box/internal/BoxClientHelper.java b/components/camel-box/src/main/java/org/apache/camel/component/box/internal/BoxClientHelper.java index 0f94aec..54c3e49 100644 --- a/components/camel-box/src/main/java/org/apache/camel/component/box/internal/BoxClientHelper.java +++ b/components/camel-box/src/main/java/org/apache/camel/component/box/internal/BoxClientHelper.java @@ -16,6 +16,8 @@ */ package org.apache.camel.component.box.internal; +import java.io.IOException; +import java.security.GeneralSecurityException; import java.util.Map; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @@ -29,11 +31,16 @@ import com.box.boxjavalibv2.exceptions.AuthFatalFailureException; import com.box.boxjavalibv2.exceptions.BoxServerException; import com.box.restclientv2.IBoxRESTClient; import com.box.restclientv2.exceptions.BoxRestException; + import org.apache.camel.RuntimeCamelException; import org.apache.camel.component.box.BoxConfiguration; import org.apache.camel.util.ObjectHelper; +import org.apache.camel.util.jsse.SSLContextParameters; import org.apache.http.client.HttpClient; import org.apache.http.conn.ClientConnectionManager; +import org.apache.http.conn.scheme.Scheme; +import org.apache.http.conn.scheme.SchemeRegistry; +import org.apache.http.conn.ssl.SSLSocketFactory; import org.apache.http.params.HttpParams; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -79,6 +86,21 @@ public final class BoxClientHelper { public HttpClient getRawHttpClient() { final HttpClient httpClient = super.getRawHttpClient(); clientConnectionManager[0] = httpClient.getConnectionManager(); + final SchemeRegistry schemeRegistry = clientConnectionManager[0].getSchemeRegistry(); + SSLContextParameters sslContextParameters = configuration.getSslContextParameters(); + if (sslContextParameters == null) { + sslContextParameters = new SSLContextParameters(); + } + try { + final SSLSocketFactory socketFactory = new SSLSocketFactory( + sslContextParameters.createSSLContext(), + SSLSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); + schemeRegistry.register(new Scheme("https", socketFactory, 443)); + } catch (GeneralSecurityException e) { + throw ObjectHelper.wrapRuntimeCamelException(e); + } catch (IOException e) { + throw ObjectHelper.wrapRuntimeCamelException(e); + } // set custom HTTP params final Map configParams = configuration.getHttpParams(); http://git-wip-us.apache.org/repos/asf/camel/blob/bfa2388b/components/camel-box/src/main/java/org/apache/camel/component/box/internal/LoginAuthFlowUI.java ---------------------------------------------------------------------- diff --git a/components/camel-box/src/main/java/org/apache/camel/component/box/internal/LoginAuthFlowUI.java b/components/camel-box/src/main/java/org/apache/camel/component/box/internal/LoginAuthFlowUI.java index 568d27c..0568ad9 100644 --- a/components/camel-box/src/main/java/org/apache/camel/component/box/internal/LoginAuthFlowUI.java +++ b/components/camel-box/src/main/java/org/apache/camel/component/box/internal/LoginAuthFlowUI.java @@ -16,12 +16,16 @@ */ package org.apache.camel.component.box.internal; +import java.io.IOException; +import java.security.GeneralSecurityException; import java.security.SecureRandom; import java.util.HashMap; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; +import javax.net.ssl.SSLContext; + import com.box.boxjavalibv2.BoxClient; import com.box.boxjavalibv2.authorization.IAuthFlowListener; import com.box.boxjavalibv2.authorization.IAuthFlowUI; @@ -43,6 +47,8 @@ import com.gargoylesoftware.htmlunit.html.HtmlPasswordInput; import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput; import com.gargoylesoftware.htmlunit.html.HtmlTextInput; import org.apache.camel.component.box.BoxConfiguration; +import org.apache.camel.util.ObjectHelper; +import org.apache.camel.util.jsse.SSLContextParameters; import org.apache.http.HttpHost; import org.apache.http.HttpStatus; import org.apache.http.conn.params.ConnRoutePNames; @@ -81,6 +87,15 @@ public final class LoginAuthFlowUI implements IAuthFlowUI { options.setThrowExceptionOnFailingStatusCode(true); options.setThrowExceptionOnScriptError(true); options.setPrintContentOnFailingStatusCode(LOG.isDebugEnabled()); + try { + // use default SSP to create supported non-SSL protocols list + final SSLContext sslContext = new SSLContextParameters().createSSLContext(); + options.setSSLClientProtocols(sslContext.createSSLEngine().getEnabledProtocols()); + } catch (GeneralSecurityException e) { + throw ObjectHelper.wrapRuntimeCamelException(e); + } catch (IOException e) { + throw ObjectHelper.wrapRuntimeCamelException(e); + } // add HTTP proxy if set final Map httpParams = configuration.getHttpParams();