You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ho...@apache.org on 2016/05/06 22:32:49 UTC
[1/2] lucene-solr:master: SOLR-9068 / SOLR-5776: Alternate (psuedo
random) NullSecureRandom for Constants.SUN_OS
Repository: lucene-solr
Updated Branches:
refs/heads/branch_6x 4d15b9fa0 -> 7e2f9f506
refs/heads/master 26027259a -> a5586d29b
SOLR-9068 / SOLR-5776: Alternate (psuedo random) NullSecureRandom for Constants.SUN_OS
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/a5586d29
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/a5586d29
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/a5586d29
Branch: refs/heads/master
Commit: a5586d29b23f7d032e6d8f0cf8758e56b09e0208
Parents: 2602725
Author: Chris Hostetter <ho...@apache.org>
Authored: Fri May 6 15:17:11 2016 -0700
Committer: Chris Hostetter <ho...@apache.org>
Committed: Fri May 6 15:17:11 2016 -0700
----------------------------------------------------------------------
.../org/apache/solr/util/SSLTestConfig.java | 85 ++++++++++++++++----
1 file changed, 71 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/a5586d29/solr/test-framework/src/java/org/apache/solr/util/SSLTestConfig.java
----------------------------------------------------------------------
diff --git a/solr/test-framework/src/java/org/apache/solr/util/SSLTestConfig.java b/solr/test-framework/src/java/org/apache/solr/util/SSLTestConfig.java
index 6235aff..16981ce 100644
--- a/solr/test-framework/src/java/org/apache/solr/util/SSLTestConfig.java
+++ b/solr/test-framework/src/java/org/apache/solr/util/SSLTestConfig.java
@@ -17,6 +17,7 @@
package org.apache.solr.util;
import java.io.File;
+import java.util.Random;
import java.security.KeyManagementException;
import java.security.KeyStore;
import java.security.KeyStoreException;
@@ -43,6 +44,8 @@ import org.apache.solr.client.solrj.impl.HttpClientUtil;
import org.apache.solr.client.solrj.impl.HttpClientUtil.SchemaRegistryProvider;
import org.apache.solr.client.solrj.impl.SolrHttpClientBuilder;
+import org.apache.lucene.util.Constants;
+
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.util.security.CertificateUtils;
import org.eclipse.jetty.util.ssl.SslContextFactory;
@@ -266,33 +269,87 @@ public class SSLTestConfig extends SSLConfig {
* Tests do not need secure SSL.
*/
private static class NullSecureRandom extends SecureRandom {
- public static final SecureRandom INSTANCE = new NullSecureRandom();
+
+ /**
+ * The one and only instance that should be used, specific impl may vary based on platform
+ * @see Constants#SUN_OS
+ * @see <a href="https://issues.apache.org/jira/browse/SOLR-9068">SOLR-9068</a>
+ */
+ public static final SecureRandom INSTANCE = Constants.SUN_OS
+ ? new NullSecureRandom(NullSecureRandomSpi.PSUEDO_RAND_INSTANCE)
+ : new NullSecureRandom(NullSecureRandomSpi.NULL_INSTANCE);
+
+ /** A source of psuedo random data if needed */
+ private static final Random RAND = new Random(42);
- /** SPI Used to init all instances */
- private static final SecureRandomSpi NULL_SPI = new SecureRandomSpi() {
- /** NOOP: returns new uninitialized byte[] */
+ /** SPI base class for all NullSecureRandom instances */
+ private static class NullSecureRandomSpi extends SecureRandomSpi {
+ private NullSecureRandomSpi() {
+ /* NOOP */
+ }
+ /**
+ * Helper method that can be used to fill an array with non-zero data.
+ * Default impl is No-Op
+ */
+ public byte[] fillData(byte[] data) {
+ return data; /* NOOP */
+ }
+ /** returns a new byte[] filled with static data */
+ @Override
public byte[] engineGenerateSeed(int numBytes) {
- return new byte[numBytes];
+ return fillData(new byte[numBytes]);
+ }
+ /** fills the byte[] with static data */
+ @Override
+ public void engineNextBytes(byte[] bytes) {
+ fillData(bytes);
}
/** NOOP */
- public void engineNextBytes(byte[] bytes) { /* NOOP */ }
- /** NOOP */
+ @Override
public void engineSetSeed(byte[] seed) { /* NOOP */ }
- };
+
+ /** Instance to use on platforms w/SSLEngines that work fine when SecureRandom returns constant bytes */
+ public static final NullSecureRandomSpi NULL_INSTANCE = new NullSecureRandomSpi();
+
+ /**
+ * Instance to use on platforms that need at least psuedo-random data for the SSLEngine to not break
+ * (Attempted workarround of Solaris SSL Padding bug: SOLR-9068)
+ */
+ public static final NullSecureRandomSpi PSUEDO_RAND_INSTANCE = new NullSecureRandomSpi() {
+ /**
+ * Fill with Psuedo-Random data.
+ * (Attempted workarround of Solaris SSL Padding bug: SOLR-9068)
+ */
+ @Override
+ public byte[] fillData(byte[] data) {
+ RAND.nextBytes(data);
+ return data;
+ }
+ };
+ }
- private NullSecureRandom() {
- super(NULL_SPI, null) ;
+ private NullSecureRandom(NullSecureRandomSpi spi) {
+ super(spi, null);
+ this.spi = spi;
}
- /** NOOP: returns new uninitialized byte[] */
+ private NullSecureRandomSpi spi;
+
+ /** fills a new byte[] with data from SPI */
+ @Override
public byte[] generateSeed(int numBytes) {
- return new byte[numBytes];
+ return spi.fillData(new byte[numBytes]);
+ }
+ /** fills the byte[] with data from SPI */
+ @Override
+ synchronized public void nextBytes(byte[] bytes) {
+ spi.fillData(bytes);
}
/** NOOP */
- synchronized public void nextBytes(byte[] bytes) { /* NOOP */ }
- /** NOOP */
+ @Override
synchronized public void setSeed(byte[] seed) { /* NOOP */ }
/** NOOP */
+ @Override
synchronized public void setSeed(long seed) { /* NOOP */ }
}
[2/2] lucene-solr:branch_6x: SOLR-9068 / SOLR-5776: Alternate (psuedo
random) NullSecureRandom for Constants.SUN_OS
Posted by ho...@apache.org.
SOLR-9068 / SOLR-5776: Alternate (psuedo random) NullSecureRandom for Constants.SUN_OS
(cherry picked from commit a5586d29b23f7d032e6d8f0cf8758e56b09e0208)
Conflicts:
solr/test-framework/src/java/org/apache/solr/util/SSLTestConfig.java
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/7e2f9f50
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/7e2f9f50
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/7e2f9f50
Branch: refs/heads/branch_6x
Commit: 7e2f9f506dd3a94c9df0514bf0e22624a8cb0f92
Parents: 4d15b9f
Author: Chris Hostetter <ho...@apache.org>
Authored: Fri May 6 15:17:11 2016 -0700
Committer: Chris Hostetter <ho...@apache.org>
Committed: Fri May 6 15:32:13 2016 -0700
----------------------------------------------------------------------
.../org/apache/solr/util/SSLTestConfig.java | 86 ++++++++++++++++----
1 file changed, 72 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/7e2f9f50/solr/test-framework/src/java/org/apache/solr/util/SSLTestConfig.java
----------------------------------------------------------------------
diff --git a/solr/test-framework/src/java/org/apache/solr/util/SSLTestConfig.java b/solr/test-framework/src/java/org/apache/solr/util/SSLTestConfig.java
index 13b4c21..9c31fc2 100644
--- a/solr/test-framework/src/java/org/apache/solr/util/SSLTestConfig.java
+++ b/solr/test-framework/src/java/org/apache/solr/util/SSLTestConfig.java
@@ -17,6 +17,7 @@
package org.apache.solr.util;
import java.io.File;
+import java.util.Random;
import java.security.KeyManagementException;
import java.security.KeyStore;
import java.security.KeyStoreException;
@@ -41,6 +42,9 @@ import org.apache.solr.client.solrj.embedded.SSLConfig;
import org.apache.solr.client.solrj.impl.HttpClientUtil;
import org.apache.solr.client.solrj.impl.HttpClientConfigurer;
import org.apache.solr.common.params.SolrParams;
+
+import org.apache.lucene.util.Constants;
+
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.util.security.CertificateUtils;
import org.eclipse.jetty.util.ssl.SslContextFactory;
@@ -265,33 +269,87 @@ public class SSLTestConfig extends SSLConfig {
* Tests do not need secure SSL.
*/
private static class NullSecureRandom extends SecureRandom {
- public static final SecureRandom INSTANCE = new NullSecureRandom();
+
+ /**
+ * The one and only instance that should be used, specific impl may vary based on platform
+ * @see Constants#SUN_OS
+ * @see <a href="https://issues.apache.org/jira/browse/SOLR-9068">SOLR-9068</a>
+ */
+ public static final SecureRandom INSTANCE = Constants.SUN_OS
+ ? new NullSecureRandom(NullSecureRandomSpi.PSUEDO_RAND_INSTANCE)
+ : new NullSecureRandom(NullSecureRandomSpi.NULL_INSTANCE);
+
+ /** A source of psuedo random data if needed */
+ private static final Random RAND = new Random(42);
- /** SPI Used to init all instances */
- private static final SecureRandomSpi NULL_SPI = new SecureRandomSpi() {
- /** NOOP: returns new uninitialized byte[] */
+ /** SPI base class for all NullSecureRandom instances */
+ private static class NullSecureRandomSpi extends SecureRandomSpi {
+ private NullSecureRandomSpi() {
+ /* NOOP */
+ }
+ /**
+ * Helper method that can be used to fill an array with non-zero data.
+ * Default impl is No-Op
+ */
+ public byte[] fillData(byte[] data) {
+ return data; /* NOOP */
+ }
+ /** returns a new byte[] filled with static data */
+ @Override
public byte[] engineGenerateSeed(int numBytes) {
- return new byte[numBytes];
+ return fillData(new byte[numBytes]);
+ }
+ /** fills the byte[] with static data */
+ @Override
+ public void engineNextBytes(byte[] bytes) {
+ fillData(bytes);
}
/** NOOP */
- public void engineNextBytes(byte[] bytes) { /* NOOP */ }
- /** NOOP */
+ @Override
public void engineSetSeed(byte[] seed) { /* NOOP */ }
- };
+
+ /** Instance to use on platforms w/SSLEngines that work fine when SecureRandom returns constant bytes */
+ public static final NullSecureRandomSpi NULL_INSTANCE = new NullSecureRandomSpi();
+
+ /**
+ * Instance to use on platforms that need at least psuedo-random data for the SSLEngine to not break
+ * (Attempted workarround of Solaris SSL Padding bug: SOLR-9068)
+ */
+ public static final NullSecureRandomSpi PSUEDO_RAND_INSTANCE = new NullSecureRandomSpi() {
+ /**
+ * Fill with Psuedo-Random data.
+ * (Attempted workarround of Solaris SSL Padding bug: SOLR-9068)
+ */
+ @Override
+ public byte[] fillData(byte[] data) {
+ RAND.nextBytes(data);
+ return data;
+ }
+ };
+ }
- private NullSecureRandom() {
- super(NULL_SPI, null) ;
+ private NullSecureRandom(NullSecureRandomSpi spi) {
+ super(spi, null);
+ this.spi = spi;
}
- /** NOOP: returns new uninitialized byte[] */
+ private NullSecureRandomSpi spi;
+
+ /** fills a new byte[] with data from SPI */
+ @Override
public byte[] generateSeed(int numBytes) {
- return new byte[numBytes];
+ return spi.fillData(new byte[numBytes]);
+ }
+ /** fills the byte[] with data from SPI */
+ @Override
+ synchronized public void nextBytes(byte[] bytes) {
+ spi.fillData(bytes);
}
/** NOOP */
- synchronized public void nextBytes(byte[] bytes) { /* NOOP */ }
- /** NOOP */
+ @Override
synchronized public void setSeed(byte[] seed) { /* NOOP */ }
/** NOOP */
+ @Override
synchronized public void setSeed(long seed) { /* NOOP */ }
}