mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 21:27:40 +00:00
GUACAMOLE-362: Move PrivateKeyGuacamoleProperty into CAS extension and use ByteArrayOutputStream for reading thefile.
This commit is contained in:
@@ -19,7 +19,6 @@
|
|||||||
|
|
||||||
package org.apache.guacamole.auth.cas.conf;
|
package org.apache.guacamole.auth.cas.conf;
|
||||||
|
|
||||||
import org.apache.guacamole.properties.PrivateKeyGuacamoleProperty;
|
|
||||||
import org.apache.guacamole.properties.StringGuacamoleProperty;
|
import org.apache.guacamole.properties.StringGuacamoleProperty;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -17,9 +17,9 @@
|
|||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.apache.guacamole.properties;
|
package org.apache.guacamole.auth.cas.conf;
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
@@ -33,6 +33,7 @@ import java.security.PrivateKey;
|
|||||||
import java.security.spec.InvalidKeySpecException;
|
import java.security.spec.InvalidKeySpecException;
|
||||||
import java.security.spec.KeySpec;
|
import java.security.spec.KeySpec;
|
||||||
import java.security.spec.PKCS8EncodedKeySpec;
|
import java.security.spec.PKCS8EncodedKeySpec;
|
||||||
|
import org.apache.guacamole.properties.GuacamoleProperty;
|
||||||
import org.apache.guacamole.GuacamoleServerException;
|
import org.apache.guacamole.GuacamoleServerException;
|
||||||
import org.apache.guacamole.environment.Environment;
|
import org.apache.guacamole.environment.Environment;
|
||||||
import org.apache.guacamole.environment.LocalEnvironment;
|
import org.apache.guacamole.environment.LocalEnvironment;
|
||||||
@@ -52,25 +53,18 @@ public abstract class PrivateKeyGuacamoleProperty implements GuacamoleProperty<P
|
|||||||
|
|
||||||
// Open and read the file specified in the configuration.
|
// Open and read the file specified in the configuration.
|
||||||
File keyFile = new File(value);
|
File keyFile = new File(value);
|
||||||
InputStream keyInput = new BufferedInputStream(new FileInputStream(keyFile));
|
FileInputStream keyStreamIn = new FileInputStream(keyFile);
|
||||||
int keyLength = (int) keyFile.length();
|
ByteArrayOutputStream keyStreamOut = new ByteArrayOutputStream();
|
||||||
final byte[] keyBytes = new byte[keyLength];
|
byte[] keyBuffer = new byte[1024];
|
||||||
int totalBytesRead = 0;
|
try {
|
||||||
for(int keyRead = keyInput.read(keyBytes, 0, keyBytes.length);
|
for (int readBytes; (readBytes = keyStreamIn.read(keyBuffer)) != -1;)
|
||||||
keyRead >= 0;
|
keyStreamOut.write(keyBuffer, 0, readBytes);
|
||||||
keyRead = keyInput.read(keyBytes, totalBytesRead, (keyBytes.length - totalBytesRead))) {
|
}
|
||||||
totalBytesRead += keyRead;
|
catch (IOException e) {
|
||||||
|
throw new GuacamoleServerException("IOException while trying to read bytes from file.", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Zero-sized key
|
final byte[] keyBytes = keyStreamOut.toByteArray();
|
||||||
if (totalBytesRead == 0)
|
|
||||||
throw new GuacamoleServerException("Failed to ready key because key is empty.");
|
|
||||||
|
|
||||||
// Fewer bytes read than contained in the key
|
|
||||||
else if (totalBytesRead < keyLength)
|
|
||||||
throw new GuacamoleServerException("Unable to read the full length of the key.");
|
|
||||||
|
|
||||||
keyInput.close();
|
|
||||||
|
|
||||||
// Set up decryption infrastructure
|
// Set up decryption infrastructure
|
||||||
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
|
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
|
Reference in New Issue
Block a user