Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Disable SNI when SSL check is disabled #25

Merged
merged 4 commits into from
Jun 25, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions zanata-cli/etc/scripts/zanata-cli
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash -e
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
PROJ_DIR=$SCRIPT_DIR/../..
exec mvn -f $PROJ_DIR/pom.xml -q exec:java -Dexec.args="$*"
2 changes: 0 additions & 2 deletions zanata-cli/etc/scripts/zanataj

This file was deleted.

51 changes: 16 additions & 35 deletions zanata-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,31 @@
<build>
<plugins>
<plugin>
<!-- See the script etc/zanataj -->
<!-- See the script etc/zanata-cli -->
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>zanata-cli</id>
<goals>
<goal>java</goal>
</goals>
</execution>
<execution>
<id>generate-zanata-cli-completion</id>
<phase>test</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>org.zanata.client.BashCompletionGenerator</mainClass>
<arguments>
<argument>${project.build.directory}/zanata-cli-completion</argument>
</arguments>
<classpathScope>test</classpathScope>
</configuration>
</execution>
</executions>
<configuration>
<mainClass>org.zanata.client.ZanataClient</mainClass>
Expand Down Expand Up @@ -92,40 +107,6 @@
</plugins>
</build>

<profiles>
<profile>
<id>bash</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>org.zanata.client.BashCompletionGenerator</mainClass>
<arguments>
<argument>${project.build.directory}/zanata-cli-completion</argument>
</arguments>
<classpathScope>test</classpathScope>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>


<dependencies>
<dependency>
<groupId>args4j</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,28 +137,35 @@ private static ClientExecutor createClientExecutor(boolean sslCertDisabled) {

sslContext.init(null, trustAllCerts, new SecureRandom());

SSLSocketFactory factory = new SSLSocketFactory(sslContext) {
@Override
public Socket connectSocket(
int connectTimeout,
Socket socket,
HttpHost host,
InetSocketAddress remoteAddress,
InetSocketAddress localAddress,
HttpContext context) throws IOException,
ConnectTimeoutException {
if (socket instanceof SSLSocket) {
try {
PropertyUtils.setProperty(socket, "host",
host.getHostName());
} catch (Exception ex) {
log.warn("Unable to enable SNI; you may have trouble connecting to some secure hosts. Please ensure that you are running Java 1.7 or later.");
SSLSocketFactory factory;
if (sslCertDisabled) {
// avoid triggering the problem described here:
// https://stackoverflow.com/questions/7615645/ssl-handshake-alert-unrecognized-name-error-since-upgrade-to-java-1-7-0
factory = new SSLSocketFactory(sslContext);
} else {
factory = new SSLSocketFactory(sslContext) {
@Override
public Socket connectSocket(
int connectTimeout,
Socket socket,
HttpHost host,
InetSocketAddress remoteAddress,
InetSocketAddress localAddress,
HttpContext context) throws IOException {
if (socket instanceof SSLSocket) {
try {
PropertyUtils.setProperty(socket, "host",
host.getHostName());
} catch (Exception ex) {
log.warn(
"Unable to enable SNI; you may have trouble connecting to some secure hosts. Please ensure that you are running Java 1.7 or later.");
}
}
return super.connectSocket(connectTimeout, socket, host,
remoteAddress, localAddress, context);
}
return super.connectSocket(connectTimeout, socket, host, remoteAddress,
localAddress, context);
}
};
};
}

HttpClient client = new DefaultHttpClient();

Expand Down