use of org.apache.commons.configuration.ConversionException in project zaproxy by zaproxy.
the class ExtensionParam method parse.
@Override
protected void parse() {
try {
List<HierarchicalConfiguration> fields = ((HierarchicalConfiguration) getConfig()).configurationsAt(ALL_EXTENSIONS_KEY);
Map<String, Boolean> extensions = new HashMap<>();
for (HierarchicalConfiguration sub : fields) {
if (!sub.getBoolean(EXTENSION_ENABLED_KEY, true)) {
extensions.put(sub.getString(EXTENSION_NAME_KEY, ""), Boolean.FALSE);
}
}
extensionsState = Collections.unmodifiableMap(extensions);
} catch (ConversionException e) {
LOGGER.error("Error while loading extensions' state: " + e.getMessage(), e);
extensionsState = Collections.emptyMap();
}
}
use of org.apache.commons.configuration.ConversionException in project zaproxy by zaproxy.
the class Constant method initializeFilesAndDirectories.
public void initializeFilesAndDirectories() {
FileCopier copier = new FileCopier();
File f = null;
// Set up the version from the manifest
PROGRAM_VERSION = getVersionFromManifest();
PROGRAM_TITLE = PROGRAM_NAME + " " + PROGRAM_VERSION;
if (zapHome == null) {
zapHome = getDefaultHomeDirectory(true);
}
zapHome = getAbsolutePath(zapHome);
f = new File(zapHome);
FILE_CONFIG = zapHome + FILE_CONFIG;
FOLDER_SESSION = zapHome + FOLDER_SESSION;
DBNAME_UNTITLED = zapHome + DBNAME_UNTITLED;
ACCEPTED_LICENSE = zapHome + ACCEPTED_LICENSE;
DIRBUSTER_CUSTOM_DIR = zapHome + DIRBUSTER_DIR;
FUZZER_DIR = zapHome + FUZZER_DIR;
FOLDER_LOCAL_PLUGIN = zapHome + FOLDER_LOCAL_PLUGIN;
try {
System.setProperty(SYSTEM_PAROS_USER_LOG, zapHome);
if (!f.isDirectory()) {
if (!f.mkdir()) {
// ZAP: report failure to create directory
System.out.println("Failed to create directory " + f.getAbsolutePath());
}
}
// Setup the logging
File logFile = new File(zapHome + "/log4j.properties");
if (!logFile.exists()) {
copier.copy(new File(zapInstall, "xml/log4j.properties"), logFile);
}
System.setProperty("log4j.configuration", logFile.getAbsolutePath());
PropertyConfigurator.configure(logFile.getAbsolutePath());
f = new File(FILE_CONFIG);
if (!f.isFile()) {
this.copyDefaultConfigs(f, false);
}
f = new File(FOLDER_SESSION);
if (!f.isDirectory()) {
LOG.info("Creating directory " + FOLDER_SESSION);
if (!f.mkdir()) {
// ZAP: report failure to create directory
System.out.println("Failed to create directory " + f.getAbsolutePath());
}
}
f = new File(DIRBUSTER_CUSTOM_DIR);
if (!f.isDirectory()) {
LOG.info("Creating directory " + DIRBUSTER_CUSTOM_DIR);
if (!f.mkdir()) {
// ZAP: report failure to create directory
System.out.println("Failed to create directory " + f.getAbsolutePath());
}
}
f = new File(FUZZER_DIR);
if (!f.isDirectory()) {
LOG.info("Creating directory " + FUZZER_DIR);
if (!f.mkdir()) {
// ZAP: report failure to create directory
System.out.println("Failed to create directory " + f.getAbsolutePath());
}
}
f = new File(FOLDER_LOCAL_PLUGIN);
if (!f.isDirectory()) {
LOG.info("Creating directory " + FOLDER_LOCAL_PLUGIN);
if (!f.mkdir()) {
// ZAP: report failure to create directory
System.out.println("Failed to create directory " + f.getAbsolutePath());
}
}
f = new File(zapHome, FOLDER_FILTER);
if (!f.isDirectory()) {
LOG.info("Creating directory: " + f.getAbsolutePath());
if (!f.mkdir()) {
System.out.println("Failed to create directory " + f.getAbsolutePath());
}
}
} catch (Exception e) {
System.err.println("Unable to initialize home directory! " + e.getMessage());
e.printStackTrace(System.err);
System.exit(1);
}
// Upgrade actions
try {
try {
// ZAP: Changed to use ZapXmlConfiguration, to enforce the same character encoding when reading/writing configurations.
XMLConfiguration config = new ZapXmlConfiguration(FILE_CONFIG);
config.setAutoSave(false);
long ver = config.getLong("version");
if (ver == VERSION_TAG) {
// Nothing to do
} else if (isDevBuild() || isDailyBuild()) {
// Nothing to do
} else {
// Backup the old one
LOG.info("Backing up config file to " + FILE_CONFIG + ".bak");
f = new File(FILE_CONFIG);
try {
copier.copy(f, new File(FILE_CONFIG + ".bak"));
} catch (IOException e) {
String msg = "Failed to backup config file " + FILE_CONFIG + " to " + FILE_CONFIG + ".bak " + e.getMessage();
System.err.println(msg);
LOG.error(msg, e);
}
if (ver == V_PAROS_TAG) {
upgradeFrom1_1_0(config);
upgradeFrom1_2_0(config);
}
if (ver <= V_1_0_0_TAG) {
// Nothing to do
}
if (ver <= V_1_1_0_TAG) {
upgradeFrom1_1_0(config);
}
if (ver <= V_1_2_0_TAG) {
upgradeFrom1_2_0(config);
}
if (ver <= V_1_2_1_TAG) {
// Nothing to do
}
if (ver <= V_1_3_0_TAG) {
// Nothing to do
}
if (ver <= V_1_3_1_TAG) {
// Nothing to do
}
if (ver <= V_1_4_1_TAG) {
upgradeFrom1_4_1(config);
}
if (ver <= V_2_0_0_TAG) {
upgradeFrom2_0_0(config);
}
if (ver <= V_2_1_0_TAG) {
// Nothing to do
}
if (ver <= V_2_2_0_TAG) {
upgradeFrom2_2_0(config);
}
if (ver <= V_2_3_1_TAG) {
upgradeFrom2_3_1(config);
}
if (ver <= V_2_4_3_TAG) {
upgradeFrom2_4_3(config);
}
if (ver <= V_2_5_0_TAG) {
upgradeFrom2_5_0(config);
}
LOG.info("Upgraded from " + ver);
// Update the version
config.setProperty("version", VERSION_TAG);
config.save();
}
} catch (ConfigurationException | ConversionException | NoSuchElementException e) {
// if there is any error in config file (eg config file not exist, corrupted),
// overwrite previous configuration file
// ZAP: changed to use the correct file
copier.copy(getPathDefaultConfigFile().toFile(), new File(FILE_CONFIG));
}
} catch (Exception e) {
System.err.println("Unable to upgrade config file " + FILE_CONFIG + " " + e.getMessage());
e.printStackTrace(System.err);
System.exit(1);
}
// ZAP: Init i18n
String lang;
Locale locale = Locale.ENGLISH;
try {
// Select the correct locale
// ZAP: Changed to use ZapXmlConfiguration, to enforce the same character encoding when reading/writing configurations.
XMLConfiguration config = new ZapXmlConfiguration(FILE_CONFIG);
config.setAutoSave(false);
lang = config.getString(OptionsParamView.LOCALE, OptionsParamView.DEFAULT_LOCALE);
if (lang.length() == 0) {
lang = OptionsParamView.DEFAULT_LOCALE;
}
String[] langArray = lang.split("_");
locale = new Locale(langArray[0], langArray[1]);
} catch (Exception e) {
System.out.println("Failed to initialise locale " + e);
}
Locale.setDefault(locale);
messages = new I18N(locale);
}
use of org.apache.commons.configuration.ConversionException in project zaproxy by zaproxy.
the class PassiveScanParam method parse.
@Override
protected void parse() {
try {
List<HierarchicalConfiguration> fields = ((HierarchicalConfiguration) getConfig()).configurationsAt(ALL_AUTO_TAG_SCANNERS_KEY);
this.autoTagScanners = new ArrayList<>(fields.size());
List<String> tempListNames = new ArrayList<>(fields.size());
for (HierarchicalConfiguration sub : fields) {
String name = sub.getString(AUTO_TAG_SCANNER_NAME_KEY, "");
if (!"".equals(name) && !tempListNames.contains(name)) {
tempListNames.add(name);
RegexAutoTagScanner app = new RegexAutoTagScanner(sub.getString(AUTO_TAG_SCANNER_NAME_KEY), RegexAutoTagScanner.TYPE.valueOf(sub.getString(AUTO_TAG_SCANNER_TYPE_KEY)), sub.getString(AUTO_TAG_SCANNER_CONFIG_KEY), sub.getString(AUTO_TAG_SCANNER_REQ_URL_REGEX_KEY), sub.getString(AUTO_TAG_SCANNER_REQ_HEAD_REGEX_KEY), sub.getString(AUTO_TAG_SCANNER_RES_HEAD_REGEX_KEY), sub.getString(AUTO_TAG_SCANNER_RES_BODY_REGEX_KEY), sub.getBoolean(AUTO_TAG_SCANNER_ENABLED_KEY, true));
autoTagScanners.add(app);
}
}
} catch (ConversionException e) {
logger.error("Error while loading the auto tag scanners: " + e.getMessage(), e);
}
try {
this.confirmRemoveAutoTagScanner = getConfig().getBoolean(CONFIRM_REMOVE_AUTO_TAG_SCANNER_KEY, true);
} catch (ConversionException e) {
logger.error("Error while loading the confirm remove option: " + e.getMessage(), e);
}
try {
this.scanOnlyInScope = getConfig().getBoolean(SCAN_ONLY_IN_SCOPE_KEY, false);
} catch (ConversionException e) {
logger.error("Error while loading \"scanOnlyInScope\" option: " + e.getMessage(), e);
}
}
use of org.apache.commons.configuration.ConversionException in project zaproxy by zaproxy.
the class AntiCsrfParam method parse.
@Override
protected void parse() {
try {
List<HierarchicalConfiguration> fields = ((HierarchicalConfiguration) getConfig()).configurationsAt(ALL_TOKENS_KEY);
this.tokens = new ArrayList<>(fields.size());
enabledTokensNames = new ArrayList<>(fields.size());
List<String> tempTokensNames = new ArrayList<>(fields.size());
for (HierarchicalConfiguration sub : fields) {
String name = sub.getString(TOKEN_NAME_KEY, "");
if (!"".equals(name) && !tempTokensNames.contains(name)) {
boolean enabled = sub.getBoolean(TOKEN_ENABLED_KEY, true);
this.tokens.add(new AntiCsrfParamToken(name, enabled));
tempTokensNames.add(name);
if (enabled) {
enabledTokensNames.add(name);
}
}
}
} catch (ConversionException e) {
logger.error("Error while loading anti CSRF tokens: " + e.getMessage(), e);
this.tokens = new ArrayList<>(DEFAULT_TOKENS_NAMES.length);
this.enabledTokensNames = new ArrayList<>(DEFAULT_TOKENS_NAMES.length);
}
if (this.tokens.size() == 0) {
for (String tokenName : DEFAULT_TOKENS_NAMES) {
this.tokens.add(new AntiCsrfParamToken(tokenName));
this.enabledTokensNames.add(tokenName);
}
}
try {
this.confirmRemoveToken = getConfig().getBoolean(CONFIRM_REMOVE_TOKEN_KEY, true);
} catch (ConversionException e) {
logger.error("Error while loading the confirm remove token option: " + e.getMessage(), e);
}
}
use of org.apache.commons.configuration.ConversionException in project zaproxy by zaproxy.
the class VulnerabilitiesLoader method loadVulnerabilitiesFile.
private List<Vulnerability> loadVulnerabilitiesFile(Path file) {
ZapXmlConfiguration config;
try {
config = new ZapXmlConfiguration(file.toFile());
} catch (ConfigurationException e) {
logger.error(e.getMessage(), e);
return null;
}
String[] test;
try {
test = config.getStringArray("vuln_items");
} catch (ConversionException e) {
logger.error(e.getMessage(), e);
return null;
}
final int numberOfVulns = test.length;
List<Vulnerability> tempVulns = new ArrayList<>(numberOfVulns);
String name;
List<String> references;
for (String item : test) {
name = "vuln_item_" + item;
try {
references = new ArrayList<>(Arrays.asList(config.getStringArray(name + ".reference")));
} catch (ConversionException e) {
logger.error(e.getMessage(), e);
references = new ArrayList<>(0);
}
Vulnerability v = new Vulnerability(item, config.getString(name + ".alert"), config.getString(name + ".desc"), config.getString(name + ".solution"), references);
tempVulns.add(v);
}
return tempVulns;
}
Aggregations