diff --git a/src/main/java/org/opensearch/security/tools/ChecksumCalculator.java b/src/main/java/org/opensearch/security/tools/ChecksumCalculator.java deleted file mode 100644 index 2a9f6f95bb..0000000000 --- a/src/main/java/org/opensearch/security/tools/ChecksumCalculator.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * The OpenSearch Contributors require contributions made to - * this file be licensed under the Apache-2.0 license or a - * compatible open source license. - * - * Modifications Copyright OpenSearch Contributors. See - * GitHub history for details. - */ - -package org.opensearch.security.tools; - -import org.bouncycastle.jcajce.provider.digest.SHA256; -import org.bouncycastle.util.encoders.Hex; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.stream.Stream; - -/** - * This tool helps generate checksums for demo certs - * Refer here: {@link org.opensearch.security.OpenSearchSecurityPlugin#demoCertHashes} - */ -public class ChecksumCalculator { - public static void main(String[] args) throws IOException { - if (args.length != 2) { - System.err.println("Usage: java ChecksumCalculator "); - System.exit(1); - } - - // Get the path to the certificate file from the command-line argument. - String folderPath = args[0]; - String fileExtension = args[1]; - Path p = Path.of(folderPath); - System.out.println("Certificate Hash (SHA-256): "); - sha256(p, fileExtension); - } - - /** - * Generate SHA 256 hash for all file with given extension in provided folder - * - * @param folderPath path to certificate file - * @param fileExtension extension of the certificate file - */ - private static void sha256(Path folderPath, String fileExtension) throws IOException { - - // Walk through the directory and filter for PEM files. - try ( - Stream pemFiles = Files.walk(folderPath, 1) - .filter(path -> Files.isRegularFile(path) && path.getFileName().toString().toLowerCase().endsWith(fileExtension)) - ) { - - // Initialize the digester with the desired hash algorithm (SHA-256). - SHA256.Digest digester = new SHA256.Digest(); - - // Calculate and print the hash for each PEM file. - pemFiles.forEach(pemFile -> { - try { - byte[] pemBytes = Files.readAllBytes(pemFile); - byte[] hash = digester.digest(pemBytes); - String hexHash = Hex.toHexString(hash); - System.out.println("File: " + pemFile.getFileName() + ", Hash (SHA-256): " + hexHash); - } catch (IOException e) { - // do nothing - } - }); - } - } -} diff --git a/tools/checksum_calculator.bat b/tools/checksum_calculator.bat deleted file mode 100644 index 411ee256af..0000000000 --- a/tools/checksum_calculator.bat +++ /dev/null @@ -1,16 +0,0 @@ -@echo off -setlocal enabledelayedexpansion - -set "DIR=%~dp0" - -if defined OPENSEARCH_JAVA_HOME ( - set BIN_PATH=%OPENSEARCH_JAVA_HOME%\bin\java.exe -) else if defined JAVA_HOME ( - set BIN_PATH=%JAVA_HOME%\bin\java.exe -) else ( - echo Unable to find Java runtime. - echo OPENSEARCH_JAVA_HOME or JAVA_HOME must be defined. - exit /b 1 -) - -"%BIN_PATH%" -cp "%DIR%\..\*;%DIR%\..\..\..\lib\*;%DIR%\..\deps\*" org.opensearch.security.tools.ChecksumCalculator %* diff --git a/tools/checksum_calculator.sh b/tools/checksum_calculator.sh deleted file mode 100755 index 6864ca5cf5..0000000000 --- a/tools/checksum_calculator.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/bash - -# Determine the script directory -SCRIPT_PATH="${BASH_SOURCE[0]}" -if [ -L "$SCRIPT_PATH" ]; then - if [ -x "$(command -v readlink)" ]; then - DIR="$(cd "$(dirname "$(readlink "$SCRIPT_PATH")")" && pwd -P)" - else - echo "Not able to resolve symlink. Install readlink." - exit 1 - fi -else - DIR="$(cd "$(dirname "$SCRIPT_PATH")" && pwd -P)" -fi - -# Set the default Java binary path -BIN_PATH="java" - -# Check for OPENSEARCH_JAVA_HOME and JAVA_HOME -if [ ! -z "$OPENSEARCH_JAVA_HOME" ]; then - BIN_PATH="$OPENSEARCH_JAVA_HOME/bin/java" -elif [ ! -z "$JAVA_HOME" ]; then - BIN_PATH="$JAVA_HOME/bin/java" -else - echo "WARNING: Neither OPENSEARCH_JAVA_HOME nor JAVA_HOME is set, will use $(which $BIN_PATH)" -fi - -# Execute the Java class -"$BIN_PATH" $JAVA_OPTS -cp "$DIR/../../opendistro_security_ssl/*:$DIR/../*:$DIR/../deps/*:$DIR/../../../lib/*" org.opensearch.security.tools.ChecksumCalculator "$@"