GUACAMOLE-362: Merge changes addressing InputStream leak when reading CAS ClearPass private key.

This commit is contained in:
Michael Jumper
2017-10-28 22:20:53 -07:00

View File

@@ -49,11 +49,14 @@ public abstract class PrivateKeyGuacamoleProperty implements GuacamoleProperty<P
if (value == null || value.isEmpty())
return null;
FileInputStream keyStreamIn = null;
try {
try {
// Open and read the file specified in the configuration.
File keyFile = new File(value);
FileInputStream keyStreamIn = new FileInputStream(keyFile);
keyStreamIn = new FileInputStream(keyFile);
ByteArrayOutputStream keyStreamOut = new ByteArrayOutputStream();
byte[] keyBuffer = new byte[1024];
@@ -71,16 +74,20 @@ public abstract class PrivateKeyGuacamoleProperty implements GuacamoleProperty<P
catch (FileNotFoundException e) {
throw new GuacamoleServerException("Could not find the specified key file.", e);
}
catch (IOException e) {
throw new GuacamoleServerException("Could not read in the specified key file.", e);
}
catch (NoSuchAlgorithmException e) {
throw new GuacamoleServerException("RSA algorithm is not available.", e);
}
catch (InvalidKeySpecException e) {
throw new GuacamoleServerException("Key is not in expected PKCS8 encoding.", e);
}
finally {
if (keyStreamIn != null)
keyStreamIn.close();
}
}
catch (IOException e) {
throw new GuacamoleServerException("Could not read in the specified key file.", e);
}
}
}