You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@guacamole.apache.org by mj...@apache.org on 2017/10/27 17:51:39 UTC

[01/25] incubator-guacamole-client git commit: GUACAMOLE-362: Update documentation to reflect code.

Repository: incubator-guacamole-client
Updated Branches:
  refs/heads/master d955fbea1 -> e5c542262


GUACAMOLE-362: Update documentation to reflect code.


Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/commit/6f04573b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/tree/6f04573b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/diff/6f04573b

Branch: refs/heads/master
Commit: 6f04573b8476a817dffa3bbd1fa97288644e37d3
Parents: 1592cf5
Author: Nick Couchman <vn...@apache.org>
Authored: Wed Sep 27 10:25:52 2017 -0400
Committer: Nick Couchman <ni...@yahoo.com>
Committed: Fri Oct 27 13:05:12 2017 -0400

----------------------------------------------------------------------
 .../guacamole/auth/cas/conf/ConfigurationService.java  |  7 +++----
 .../auth/cas/ticket/TicketValidationService.java       | 13 ++++++-------
 2 files changed, 9 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/6f04573b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/conf/ConfigurationService.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/conf/ConfigurationService.java b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/conf/ConfigurationService.java
index 409097e..dee9c4d 100644
--- a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/conf/ConfigurationService.java
+++ b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/conf/ConfigurationService.java
@@ -71,12 +71,11 @@ public class ConfigurationService {
     }
 
     /**
-     * Returns the path to the file that contains the private key
-     * used to decrypt the credential that is sent encrypted by CAS,
-     * or null if no key is defined.
+     * Returns the PrivateKey used to decrypt the credential object
+     * sent encrypted by CAS, or null if no key is defined.
      *
      * @return
-     *     The path to the private key to decrypt the ClearPass
+     *     The PrivateKey used to decrypt the ClearPass
      *     credential returned by CAS.
      *
      * @throws GuacamoleException

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/6f04573b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/ticket/TicketValidationService.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/ticket/TicketValidationService.java b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/ticket/TicketValidationService.java
index fca2ccf..96da6ff 100644
--- a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/ticket/TicketValidationService.java
+++ b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/ticket/TicketValidationService.java
@@ -42,20 +42,19 @@ public class TicketValidationService {
     private ConfigurationService confService;
 
     /**
-     * Validates and parses the given ID ticket, returning the username contained
-     * therein, as defined by the username claim type given in
-     * guacamole.properties. If the username claim type is missing or the ID
-     * ticket is invalid, an exception is thrown instead.
+     * Validates and parses the given ID ticket, returning the AttributePrincipal
+     * derived from the parameters provided by the CAS server in the ticket.  If the
+     * ticket is invalid an exception is thrown.
      *
      * @param ticket
      *     The ID ticket to validate and parse.
      *
      * @return
-     *     The username contained within the given ID ticket.
+     *     The AttributePrincipal derived from parameters provided in the ticket.
      *
      * @throws GuacamoleException
-     *     If the ID ticket is not valid, the username claim type is missing, or
-     *     guacamole.properties could not be parsed.
+     *     If the ID ticket is not valid or guacamole.properties could
+     *     not be parsed.
      */
     public AttributePrincipal validateTicket(String ticket) throws GuacamoleException {
 


[13/25] incubator-guacamole-client git commit: GUACAMOLE-362: More useful error messages for exceptions in PrivateKey property.

Posted by mj...@apache.org.
GUACAMOLE-362: More useful error messages for exceptions in PrivateKey property.


Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/commit/3ce0980e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/tree/3ce0980e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/diff/3ce0980e

Branch: refs/heads/master
Commit: 3ce0980efcb170a0ca96373ba842466dc3aa1445
Parents: 6f04573
Author: Nick Couchman <vn...@apache.org>
Authored: Wed Sep 27 10:28:34 2017 -0400
Committer: Nick Couchman <ni...@yahoo.com>
Committed: Fri Oct 27 13:05:13 2017 -0400

----------------------------------------------------------------------
 .../apache/guacamole/properties/PrivateKeyGuacamoleProperty.java | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/3ce0980e/guacamole-ext/src/main/java/org/apache/guacamole/properties/PrivateKeyGuacamoleProperty.java
----------------------------------------------------------------------
diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/properties/PrivateKeyGuacamoleProperty.java b/guacamole-ext/src/main/java/org/apache/guacamole/properties/PrivateKeyGuacamoleProperty.java
index 904a4d1..570b776 100644
--- a/guacamole-ext/src/main/java/org/apache/guacamole/properties/PrivateKeyGuacamoleProperty.java
+++ b/guacamole-ext/src/main/java/org/apache/guacamole/properties/PrivateKeyGuacamoleProperty.java
@@ -70,10 +70,10 @@ public abstract class PrivateKeyGuacamoleProperty implements GuacamoleProperty<P
             throw new GuacamoleServerException("Could not read in the specified key file.", e);
         }
         catch (NoSuchAlgorithmException e) {
-            throw new GuacamoleServerException("Specified algorithm does not exist.", e);
+            throw new GuacamoleServerException("Key is not in expected RSA algorithm.", e);
         }
         catch (InvalidKeySpecException e) {
-            throw new GuacamoleServerException("Invalid KeySpec initialization.", e);
+            throw new GuacamoleServerException("KeyS is not in expected PKCS8 encoding.", e);
         }
 
     }


[11/25] incubator-guacamole-client git commit: GUACAMOLE-362: Catch exceptions individually and display useful error messages.

Posted by mj...@apache.org.
GUACAMOLE-362: Catch exceptions individually and display useful error messages.


Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/commit/453a8798
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/tree/453a8798
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/diff/453a8798

Branch: refs/heads/master
Commit: 453a87987698f83479466450560bbab7ef0ee52e
Parents: 3ce0980
Author: Nick Couchman <vn...@apache.org>
Authored: Wed Sep 27 10:42:20 2017 -0400
Committer: Nick Couchman <ni...@yahoo.com>
Committed: Fri Oct 27 13:05:13 2017 -0400

----------------------------------------------------------------------
 .../auth/cas/AuthenticationProviderService.java | 22 +++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/453a8798/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/AuthenticationProviderService.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/AuthenticationProviderService.java b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/AuthenticationProviderService.java
index 617d3d9..ecb02d2 100644
--- a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/AuthenticationProviderService.java
+++ b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/AuthenticationProviderService.java
@@ -36,8 +36,10 @@ import java.security.spec.KeySpec;
 import java.security.spec.PKCS8EncodedKeySpec;
 import java.util.Arrays;
 import java.util.Enumeration;
+import javax.crypto.BadPaddingException;
 import javax.crypto.Cipher;
 import javax.crypto.IllegalBlockSizeException;
+import javax.crypto.NoSuchPaddingException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpSession;
 import javax.xml.bind.DatatypeConverter;
@@ -193,9 +195,23 @@ public class AuthenticationProviderService {
             return new String(cipherData);
 
         }
-        catch (Throwable t) {
-            logger.debug("Failed to either convert Base64 or decrypt the password.  CAS Password will not be available inside Guacamole.  Exception is: {}", t);
-            throw new GuacamoleServerException("Failed to decrypt CAS ClearPass password.", t);
+        catch (BadPaddingException e) {
+            throw new GuacamoleServerException("Bad padding when decrypting cipher data.", e);
+        }
+        catch (IllegalBlockSizeException e) {
+            throw new GuacamoleServerException("Illegal block size while opening private key.", e);
+        }
+        catch (InvalidKeyException e) {
+            throw new GuacamoleServerException("Specified private key for ClearPass decryption is invalid.", e);
+        }
+        catch (NoSuchAlgorithmException e) {
+            throw new GuacamoleServerException("Unexpected algorithm for the private key.", e);
+        }
+        catch (NoSuchPaddingException e) {
+            throw new GuacamoleServerException("No such padding tryingto initialize cipher with private key.", e);
+        }
+        finally {
+            logger.debug("Yah.");
         }
 
     }


[15/25] incubator-guacamole-client git commit: GUACAMOLE-362: Refactor ticket validation handling of credentials.

Posted by mj...@apache.org.
GUACAMOLE-362: Refactor ticket validation handling of credentials.


Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/commit/b410b99d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/tree/b410b99d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/diff/b410b99d

Branch: refs/heads/master
Commit: b410b99d49c4fd259c3af60a336808a59fec7ba5
Parents: 62fafcb
Author: Nick Couchman <vn...@apache.org>
Authored: Sat Sep 30 20:55:44 2017 -0400
Committer: Nick Couchman <ni...@yahoo.com>
Committed: Fri Oct 27 13:05:13 2017 -0400

----------------------------------------------------------------------
 .../auth/cas/AuthenticationProviderService.java     | 16 +++++-----------
 .../auth/cas/ticket/TicketValidationService.java    | 15 +++++++--------
 2 files changed, 12 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/b410b99d/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/AuthenticationProviderService.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/AuthenticationProviderService.java b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/AuthenticationProviderService.java
index 325268e..a9b3230 100644
--- a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/AuthenticationProviderService.java
+++ b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/AuthenticationProviderService.java
@@ -87,18 +87,12 @@ public class AuthenticationProviderService {
         if (request != null) {
             String ticket = request.getParameter(CASTicketField.PARAMETER_NAME);
             if (ticket != null) {
-                Credentials ticketCredentials = ticketService.validateTicket(ticket);
-                if (ticketCredentials != null) {
-                    String username = ticketCredentials.getUsername();
-                    if (username != null)
-                        credentials.setUsername(username);
-                    String password = ticketCredentials.getPassword();
-                    if (password != null)
-                        credentials.setPassword(password);
+                String username = ticketService.validateTicket(ticket, credentials);
+                if (username != null) {
+                    AuthenticatedUser authenticatedUser = authenticatedUserProvider.get();
+                    authenticatedUser.init(username, credentials);
+                    return authenticatedUser;
                 }
-                AuthenticatedUser authenticatedUser = authenticatedUserProvider.get();
-                authenticatedUser.init(credentials.getUsername(), credentials);
-                return authenticatedUser;
             }
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/b410b99d/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/ticket/TicketValidationService.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/ticket/TicketValidationService.java b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/ticket/TicketValidationService.java
index 0162801..de38964 100644
--- a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/ticket/TicketValidationService.java
+++ b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/ticket/TicketValidationService.java
@@ -57,21 +57,21 @@ public class TicketValidationService {
     private ConfigurationService confService;
 
     /**
-     * Validates and parses the given ID ticket, returning the Credentials object
-     * derived from the parameters provided by the CAS server in the ticket.  If the
+     * Validates and parses the given ID ticket, returning the username
+     * provided by the CAS server in the ticket.  If the
      * ticket is invalid an exception is thrown.
      *
      * @param ticket
      *     The ID ticket to validate and parse.
      *
      * @return
-     *     The Credentials object derived from parameters provided in the ticket.
+     *     The username derived from the ticket.
      *
      * @throws GuacamoleException
      *     If the ID ticket is not valid or guacamole.properties could
      *     not be parsed.
      */
-    public Credentials validateTicket(String ticket) throws GuacamoleException {
+    public String validateTicket(String ticket, Credentials credentials) throws GuacamoleException {
 
         // Retrieve the configured CAS URL, establish a ticket validator,
         // and then attempt to validate the supplied ticket.  If that succeeds,
@@ -80,7 +80,6 @@ public class TicketValidationService {
         Cas20ProxyTicketValidator validator = new Cas20ProxyTicketValidator(casServerUrl);
         validator.setAcceptAnyProxy(true);
         try {
-            Credentials ticketCredentials = new Credentials();
             String confRedirectURI = confService.getRedirectURI();
             Assertion a = validator.validate(ticket, confRedirectURI);
             AttributePrincipal principal =  a.getPrincipal();
@@ -88,17 +87,17 @@ public class TicketValidationService {
             // Retrieve username and set the credentials.
             String username = principal.getName();
             if (username != null)
-                ticketCredentials.setUsername(username);
+                credentials.setUsername(username);
 
             // Retrieve password, attempt decryption, and set credentials.
             Object credObj = principal.getAttributes().get("credential");
             if (credObj != null) {
                 String clearPass = decryptPassword(credObj.toString());
                 if (clearPass != null && !clearPass.isEmpty())
-                    ticketCredentials.setPassword(clearPass);
+                    credentials.setPassword(clearPass);
             }
 
-            return ticketCredentials;
+            return username;
 
         } 
         catch (TicketValidationException e) {


[08/25] incubator-guacamole-client git commit: GUACAMOLE-362: Implement new CipherGuacamoleProperty and move cipher functionality to it.

Posted by mj...@apache.org.
GUACAMOLE-362: Implement new CipherGuacamoleProperty and move cipher functionality to it.


Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/commit/36489ff4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/tree/36489ff4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/diff/36489ff4

Branch: refs/heads/master
Commit: 36489ff403ae66219e858773b7e5095241628c2a
Parents: c3aaf0a
Author: Nick Couchman <vn...@apache.org>
Authored: Sun Aug 27 20:34:46 2017 -0400
Committer: Nick Couchman <ni...@yahoo.com>
Committed: Fri Oct 27 13:05:12 2017 -0400

----------------------------------------------------------------------
 .../auth/cas/AuthenticationProviderService.java | 46 ++--------
 .../auth/cas/conf/CASGuacamoleProperties.java   |  6 +-
 .../auth/cas/conf/ConfigurationService.java     |  3 +-
 .../properties/CipherGuacamoleProperty.java     | 92 ++++++++++++++++++++
 4 files changed, 102 insertions(+), 45 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/36489ff4/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/AuthenticationProviderService.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/AuthenticationProviderService.java b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/AuthenticationProviderService.java
index feb842d..b7ebdf7 100644
--- a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/AuthenticationProviderService.java
+++ b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/AuthenticationProviderService.java
@@ -37,6 +37,7 @@ import java.security.spec.PKCS8EncodedKeySpec;
 import java.util.Arrays;
 import java.util.Enumeration;
 import javax.crypto.Cipher;
+import javax.crypto.IllegalBlockSizeException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpSession;
 import javax.xml.bind.DatatypeConverter;
@@ -170,53 +171,16 @@ public class AuthenticationProviderService {
 
         try {
 
-            // Open and read the file specified in the configuration.
-            File keyFile = new File(environment.getGuacamoleHome(), confService.getClearpassKey().toString());
-            InputStream keyInput = new BufferedInputStream(new FileInputStream(keyFile));
-            final byte[] keyBytes = new byte[(int) keyFile.length()];
-            keyInput.read(keyBytes);
-            keyInput.close();
-      
-            // Set up decryption infrastructure
-            KeyFactory keyFactory = KeyFactory.getInstance("RSA");
-            KeySpec keySpec = new PKCS8EncodedKeySpec(keyBytes); 
-            final PrivateKey privateKey = keyFactory.generatePrivate(keySpec);
-            final Cipher cipher = Cipher.getInstance(privateKey.getAlgorithm());
-            final byte[] pass64 = DatatypeConverter.parseBase64Binary(encryptedPassword);
-            cipher.init(Cipher.DECRYPT_MODE, privateKey);
+            final Cipher cipher = confService.getClearpassCipher();
 
             // Decrypt and return a new string.
+            final byte[] pass64 = DatatypeConverter.parseBase64Binary(encryptedPassword);
             final byte[] cipherData = cipher.doFinal(pass64);
             return new String(cipherData);
         }
-        catch (FileNotFoundException e) {
-            logger.error("ClearPass key file not found, password will not be decrypted.");
-            logger.debug("Error locating the ClearPass key file: {}", e);
-            return null;
-        }
-        catch (IOException e) {
-            logger.error("Error reading ClearPass key file, password will not be decrypted.");
-            logger.debug("Error reading the ClearPass key file: {}", e);
-            return null;
-        }
-        catch (NoSuchAlgorithmException e) {
-            logger.error("Unable to find the specified algorithm, password will not be decrypted.");
-            logger.debug("Algorithm was not found: {}", e);
-            return null;
-        }
-        catch (InvalidKeyException e) {
-            logger.error("Invalid key was loaded, password will not be decrypted.");
-            logger.debug("The loaded key was invalid: {}", e);
-            return null;
-        }
-        catch (IllegalArgumentException e) {
-            logger.error("Failed to parse Base64 data, password will not be decrypted.");
-            logger.debug("Data received was not valid Base64 data, so decryption cannot continue: {}", e);
-            return null;
-        }
         catch (Throwable t) {
-            logger.error("Error decrypting password, it will not be available as a token.");
-            logger.debug("Error in one of the components to decrypt the password: {}", t);
+            logger.error("Failed to decrypt the data, password token will not be available.");
+            logger.debug("Failed to either convert Base64 or decrypt the password.  CAS Password will not be available inside Guacamole.  Exception is: {}", t);
             return null;
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/36489ff4/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/conf/CASGuacamoleProperties.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/conf/CASGuacamoleProperties.java b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/conf/CASGuacamoleProperties.java
index 410e848..7a600c9 100644
--- a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/conf/CASGuacamoleProperties.java
+++ b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/conf/CASGuacamoleProperties.java
@@ -19,7 +19,7 @@
 
 package org.apache.guacamole.auth.cas.conf;
 
-import org.apache.guacamole.properties.FileGuacamoleProperty;
+import org.apache.guacamole.properties.CipherGuacamoleProperty;
 import org.apache.guacamole.properties.StringGuacamoleProperty;
 
 /**
@@ -62,8 +62,8 @@ public class CASGuacamoleProperties {
      * The location of the private key file used to retrieve the
      * password if CAS is configured to support ClearPass.
      */
-    public static final FileGuacamoleProperty CAS_CLEARPASS_KEY =
-            new FileGuacamoleProperty() {
+    public static final CipherGuacamoleProperty CAS_CLEARPASS_KEY =
+            new CipherGuacamoleProperty() {
 
         @Override
         public String getName() { return "cas-clearpass-key"; }

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/36489ff4/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/conf/ConfigurationService.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/conf/ConfigurationService.java b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/conf/ConfigurationService.java
index b2d74d5..ba969d4 100644
--- a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/conf/ConfigurationService.java
+++ b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/conf/ConfigurationService.java
@@ -21,6 +21,7 @@ package org.apache.guacamole.auth.cas.conf;
 
 import com.google.inject.Inject;
 import java.io.File;
+import javax.crypto.Cipher;
 import org.apache.guacamole.GuacamoleException;
 import org.apache.guacamole.environment.Environment;
 
@@ -81,7 +82,7 @@ public class ConfigurationService {
      * @throws GuacamoleException
      *     If guacamole.properties cannot be parsed.
      */
-    public File getClearpassKey() throws GuacamoleException {
+    public Cipher getClearpassCipher() throws GuacamoleException {
         return environment.getProperty(CASGuacamoleProperties.CAS_CLEARPASS_KEY);
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/36489ff4/guacamole-ext/src/main/java/org/apache/guacamole/properties/CipherGuacamoleProperty.java
----------------------------------------------------------------------
diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/properties/CipherGuacamoleProperty.java b/guacamole-ext/src/main/java/org/apache/guacamole/properties/CipherGuacamoleProperty.java
new file mode 100644
index 0000000..e2f95ec
--- /dev/null
+++ b/guacamole-ext/src/main/java/org/apache/guacamole/properties/CipherGuacamoleProperty.java
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.properties;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.io.IOException;
+import java.lang.IllegalArgumentException;
+import java.security.InvalidKeyException;
+import java.security.KeyFactory;
+import java.security.NoSuchAlgorithmException;
+import java.security.PrivateKey;
+import java.security.spec.InvalidKeySpecException;
+import java.security.spec.KeySpec;
+import java.security.spec.PKCS8EncodedKeySpec;
+import javax.crypto.Cipher;
+import javax.crypto.NoSuchPaddingException;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.environment.Environment;
+import org.apache.guacamole.environment.LocalEnvironment;
+
+/**
+ * A GuacamoleProperty whose value is derived from a private key file.
+ */
+public abstract class CipherGuacamoleProperty implements GuacamoleProperty<Cipher>  {
+
+    @Override
+    public Cipher parseValue(String value) throws GuacamoleException {
+
+        try {
+
+            final Environment environment = new LocalEnvironment();
+
+            // Open and read the file specified in the configuration.
+            File keyFile = new File(environment.getGuacamoleHome(), value);
+            InputStream keyInput = new BufferedInputStream(new FileInputStream(keyFile));
+            final byte[] keyBytes = new byte[(int) keyFile.length()];
+            keyInput.read(keyBytes);
+            keyInput.close();
+
+            // Set up decryption infrastructure
+            KeyFactory keyFactory = KeyFactory.getInstance("RSA");
+            KeySpec keySpec = new PKCS8EncodedKeySpec(keyBytes);
+            final PrivateKey privateKey = keyFactory.generatePrivate(keySpec);
+            final Cipher cipher = Cipher.getInstance(privateKey.getAlgorithm());
+            cipher.init(Cipher.DECRYPT_MODE, privateKey);
+
+            return cipher;
+
+        }
+        catch (FileNotFoundException e) {
+            throw new GuacamoleException("Could not find the specified key file.", e);
+        }
+        catch (IOException e) {
+            throw new GuacamoleException("Could not read in the specified key file.", e);
+        }
+        catch (NoSuchAlgorithmException e) {
+            throw new GuacamoleException("Specified algorithm does not exist.", e);
+        }
+        catch (InvalidKeyException e) {
+            throw new GuacamoleException("Specified key is invalid.", e);
+        }
+        catch (InvalidKeySpecException e) {
+            throw new GuacamoleException("Invalid KeySpec initialization.", e);
+        }
+        catch (NoSuchPaddingException e) {
+            throw new GuacamoleException("No such padding exception.", e);
+        }
+
+    }
+
+}


[25/25] incubator-guacamole-client git commit: Merge 0.9.14-incubating changes back to master.

Posted by mj...@apache.org.
Merge 0.9.14-incubating changes back to master.


Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/commit/e5c54226
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/tree/e5c54226
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/diff/e5c54226

Branch: refs/heads/master
Commit: e5c542262314540af9cd926f5af5df688f892bf2
Parents: d955fbe 0d74dc5
Author: Michael Jumper <mj...@apache.org>
Authored: Fri Oct 27 10:51:05 2017 -0700
Committer: Michael Jumper <mj...@apache.org>
Committed: Fri Oct 27 10:51:05 2017 -0700

----------------------------------------------------------------------
 .../auth/cas/AuthenticationProviderService.java |  20 ++-
 .../auth/cas/conf/CASGuacamoleProperties.java   |  12 ++
 .../auth/cas/conf/ConfigurationService.java     |  17 +++
 .../cas/conf/PrivateKeyGuacamoleProperty.java   |  86 +++++++++++++
 .../cas/ticket/TicketValidationService.java     | 125 ++++++++++++++++---
 5 files changed, 240 insertions(+), 20 deletions(-)
----------------------------------------------------------------------



[09/25] incubator-guacamole-client git commit: GUACAMOLE-362: Change new property to a PrivateKey and refactor code accordingly.

Posted by mj...@apache.org.
GUACAMOLE-362: Change new property to a PrivateKey and refactor code accordingly.


Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/commit/badbf4cc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/tree/badbf4cc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/diff/badbf4cc

Branch: refs/heads/master
Commit: badbf4cc7dd1436be8d94e3f346829bcbb9e46ca
Parents: ed4c025
Author: Nick Couchman <vn...@apache.org>
Authored: Sun Sep 24 15:58:09 2017 -0400
Committer: Nick Couchman <ni...@yahoo.com>
Committed: Fri Oct 27 13:05:12 2017 -0400

----------------------------------------------------------------------
 .../auth/cas/AuthenticationProviderService.java | 33 ++++---
 .../auth/cas/conf/CASGuacamoleProperties.java   |  6 +-
 .../auth/cas/conf/ConfigurationService.java     |  4 +-
 .../properties/CipherGuacamoleProperty.java     | 95 --------------------
 .../properties/PrivateKeyGuacamoleProperty.java | 81 +++++++++++++++++
 5 files changed, 106 insertions(+), 113 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/badbf4cc/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/AuthenticationProviderService.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/AuthenticationProviderService.java b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/AuthenticationProviderService.java
index da32f72..22a63bd 100644
--- a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/AuthenticationProviderService.java
+++ b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/AuthenticationProviderService.java
@@ -44,6 +44,7 @@ import javax.xml.bind.DatatypeConverter;
 import org.apache.guacamole.environment.Environment;
 import org.apache.guacamole.form.Field;
 import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.GuacamoleServerException;
 import org.apache.guacamole.net.auth.Credentials;
 import org.apache.guacamole.net.auth.credentials.CredentialsInfo;
 import org.apache.guacamole.net.auth.credentials.GuacamoleInsufficientCredentialsException;
@@ -166,32 +167,38 @@ public class AuthenticationProviderService {
             throws GuacamoleException {
 
         // If we get nothing, we return nothing.
-        if (encryptedPassword == null || encryptedPassword.isEmpty())
+        if (encryptedPassword == null || encryptedPassword.isEmpty()) {
+            logger.warn("No or empty encrypted password, no password will be available.");
             return null;
+        }
+
+        final PrivateKey clearpassKey = confService.getClearpassKey();
+        if (clearpassKey == null) {
+            logger.warn("No private key available to decrypt password.");
+            return null;
+        }
 
         try {
 
-            final Cipher cipher = confService.getClearpassCipher();
+            final Cipher cipher = Cipher.getInstance(clearpassKey.getAlgorithm());
 
-            if (cipher != null) {
+            if (cipher == null)
+                throw new GuacamoleServerException("Failed to initialize cipher object with private key.");
 
-                // Decode and decrypt, and return a new string.
-                final byte[] pass64 = DatatypeConverter.parseBase64Binary(encryptedPassword);
-                final byte[] cipherData = cipher.doFinal(pass64);
-                return new String(cipherData);
+            // Initialize the Cipher in decrypt mode.
+            cipher.init(Cipher.DECRYPT_MODE, clearpassKey);
 
-            }
+            // Decode and decrypt, and return a new string.
+            final byte[] pass64 = DatatypeConverter.parseBase64Binary(encryptedPassword);
+            final byte[] cipherData = cipher.doFinal(pass64);
+            return new String(cipherData);
 
         }
         catch (Throwable t) {
-            logger.error("Failed to decrypt the data, password token will not be available.");
             logger.debug("Failed to either convert Base64 or decrypt the password.  CAS Password will not be available inside Guacamole.  Exception is: {}", t);
-            return null;
+            throw new GuacamoleServerException("Failed to decrypt CAS ClearPass password.", t);
         }
 
-        logger.warn("Encrypted password provided by CAS, but no Private Key was available to decrypt it.");
-        return null;
-
     }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/badbf4cc/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/conf/CASGuacamoleProperties.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/conf/CASGuacamoleProperties.java b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/conf/CASGuacamoleProperties.java
index 7a600c9..aa4a06e 100644
--- a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/conf/CASGuacamoleProperties.java
+++ b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/conf/CASGuacamoleProperties.java
@@ -19,7 +19,7 @@
 
 package org.apache.guacamole.auth.cas.conf;
 
-import org.apache.guacamole.properties.CipherGuacamoleProperty;
+import org.apache.guacamole.properties.PrivateKeyGuacamoleProperty;
 import org.apache.guacamole.properties.StringGuacamoleProperty;
 
 /**
@@ -62,8 +62,8 @@ public class CASGuacamoleProperties {
      * The location of the private key file used to retrieve the
      * password if CAS is configured to support ClearPass.
      */
-    public static final CipherGuacamoleProperty CAS_CLEARPASS_KEY =
-            new CipherGuacamoleProperty() {
+    public static final PrivateKeyGuacamoleProperty CAS_CLEARPASS_KEY =
+            new PrivateKeyGuacamoleProperty() {
 
         @Override
         public String getName() { return "cas-clearpass-key"; }

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/badbf4cc/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/conf/ConfigurationService.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/conf/ConfigurationService.java b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/conf/ConfigurationService.java
index ba969d4..409097e 100644
--- a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/conf/ConfigurationService.java
+++ b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/conf/ConfigurationService.java
@@ -21,7 +21,7 @@ package org.apache.guacamole.auth.cas.conf;
 
 import com.google.inject.Inject;
 import java.io.File;
-import javax.crypto.Cipher;
+import java.security.PrivateKey;
 import org.apache.guacamole.GuacamoleException;
 import org.apache.guacamole.environment.Environment;
 
@@ -82,7 +82,7 @@ public class ConfigurationService {
      * @throws GuacamoleException
      *     If guacamole.properties cannot be parsed.
      */
-    public Cipher getClearpassCipher() throws GuacamoleException {
+    public PrivateKey getClearpassKey() throws GuacamoleException {
         return environment.getProperty(CASGuacamoleProperties.CAS_CLEARPASS_KEY);
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/badbf4cc/guacamole-ext/src/main/java/org/apache/guacamole/properties/CipherGuacamoleProperty.java
----------------------------------------------------------------------
diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/properties/CipherGuacamoleProperty.java b/guacamole-ext/src/main/java/org/apache/guacamole/properties/CipherGuacamoleProperty.java
deleted file mode 100644
index d4d763f..0000000
--- a/guacamole-ext/src/main/java/org/apache/guacamole/properties/CipherGuacamoleProperty.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.guacamole.properties;
-
-import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.InputStream;
-import java.io.IOException;
-import java.lang.IllegalArgumentException;
-import java.security.InvalidKeyException;
-import java.security.KeyFactory;
-import java.security.NoSuchAlgorithmException;
-import java.security.PrivateKey;
-import java.security.spec.InvalidKeySpecException;
-import java.security.spec.KeySpec;
-import java.security.spec.PKCS8EncodedKeySpec;
-import javax.crypto.Cipher;
-import javax.crypto.NoSuchPaddingException;
-import org.apache.guacamole.GuacamoleException;
-import org.apache.guacamole.environment.Environment;
-import org.apache.guacamole.environment.LocalEnvironment;
-
-/**
- * A GuacamoleProperty whose value is derived from a private key file.
- */
-public abstract class CipherGuacamoleProperty implements GuacamoleProperty<Cipher>  {
-
-    @Override
-    public Cipher parseValue(String value) throws GuacamoleException {
-
-        if (value == null || value.isEmpty())
-            return null;
-
-        try {
-
-            final Environment environment = new LocalEnvironment();
-
-            // Open and read the file specified in the configuration.
-            File keyFile = new File(environment.getGuacamoleHome(), value);
-            InputStream keyInput = new BufferedInputStream(new FileInputStream(keyFile));
-            final byte[] keyBytes = new byte[(int) keyFile.length()];
-            keyInput.read(keyBytes);
-            keyInput.close();
-
-            // Set up decryption infrastructure
-            KeyFactory keyFactory = KeyFactory.getInstance("RSA");
-            KeySpec keySpec = new PKCS8EncodedKeySpec(keyBytes);
-            final PrivateKey privateKey = keyFactory.generatePrivate(keySpec);
-            final Cipher cipher = Cipher.getInstance(privateKey.getAlgorithm());
-            cipher.init(Cipher.DECRYPT_MODE, privateKey);
-
-            return cipher;
-
-        }
-        catch (FileNotFoundException e) {
-            throw new GuacamoleException("Could not find the specified key file.", e);
-        }
-        catch (IOException e) {
-            throw new GuacamoleException("Could not read in the specified key file.", e);
-        }
-        catch (NoSuchAlgorithmException e) {
-            throw new GuacamoleException("Specified algorithm does not exist.", e);
-        }
-        catch (InvalidKeyException e) {
-            throw new GuacamoleException("Specified key is invalid.", e);
-        }
-        catch (InvalidKeySpecException e) {
-            throw new GuacamoleException("Invalid KeySpec initialization.", e);
-        }
-        catch (NoSuchPaddingException e) {
-            throw new GuacamoleException("No such padding exception.", e);
-        }
-
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/badbf4cc/guacamole-ext/src/main/java/org/apache/guacamole/properties/PrivateKeyGuacamoleProperty.java
----------------------------------------------------------------------
diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/properties/PrivateKeyGuacamoleProperty.java b/guacamole-ext/src/main/java/org/apache/guacamole/properties/PrivateKeyGuacamoleProperty.java
new file mode 100644
index 0000000..904a4d1
--- /dev/null
+++ b/guacamole-ext/src/main/java/org/apache/guacamole/properties/PrivateKeyGuacamoleProperty.java
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.properties;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.io.IOException;
+import java.lang.IllegalArgumentException;
+import java.security.InvalidKeyException;
+import java.security.KeyFactory;
+import java.security.NoSuchAlgorithmException;
+import java.security.PrivateKey;
+import java.security.spec.InvalidKeySpecException;
+import java.security.spec.KeySpec;
+import java.security.spec.PKCS8EncodedKeySpec;
+import org.apache.guacamole.GuacamoleServerException;
+import org.apache.guacamole.environment.Environment;
+import org.apache.guacamole.environment.LocalEnvironment;
+
+/**
+ * A GuacamoleProperty whose value is derived from a private key file.
+ */
+public abstract class PrivateKeyGuacamoleProperty implements GuacamoleProperty<PrivateKey>  {
+
+    @Override
+    public PrivateKey parseValue(String value) throws GuacamoleServerException {
+
+        if (value == null || value.isEmpty())
+            return null;
+
+        try {
+
+            // Open and read the file specified in the configuration.
+            File keyFile = new File(value);
+            InputStream keyInput = new BufferedInputStream(new FileInputStream(keyFile));
+            final byte[] keyBytes = new byte[(int) keyFile.length()];
+            keyInput.read(keyBytes);
+            keyInput.close();
+
+            // Set up decryption infrastructure
+            KeyFactory keyFactory = KeyFactory.getInstance("RSA");
+            KeySpec keySpec = new PKCS8EncodedKeySpec(keyBytes);
+            return keyFactory.generatePrivate(keySpec);
+
+        }
+        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("Specified algorithm does not exist.", e);
+        }
+        catch (InvalidKeySpecException e) {
+            throw new GuacamoleServerException("Invalid KeySpec initialization.", e);
+        }
+
+    }
+
+}


[04/25] incubator-guacamole-client git commit: GUACAMOLE-362: Removed unnecesary addition of username to credentials.

Posted by mj...@apache.org.
GUACAMOLE-362: Removed unnecesary addition of username to credentials.


Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/commit/1592cf56
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/tree/1592cf56
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/diff/1592cf56

Branch: refs/heads/master
Commit: 1592cf563a878ccfab720f666ce11865e71d5a26
Parents: badbf4c
Author: Nick Couchman <vn...@apache.org>
Authored: Tue Sep 26 22:21:08 2017 -0400
Committer: Nick Couchman <ni...@yahoo.com>
Committed: Fri Oct 27 13:05:12 2017 -0400

----------------------------------------------------------------------
 .../apache/guacamole/auth/cas/AuthenticationProviderService.java    | 1 -
 1 file changed, 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/1592cf56/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/AuthenticationProviderService.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/AuthenticationProviderService.java b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/AuthenticationProviderService.java
index 22a63bd..617d3d9 100644
--- a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/AuthenticationProviderService.java
+++ b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/AuthenticationProviderService.java
@@ -117,7 +117,6 @@ public class AuthenticationProviderService {
                 AuthenticatedUser authenticatedUser = authenticatedUserProvider.get();
                 AttributePrincipal principal = ticketService.validateTicket(ticket);
                 String username = principal.getName();
-                credentials.setUsername(username);
                 Object credObj = principal.getAttributes().get("credential");
                 if (credObj != null) {
                     String clearPass = decryptPassword(credObj.toString());


[24/25] incubator-guacamole-client git commit: GUACAMOLE-362: Merge support for CAS ClearPass.

Posted by mj...@apache.org.
GUACAMOLE-362: Merge support for CAS ClearPass.


Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/commit/0d74dc58
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/tree/0d74dc58
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/diff/0d74dc58

Branch: refs/heads/master
Commit: 0d74dc582108f1840271bfd92c101d514a77164b
Parents: d955fbe ad8820c
Author: Michael Jumper <mj...@apache.org>
Authored: Fri Oct 27 10:50:08 2017 -0700
Committer: Michael Jumper <mj...@apache.org>
Committed: Fri Oct 27 10:50:08 2017 -0700

----------------------------------------------------------------------
 .../auth/cas/AuthenticationProviderService.java |  20 ++-
 .../auth/cas/conf/CASGuacamoleProperties.java   |  12 ++
 .../auth/cas/conf/ConfigurationService.java     |  17 +++
 .../cas/conf/PrivateKeyGuacamoleProperty.java   |  86 +++++++++++++
 .../cas/ticket/TicketValidationService.java     | 125 ++++++++++++++++---
 5 files changed, 240 insertions(+), 20 deletions(-)
----------------------------------------------------------------------



[17/25] incubator-guacamole-client git commit: GUACAMOLE-362: Add missing parameter documentation for credentials object.

Posted by mj...@apache.org.
GUACAMOLE-362: Add missing parameter documentation for credentials object.


Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/commit/bd57938d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/tree/bd57938d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/diff/bd57938d

Branch: refs/heads/master
Commit: bd57938dff460ca0f90d9bd8258c4dbc0bb2966e
Parents: b410b99
Author: Nick Couchman <vn...@apache.org>
Authored: Sat Sep 30 22:30:46 2017 -0400
Committer: Nick Couchman <ni...@yahoo.com>
Committed: Fri Oct 27 13:05:13 2017 -0400

----------------------------------------------------------------------
 .../apache/guacamole/auth/cas/ticket/TicketValidationService.java | 3 +++
 1 file changed, 3 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/bd57938d/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/ticket/TicketValidationService.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/ticket/TicketValidationService.java b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/ticket/TicketValidationService.java
index de38964..482c73a 100644
--- a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/ticket/TicketValidationService.java
+++ b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/ticket/TicketValidationService.java
@@ -63,6 +63,9 @@ public class TicketValidationService {
      *
      * @param ticket
      *     The ID ticket to validate and parse.
+     * @param credentials
+     *     The Credentials object to store retrieved username and
+     *     password values in.
      *
      * @return
      *     The username derived from the ticket.


[14/25] incubator-guacamole-client git commit: GUACAMOLE-362: Move password decryption logic into TicketValidationService class.

Posted by mj...@apache.org.
GUACAMOLE-362: Move password decryption logic into TicketValidationService class.


Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/commit/62fafcb3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/tree/62fafcb3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/diff/62fafcb3

Branch: refs/heads/master
Commit: 62fafcb379f96bb6850f1b4cbb0339072fe0f9f6
Parents: 6313432
Author: Nick Couchman <vn...@apache.org>
Authored: Wed Sep 27 11:13:51 2017 -0400
Committer: Nick Couchman <ni...@yahoo.com>
Committed: Fri Oct 27 13:05:13 2017 -0400

----------------------------------------------------------------------
 .../auth/cas/AuthenticationProviderService.java | 114 ++-----------------
 .../cas/ticket/TicketValidationService.java     | 108 +++++++++++++++++-
 2 files changed, 113 insertions(+), 109 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/62fafcb3/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/AuthenticationProviderService.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/AuthenticationProviderService.java b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/AuthenticationProviderService.java
index 171c30f..325268e 100644
--- a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/AuthenticationProviderService.java
+++ b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/AuthenticationProviderService.java
@@ -21,32 +21,11 @@ package org.apache.guacamole.auth.cas;
 
 import com.google.inject.Inject;
 import com.google.inject.Provider;
-import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.InputStream;
-import java.io.IOException;
-import java.lang.IllegalArgumentException;
-import java.security.InvalidKeyException;
-import java.security.KeyFactory;
-import java.security.NoSuchAlgorithmException;
-import java.security.PrivateKey;
-import java.security.spec.KeySpec;
-import java.security.spec.PKCS8EncodedKeySpec;
 import java.util.Arrays;
-import java.util.Enumeration;
-import javax.crypto.BadPaddingException;
-import javax.crypto.Cipher;
-import javax.crypto.IllegalBlockSizeException;
-import javax.crypto.NoSuchPaddingException;
 import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpSession;
-import javax.xml.bind.DatatypeConverter;
 import org.apache.guacamole.environment.Environment;
 import org.apache.guacamole.form.Field;
 import org.apache.guacamole.GuacamoleException;
-import org.apache.guacamole.GuacamoleServerException;
 import org.apache.guacamole.net.auth.Credentials;
 import org.apache.guacamole.net.auth.credentials.CredentialsInfo;
 import org.apache.guacamole.net.auth.credentials.GuacamoleInsufficientCredentialsException;
@@ -54,9 +33,6 @@ import org.apache.guacamole.auth.cas.conf.ConfigurationService;
 import org.apache.guacamole.auth.cas.form.CASTicketField;
 import org.apache.guacamole.auth.cas.ticket.TicketValidationService;
 import org.apache.guacamole.auth.cas.user.AuthenticatedUser;
-import org.jasig.cas.client.authentication.AttributePrincipal;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 /**
  * Service providing convenience functions for the CAS AuthenticationProvider
@@ -65,11 +41,6 @@ import org.slf4j.LoggerFactory;
 public class AuthenticationProviderService {
 
     /**
-     * Logger for this class.
-     */
-    private static final Logger logger = LoggerFactory.getLogger(AuthenticationProviderService.class);
-
-    /**
      * Service for retrieving CAS configuration information.
      */
     @Inject
@@ -116,16 +87,17 @@ public class AuthenticationProviderService {
         if (request != null) {
             String ticket = request.getParameter(CASTicketField.PARAMETER_NAME);
             if (ticket != null) {
-                AuthenticatedUser authenticatedUser = authenticatedUserProvider.get();
-                AttributePrincipal principal = ticketService.validateTicket(ticket);
-                String username = principal.getName();
-                Object credObj = principal.getAttributes().get("credential");
-                if (credObj != null) {
-                    String clearPass = decryptPassword(credObj.toString());
-                    if (clearPass != null && !clearPass.isEmpty())
-                        credentials.setPassword(clearPass);
+                Credentials ticketCredentials = ticketService.validateTicket(ticket);
+                if (ticketCredentials != null) {
+                    String username = ticketCredentials.getUsername();
+                    if (username != null)
+                        credentials.setUsername(username);
+                    String password = ticketCredentials.getPassword();
+                    if (password != null)
+                        credentials.setPassword(password);
                 }
-                authenticatedUser.init(username, credentials);
+                AuthenticatedUser authenticatedUser = authenticatedUserProvider.get();
+                authenticatedUser.init(credentials.getUsername(), credentials);
                 return authenticatedUser;
             }
         }
@@ -147,70 +119,4 @@ public class AuthenticationProviderService {
 
     }
 
-    /**
-     * Takes an encrypted string representing a password provided by
-     * the CAS ClearPass service and decrypts it using the private
-     * key configured for this extension.  Returns null if it is
-     * unable to decrypt the password.
-     *
-     * @param encryptedPassword
-     *     A string with the encrypted password provided by the
-     *     CAS service.
-     *
-     * @return
-     *     The decrypted password, or null if it is unable to
-     *     decrypt the password.
-     *
-     * @throws GuacamoleException
-     *     If unable to get Guacamole configuration data
-     */
-    private final String decryptPassword(String encryptedPassword)
-            throws GuacamoleException {
-
-        // If we get nothing, we return nothing.
-        if (encryptedPassword == null || encryptedPassword.isEmpty()) {
-            logger.warn("No or empty encrypted password, no password will be available.");
-            return null;
-        }
-
-        final PrivateKey clearpassKey = confService.getClearpassKey();
-        if (clearpassKey == null) {
-            logger.warn("No private key available to decrypt password.");
-            return null;
-        }
-
-        try {
-
-            final Cipher cipher = Cipher.getInstance(clearpassKey.getAlgorithm());
-
-            if (cipher == null)
-                throw new GuacamoleServerException("Failed to initialize cipher object with private key.");
-
-            // Initialize the Cipher in decrypt mode.
-            cipher.init(Cipher.DECRYPT_MODE, clearpassKey);
-
-            // Decode and decrypt, and return a new string.
-            final byte[] pass64 = DatatypeConverter.parseBase64Binary(encryptedPassword);
-            final byte[] cipherData = cipher.doFinal(pass64);
-            return new String(cipherData);
-
-        }
-        catch (BadPaddingException e) {
-            throw new GuacamoleServerException("Bad padding when decrypting cipher data.", e);
-        }
-        catch (IllegalBlockSizeException e) {
-            throw new GuacamoleServerException("Illegal block size while opening private key.", e);
-        }
-        catch (InvalidKeyException e) {
-            throw new GuacamoleServerException("Specified private key for ClearPass decryption is invalid.", e);
-        }
-        catch (NoSuchAlgorithmException e) {
-            throw new GuacamoleServerException("Unexpected algorithm for the private key.", e);
-        }
-        catch (NoSuchPaddingException e) {
-            throw new GuacamoleServerException("No such padding tryingto initialize cipher with private key.", e);
-        }
-
-    }
-
 }

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/62fafcb3/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/ticket/TicketValidationService.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/ticket/TicketValidationService.java b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/ticket/TicketValidationService.java
index 96da6ff..0162801 100644
--- a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/ticket/TicketValidationService.java
+++ b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/ticket/TicketValidationService.java
@@ -20,14 +20,24 @@
 package org.apache.guacamole.auth.cas.ticket;
 
 import com.google.inject.Inject;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+import java.security.PrivateKey;
+import javax.crypto.BadPaddingException;
+import javax.crypto.Cipher;
+import javax.crypto.IllegalBlockSizeException;
+import javax.crypto.NoSuchPaddingException;
+import javax.xml.bind.DatatypeConverter;
 import org.apache.guacamole.GuacamoleException;
-import org.apache.guacamole.GuacamoleSecurityException;
 import org.apache.guacamole.GuacamoleServerException;
 import org.apache.guacamole.auth.cas.conf.ConfigurationService;
+import org.apache.guacamole.net.auth.Credentials;
 import org.jasig.cas.client.authentication.AttributePrincipal;
 import org.jasig.cas.client.validation.Assertion;
 import org.jasig.cas.client.validation.Cas20ProxyTicketValidator;
 import org.jasig.cas.client.validation.TicketValidationException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Service for validating ID tickets forwarded to us by the client, verifying
@@ -36,13 +46,18 @@ import org.jasig.cas.client.validation.TicketValidationException;
 public class TicketValidationService {
 
     /**
+     * Logger for this class.
+     */
+    private static final Logger logger = LoggerFactory.getLogger(TicketValidationService.class);
+
+    /**
      * Service for retrieving CAS configuration information.
      */
     @Inject
     private ConfigurationService confService;
 
     /**
-     * Validates and parses the given ID ticket, returning the AttributePrincipal
+     * Validates and parses the given ID ticket, returning the Credentials object
      * derived from the parameters provided by the CAS server in the ticket.  If the
      * ticket is invalid an exception is thrown.
      *
@@ -50,13 +65,13 @@ public class TicketValidationService {
      *     The ID ticket to validate and parse.
      *
      * @return
-     *     The AttributePrincipal derived from parameters provided in the ticket.
+     *     The Credentials object derived from parameters provided in the ticket.
      *
      * @throws GuacamoleException
      *     If the ID ticket is not valid or guacamole.properties could
      *     not be parsed.
      */
-    public AttributePrincipal validateTicket(String ticket) throws GuacamoleException {
+    public Credentials validateTicket(String ticket) throws GuacamoleException {
 
         // Retrieve the configured CAS URL, establish a ticket validator,
         // and then attempt to validate the supplied ticket.  If that succeeds,
@@ -65,9 +80,26 @@ public class TicketValidationService {
         Cas20ProxyTicketValidator validator = new Cas20ProxyTicketValidator(casServerUrl);
         validator.setAcceptAnyProxy(true);
         try {
+            Credentials ticketCredentials = new Credentials();
             String confRedirectURI = confService.getRedirectURI();
             Assertion a = validator.validate(ticket, confRedirectURI);
-            return a.getPrincipal();
+            AttributePrincipal principal =  a.getPrincipal();
+
+            // Retrieve username and set the credentials.
+            String username = principal.getName();
+            if (username != null)
+                ticketCredentials.setUsername(username);
+
+            // Retrieve password, attempt decryption, and set credentials.
+            Object credObj = principal.getAttributes().get("credential");
+            if (credObj != null) {
+                String clearPass = decryptPassword(credObj.toString());
+                if (clearPass != null && !clearPass.isEmpty())
+                    ticketCredentials.setPassword(clearPass);
+            }
+
+            return ticketCredentials;
+
         } 
         catch (TicketValidationException e) {
             throw new GuacamoleException("Ticket validation failed.", e);
@@ -75,4 +107,70 @@ public class TicketValidationService {
 
     }
 
+    /**
+     * Takes an encrypted string representing a password provided by
+     * the CAS ClearPass service and decrypts it using the private
+     * key configured for this extension.  Returns null if it is
+     * unable to decrypt the password.
+     *
+     * @param encryptedPassword
+     *     A string with the encrypted password provided by the
+     *     CAS service.
+     *
+     * @return
+     *     The decrypted password, or null if it is unable to
+     *     decrypt the password.
+     *
+     * @throws GuacamoleException
+     *     If unable to get Guacamole configuration data
+     */
+    private final String decryptPassword(String encryptedPassword)
+            throws GuacamoleException {
+
+        // If we get nothing, we return nothing.
+        if (encryptedPassword == null || encryptedPassword.isEmpty()) {
+            logger.warn("No or empty encrypted password, no password will be available.");
+            return null;
+        }
+
+        final PrivateKey clearpassKey = confService.getClearpassKey();
+        if (clearpassKey == null) {
+            logger.warn("No private key available to decrypt password.");
+            return null;
+        }
+
+        try {
+
+            final Cipher cipher = Cipher.getInstance(clearpassKey.getAlgorithm());
+
+            if (cipher == null)
+                throw new GuacamoleServerException("Failed to initialize cipher object with private key.");
+
+            // Initialize the Cipher in decrypt mode.
+            cipher.init(Cipher.DECRYPT_MODE, clearpassKey);
+
+            // Decode and decrypt, and return a new string.
+            final byte[] pass64 = DatatypeConverter.parseBase64Binary(encryptedPassword);
+            final byte[] cipherData = cipher.doFinal(pass64);
+            return new String(cipherData);
+
+        }
+        catch (BadPaddingException e) {
+            throw new GuacamoleServerException("Bad padding when decrypting cipher data.", e);
+        }
+        catch (IllegalBlockSizeException e) {
+            throw new GuacamoleServerException("Illegal block size while opening private key.", e);
+        }
+        catch (InvalidKeyException e) {
+            throw new GuacamoleServerException("Specified private key for ClearPass decryption is invalid.", e);
+        }
+        catch (NoSuchAlgorithmException e) {
+            throw new GuacamoleServerException("Unexpected algorithm for the private key.", e);
+        }
+        catch (NoSuchPaddingException e) {
+            throw new GuacamoleServerException("No such padding tryingto initialize cipher with private key.", e);
+        }
+
+    }
+
 }


[03/25] incubator-guacamole-client git commit: GUACAMOLE-362: Add support for CAS ClearPass, parsing and decrypting the password and assigning it a token.

Posted by mj...@apache.org.
GUACAMOLE-362: Add support for CAS ClearPass, parsing and decrypting the password and assigning it a token.


Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/commit/1c4831dd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/tree/1c4831dd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/diff/1c4831dd

Branch: refs/heads/master
Commit: 1c4831dd5191a9043edff7b771fef919a56281db
Parents: d955fbe
Author: Nick Couchman <vn...@apache.org>
Authored: Wed Aug 16 11:58:26 2017 -0400
Committer: Nick Couchman <ni...@yahoo.com>
Committed: Fri Oct 27 13:05:12 2017 -0400

----------------------------------------------------------------------
 .../auth/cas/AuthenticationProviderService.java | 103 ++++++++++++++++++-
 .../auth/cas/conf/CASGuacamoleProperties.java   |  13 +++
 .../auth/cas/conf/ConfigurationService.java     |  17 +++
 .../cas/ticket/TicketValidationService.java     |   9 +-
 4 files changed, 134 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/1c4831dd/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/AuthenticationProviderService.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/AuthenticationProviderService.java b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/AuthenticationProviderService.java
index f3870a6..0422d30 100644
--- a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/AuthenticationProviderService.java
+++ b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/AuthenticationProviderService.java
@@ -21,11 +21,26 @@ package org.apache.guacamole.auth.cas;
 
 import com.google.inject.Inject;
 import com.google.inject.Provider;
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.io.IOException;
+import java.security.InvalidKeyException;
+import java.security.KeyFactory;
+import java.security.NoSuchAlgorithmException;
+import java.security.PrivateKey;
+import java.security.spec.KeySpec;
+import java.security.spec.PKCS8EncodedKeySpec;
 import java.util.Arrays;
 import java.util.Enumeration;
+import javax.crypto.Cipher;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpSession;
+import javax.xml.bind.DatatypeConverter;
 import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.environment.LocalEnvironment;
 import org.apache.guacamole.form.Field;
 import org.apache.guacamole.net.auth.Credentials;
 import org.apache.guacamole.net.auth.credentials.CredentialsInfo;
@@ -34,6 +49,9 @@ import org.apache.guacamole.auth.cas.conf.ConfigurationService;
 import org.apache.guacamole.auth.cas.form.CASTicketField;
 import org.apache.guacamole.auth.cas.ticket.TicketValidationService;
 import org.apache.guacamole.auth.cas.user.AuthenticatedUser;
+import org.jasig.cas.client.authentication.AttributePrincipal;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Service providing convenience functions for the CAS AuthenticationProvider
@@ -42,6 +60,11 @@ import org.apache.guacamole.auth.cas.user.AuthenticatedUser;
 public class AuthenticationProviderService {
 
     /**
+     * Logger for this class.
+     */
+    private static final Logger logger = LoggerFactory.getLogger(AuthenticationProviderService.class);
+
+    /**
      * Service for retrieving CAS configuration information.
      */
     @Inject
@@ -83,7 +106,13 @@ public class AuthenticationProviderService {
             String ticket = request.getParameter(CASTicketField.PARAMETER_NAME);
             if (ticket != null) {
                 AuthenticatedUser authenticatedUser = authenticatedUserProvider.get();
-                authenticatedUser.init(ticketService.processUsername(ticket), credentials);
+                AttributePrincipal principal = ticketService.validateTicket(ticket);
+                String username = principal.getName();
+                credentials.setUsername(username);
+                String clearPass = decryptPassword(principal.getAttributes().get("credential").toString());
+                if (clearPass != null && !clearPass.isEmpty())
+                    credentials.setPassword(clearPass);
+                authenticatedUser.init(username, credentials);
                 return authenticatedUser;
             }
         }
@@ -105,4 +134,76 @@ public class AuthenticationProviderService {
 
     }
 
+    /**
+     * Takes an encrypted string representing a password provided by
+     * the CAS ClearPass service and decrypts it using the private
+     * key configured for this extension.  Returns null if it is
+     * unable to decrypt the password.
+     *
+     * @param encryptedPassword
+     *     A string with the encrypted password provided by the
+     *     CAS service.
+     *
+     * @return
+     *     The decrypted password, or null if it is unable to
+     *     decrypt the password.
+     * @throws GuacamoleException
+     *     If unable to get Guacamole configuration data
+     */
+    private final String decryptPassword(String encryptedPassword)
+            throws GuacamoleException {
+
+        // If we get nothing, we return nothing.
+        if (encryptedPassword == null || encryptedPassword.isEmpty())
+            return null;
+
+        try {
+
+            // Open and read the file specified in the configuration.
+            File keyFile = new File(new LocalEnvironment().getGuacamoleHome(), confService.getClearpassKey().toString());
+            InputStream keyInput = new BufferedInputStream(new FileInputStream(keyFile));
+            final byte[] keyBytes = new byte[(int) keyFile.length()];
+            keyInput.read(keyBytes);
+            keyInput.close();
+      
+            // Set up decryption infrastructure
+            KeyFactory keyFactory = KeyFactory.getInstance("RSA");
+            KeySpec keySpec = new PKCS8EncodedKeySpec(keyBytes); 
+            final PrivateKey privateKey = keyFactory.generatePrivate(keySpec);
+            final Cipher cipher = Cipher.getInstance(privateKey.getAlgorithm());
+            final byte[] pass64 = DatatypeConverter.parseBase64Binary(encryptedPassword);
+            cipher.init(Cipher.DECRYPT_MODE, privateKey);
+
+            // Decrypt and return a new string.
+            final byte[] cipherData = cipher.doFinal(pass64);
+            return new String(cipherData);
+        }
+        catch (FileNotFoundException e) {
+            logger.error("ClearPass key file not found, password will not be decrypted.");
+            logger.debug("Error locating the ClearPass key file: {}", e.getMessage());
+            return null;
+        }
+        catch (IOException e) {
+            logger.error("Error reading ClearPass key file, password will not be decrypted.");
+            logger.debug("Error reading the ClearPass key file: {}", e.getMessage());
+            return null;
+        }
+        catch (NoSuchAlgorithmException e) {
+            logger.error("Unable to find the specified algorithm, password will not be decrypted.");
+            logger.debug("Algorithm was not found: {}", e.getMessage());
+            return null;
+        }
+        catch (InvalidKeyException e) {
+            logger.error("Invalid key was loaded, password will not be decrypted.");
+            logger.debug("The loaded key was invalid: {}", e.getMessage());
+            return null;
+        }
+        catch (Throwable t) {
+            logger.error("Error decrypting password, it will not be available as a token.");
+            logger.debug("Error in one of the components to decrypt the password: {}", t.getMessage());
+            return null;
+        }
+
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/1c4831dd/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/conf/CASGuacamoleProperties.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/conf/CASGuacamoleProperties.java b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/conf/CASGuacamoleProperties.java
index 00fb901..410e848 100644
--- a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/conf/CASGuacamoleProperties.java
+++ b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/conf/CASGuacamoleProperties.java
@@ -19,6 +19,7 @@
 
 package org.apache.guacamole.auth.cas.conf;
 
+import org.apache.guacamole.properties.FileGuacamoleProperty;
 import org.apache.guacamole.properties.StringGuacamoleProperty;
 
 /**
@@ -57,4 +58,16 @@ public class CASGuacamoleProperties {
 
     };
 
+    /**
+     * The location of the private key file used to retrieve the
+     * password if CAS is configured to support ClearPass.
+     */
+    public static final FileGuacamoleProperty CAS_CLEARPASS_KEY =
+            new FileGuacamoleProperty() {
+
+        @Override
+        public String getName() { return "cas-clearpass-key"; }
+
+    };
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/1c4831dd/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/conf/ConfigurationService.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/conf/ConfigurationService.java b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/conf/ConfigurationService.java
index 17be2d3..b2d74d5 100644
--- a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/conf/ConfigurationService.java
+++ b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/conf/ConfigurationService.java
@@ -20,6 +20,7 @@
 package org.apache.guacamole.auth.cas.conf;
 
 import com.google.inject.Inject;
+import java.io.File;
 import org.apache.guacamole.GuacamoleException;
 import org.apache.guacamole.environment.Environment;
 
@@ -68,4 +69,20 @@ public class ConfigurationService {
         return environment.getRequiredProperty(CASGuacamoleProperties.CAS_REDIRECT_URI);
     }
 
+    /**
+     * Returns the path to the file that contains the private key
+     * used to decrypt the credential that is sent encrypted by CAS,
+     * or null if no key is defined.
+     *
+     * @return
+     *     The path to the private key to decrypt the ClearPass
+     *     credential returned by CAS.
+     *
+     * @throws GuacamoleException
+     *     If guacamole.properties cannot be parsed.
+     */
+    public File getClearpassKey() throws GuacamoleException {
+        return environment.getProperty(CASGuacamoleProperties.CAS_CLEARPASS_KEY);
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/1c4831dd/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/ticket/TicketValidationService.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/ticket/TicketValidationService.java b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/ticket/TicketValidationService.java
index 9644c68..fca2ccf 100644
--- a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/ticket/TicketValidationService.java
+++ b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/ticket/TicketValidationService.java
@@ -57,9 +57,7 @@ public class TicketValidationService {
      *     If the ID ticket is not valid, the username claim type is missing, or
      *     guacamole.properties could not be parsed.
      */
-    public String processUsername(String ticket) throws GuacamoleException {
-
-        AttributePrincipal principal = null;
+    public AttributePrincipal validateTicket(String ticket) throws GuacamoleException {
 
         // Retrieve the configured CAS URL, establish a ticket validator,
         // and then attempt to validate the supplied ticket.  If that succeeds,
@@ -70,15 +68,12 @@ public class TicketValidationService {
         try {
             String confRedirectURI = confService.getRedirectURI();
             Assertion a = validator.validate(ticket, confRedirectURI);
-            principal = a.getPrincipal();
+            return a.getPrincipal();
         } 
         catch (TicketValidationException e) {
             throw new GuacamoleException("Ticket validation failed.", e);
         }
 
-        // Return the principal name as the username.
-        return principal.getName();
-
     }
 
 }


[06/25] incubator-guacamole-client git commit: GUACAMOLE-362: Debug should throw full exception, not just getMessage() output.

Posted by mj...@apache.org.
GUACAMOLE-362: Debug should throw full exception, not just getMessage() output.


Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/commit/c3aaf0aa
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/tree/c3aaf0aa
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/diff/c3aaf0aa

Branch: refs/heads/master
Commit: c3aaf0aa032713e70c72326e19e3733db8f7670f
Parents: 87fba0e
Author: Nick Couchman <vn...@apache.org>
Authored: Wed Aug 23 10:27:09 2017 -0400
Committer: Nick Couchman <ni...@yahoo.com>
Committed: Fri Oct 27 13:05:12 2017 -0400

----------------------------------------------------------------------
 .../auth/cas/AuthenticationProviderService.java     | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/c3aaf0aa/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/AuthenticationProviderService.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/AuthenticationProviderService.java b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/AuthenticationProviderService.java
index 1797060..feb842d 100644
--- a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/AuthenticationProviderService.java
+++ b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/AuthenticationProviderService.java
@@ -27,6 +27,7 @@ import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.InputStream;
 import java.io.IOException;
+import java.lang.IllegalArgumentException;
 import java.security.InvalidKeyException;
 import java.security.KeyFactory;
 import java.security.NoSuchAlgorithmException;
@@ -190,27 +191,32 @@ public class AuthenticationProviderService {
         }
         catch (FileNotFoundException e) {
             logger.error("ClearPass key file not found, password will not be decrypted.");
-            logger.debug("Error locating the ClearPass key file: {}", e.getMessage());
+            logger.debug("Error locating the ClearPass key file: {}", e);
             return null;
         }
         catch (IOException e) {
             logger.error("Error reading ClearPass key file, password will not be decrypted.");
-            logger.debug("Error reading the ClearPass key file: {}", e.getMessage());
+            logger.debug("Error reading the ClearPass key file: {}", e);
             return null;
         }
         catch (NoSuchAlgorithmException e) {
             logger.error("Unable to find the specified algorithm, password will not be decrypted.");
-            logger.debug("Algorithm was not found: {}", e.getMessage());
+            logger.debug("Algorithm was not found: {}", e);
             return null;
         }
         catch (InvalidKeyException e) {
             logger.error("Invalid key was loaded, password will not be decrypted.");
-            logger.debug("The loaded key was invalid: {}", e.getMessage());
+            logger.debug("The loaded key was invalid: {}", e);
+            return null;
+        }
+        catch (IllegalArgumentException e) {
+            logger.error("Failed to parse Base64 data, password will not be decrypted.");
+            logger.debug("Data received was not valid Base64 data, so decryption cannot continue: {}", e);
             return null;
         }
         catch (Throwable t) {
             logger.error("Error decrypting password, it will not be available as a token.");
-            logger.debug("Error in one of the components to decrypt the password: {}", t.getMessage());
+            logger.debug("Error in one of the components to decrypt the password: {}", t);
             return null;
         }
 


[20/25] incubator-guacamole-client git commit: GUACAMOLE-362: Deal correctly with return value when reading the key.

Posted by mj...@apache.org.
GUACAMOLE-362: Deal correctly with return value when reading the key.


Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/commit/3d091411
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/tree/3d091411
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/diff/3d091411

Branch: refs/heads/master
Commit: 3d091411f3290aaee37be1d0cf82dfeeea23bc15
Parents: ab41f44
Author: Nick Couchman <vn...@apache.org>
Authored: Sun Oct 1 07:15:19 2017 -0400
Committer: Nick Couchman <ni...@yahoo.com>
Committed: Fri Oct 27 13:05:13 2017 -0400

----------------------------------------------------------------------
 .../properties/PrivateKeyGuacamoleProperty.java   | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/3d091411/guacamole-ext/src/main/java/org/apache/guacamole/properties/PrivateKeyGuacamoleProperty.java
----------------------------------------------------------------------
diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/properties/PrivateKeyGuacamoleProperty.java b/guacamole-ext/src/main/java/org/apache/guacamole/properties/PrivateKeyGuacamoleProperty.java
index 174f183..c360f4b 100644
--- a/guacamole-ext/src/main/java/org/apache/guacamole/properties/PrivateKeyGuacamoleProperty.java
+++ b/guacamole-ext/src/main/java/org/apache/guacamole/properties/PrivateKeyGuacamoleProperty.java
@@ -53,8 +53,22 @@ public abstract class PrivateKeyGuacamoleProperty implements GuacamoleProperty<P
             // Open and read the file specified in the configuration.
             File keyFile = new File(value);
             InputStream keyInput = new BufferedInputStream(new FileInputStream(keyFile));
-            final byte[] keyBytes = new byte[(int) keyFile.length()];
-            keyInput.read(keyBytes);
+            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.");
+
+            // Zero-sized key
+            else if(keyRead == 0)
+                throw new GuacamoleServerException("Failed to ready key because key is empty.");
+
+            // Fewer bytes read than contained in the key
+            else if (keyRead < keyLength)
+                throw new GuacamoleServerException("Unable to read the full length of the key.");
+
             keyInput.close();
 
             // Set up decryption infrastructure


[02/25] incubator-guacamole-client git commit: GUACAMOLE-362: Fix case where credential object is null.

Posted by mj...@apache.org.
GUACAMOLE-362: Fix case where credential object is null.


Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/commit/1c333106
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/tree/1c333106
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/diff/1c333106

Branch: refs/heads/master
Commit: 1c333106c03a188418679e7e248a3e848dd604b7
Parents: 1c4831d
Author: Nick Couchman <vn...@apache.org>
Authored: Sat Aug 19 14:06:05 2017 -0400
Committer: Nick Couchman <ni...@yahoo.com>
Committed: Fri Oct 27 13:05:12 2017 -0400

----------------------------------------------------------------------
 .../guacamole/auth/cas/AuthenticationProviderService.java   | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/1c333106/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/AuthenticationProviderService.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/AuthenticationProviderService.java b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/AuthenticationProviderService.java
index 0422d30..6a13a83 100644
--- a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/AuthenticationProviderService.java
+++ b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/AuthenticationProviderService.java
@@ -109,9 +109,12 @@ public class AuthenticationProviderService {
                 AttributePrincipal principal = ticketService.validateTicket(ticket);
                 String username = principal.getName();
                 credentials.setUsername(username);
-                String clearPass = decryptPassword(principal.getAttributes().get("credential").toString());
-                if (clearPass != null && !clearPass.isEmpty())
-                    credentials.setPassword(clearPass);
+                Object credObj = principal.getAttributes().get("credential");
+                if (credObj != null) {
+                    String clearPass = decryptPassword(credObj.toString());
+                    if (clearPass != null && !clearPass.isEmpty())
+                        credentials.setPassword(clearPass);
+                }
                 authenticatedUser.init(username, credentials);
                 return authenticatedUser;
             }


[18/25] incubator-guacamole-client git commit: GUACAMOLE-362: Fix style and error messages.

Posted by mj...@apache.org.
GUACAMOLE-362: Fix style and error messages.


Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/commit/ab41f441
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/tree/ab41f441
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/diff/ab41f441

Branch: refs/heads/master
Commit: ab41f441003bb5524509fc22aeb130184dab271f
Parents: bd57938
Author: Nick Couchman <vn...@apache.org>
Authored: Sun Oct 1 07:06:20 2017 -0400
Committer: Nick Couchman <ni...@yahoo.com>
Committed: Fri Oct 27 13:05:13 2017 -0400

----------------------------------------------------------------------
 .../guacamole/auth/cas/ticket/TicketValidationService.java       | 1 +
 .../apache/guacamole/properties/PrivateKeyGuacamoleProperty.java | 4 ++--
 2 files changed, 3 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/ab41f441/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/ticket/TicketValidationService.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/ticket/TicketValidationService.java b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/ticket/TicketValidationService.java
index 482c73a..009f955 100644
--- a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/ticket/TicketValidationService.java
+++ b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/ticket/TicketValidationService.java
@@ -63,6 +63,7 @@ public class TicketValidationService {
      *
      * @param ticket
      *     The ID ticket to validate and parse.
+     *
      * @param credentials
      *     The Credentials object to store retrieved username and
      *     password values in.

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/ab41f441/guacamole-ext/src/main/java/org/apache/guacamole/properties/PrivateKeyGuacamoleProperty.java
----------------------------------------------------------------------
diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/properties/PrivateKeyGuacamoleProperty.java b/guacamole-ext/src/main/java/org/apache/guacamole/properties/PrivateKeyGuacamoleProperty.java
index 570b776..174f183 100644
--- a/guacamole-ext/src/main/java/org/apache/guacamole/properties/PrivateKeyGuacamoleProperty.java
+++ b/guacamole-ext/src/main/java/org/apache/guacamole/properties/PrivateKeyGuacamoleProperty.java
@@ -70,10 +70,10 @@ public abstract class PrivateKeyGuacamoleProperty implements GuacamoleProperty<P
             throw new GuacamoleServerException("Could not read in the specified key file.", e);
         }
         catch (NoSuchAlgorithmException e) {
-            throw new GuacamoleServerException("Key is not in expected RSA algorithm.", e);
+            throw new GuacamoleServerException("RSA algorithm is not available.", e);
         }
         catch (InvalidKeySpecException e) {
-            throw new GuacamoleServerException("KeyS is not in expected PKCS8 encoding.", e);
+            throw new GuacamoleServerException("Key is not in expected PKCS8 encoding.", e);
         }
 
     }


[05/25] incubator-guacamole-client git commit: GUACAMOLE-362: Deal gracefully with situations where password cannot be decrypted.

Posted by mj...@apache.org.
GUACAMOLE-362: Deal gracefully with situations where password cannot be decrypted.


Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/commit/ed4c025a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/tree/ed4c025a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/diff/ed4c025a

Branch: refs/heads/master
Commit: ed4c025a2e642899427a1866a418d119ebff3bf8
Parents: 36489ff
Author: Nick Couchman <vn...@apache.org>
Authored: Sun Aug 27 20:55:27 2017 -0400
Committer: Nick Couchman <ni...@yahoo.com>
Committed: Fri Oct 27 13:05:12 2017 -0400

----------------------------------------------------------------------
 .../auth/cas/AuthenticationProviderService.java     | 16 ++++++++++++----
 .../properties/CipherGuacamoleProperty.java         |  3 +++
 2 files changed, 15 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/ed4c025a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/AuthenticationProviderService.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/AuthenticationProviderService.java b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/AuthenticationProviderService.java
index b7ebdf7..da32f72 100644
--- a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/AuthenticationProviderService.java
+++ b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/AuthenticationProviderService.java
@@ -173,10 +173,15 @@ public class AuthenticationProviderService {
 
             final Cipher cipher = confService.getClearpassCipher();
 
-            // Decrypt and return a new string.
-            final byte[] pass64 = DatatypeConverter.parseBase64Binary(encryptedPassword);
-            final byte[] cipherData = cipher.doFinal(pass64);
-            return new String(cipherData);
+            if (cipher != null) {
+
+                // Decode and decrypt, and return a new string.
+                final byte[] pass64 = DatatypeConverter.parseBase64Binary(encryptedPassword);
+                final byte[] cipherData = cipher.doFinal(pass64);
+                return new String(cipherData);
+
+            }
+
         }
         catch (Throwable t) {
             logger.error("Failed to decrypt the data, password token will not be available.");
@@ -184,6 +189,9 @@ public class AuthenticationProviderService {
             return null;
         }
 
+        logger.warn("Encrypted password provided by CAS, but no Private Key was available to decrypt it.");
+        return null;
+
     }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/ed4c025a/guacamole-ext/src/main/java/org/apache/guacamole/properties/CipherGuacamoleProperty.java
----------------------------------------------------------------------
diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/properties/CipherGuacamoleProperty.java b/guacamole-ext/src/main/java/org/apache/guacamole/properties/CipherGuacamoleProperty.java
index e2f95ec..d4d763f 100644
--- a/guacamole-ext/src/main/java/org/apache/guacamole/properties/CipherGuacamoleProperty.java
+++ b/guacamole-ext/src/main/java/org/apache/guacamole/properties/CipherGuacamoleProperty.java
@@ -47,6 +47,9 @@ public abstract class CipherGuacamoleProperty implements GuacamoleProperty<Ciphe
     @Override
     public Cipher parseValue(String value) throws GuacamoleException {
 
+        if (value == null || value.isEmpty())
+            return null;
+
         try {
 
             final Environment environment = new LocalEnvironment();


[12/25] incubator-guacamole-client git commit: GUACAMOLE-362: Remove debug line.

Posted by mj...@apache.org.
GUACAMOLE-362: Remove debug line.


Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/commit/63134322
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/tree/63134322
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/diff/63134322

Branch: refs/heads/master
Commit: 63134322b0ca5e788b6206c252d8e7e7262c0b55
Parents: 453a879
Author: Nick Couchman <vn...@apache.org>
Authored: Wed Sep 27 10:42:47 2017 -0400
Committer: Nick Couchman <ni...@yahoo.com>
Committed: Fri Oct 27 13:05:13 2017 -0400

----------------------------------------------------------------------
 .../apache/guacamole/auth/cas/AuthenticationProviderService.java  | 3 ---
 1 file changed, 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/63134322/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/AuthenticationProviderService.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/AuthenticationProviderService.java b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/AuthenticationProviderService.java
index ecb02d2..171c30f 100644
--- a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/AuthenticationProviderService.java
+++ b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/AuthenticationProviderService.java
@@ -210,9 +210,6 @@ public class AuthenticationProviderService {
         catch (NoSuchPaddingException e) {
             throw new GuacamoleServerException("No such padding tryingto initialize cipher with private key.", e);
         }
-        finally {
-            logger.debug("Yah.");
-        }
 
     }
 


[16/25] incubator-guacamole-client git commit: GUACAMOLE-362: Fix error message typo.

Posted by mj...@apache.org.
GUACAMOLE-362: Fix error message typo.


Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/commit/61f70c57
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/tree/61f70c57
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/diff/61f70c57

Branch: refs/heads/master
Commit: 61f70c57be2fab5a815aabb0ea5688f63fbda6e4
Parents: a196134
Author: Nick Couchman <vn...@apache.org>
Authored: Tue Oct 10 21:49:02 2017 -0400
Committer: Nick Couchman <ni...@yahoo.com>
Committed: Fri Oct 27 13:05:13 2017 -0400

----------------------------------------------------------------------
 .../apache/guacamole/auth/cas/ticket/TicketValidationService.java  | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/61f70c57/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/ticket/TicketValidationService.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/ticket/TicketValidationService.java b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/ticket/TicketValidationService.java
index f64481d..122059c 100644
--- a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/ticket/TicketValidationService.java
+++ b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/ticket/TicketValidationService.java
@@ -173,7 +173,7 @@ public class TicketValidationService {
             throw new GuacamoleServerException("Unexpected algorithm for the private key.", e);
         }
         catch (NoSuchPaddingException e) {
-            throw new GuacamoleServerException("No such padding tryingto initialize cipher with private key.", e);
+            throw new GuacamoleServerException("No such padding trying to initialize cipher with private key.", e);
         }
 
     }


[07/25] incubator-guacamole-client git commit: GUACAMOLE-362: Fix style issue; remove unnecessary LocalEnvironment initilization.

Posted by mj...@apache.org.
GUACAMOLE-362: Fix style issue; remove unnecessary LocalEnvironment initilization.


Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/commit/87fba0ed
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/tree/87fba0ed
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/diff/87fba0ed

Branch: refs/heads/master
Commit: 87fba0ed7bb640e305a81626e6e6b03cc57221ea
Parents: 1c33310
Author: Nick Couchman <vn...@apache.org>
Authored: Wed Aug 23 10:21:24 2017 -0400
Committer: Nick Couchman <ni...@yahoo.com>
Committed: Fri Oct 27 13:05:12 2017 -0400

----------------------------------------------------------------------
 .../auth/cas/AuthenticationProviderService.java        | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/87fba0ed/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/AuthenticationProviderService.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/AuthenticationProviderService.java b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/AuthenticationProviderService.java
index 6a13a83..1797060 100644
--- a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/AuthenticationProviderService.java
+++ b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/AuthenticationProviderService.java
@@ -39,9 +39,9 @@ import javax.crypto.Cipher;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpSession;
 import javax.xml.bind.DatatypeConverter;
-import org.apache.guacamole.GuacamoleException;
-import org.apache.guacamole.environment.LocalEnvironment;
+import org.apache.guacamole.environment.Environment;
 import org.apache.guacamole.form.Field;
+import org.apache.guacamole.GuacamoleException;
 import org.apache.guacamole.net.auth.Credentials;
 import org.apache.guacamole.net.auth.credentials.CredentialsInfo;
 import org.apache.guacamole.net.auth.credentials.GuacamoleInsufficientCredentialsException;
@@ -71,6 +71,12 @@ public class AuthenticationProviderService {
     private ConfigurationService confService;
 
     /**
+     * The Guacamole server environment.
+     */
+    @Inject
+    private Environment environment;
+
+    /**
      * Service for validating received ID tickets.
      */
     @Inject
@@ -150,6 +156,7 @@ public class AuthenticationProviderService {
      * @return
      *     The decrypted password, or null if it is unable to
      *     decrypt the password.
+     *
      * @throws GuacamoleException
      *     If unable to get Guacamole configuration data
      */
@@ -163,7 +170,7 @@ public class AuthenticationProviderService {
         try {
 
             // Open and read the file specified in the configuration.
-            File keyFile = new File(new LocalEnvironment().getGuacamoleHome(), confService.getClearpassKey().toString());
+            File keyFile = new File(environment.getGuacamoleHome(), confService.getClearpassKey().toString());
             InputStream keyInput = new BufferedInputStream(new FileInputStream(keyFile));
             final byte[] keyBytes = new byte[(int) keyFile.length()];
             keyInput.read(keyBytes);


[23/25] incubator-guacamole-client git commit: GUACAMOLE-362: Remove unnecessary IOException catch.

Posted by mj...@apache.org.
GUACAMOLE-362: Remove unnecessary IOException catch.


Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/commit/ad8820cf
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/tree/ad8820cf
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/diff/ad8820cf

Branch: refs/heads/master
Commit: ad8820cf054721eda95d72fc06a42356501c6ca2
Parents: b968e07
Author: Nick Couchman <vn...@apache.org>
Authored: Fri Oct 27 13:45:25 2017 -0400
Committer: Nick Couchman <vn...@apache.org>
Committed: Fri Oct 27 13:45:25 2017 -0400

----------------------------------------------------------------------
 .../auth/cas/conf/PrivateKeyGuacamoleProperty.java        | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/ad8820cf/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/conf/PrivateKeyGuacamoleProperty.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/conf/PrivateKeyGuacamoleProperty.java b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/conf/PrivateKeyGuacamoleProperty.java
index caa84cc..bd0bd69 100644
--- a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/conf/PrivateKeyGuacamoleProperty.java
+++ b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/conf/PrivateKeyGuacamoleProperty.java
@@ -56,13 +56,9 @@ public abstract class PrivateKeyGuacamoleProperty implements GuacamoleProperty<P
             FileInputStream keyStreamIn = new FileInputStream(keyFile);
             ByteArrayOutputStream keyStreamOut = new ByteArrayOutputStream();
             byte[] keyBuffer = new byte[1024];
-            try {
-                for (int readBytes; (readBytes = keyStreamIn.read(keyBuffer)) != -1;)
-                    keyStreamOut.write(keyBuffer, 0, readBytes);
-            }
-            catch (IOException e) {
-                throw new GuacamoleServerException("IOException while trying to read bytes from file.", e);
-            }
+
+            for (int readBytes; (readBytes = keyStreamIn.read(keyBuffer)) != -1;)
+                keyStreamOut.write(keyBuffer, 0, readBytes);
 
             final byte[] keyBytes = keyStreamOut.toByteArray();
 


[19/25] incubator-guacamole-client git commit: GUACAMOLE-362: Loop through reading bytes from key file.

Posted by mj...@apache.org.
GUACAMOLE-362: Loop through reading bytes from key file.


Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/commit/c92d2e35
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/tree/c92d2e35
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/diff/c92d2e35

Branch: refs/heads/master
Commit: c92d2e35986730d859f36015169b98127fefba60
Parents: 61f70c5
Author: Nick Couchman <vn...@apache.org>
Authored: Tue Oct 10 22:29:38 2017 -0400
Committer: Nick Couchman <ni...@yahoo.com>
Committed: Fri Oct 27 13:05:13 2017 -0400

----------------------------------------------------------------------
 .../properties/PrivateKeyGuacamoleProperty.java      | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/c92d2e35/guacamole-ext/src/main/java/org/apache/guacamole/properties/PrivateKeyGuacamoleProperty.java
----------------------------------------------------------------------
diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/properties/PrivateKeyGuacamoleProperty.java b/guacamole-ext/src/main/java/org/apache/guacamole/properties/PrivateKeyGuacamoleProperty.java
index c360f4b..68070f5 100644
--- a/guacamole-ext/src/main/java/org/apache/guacamole/properties/PrivateKeyGuacamoleProperty.java
+++ b/guacamole-ext/src/main/java/org/apache/guacamole/properties/PrivateKeyGuacamoleProperty.java
@@ -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();


[10/25] incubator-guacamole-client git commit: GUACAMOLE-362: Change warn to debug for missing private key.

Posted by mj...@apache.org.
GUACAMOLE-362: Change warn to debug for missing private key.


Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/commit/a196134f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/tree/a196134f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/diff/a196134f

Branch: refs/heads/master
Commit: a196134f2dd266fc3b8fac7b781eef05b016a209
Parents: 17599d9
Author: Nick Couchman <vn...@apache.org>
Authored: Sun Oct 1 15:39:32 2017 -0400
Committer: Nick Couchman <ni...@yahoo.com>
Committed: Fri Oct 27 13:05:13 2017 -0400

----------------------------------------------------------------------
 .../apache/guacamole/auth/cas/ticket/TicketValidationService.java  | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/a196134f/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/ticket/TicketValidationService.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/ticket/TicketValidationService.java b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/ticket/TicketValidationService.java
index 515deed..f64481d 100644
--- a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/ticket/TicketValidationService.java
+++ b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/ticket/TicketValidationService.java
@@ -140,7 +140,7 @@ public class TicketValidationService {
 
         final PrivateKey clearpassKey = confService.getClearpassKey();
         if (clearpassKey == null) {
-            logger.warn("No private key available to decrypt password.");
+            logger.debug("No private key available to decrypt password.");
             return null;
         }
 


[21/25] incubator-guacamole-client git commit: GUACAMOLE-362: Set encoding of ticket validator to UTF-8.

Posted by mj...@apache.org.
GUACAMOLE-362: Set encoding of ticket validator to UTF-8.


Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/commit/17599d91
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/tree/17599d91
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/diff/17599d91

Branch: refs/heads/master
Commit: 17599d9153131fdac94bc17c28e07af487955582
Parents: 3d09141
Author: Nick Couchman <vn...@apache.org>
Authored: Sun Oct 1 08:17:10 2017 -0400
Committer: Nick Couchman <ni...@yahoo.com>
Committed: Fri Oct 27 13:05:13 2017 -0400

----------------------------------------------------------------------
 .../guacamole/auth/cas/ticket/TicketValidationService.java       | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/17599d91/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/ticket/TicketValidationService.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/ticket/TicketValidationService.java b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/ticket/TicketValidationService.java
index 009f955..515deed 100644
--- a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/ticket/TicketValidationService.java
+++ b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/ticket/TicketValidationService.java
@@ -27,6 +27,7 @@ import javax.crypto.BadPaddingException;
 import javax.crypto.Cipher;
 import javax.crypto.IllegalBlockSizeException;
 import javax.crypto.NoSuchPaddingException;
+import java.nio.charset.Charset;
 import javax.xml.bind.DatatypeConverter;
 import org.apache.guacamole.GuacamoleException;
 import org.apache.guacamole.GuacamoleServerException;
@@ -83,6 +84,7 @@ public class TicketValidationService {
         String casServerUrl = confService.getAuthorizationEndpoint();
         Cas20ProxyTicketValidator validator = new Cas20ProxyTicketValidator(casServerUrl);
         validator.setAcceptAnyProxy(true);
+        validator.setEncoding("UTF-8");
         try {
             String confRedirectURI = confService.getRedirectURI();
             Assertion a = validator.validate(ticket, confRedirectURI);
@@ -155,7 +157,7 @@ public class TicketValidationService {
             // Decode and decrypt, and return a new string.
             final byte[] pass64 = DatatypeConverter.parseBase64Binary(encryptedPassword);
             final byte[] cipherData = cipher.doFinal(pass64);
-            return new String(cipherData);
+            return new String(cipherData, Charset.forName("UTF-8"));
 
         }
         catch (BadPaddingException e) {


[22/25] incubator-guacamole-client git commit: GUACAMOLE-362: Move PrivateKeyGuacamoleProperty into CAS extension and use ByteArrayOutputStream for reading thefile.

Posted by mj...@apache.org.
GUACAMOLE-362: Move PrivateKeyGuacamoleProperty into CAS extension and use ByteArrayOutputStream for reading thefile.


Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/commit/b968e073
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/tree/b968e073
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/diff/b968e073

Branch: refs/heads/master
Commit: b968e073c26d2bcfeeb6ce8a813f201136e1cad0
Parents: c92d2e3
Author: Nick Couchman <vn...@apache.org>
Authored: Fri Oct 27 12:57:15 2017 -0400
Committer: Nick Couchman <vn...@apache.org>
Committed: Fri Oct 27 13:06:07 2017 -0400

----------------------------------------------------------------------
 .../auth/cas/conf/CASGuacamoleProperties.java   |  1 -
 .../cas/conf/PrivateKeyGuacamoleProperty.java   | 90 ++++++++++++++++++
 .../properties/PrivateKeyGuacamoleProperty.java | 96 --------------------
 3 files changed, 90 insertions(+), 97 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/b968e073/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/conf/CASGuacamoleProperties.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/conf/CASGuacamoleProperties.java b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/conf/CASGuacamoleProperties.java
index aa4a06e..dd741a3 100644
--- a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/conf/CASGuacamoleProperties.java
+++ b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/conf/CASGuacamoleProperties.java
@@ -19,7 +19,6 @@
 
 package org.apache.guacamole.auth.cas.conf;
 
-import org.apache.guacamole.properties.PrivateKeyGuacamoleProperty;
 import org.apache.guacamole.properties.StringGuacamoleProperty;
 
 /**

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/b968e073/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/conf/PrivateKeyGuacamoleProperty.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/conf/PrivateKeyGuacamoleProperty.java b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/conf/PrivateKeyGuacamoleProperty.java
new file mode 100644
index 0000000..caa84cc
--- /dev/null
+++ b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/conf/PrivateKeyGuacamoleProperty.java
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.cas.conf;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.io.IOException;
+import java.lang.IllegalArgumentException;
+import java.security.InvalidKeyException;
+import java.security.KeyFactory;
+import java.security.NoSuchAlgorithmException;
+import java.security.PrivateKey;
+import java.security.spec.InvalidKeySpecException;
+import java.security.spec.KeySpec;
+import java.security.spec.PKCS8EncodedKeySpec;
+import org.apache.guacamole.properties.GuacamoleProperty;
+import org.apache.guacamole.GuacamoleServerException;
+import org.apache.guacamole.environment.Environment;
+import org.apache.guacamole.environment.LocalEnvironment;
+
+/**
+ * A GuacamoleProperty whose value is derived from a private key file.
+ */
+public abstract class PrivateKeyGuacamoleProperty implements GuacamoleProperty<PrivateKey>  {
+
+    @Override
+    public PrivateKey parseValue(String value) throws GuacamoleServerException {
+
+        if (value == null || value.isEmpty())
+            return null;
+
+        try {
+
+            // Open and read the file specified in the configuration.
+            File keyFile = new File(value);
+            FileInputStream keyStreamIn = new FileInputStream(keyFile);
+            ByteArrayOutputStream keyStreamOut = new ByteArrayOutputStream();
+            byte[] keyBuffer = new byte[1024];
+            try {
+                for (int readBytes; (readBytes = keyStreamIn.read(keyBuffer)) != -1;)
+                    keyStreamOut.write(keyBuffer, 0, readBytes);
+            }
+            catch (IOException e) {
+                throw new GuacamoleServerException("IOException while trying to read bytes from file.", e);
+            }
+
+            final byte[] keyBytes = keyStreamOut.toByteArray();
+
+            // Set up decryption infrastructure
+            KeyFactory keyFactory = KeyFactory.getInstance("RSA");
+            KeySpec keySpec = new PKCS8EncodedKeySpec(keyBytes);
+            return keyFactory.generatePrivate(keySpec);
+
+        }
+        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);
+        }
+
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/b968e073/guacamole-ext/src/main/java/org/apache/guacamole/properties/PrivateKeyGuacamoleProperty.java
----------------------------------------------------------------------
diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/properties/PrivateKeyGuacamoleProperty.java b/guacamole-ext/src/main/java/org/apache/guacamole/properties/PrivateKeyGuacamoleProperty.java
deleted file mode 100644
index 68070f5..0000000
--- a/guacamole-ext/src/main/java/org/apache/guacamole/properties/PrivateKeyGuacamoleProperty.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.guacamole.properties;
-
-import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.InputStream;
-import java.io.IOException;
-import java.lang.IllegalArgumentException;
-import java.security.InvalidKeyException;
-import java.security.KeyFactory;
-import java.security.NoSuchAlgorithmException;
-import java.security.PrivateKey;
-import java.security.spec.InvalidKeySpecException;
-import java.security.spec.KeySpec;
-import java.security.spec.PKCS8EncodedKeySpec;
-import org.apache.guacamole.GuacamoleServerException;
-import org.apache.guacamole.environment.Environment;
-import org.apache.guacamole.environment.LocalEnvironment;
-
-/**
- * A GuacamoleProperty whose value is derived from a private key file.
- */
-public abstract class PrivateKeyGuacamoleProperty implements GuacamoleProperty<PrivateKey>  {
-
-    @Override
-    public PrivateKey parseValue(String value) throws GuacamoleServerException {
-
-        if (value == null || value.isEmpty())
-            return null;
-
-        try {
-
-            // Open and read the file specified in the configuration.
-            File keyFile = new File(value);
-            InputStream keyInput = new BufferedInputStream(new FileInputStream(keyFile));
-            int keyLength = (int) keyFile.length();
-            final byte[] keyBytes = new byte[keyLength];
-            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
-            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
-            KeyFactory keyFactory = KeyFactory.getInstance("RSA");
-            KeySpec keySpec = new PKCS8EncodedKeySpec(keyBytes);
-            return keyFactory.generatePrivate(keySpec);
-
-        }
-        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);
-        }
-
-    }
-
-}