use of horse.wtf.nzyme.configuration.leader.LeaderConfiguration in project nzyme by lennartkoopmann.
the class Main method main.
public static void main(String[] argv) {
final CLIArguments cliArguments = new CLIArguments();
// Parse CLI arguments.
JCommander.newBuilder().addObject(cliArguments).build().parse(argv);
// Override log level if requested.
if (cliArguments.isDebugMode()) {
Logging.setRootLoggerLevel(Level.DEBUG);
}
if (cliArguments.isTraceMode()) {
Logging.setRootLoggerLevel(Level.TRACE);
}
// Parse configuration.
BaseConfiguration baseConfiguration = null;
try {
baseConfiguration = new BaseConfigurationLoader(new File(cliArguments.getConfigFilePath())).get();
} catch (InvalidConfigurationException | ConfigException e) {
LOG.error("Invalid baseconfiguration. Please refer to the example configuration file or documentation.", e);
System.exit(FAILURE);
} catch (IncompleteConfigurationException e) {
LOG.error("Incomplete base configuration. Please refer to the example configuration file or documentation.", e);
System.exit(FAILURE);
} catch (FileNotFoundException e) {
LOG.error("Could not read configuration file.", e);
System.exit(FAILURE);
}
switch(baseConfiguration.mode()) {
case LEADER:
LeaderConfiguration leaderConfiguration = null;
try {
leaderConfiguration = new LeaderConfigurationLoader(new File(cliArguments.getConfigFilePath()), false).get();
} catch (InvalidConfigurationException | ConfigException e) {
LOG.error("Invalid configuration. Please refer to the example configuration file or documentation.", e);
System.exit(FAILURE);
} catch (IncompleteConfigurationException e) {
LOG.error("Incomplete configuration. Please refer to the example configuration file or documentation.", e);
System.exit(FAILURE);
} catch (FileNotFoundException e) {
LOG.error("Could not read configuration file.", e);
System.exit(FAILURE);
}
// Database.
Database database = new Database(leaderConfiguration);
try {
database.initializeAndMigrate();
} catch (LiquibaseException e) {
LOG.fatal("Error during database initialization and migration.", e);
System.exit(FAILURE);
}
NzymeLeader nzyme = new NzymeLeaderImpl(baseConfiguration, leaderConfiguration, database);
try {
nzyme.initialize();
} catch (Exception e) {
LOG.fatal("Could not initialize nzyme.", e);
System.exit(FAILURE);
}
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
Thread.currentThread().setName("shutdown-hook");
nzyme.shutdown();
}));
break;
case TRACKER:
TrackerConfiguration trackerConfiguration = null;
try {
trackerConfiguration = new TrackerConfigurationLoader(new File(cliArguments.getConfigFilePath())).get();
} catch (InvalidConfigurationException | ConfigException e) {
LOG.error("Invalid configuration. Please refer to the example configuration file or documentation.", e);
System.exit(FAILURE);
} catch (IncompleteConfigurationException e) {
LOG.error("Incomplete configuration. Please refer to the example configuration file or documentation.", e);
System.exit(FAILURE);
} catch (FileNotFoundException e) {
LOG.error("Could not read configuration file.", e);
System.exit(FAILURE);
}
NzymeTracker tracker = new NzymeTrackerImpl(baseConfiguration, trackerConfiguration);
try {
tracker.initialize();
} catch (Exception e) {
LOG.fatal("Could not initialize nzyme.", e);
System.exit(FAILURE);
}
}
while (true) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
break;
/* nein */
}
}
}
use of horse.wtf.nzyme.configuration.leader.LeaderConfiguration in project nzyme by lennartkoopmann.
the class NzymeLeaderConfigurationLoaderTest method testGetValidConfig.
@Test
public void testGetValidConfig() throws InvalidConfigurationException, IncompleteConfigurationException, FileNotFoundException {
String configFile = "nzyme-test-complete-valid.conf.test";
if (System.getProperty("os.name").startsWith("Windows")) {
configFile = "nzyme-test-complete-valid-windows.conf.test";
System.out.println("loading Windows nzyme configuration file");
}
LeaderConfiguration c = new LeaderConfigurationLoader(loadFromResourceFile(configFile), false).get();
assertEquals(c.role(), Role.LEADER);
// This one is different based on ENV vars
assertFalse(c.databasePath().isEmpty());
assertEquals(c.pythonScriptPrefix(), "nzyme_");
assertEquals(c.alertingTrainingPeriodSeconds(), 300);
assertTrue(c.fetchOuis());
assertTrue(c.versionchecksEnabled());
assertEquals(c.restListenUri(), URI.create("http://127.0.0.1:22900/"));
assertEquals(c.dot11Monitors(), new ArrayList<Dot11MonitorDefinition>() {
{
add(Dot11MonitorDefinition.create("wlx00c0ca8fd89a", ImmutableList.of(1, 2, 3, 4, 5, 6), "sudo /sbin/iwconfig {interface} channel {channel}", 1, false, 60));
add(Dot11MonitorDefinition.create("wlx00c0ca971216", ImmutableList.of(7, 8, 9, 10, 11), "sudo /sbin/iwconfig {interface} channel {channel}", 3, false, 60));
}
});
assertEquals(c.dot11Networks(), new ArrayList<Dot11NetworkDefinition>() {
{
add(Dot11NetworkDefinition.create("United_Wi-Fi", new ArrayList<Dot11BSSIDDefinition>() {
{
add(Dot11BSSIDDefinition.create("06:0d:2d:c9:36:23", ImmutableList.of("c9ed4adc12dc3e17208446b6a10070b70a73b9ce3a99215e05426faea6de91c7"), null));
add(Dot11BSSIDDefinition.create("24:a4:3c:7d:01:cc", ImmutableList.of("def456"), null));
}
}, new ArrayList<Integer>() {
{
add(1);
add(3);
add(6);
add(11);
}
}, new ArrayList<String>() {
{
add("NONE");
}
}, 40));
add(Dot11NetworkDefinition.create("WTF", new ArrayList<Dot11BSSIDDefinition>() {
{
add(Dot11BSSIDDefinition.create("00:c0:ca:95:68:3b", ImmutableList.of("dfac3abce0c722f9609343f7dfa208afa51a1c7decbd2eb6f96c78051f0a594b"), null));
}
}, new ArrayList<Integer>() {
{
add(1);
add(11);
}
}, new ArrayList<String>() {
{
add("WPA1-EAM-PSK-CCMP");
add("WPA2-EAM-PSK-CCMP");
}
}, 40));
}
});
assertEquals(c.dot11Alerts(), new ArrayList<Alert.TYPE_WIDE>() {
{
add(Alert.TYPE_WIDE.UNEXPECTED_BSSID);
add(Alert.TYPE_WIDE.UNEXPECTED_SSID);
add(Alert.TYPE_WIDE.UNEXPECTED_CHANNEL);
add(Alert.TYPE_WIDE.CRYPTO_CHANGE);
add(Alert.TYPE_WIDE.DEAUTH_FLOOD);
}
});
assertEquals(c.uplinks().size(), 4);
assertEquals(c.uplinks().get(0).type(), "syslog_udp_rfc5424");
assertEquals(c.uplinks().get(0).configuration().getString(ConfigurationKeys.HOST), "localhost");
assertEquals(c.uplinks().get(0).configuration().getInt(ConfigurationKeys.PORT), 5516);
assertEquals(c.uplinks().get(1).type(), "graylog");
assertEquals(c.uplinks().get(1).configuration().getString(ConfigurationKeys.HOST), "example.org");
assertEquals(c.uplinks().get(1).configuration().getInt(ConfigurationKeys.PORT), 5517);
assertEquals(c.uplinks().get(2).type(), "graylog");
assertEquals(c.uplinks().get(2).configuration().getString(ConfigurationKeys.HOST), "10.243.255.10");
assertEquals(c.uplinks().get(2).configuration().getInt(ConfigurationKeys.PORT), 33001);
assertEquals(c.uplinks().get(3).type(), "graylog");
assertEquals(c.uplinks().get(3).configuration().getString(ConfigurationKeys.HOST), "127.0.0.1");
assertEquals(c.uplinks().get(3).configuration().getInt(ConfigurationKeys.PORT), 9001);
assertEquals(c.remoteInputAddress(), new InetSocketAddress("0.0.0.0", 9002));
assertEquals(c.reporting().email().transportStrategy(), TransportStrategy.SMTP_TLS);
assertEquals(c.reporting().email().host(), "smtp.example.org");
assertEquals(c.reporting().email().port(), 587);
assertEquals(c.reporting().email().username(), "your_username");
assertEquals(c.reporting().email().password(), "your_password");
assertEquals(c.reporting().email().from(), new Recipient("nzyme", "nzyme@example.org", Message.RecipientType.TO));
assertEquals(c.reporting().email().subjectPrefix(), "[NZYME]");
assertEquals(c.deauth().globalThreshold(), 10);
}
Aggregations