Github user mike-jumper commented on a diff in the pull request:
https://github.com/apache/incubator-guacamole-client/pull/183#discussion_r134756239
--- Diff:
extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/AuthenticationProviderService.java
---
@@ -105,4 +137,76 @@ public AuthenticatedUser authenticateUser(Credentials
credentials)
}
+ /**
+ * 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);
--- End diff --
Beware that this will throw an `IllegalArgumentException` provided data is
not valid base64. That case will need to be handled for this function to behave
in a robust manner.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---