-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
install certificate for Java needed by Android
- Loading branch information
1 parent
d87f4cb
commit 7838189
Showing
2 changed files
with
73 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#!/usr/bin/env bash | ||
set -o errexit -o nounset -o pipefail | ||
|
||
SSL_CERT_FILE="$(realpath '/Library/Application Support'/*/*/data/*cacert.pem 2>/dev/null || true)" | ||
|
||
SCRIPT_FOLDER="$(dirname "$(realpath "$0")")" | ||
|
||
remove_certificate_bundle_safe() { | ||
if [ -f "$SSL_CERT_BUNDLE_FILE" ]; then | ||
sudo rm "$SSL_CERT_BUNDLE_FILE" | ||
fi | ||
} | ||
|
||
has_certificate() { | ||
echo "${KEYTOOL_PASSWORD}" | | ||
sudo keytool -cacerts -list -alias "mykey" | ||
} | ||
|
||
remove_certificate() { | ||
echo "${KEYTOOL_PASSWORD}" | | ||
sudo keytool -delete -cacerts -alias "mykey" >/dev/null | ||
} | ||
|
||
remove_certificate_safe() { | ||
remove_certificate_bundle_safe | ||
|
||
if has_certificate; then | ||
remove_certificate | ||
fi | ||
} | ||
|
||
add_certificate() { | ||
{ | ||
echo "${KEYTOOL_PASSWORD}" | ||
echo "oui" | ||
} | | ||
sudo keytool -import -cacerts -file "$SSL_CERT_BUNDLE_FILE" >/dev/null | ||
} | ||
|
||
add_certificate_safe() { | ||
if ! has_certificate; then | ||
add_certificate | ||
fi | ||
} | ||
|
||
if [ -f "$SSL_CERT_FILE" ]; then | ||
SSL_CERT_DIR="$(dirname "$SSL_CERT_FILE")" | ||
SSL_CERT_TENANT="$(realpath "$SSL_CERT_DIR"/*tenantcert.pem)" | ||
SSL_CERT_BUNDLE_FILE="$SSL_CERT_DIR/cert-bundle.pem" | ||
|
||
# remove_certificate_safe # to be able to debug, remove everything done, comment this when not debugging | ||
|
||
if "$SCRIPT_FOLDER/is_proxy_enabled.sh"; then | ||
if [ -f "$SSL_CERT_TENANT" ]; then | ||
echo "Adding certificate for proxy in Java's keytool system requires root password" | ||
|
||
if [ ! -f "$SSL_CERT_BUNDLE_FILE" ]; then | ||
cat "$SSL_CERT_TENANT" "$SSL_CERT_FILE" | sudo tee "$SSL_CERT_BUNDLE_FILE" >/dev/null | ||
fi | ||
|
||
add_certificate_safe | ||
fi | ||
else | ||
remove_certificate_safe | ||
fi | ||
fi |