Created
December 26, 2019 16:45
-
-
Save sachsgit/568095a0b2ff2088a05edd7a194acd91 to your computer and use it in GitHub Desktop.
A batch file takes cert with underscores for periods and add it to cacerts file. The alias is generated from the file name converting underscore to period, and removing .cer
This file contains hidden or 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
@ECHO OFF | |
:: REM :: | |
SET CERTFILE=%1 | |
IF NOT EXIST %CERTFILE% GOTO :MissingCert | |
FOR /F %%i IN ("%CERTFILE%") DO @SET BASE=%%~ni | |
SET ALIASNAME=%BASE:_=.% | |
IF "x%CERTFILE%x" == "xx" GOTO :MissingCert | |
SET KEYTOOL="%JAVA_HOME%\bin\keytool.exe" | |
SET KEYSTOREFILE="%JAVA_HOME%\jre\lib\security\cacerts" | |
IF NOT EXIST %KEYSTOREFILE% SET KEYSTOREFILE="%JAVA_HOME%\lib\security\cacerts" | |
IF NOT EXIST %KEYSTOREFILE% GOTO :MissingKeyStore | |
SET STOREP="changeit" | |
:: REM :: | |
ECHO %KEYTOOL% -import -noprompt -trustcacerts -alias %ALIASNAME% -file %CERTFILE% -keystore %KEYSTOREFILE% -storepass %STOREP% | |
%KEYTOOL% -import -noprompt -trustcacerts -alias %ALIASNAME% -file %CERTFILE% -keystore %KEYSTOREFILE% -storepass %STOREP% | |
GOTO :EOF | |
:MissingCert | |
ECHO Cert %CERTFILE% is missing | |
GOTO :EOF | |
:MissingKeyStore | |
ECHO No Key-Store File Found. | |
EXIT /B 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment