Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 9410B200C3F for ; Wed, 22 Mar 2017 14:07:54 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 929C5160B86; Wed, 22 Mar 2017 13:07:54 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id B3E4F160B83 for ; Wed, 22 Mar 2017 14:07:53 +0100 (CET) Received: (qmail 54360 invoked by uid 500); 22 Mar 2017 13:07:52 -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 54351 invoked by uid 99); 22 Mar 2017 13:07:52 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 22 Mar 2017 13:07:52 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id B2041DFE1D; Wed, 22 Mar 2017 13:07:52 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: siano@apache.org To: commits@camel.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: camel git commit: CAMEL-11047: STARTTLS broken with camel-mail Date: Wed, 22 Mar 2017 13:07:52 +0000 (UTC) archived-at: Wed, 22 Mar 2017 13:07:54 -0000 Repository: camel Updated Branches: refs/heads/camel-2.18.x ae529584f -> 82dec08fc CAMEL-11047: STARTTLS broken with camel-mail Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/82dec08f Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/82dec08f Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/82dec08f Branch: refs/heads/camel-2.18.x Commit: 82dec08fc754453218e4651b90c7969c316c2551 Parents: ae52958 Author: Stephan Siano Authored: Wed Mar 22 13:30:19 2017 +0100 Committer: Stephan Siano Committed: Wed Mar 22 14:07:10 2017 +0100 ---------------------------------------------------------------------- .../camel/component/mail/MailConfiguration.java | 35 ++++++++++++-------- .../component/mail/MailEndpointTlsTest.java | 15 ++++----- 2 files changed, 28 insertions(+), 22 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/82dec08f/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java ---------------------------------------------------------------------- diff --git a/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java b/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java index 8fee016..8a708f9 100644 --- a/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java +++ b/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java @@ -244,27 +244,38 @@ public class MailConfiguration implements Cloneable { properties.put("javax.net.debug", "all"); } - if (sslContextParameters != null && (isSecureProtocol() || isStartTlsEnabled())) { - SSLContext sslContext; - try { - sslContext = sslContextParameters.createSSLContext(); - } catch (Exception e) { - throw new RuntimeCamelException("Error initializing SSLContext.", e); - } - properties.put("mail." + protocol + ".socketFactory", sslContext.getSocketFactory()); + if (sslContextParameters != null && isSecureProtocol()) { + properties.put("mail." + protocol + ".socketFactory", createSSLContext().getSocketFactory()); properties.put("mail." + protocol + ".socketFactory.fallback", "false"); properties.put("mail." + protocol + ".socketFactory.port", "" + port); } - if (dummyTrustManager && (isSecureProtocol() || isStartTlsEnabled())) { + if (sslContextParameters != null && isStartTlsEnabled()) { + properties.put("mail." + protocol + ".ssl.socketFactory", createSSLContext().getSocketFactory()); + properties.put("mail." + protocol + ".ssl.socketFactory.port", "" + port); + } + if (dummyTrustManager && isSecureProtocol()) { // set the custom SSL properties properties.put("mail." + protocol + ".socketFactory.class", "org.apache.camel.component.mail.DummySSLSocketFactory"); properties.put("mail." + protocol + ".socketFactory.fallback", "false"); properties.put("mail." + protocol + ".socketFactory.port", "" + port); } + if (dummyTrustManager && isStartTlsEnabled()) { + // set the custom SSL properties + properties.put("mail." + protocol + ".ssl.socketFactory.class", "org.apache.camel.component.mail.DummySSLSocketFactory"); + properties.put("mail." + protocol + ".ssl.socketFactory.port", "" + port); + } return properties; } + private SSLContext createSSLContext() { + try { + return sslContextParameters.createSSLContext(); + } catch (Exception e) { + throw new RuntimeCamelException("Error initializing SSLContext.", e); + } + } + /** * Is the used protocol to be secure or not */ @@ -275,10 +286,8 @@ public class MailConfiguration implements Cloneable { public boolean isStartTlsEnabled() { if (additionalJavaMailProperties != null) { - return ObjectHelper.equal( - additionalJavaMailProperties.getProperty("mail." + protocol + ".starttls.enable"), - "true", - true); + return ObjectHelper.equal(additionalJavaMailProperties.getProperty("mail." + protocol + ".starttls.enable"), "true", true) + || ObjectHelper.equal(additionalJavaMailProperties.getProperty("mail." + protocol + ".starttls.required"), "true", true); } return false; http://git-wip-us.apache.org/repos/asf/camel/blob/82dec08f/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailEndpointTlsTest.java ---------------------------------------------------------------------- diff --git a/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailEndpointTlsTest.java b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailEndpointTlsTest.java index fcd70e1..9e6782a 100644 --- a/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailEndpointTlsTest.java +++ b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailEndpointTlsTest.java @@ -62,9 +62,8 @@ public class MailEndpointTlsTest extends CamelTestSupport { assertTrue(cfg.isStartTlsEnabled()); Properties javaMailProperties = cfg.createJavaMailSender().getJavaMailProperties(); - assertNull(javaMailProperties.get("mail." + protocol + ".socketFactory")); - assertNull(javaMailProperties.get("mail." + protocol + ".socketFactory.fallback")); - assertNull(javaMailProperties.get("mail." + protocol + ".socketFactory.port")); + assertNull(javaMailProperties.get("mail." + protocol + ".ssl.socketFactory")); + assertNull(javaMailProperties.get("mail." + protocol + ".ssl.socketFactory.port")); } @Test @@ -111,9 +110,8 @@ public class MailEndpointTlsTest extends CamelTestSupport { assertTrue(cfg.isStartTlsEnabled()); Properties javaMailProperties = cfg.createJavaMailSender().getJavaMailProperties(); - assertNotNull(javaMailProperties.get("mail." + protocol + ".socketFactory")); - assertNotNull(javaMailProperties.get("mail." + protocol + ".socketFactory.fallback")); - assertNotNull(javaMailProperties.get("mail." + protocol + ".socketFactory.port")); + assertNotNull(javaMailProperties.get("mail." + protocol + ".ssl.socketFactory")); + assertNotNull(javaMailProperties.get("mail." + protocol + ".ssl.socketFactory.port")); } @Test @@ -133,8 +131,7 @@ public class MailEndpointTlsTest extends CamelTestSupport { assertTrue(cfg.isStartTlsEnabled()); Properties javaMailProperties = cfg.createJavaMailSender().getJavaMailProperties(); - assertNotNull(javaMailProperties.get("mail." + protocol + ".socketFactory.class")); - assertNotNull(javaMailProperties.get("mail." + protocol + ".socketFactory.fallback")); - assertNotNull(javaMailProperties.get("mail." + protocol + ".socketFactory.port")); + assertNotNull(javaMailProperties.get("mail." + protocol + ".ssl.socketFactory.class")); + assertNotNull(javaMailProperties.get("mail." + protocol + ".ssl.socketFactory.port")); } }