GUACAMOLE-362: Loop through reading bytes from key file.

This commit is contained in:
Nick Couchman
2017-10-10 22:29:38 -04:00
committed by Nick Couchman
parent 61f70c57be
commit c92d2e3598

View File

@@ -55,18 +55,19 @@ public abstract class PrivateKeyGuacamoleProperty implements GuacamoleProperty<P
InputStream keyInput = new BufferedInputStream(new FileInputStream(keyFile)); InputStream keyInput = new BufferedInputStream(new FileInputStream(keyFile));
int keyLength = (int) keyFile.length(); int keyLength = (int) keyFile.length();
final byte[] keyBytes = new byte[keyLength]; final byte[] keyBytes = new byte[keyLength];
int keyRead = keyInput.read(keyBytes); int totalBytesRead = 0;
for(int keyRead = keyInput.read(keyBytes, 0, keyBytes.length);
// Error reading any bytes out of the key. keyRead >= 0;
if (keyRead == -1) keyRead = keyInput.read(keyBytes, totalBytesRead, (keyBytes.length - totalBytesRead))) {
throw new GuacamoleServerException("Failed to get any bytes while reading key."); totalBytesRead += keyRead;
}
// Zero-sized key // Zero-sized key
else if(keyRead == 0) if (totalBytesRead == 0)
throw new GuacamoleServerException("Failed to ready key because key is empty."); throw new GuacamoleServerException("Failed to ready key because key is empty.");
// Fewer bytes read than contained in the key // Fewer bytes read than contained in the key
else if (keyRead < keyLength) else if (totalBytesRead < keyLength)
throw new GuacamoleServerException("Unable to read the full length of the key."); throw new GuacamoleServerException("Unable to read the full length of the key.");
keyInput.close(); keyInput.close();