Skip to content

Commit

Permalink
Fixing contrast security issues (#172)
Browse files Browse the repository at this point in the history
* Fixing contrast security issues

Signed-off-by: Arun Venmany <[email protected]>

* correcting message per review comments

Signed-off-by: Arun Venmany <[email protected]>

---------

Signed-off-by: Arun Venmany <[email protected]>
  • Loading branch information
arunvenmany-ibm committed Sep 13, 2024
1 parent 696f7d1 commit adc0402
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 15 deletions.
8 changes: 5 additions & 3 deletions src/main/java/io/openliberty/tools/ant/AbstractTask.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* (C) Copyright IBM Corporation 2014, 2023.
* (C) Copyright IBM Corporation 2014, 2024.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -136,7 +136,8 @@ protected void initTask() {
log(MessageFormat.format(messages.getString("info.variable"), "server.output.dir", serverOutputDir.getCanonicalPath()),
Project.MSG_VERBOSE);
} catch (IOException e) {
throw new BuildException(e);
log(e,Project.MSG_ERR);
throw new BuildException("Exception while configuring liberty installation directories. See previous messages for information on the issue(s).");
}

// Check for windows..
Expand Down Expand Up @@ -312,7 +313,8 @@ public void run() {
}
} catch (IOException ex) {
sb.setLength(0);
throw new BuildException(ex);
log(ex,Project.MSG_ERR);
throw new BuildException("Exception received while checking for the return code in the output of the invoked command. See previous messages for more information on the issues().");
} finally {
if (isWindows) {
synchronized (this) {
Expand Down
38 changes: 38 additions & 0 deletions src/main/java/io/openliberty/tools/ant/RegexRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* (C) Copyright IBM Corporation 2024.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.openliberty.tools.ant;

import java.util.HashMap;
import java.util.Map;

public class RegexRepository {

private static final Map<String, String> regexMap;

static {
regexMap = new HashMap<>();
regexMap.put("ArchiveInstaller", "D/N:\\s*(.*)\\s*");
regexMap.put("WasDevInstaller", "D/N:\\s*(.*?)\\s*\\<");
}

private RegexRepository() {
}

public static String getRegex(String key) {
return regexMap.get(key);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* (C) Copyright IBM Corporation 2014.
* (C) Copyright IBM Corporation 2014, 2024.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,12 +21,11 @@
import java.util.jar.JarFile;
import java.util.zip.ZipEntry;

import io.openliberty.tools.ant.RegexRepository;
import org.apache.tools.ant.BuildException;

public class ArchiveInstaller implements Installer {

private static final String LICENSE_REGEX = "D/N:\\s*(.*)\\s*";

private String runtimeUrl;
private String extendedUrl;
private String licenseCode;
Expand Down Expand Up @@ -107,7 +106,7 @@ private String getLicenseCode(File jarFile) throws Exception {
throw new BuildException("Unable to find license file in " + jarFile);
}
in = jar.getInputStream(entry);
return InstallUtils.getLicenseCode(in, "UTF-16", LICENSE_REGEX);
return InstallUtils.getLicenseCode(in, "UTF-16", RegexRepository.getRegex(ArchiveInstaller.class.getName()));
} finally {
InstallUtils.close(in);
jar.close();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package io.openliberty.tools.ant.install;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.List;

import org.apache.commons.io.IOUtils;
Expand Down Expand Up @@ -32,7 +32,7 @@ public void install(InstallLibertyTask task) throws Exception {
task.downloadFile(versionInfoUrl, versionInfoFile);

// Parse JSON
InputStream versionInfoIs = new FileInputStream(versionInfoFile);
InputStream versionInfoIs = Files.newInputStream(versionInfoFile.toPath());
String versionInfoTxt = IOUtils.toString(versionInfoIs, StandardCharsets.UTF_8);
JSONObject versionInfoJson = new JSONObject(versionInfoTxt);

Expand All @@ -56,7 +56,7 @@ public void install(InstallLibertyTask task) throws Exception {
task.downloadFile(runtimeInfoUrl, runtimeInfoFile, true);

// Parse JSON
InputStream runtimeInfoIs = new FileInputStream(runtimeInfoFile);
InputStream runtimeInfoIs = Files.newInputStream(runtimeInfoFile.toPath());
String runtimeInfoTxt = IOUtils.toString(runtimeInfoIs, StandardCharsets.UTF_8);
JSONObject runtimeInfoJson = new JSONObject(runtimeInfoTxt);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* (C) Copyright IBM Corporation 2014.
* (C) Copyright IBM Corporation 2014, 2024.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,11 +20,10 @@
import java.util.Iterator;
import java.util.List;

import io.openliberty.tools.ant.RegexRepository;
import org.apache.tools.ant.BuildException;

public class WasDevInstaller implements Installer {

private static final String LICENSE_REGEX = "D/N:\\s*(.*?)\\s*\\<";

private String licenseCode;
private String version;
Expand Down Expand Up @@ -106,7 +105,7 @@ public void install(InstallLibertyTask task) throws Exception {
task.downloadFile(licenseURL, licenseFile, true);

// do license check
task.checkLicense(InstallUtils.getLicenseCode(licenseFile, LICENSE_REGEX));
task.checkLicense(InstallUtils.getLicenseCode(licenseFile, RegexRepository.getRegex(WasDevInstaller.class.getName())));

// download Liberty jar
URL libertyURL = new URL(uri);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/io/openliberty/tools/ant/jsp/CompileJSPs.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ public void execute() {
}
}
} catch (IOException e) {
throw new BuildException("A failure occurred: " + e.toString(), e);
log(e,Project.MSG_ERR);
throw new BuildException("A failure occurred: " + e.getLocalizedMessage());
}

}
Expand Down

0 comments on commit adc0402

Please sign in to comment.