Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SAML read Certificate and private key #990

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,13 @@ public int getAuthenticationTimeout() throws GuacamoleException {
* If the X.509 certificate cannot be parsed.
*/
public File getCertificateFile() throws GuacamoleException {
return environment.getProperty(SAML_X509_CERT_PATH);
File certificate = null;
try {
certificate = environment.getProperty(SAML_X509_CERT_PATH).getCanonicalFile();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will throw a NullPointerException if getProperty() returns null (if the property is not present). Same for the other call to getCanonicalFile().

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the problem you're encountering that is fixed by calling getCanonicalFile()?

} catch (IOException | GuacamoleException e) {
e.printStackTrace();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If an error should be logged, it should be logged by a Logger instance with the stack trace logged only at the debug level. We typically do this by logging things twice, with an admin-facing message at the error level and a developer-facing message at the debug level.

That said, I think the proper thing to do here would be to just rethrow the IOException as a GuacamoleException, with the GuacamoleException adding a meaningful message.

}
return certificate;
}

/**
Expand All @@ -387,7 +393,13 @@ public File getCertificateFile() throws GuacamoleException {
* If the private key file cannot be parsed.
*/
public File getPrivateKeyFile() throws GuacamoleException {
return environment.getProperty(SAML_PRIVATE_KEY_PATH);
File privateKey = null;
try {
privateKey = environment.getProperty(SAML_PRIVATE_KEY_PATH).getCanonicalFile();
} catch (IOException | GuacamoleException e) {
e.printStackTrace();
}
return privateKey;
}

/**
Expand Down Expand Up @@ -480,7 +492,7 @@ public Saml2Settings getSamlSettings() throws GuacamoleException {
readFileContentsIntoString(privateKeyFile, "Private Key"));

// If a certificate file is set, load the value into the builder now
File certificateFile = getCertificateFile();
File certificateFile = getCertificateFile();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this line was changed only by adding several spaces to the end.

if (certificateFile != null)
samlMap.put(SettingsBuilder.SP_X509CERT_PROPERTY_KEY,
readFileContentsIntoString(certificateFile, "X.509 Certificate"));
Expand Down