-
Notifications
You must be signed in to change notification settings - Fork 2
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
Move config stuff to own Config class, cleanup readme about logging c… #15
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,35 @@ | ||||||||||
package com.teragrep.rlp_07; | ||||||||||
public class Config { | ||||||||||
private final int port; | ||||||||||
|
||||||||||
public int getPort() { | ||||||||||
return port; | ||||||||||
} | ||||||||||
|
||||||||||
private final boolean isTls; | ||||||||||
|
||||||||||
public boolean isTls() { | ||||||||||
return isTls; | ||||||||||
} | ||||||||||
|
||||||||||
private final String keystorePassword; | ||||||||||
|
||||||||||
public String getKeystorePassword() { | ||||||||||
return keystorePassword; | ||||||||||
} | ||||||||||
|
||||||||||
private final String keystorePath; | ||||||||||
public String getKeystorePath() { | ||||||||||
return keystorePath; | ||||||||||
} | ||||||||||
public Config() { | ||||||||||
try { | ||||||||||
port = Integer.parseInt(System.getProperty("port", "1601")); | ||||||||||
} catch (NumberFormatException e) { | ||||||||||
throw new RuntimeException("Can't parse port: " + e.getMessage()); | ||||||||||
} | ||||||||||
isTls = Boolean.parseBoolean(System.getProperty("tls", "false")); | ||||||||||
keystorePassword = System.getProperty("tlsKeystorePassword", "changeit"); | ||||||||||
keystorePath = System.getProperty("tlsKeystore", null); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. StaticAssignmentInConstructor: This assignment is to a static field. Mutating static state from a constructor is highly error-prone. ℹ️ Expand to see all @sonatype-lift commandsYou can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.
Note: When talking to LiftBot, you need to refresh the page to see its response. |
||||||||||
} | ||||||||||
} |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -25,55 +25,57 @@ class Main { | |||||||||
LOGGER.info(message); | ||||||||||
}; | ||||||||||
private static final FrameProcessor syslogFrameProcessor = new SyslogFrameProcessor(byteConsumer); | ||||||||||
static Config config; | ||||||||||
|
||||||||||
public static void main(String[] args) throws IOException, InterruptedException { | ||||||||||
int port = Integer.parseInt(System.getProperty("port", "1601")); | ||||||||||
boolean tlsMode = Boolean.parseBoolean(System.getProperty("tls", "false")); | ||||||||||
config = new Config(); | ||||||||||
try { | ||||||||||
if (tlsMode) { | ||||||||||
tlsServer(port); | ||||||||||
if (config.isTls()) { | ||||||||||
tlsServer(); | ||||||||||
} else { | ||||||||||
plainServer(port); | ||||||||||
plainServer(); | ||||||||||
} | ||||||||||
} | ||||||||||
catch (Exception e) { | ||||||||||
LOGGER.error("Failed to run: " + e.getMessage()); | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
private static void plainServer(int port) throws IOException, InterruptedException { | ||||||||||
LOGGER.info("Starting plain server on port " +port); | ||||||||||
Server relpServer = new Server(port, syslogFrameProcessor); | ||||||||||
private static void plainServer() throws IOException, InterruptedException { | ||||||||||
LOGGER.info("Starting plain server on port " + config.getPort()); | ||||||||||
Server relpServer = new Server(config.getPort(), syslogFrameProcessor); | ||||||||||
relpServer.start(); | ||||||||||
Thread.sleep(Long.MAX_VALUE); | ||||||||||
} | ||||||||||
|
||||||||||
private static void tlsServer(int port) throws IOException, InterruptedException { | ||||||||||
LOGGER.info("Starting TLS server on port " + port); | ||||||||||
String keystorePath = System.getProperty("tlsKeystore"); | ||||||||||
InputStream keyStoreStream; | ||||||||||
private static void tlsServer() throws IOException, InterruptedException { | ||||||||||
LOGGER.info("Starting TLS server on port " + config.getPort()); | ||||||||||
|
||||||||||
String keystorePath = config.getKeystorePath(); | ||||||||||
InputStream keystoreStream; | ||||||||||
if(keystorePath != null) { | ||||||||||
LOGGER.info("Using user supplied keystore"); | ||||||||||
Path path = Paths.get(keystorePath); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PATH_TRAVERSAL_IN: This API (java/nio/file/Paths.get(Ljava/lang/String;[Ljava/lang/String;)Ljava/nio/file/Path;) reads a file whose location might be specified by user input ℹ️ Expand to see all @sonatype-lift commandsYou can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.
Note: When talking to LiftBot, you need to refresh the page to see its response. |
||||||||||
if(!path.toFile().exists()) { | ||||||||||
throw new RuntimeException("File " + keystorePath + " doesn't exist"); | ||||||||||
} | ||||||||||
keyStoreStream = Files.newInputStream(path); | ||||||||||
keystoreStream = Files.newInputStream(path); | ||||||||||
} | ||||||||||
else { | ||||||||||
LOGGER.info("Using default keystore"); | ||||||||||
// get server keyStore as inputstream, works on JAR packaging as well this way | ||||||||||
keyStoreStream = Main.class.getClassLoader().getResourceAsStream("keystore-server.jks"); | ||||||||||
keystoreStream = Main.class.getClassLoader().getResourceAsStream("keystore-server.jks"); | ||||||||||
} | ||||||||||
|
||||||||||
SSLContext sslContext; | ||||||||||
try { | ||||||||||
sslContext = TLSContextFactory.authenticatedContext( | ||||||||||
keyStoreStream, | ||||||||||
"changeit", | ||||||||||
keystoreStream, | ||||||||||
config.getKeystorePassword(), | ||||||||||
"TLSv1.3" | ||||||||||
); | ||||||||||
} catch (GeneralSecurityException e) { | ||||||||||
throw new RuntimeException("SSL.demoContext Error: " + e); | ||||||||||
throw new RuntimeException("Can't create sslContext: " + e); | ||||||||||
} | ||||||||||
|
||||||||||
Function<SSLContext, SSLEngine> sslEngineFunction = sslCtx -> { | ||||||||||
|
@@ -82,10 +84,8 @@ private static void tlsServer(int port) throws IOException, InterruptedException | |||||||||
return sslEngine; | ||||||||||
}; | ||||||||||
|
||||||||||
Server relpServer = new Server(port, syslogFrameProcessor, sslContext, sslEngineFunction); | ||||||||||
|
||||||||||
Server relpServer = new Server(config.getPort(), syslogFrameProcessor, sslContext, sslEngineFunction); | ||||||||||
relpServer.start(); | ||||||||||
|
||||||||||
Thread.sleep(Long.MAX_VALUE); | ||||||||||
} | ||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
StaticAssignmentInConstructor: This assignment is to a static field. Mutating static state from a constructor is highly error-prone.
❗❗ 2 similar findings have been found in this PR
🔎 Expand here to view all instances of this finding
Visit the Lift Web Console to find more details in your report.
ℹ️ Expand to see all @sonatype-lift commands
You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.
@sonatype-lift ignore
@sonatype-lift ignoreall
@sonatype-lift exclude <file|issue|path|tool>
file|issue|path|tool
from Lift findings by updating your config.toml fileNote: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.