mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 05:07:41 +00:00
GUACAMOLE-362: Loop through reading bytes from key file.
This commit is contained in:
committed by
Nick Couchman
parent
61f70c57be
commit
c92d2e3598
@@ -55,18 +55,19 @@ public abstract class PrivateKeyGuacamoleProperty implements GuacamoleProperty<P
|
||||
InputStream keyInput = new BufferedInputStream(new FileInputStream(keyFile));
|
||||
int keyLength = (int) keyFile.length();
|
||||
final byte[] keyBytes = new byte[keyLength];
|
||||
int keyRead = keyInput.read(keyBytes);
|
||||
|
||||
// Error reading any bytes out of the key.
|
||||
if (keyRead == -1)
|
||||
throw new GuacamoleServerException("Failed to get any bytes while reading key.");
|
||||
int totalBytesRead = 0;
|
||||
for(int keyRead = keyInput.read(keyBytes, 0, keyBytes.length);
|
||||
keyRead >= 0;
|
||||
keyRead = keyInput.read(keyBytes, totalBytesRead, (keyBytes.length - totalBytesRead))) {
|
||||
totalBytesRead += keyRead;
|
||||
}
|
||||
|
||||
// Zero-sized key
|
||||
else if(keyRead == 0)
|
||||
if (totalBytesRead == 0)
|
||||
throw new GuacamoleServerException("Failed to ready key because key is empty.");
|
||||
|
||||
// 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.");
|
||||
|
||||
keyInput.close();
|
||||
|
Reference in New Issue
Block a user