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 NullPointerException when disabling and reenabling SSL #1027

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
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
5 changes: 0 additions & 5 deletions src/freenet/clients/http/ToadletContextImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -440,11 +440,6 @@ static void sendReplyHeaders(
mvt.put("x-content-security-policy", contentSecurityPolicy);
mvt.put("x-webkit-csp", contentSecurityPolicy);
mvt.put("x-frame-options", allowFrames ? "SAMEORIGIN" : "DENY");
String HSTS = SSL.getHSTSHeader();
if(!HSTS.isEmpty() && !mvt.containsKey("strict-transport-security")) {
// SSL enabled, set strict-transport-security so that the user agent upgrade future requests to SSL.
mvt.put("strict-transport-security", HSTS);
}
ArneBab marked this conversation as resolved.
Show resolved Hide resolved
StringBuilder buf = new StringBuilder(1024);
buf.append("HTTP/1.1 ");
buf.append(replyCode);
Expand Down
12 changes: 10 additions & 2 deletions src/freenet/crypt/SSL.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public static boolean available() {
}

public static String getHSTSHeader() {
if(available() && HSTSMaxAge > 0)
if(enable && available() && HSTSMaxAge > 0)
return "max-age=" + HSTSMaxAge;
else
return "";
Expand Down Expand Up @@ -119,11 +119,16 @@ public void set(Boolean newValue) throws InvalidConfigValueException {
} catch(Exception e) {
enable = false;
e.printStackTrace(System.out);
Logger.error(this, "SSL could not be enabled", e);
throwConfigError("SSL could not be enabled", e);
}
else {
ssf = null;
keyStore = null;
try {
keystore.load(null, keyStorePass.toCharArray());
} catch (Exception e) {
// Just clear the key store
}
}
}
}
Expand All @@ -147,6 +152,7 @@ public void set(String newKeyStore) throws InvalidConfigValueException {
} catch(Exception e) {
keyStore = oldKeyStore;
e.printStackTrace(System.out);
Logger.error(this, "Keystore file could not be changed", e);
throwConfigError("Keystore file could not be changed", e);
}
}
Expand All @@ -171,6 +177,7 @@ public void set(String newKeyStorePass) throws InvalidConfigValueException {
} catch(Exception e) {
keyStorePass = oldKeyStorePass;
e.printStackTrace(System.out);
Logger.error(this, "Keystore password could not be changed", e);
throwConfigError("Keystore password could not be changed", e);
}
}
Expand Down Expand Up @@ -198,6 +205,7 @@ public void set(String newKeyPass) throws InvalidConfigValueException {
} catch(Exception e) {
keyPass = oldKeyPass;
e.printStackTrace(System.out);
Logger.error(this, "Private key password could not be changed", e);
throwConfigError("Private key password could not be changed", e);
}
}
Expand Down
Loading