Skip to content

Commit

Permalink
Merge pull request #4 from pmamico/3-add-a-list-function
Browse files Browse the repository at this point in the history
list certs installed by jssl
  • Loading branch information
pmamico authored Aug 9, 2024
2 parents bee2f78 + 8360283 commit ccaa079
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 23 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ brew install pmamico/java/jssl

## Manual
```
jssl v1.3
jssl v1.4
Install trusted certificate and check SSL handshake against java keystore.
Usage: jssl <host> <operation> [-p|--port <arg>] [-a|--alias <arg>] [-h|--help] [-v|--version]
<host>: without https:// and port, eg. google.com
<operation>: ping, install or uninstall
-p, --port: port (default: '443')
-a, --alias: alias in keystore (default: '<host>')
-l, --list: List installed certificates with jssl
-h, --help: Prints help
-v, --version: Prints version
```
Expand Down
68 changes: 46 additions & 22 deletions src/jssl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
### java-ssl-tools (jssl) v1.3
jssl_version="v1.3"
### java-ssl-tools (jssl) v1.4
jssl_version="v1.4"
JVM_VERSION=$(java -version 2>&1 | head -n 1)


Expand Down Expand Up @@ -56,6 +56,7 @@ print_help()
printf '\t%s\n' "<operation>: ping, install or uninstall"
printf '\t%s\n' "-p, --port: port (default: '443')"
printf '\t%s\n' "-a, --alias: alias in keystore (default: '<host>')"
printf '\t%s\n' "-l, --list: List installed certificates with jssl"
printf '\t%s\n' "-h, --help: Prints help"
printf '\t%s\n\n' "-v, --version: Prints version"

Expand Down Expand Up @@ -98,29 +99,33 @@ parse_commandline()
-p*)
_arg_port="${_key##-p}"
;;
-a|--alias)
test $# -lt 2 && die "Missing value for the optional argument '$_key'." 1
_arg_alias="$2"
shift
;;
--alias=*)
_arg_alias="${_key##--alias=}"
;;
-a*)
_arg_alias="${_key##-a}"
;;
-a|--alias)
test $# -lt 2 && die "Missing value for the optional argument '$_key'." 1
_arg_alias="$2"
shift
;;
--alias=*)
_arg_alias="${_key##--alias=}"
;;
-a*)
_arg_alias="${_key##-a}"
;;
-h|--help)
print_help
exit 0
;;
-l|--list)
list_installed_certs
exit 0
;;
-h*)
print_help
exit 0
;;
-v|--version)
print_version
exit 0
;;
-v|--version)
print_version
exit 0
;;
*)
_last_positional="$1"
_positionals+=("$_last_positional")
Expand All @@ -135,17 +140,18 @@ parse_commandline()
###################################################
handle_passed_args_count()
{
# shellcheck disable=SC2034
local _required_args_string="'host' 'operation'"
test "${_positionals_count}" -ge 2 || _PRINT_HELP=yes die "" 1
test "${_positionals_count}" -le 2 || _PRINT_HELP=yes die "" 1
}

assign_positional_args()
{
shift "$1"
_arg_host="$1"
shift
_arg_operation="$1"
shift "$1"
_arg_host="$1"
shift
_arg_operation="$1"
}

print_and_compile_java()
Expand Down Expand Up @@ -205,14 +211,32 @@ check_handshake()
clean_up_sslping
}

################
# Part: list #
################
list_installed_certs()
{
if [[ $JVM_VERSION == *"1.8"* ]]; then
"$SUDO" "$JAVA_HOME/bin/keytool" -v \
--list \
-keystore "$JAVA_HOME"/jre/lib/security/cacerts \
| grep -E "Alias name.*jssl" -A 3
else
"$SUDO" "$JAVA_HOME/bin/keytool" -v \
--list \
-cacerts \
| grep -E "Alias name.*jssl" -A 3
fi
}


###################
# Part: install #
###################
install_cert()
{
if [[ "$_arg_alias" == "<host>" ]]; then
_arg_alias="$_arg_host"
_arg_alias="jssl_$_arg_host"
fi

echo "Installing cert for $JVM_VERSION"
Expand Down

0 comments on commit ccaa079

Please sign in to comment.