HADOOP-11891. OsSecureRandom should lazily fill its reservoir (asuresh)
This commit is contained in:
parent
c55d609053
commit
f0db797be2
|
@ -603,6 +603,8 @@ Release 2.7.1 - UNRELEASED
|
||||||
HADOOP-11802. DomainSocketWatcher thread terminates sometimes after there
|
HADOOP-11802. DomainSocketWatcher thread terminates sometimes after there
|
||||||
is an I/O error during requestShortCircuitShm (cmccabe)
|
is an I/O error during requestShortCircuitShm (cmccabe)
|
||||||
|
|
||||||
|
HADOOP-11891. OsSecureRandom should lazily fill its reservoir (asuresh)
|
||||||
|
|
||||||
Release 2.7.0 - 2015-04-20
|
Release 2.7.0 - 2015-04-20
|
||||||
|
|
||||||
INCOMPATIBLE CHANGES
|
INCOMPATIBLE CHANGES
|
||||||
|
|
|
@ -58,6 +58,9 @@ public class OsSecureRandom extends Random implements Closeable, Configurable {
|
||||||
private void fillReservoir(int min) {
|
private void fillReservoir(int min) {
|
||||||
if (pos >= reservoir.length - min) {
|
if (pos >= reservoir.length - min) {
|
||||||
try {
|
try {
|
||||||
|
if (stream == null) {
|
||||||
|
stream = new FileInputStream(new File(randomDevPath));
|
||||||
|
}
|
||||||
IOUtils.readFully(stream, reservoir, 0, reservoir.length);
|
IOUtils.readFully(stream, reservoir, 0, reservoir.length);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException("failed to fill reservoir", e);
|
throw new RuntimeException("failed to fill reservoir", e);
|
||||||
|
@ -75,21 +78,7 @@ public class OsSecureRandom extends Random implements Closeable, Configurable {
|
||||||
this.randomDevPath = conf.get(
|
this.randomDevPath = conf.get(
|
||||||
HADOOP_SECURITY_SECURE_RANDOM_DEVICE_FILE_PATH_KEY,
|
HADOOP_SECURITY_SECURE_RANDOM_DEVICE_FILE_PATH_KEY,
|
||||||
HADOOP_SECURITY_SECURE_RANDOM_DEVICE_FILE_PATH_DEFAULT);
|
HADOOP_SECURITY_SECURE_RANDOM_DEVICE_FILE_PATH_DEFAULT);
|
||||||
File randomDevFile = new File(randomDevPath);
|
close();
|
||||||
|
|
||||||
try {
|
|
||||||
close();
|
|
||||||
this.stream = new FileInputStream(randomDevFile);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
fillReservoir(0);
|
|
||||||
} catch (RuntimeException e) {
|
|
||||||
close();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue