-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #489 from psmf22/tool_debricked
feat: add tool config update command (update toolversions from zip bundle)
- Loading branch information
Showing
30 changed files
with
743 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
147 changes: 147 additions & 0 deletions
147
fcli-core/fcli-tool/src/main/java/com/fortify/cli/tool/_common/helper/OsAndArchHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
package com.fortify.cli.tool._common.helper; | ||
|
||
import java.util.Locale; | ||
|
||
public class OsAndArchHelper { | ||
public static final String getOSString() { | ||
String OS = normalizeOs(System.getProperty("os.name", "generic")); | ||
if (OS.equals("linux") || OS.equals("windows") || OS.equals("darwin")) { | ||
return OS; | ||
} else { | ||
throw new RuntimeException("Unexpected OS detected: '" + OS + "'"); | ||
} | ||
} | ||
|
||
public static final String getArchString() { | ||
String arch = normalizeArch(System.getProperty("os.arch", "generic")); | ||
|
||
if(arch.equals("x86") || arch.equals("x64") || arch.equals("arm64")) { | ||
return arch; | ||
} else { | ||
throw new RuntimeException("Unexpected cpu architecture detected: '" + arch + "'"); | ||
} | ||
} | ||
|
||
private static String normalizeOs(String value) { | ||
value = normalize(value); | ||
if (value.startsWith("aix")) { | ||
return "linux"; | ||
} | ||
if (value.startsWith("hpux")) { | ||
return "linux"; | ||
} | ||
if (value.startsWith("os400")) { | ||
// Avoid the names such as os4000 | ||
if (value.length() <= 5 || !Character.isDigit(value.charAt(5))) { | ||
return "os400"; | ||
} | ||
} | ||
if (value.startsWith("linux")) { | ||
return "linux"; | ||
} | ||
if (value.startsWith("mac") || value.startsWith("osx")) { | ||
return "darwin"; | ||
} | ||
if (value.startsWith("freebsd")) { | ||
return "linux"; | ||
} | ||
if (value.startsWith("openbsd")) { | ||
return "linux"; | ||
} | ||
if (value.startsWith("netbsd")) { | ||
return "linux"; | ||
} | ||
if (value.startsWith("solaris") || value.startsWith("sunos")) { | ||
return "linux"; | ||
} | ||
if (value.startsWith("windows")) { | ||
return "windows"; | ||
} | ||
if (value.startsWith("zos")) { | ||
return "linux"; | ||
} | ||
if(value.contains("darwin")) { | ||
return "darwin"; | ||
} | ||
|
||
return "unknown"; | ||
} | ||
|
||
private static String normalizeArch(String value) { | ||
value = normalize(value); | ||
if (value.matches("^(x8664|amd64|ia32e|em64t|x64)$")) { | ||
return "x64"; | ||
} | ||
if (value.matches("^(x8632|x86|i[3-6]86|ia32|x32)$")) { | ||
return "x86"; | ||
} | ||
if (value.matches("^(ia64w?|itanium64)$")) { | ||
return "itanium_64"; | ||
} | ||
if ("ia64n".equals(value)) { | ||
return "itanium_32"; | ||
} | ||
if (value.matches("^(sparc|sparc32)$")) { | ||
return "sparc_32"; | ||
} | ||
if (value.matches("^(sparcv9|sparc64)$")) { | ||
return "sparc_64"; | ||
} | ||
if (value.matches("^(arm|arm32)$")) { | ||
return "arm_32"; | ||
} | ||
if ("aarch64".equals(value)) { | ||
return "arm64"; | ||
} | ||
if (value.matches("^(mips|mips32)$")) { | ||
return "mips_32"; | ||
} | ||
if (value.matches("^(mipsel|mips32el)$")) { | ||
return "mipsel_32"; | ||
} | ||
if ("mips64".equals(value)) { | ||
return "mips_64"; | ||
} | ||
if ("mips64el".equals(value)) { | ||
return "mipsel_64"; | ||
} | ||
if (value.matches("^(ppc|ppc32)$")) { | ||
return "ppc_32"; | ||
} | ||
if (value.matches("^(ppcle|ppc32le)$")) { | ||
return "ppcle_32"; | ||
} | ||
if ("ppc64".equals(value)) { | ||
return "ppc_64"; | ||
} | ||
if ("ppc64le".equals(value)) { | ||
return "ppcle_64"; | ||
} | ||
if ("s390".equals(value)) { | ||
return "s390_32"; | ||
} | ||
if ("s390x".equals(value)) { | ||
return "s390_64"; | ||
} | ||
if (value.matches("^(riscv|riscv32)$")) { | ||
return "riscv"; | ||
} | ||
if ("riscv64".equals(value)) { | ||
return "riscv64"; | ||
} | ||
if ("e2k".equals(value)) { | ||
return "e2k"; | ||
} | ||
if ("loongarch64".equals(value)) { | ||
return "loongarch_64"; | ||
} | ||
return "unknown"; | ||
} | ||
|
||
private static String normalize(String value) { | ||
if (value == null) { | ||
return ""; | ||
} | ||
return value.toLowerCase(Locale.US).replaceAll("[^a-z0-9]+", ""); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
fcli-core/fcli-tool/src/main/java/com/fortify/cli/tool/_common/helper/SignatureHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.fortify.cli.tool._common.helper; | ||
|
||
import java.io.File; | ||
import java.nio.file.Files; | ||
import java.security.KeyFactory; | ||
import java.security.PublicKey; | ||
import java.security.Signature; | ||
import java.security.spec.X509EncodedKeySpec; | ||
|
||
import org.apache.commons.codec.binary.Base64; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
|
||
public class SignatureHelper { | ||
private static final Logger LOG = LoggerFactory.getLogger(SignatureHelper.class); | ||
private static String pubKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArij9U9yJVNc53oEMFWYp" | ||
+ "NrXUG1UoRZseDh/p34q1uywD70RGKKWZvXIcUAZZwbZtCu4i0UzsrKRJeUwqanbc" | ||
+ "woJvYanp6lc3DccXUN1w1Y0WOHOaBxiiK3B1TtEIH1cK/X+ZzazPG5nX7TSGh8Tp" | ||
+ "/uxQzUFli2mDVLqaP62/fB9uJ2joX9Gtw8sZfuPGNMRoc8IdhjagbFkhFT7WCZnk" | ||
+ "FH/4Co007lmXLAe12lQQqR/pOTeHJv1sfda1xaHtj4/Tcrq04Kx0ZmGAd5D9lA92" | ||
+ "8pdBbzoe/mI5/Sk+nIY3AHkLXB9YAaKJf//Wb1yiP1/hchtVkfXyIaGM+cVyn7AN" | ||
+ "VQIDAQAB"; | ||
|
||
public static final void verifyFileSignature(String sigString, File destFile, boolean throwOnFailure) { | ||
X509EncodedKeySpec spec = new X509EncodedKeySpec(Base64.decodeBase64(pubKey)); | ||
try { | ||
KeyFactory kf = KeyFactory.getInstance("RSA"); | ||
PublicKey pub = kf.generatePublic(spec); | ||
|
||
Signature fileSig = Signature.getInstance("SHA256withRSA"); | ||
fileSig.initVerify(pub); | ||
fileSig.update(Files.readAllBytes(destFile.toPath())); | ||
if(!fileSig.verify(Base64.decodeBase64(sigString))) { | ||
String msg = "Signature mismatch" | ||
+"\n Expected: "+sigString | ||
+"\n Actual: "+fileSig.hashCode(); | ||
if(throwOnFailure) { | ||
throw new IllegalStateException(msg); | ||
} else { | ||
LOG.warn(msg); | ||
} | ||
} | ||
} catch (IllegalStateException e) { | ||
throw e; | ||
} catch (Exception e) { | ||
if(throwOnFailure) { | ||
throw new RuntimeException(e); | ||
} else { | ||
LOG.warn("Signature verification failed", e); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.