Skip to content

Commit a2b83b4

Browse files
author
Matthew Sackman
committed
merge in from bug 19356
2 parents e2db34d + b491d63 commit a2b83b4

File tree

9 files changed

+547
-122
lines changed

9 files changed

+547
-122
lines changed

build.xml

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,64 @@
106106
</fileset>
107107
</javadoc>
108108
</target>
109-
109+
110+
<target name="detect-ssl">
111+
<property environment="env"/>
112+
<property name="SSL_CERTS_DIR" value="${env.SSL_CERTS_DIR}"/>
113+
<available property="SSL_AVAILABLE" file="${SSL_CERTS_DIR}/client"/>
114+
<property name="CLIENT_KEYSTORE_PHRASE" value="bunnies"/>
115+
<property environment="env"/>
116+
<property name="SSL_P12_PASSWORD" value="${env.PASSWORD}"/>
117+
</target>
118+
119+
<target name="make-client-keystore" if="SSL_AVAILABLE" depends="detect-ssl">
120+
<exec executable="mktemp" outputproperty="CLIENT_KEYSTORE" failonerror="true" osfamily="unix">
121+
<arg value="-u"/>
122+
</exec>
123+
<exec executable="keytool" failonerror="true" osfamily="unix">
124+
<arg line="-import"/>
125+
<arg value="-alias"/>
126+
<arg value="server1"/>
127+
<arg value="-file"/>
128+
<arg value="${SSL_CERTS_DIR}/testca/cacert.pem"/>
129+
<arg value="-keystore"/>
130+
<arg value="${CLIENT_KEYSTORE}"/>
131+
<arg value="-noprompt"/>
132+
<arg value="-storepass"/>
133+
<arg value="${CLIENT_KEYSTORE_PHRASE}"/>
134+
</exec>
135+
<exec executable="mktemp" outputproperty="CLIENT_KEYSTORE_EMPTY" failonerror="true" osfamily="unix">
136+
<arg value="-u"/>
137+
</exec>
138+
<!-- can't create an empty keystore, so add cert in and then delete it! -->
139+
<exec executable="keytool" failonerror="true" osfamily="unix">
140+
<arg line="-import"/>
141+
<arg value="-alias"/>
142+
<arg value="server1"/>
143+
<arg value="-file"/>
144+
<arg value="${SSL_CERTS_DIR}/testca/cacert.pem"/>
145+
<arg value="-keystore"/>
146+
<arg value="${CLIENT_KEYSTORE_EMPTY}"/>
147+
<arg value="-noprompt"/>
148+
<arg value="-storepass"/>
149+
<arg value="${CLIENT_KEYSTORE_PHRASE}"/>
150+
</exec>
151+
<exec executable="keytool" failonerror="true" osfamily="unix">
152+
<arg line="-delete"/>
153+
<arg value="-alias"/>
154+
<arg value="server1"/>
155+
<arg value="-keystore"/>
156+
<arg value="${CLIENT_KEYSTORE_EMPTY}"/>
157+
<arg value="-storepass"/>
158+
<arg value="${CLIENT_KEYSTORE_PHRASE}"/>
159+
</exec>
160+
</target>
161+
162+
<target name="remove-client-keystore" if="SSL_AVAILABLE">
163+
<delete file="${CLIENT_KEYSTORE}" failonerror="false"/>
164+
<delete file="${CLIENT_KEYSTORE_EMPTY}" failonerror="false"/>
165+
</target>
166+
110167
<target name="test-prepare">
111168
<property name="haltOnFailureJunit" value="yes" />
112169
<property name="haltOnFailureJava" value="true" />
@@ -261,7 +318,7 @@
261318
</fail>
262319
</target>
263320

264-
<target name="test-suite-run" depends="test, test-persister-restart, test-functional, test-main-silent"/>
321+
<target name="test-suite-run" depends="test, test-ssl, test-persister-restart, test-functional, test-main-silent"/>
265322

266323
<target name="test" depends="test-build">
267324
<junit printSummary="withOutAndErr"
@@ -276,6 +333,26 @@
276333
</junit>
277334
</target>
278335

336+
<target name="test-ssl" depends="test-build, make-client-keystore" if="SSL_AVAILABLE">
337+
<junit printSummary="withOutAndErr"
338+
haltOnFailure="${haltOnFailureJunit}"
339+
failureproperty="test.failure"
340+
fork="yes">
341+
<classpath refid="test.classpath"/>
342+
<jvmarg value="-Dkeystore.path=${CLIENT_KEYSTORE}"/>
343+
<jvmarg value="-Dkeystore.empty.path=${CLIENT_KEYSTORE_EMPTY}"/>
344+
<jvmarg value="-Dkeystore.passwd=${CLIENT_KEYSTORE_PHRASE}"/>
345+
346+
<jvmarg value="-Dp12.path=${SSL_CERTS_DIR}/client/keycert.p12"/>
347+
<jvmarg value="-Dp12.passwd=${SSL_P12_PASSWORD}"/>
348+
349+
<formatter type="plain"/>
350+
<formatter type="xml"/>
351+
<test todir="${build.out}" name="com.rabbitmq.client.test.ssl.SSLTests"/>
352+
</junit>
353+
<antcall target="remove-client-keystore"/>
354+
</target>
355+
279356
<target name="test-functional" depends="test-build">
280357
<junit printSummary="withOutAndErr"
281358
haltOnFailure="${haltOnFailureJunit}"

src/com/rabbitmq/client/ConnectionFactory.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public class ConnectionFactory {
5555
* Holds the SocketFactory used to manufacture outbound sockets.
5656
*/
5757
private SocketFactory _factory = SocketFactory.getDefault();
58-
58+
5959
/**
6060
* Instantiate a ConnectionFactory with a default set of parameters.
6161
*/
@@ -131,6 +131,17 @@ public void useSslProtocol(String protocol, TrustManager trustManager)
131131
setSocketFactory(c.getSocketFactory());
132132
}
133133

134+
/**
135+
* Convenience method for setting up an SSL socket factory.
136+
* Pass in an initialized SSLContext.
137+
*
138+
* @param context An initialized SSLContext
139+
*/
140+
public void useSslProtocol(SSLContext context)
141+
{
142+
setSocketFactory(context.getSocketFactory());
143+
}
144+
134145
/**
135146
* The default SSL protocol (currently "SSLv3").
136147
*/
@@ -162,7 +173,10 @@ private Connection newConnection(Address[] addrs,
162173
redirectCount = 0;
163174
boolean allowRedirects = redirectCount < maxRedirects;
164175
try {
165-
return new AMQConnection(_params, !allowRedirects, frameHandler);
176+
AMQConnection conn = new AMQConnection(_params,
177+
frameHandler);
178+
conn.start(!allowRedirects);
179+
return conn;
166180
} catch (RedirectException e) {
167181
if (!allowRedirects) {
168182
//this should never happen with a well-behaved server

0 commit comments

Comments
 (0)