@echo off

TITLE KIRA, Java Certificat-ek betoltese


SET KIT=JavaSoft\Java Runtime Environment
call:ReadRegValue VER "HKLM\Software\%KIT%" "CurrentVersion"
IF "%VER%" NEQ "" GOTO FoundJRE

SET KIT=Wow6432Node\JavaSoft\Java Runtime Environment
call:ReadRegValue VER "HKLM\Software\%KIT%" "CurrentVersion"
IF "%VER%" NEQ "" GOTO FoundJRE

SET KIT=JavaSoft\Java Development Kit
call:ReadRegValue VER "HKLM\Software\%KIT%" "CurrentVersion"
IF "%VER%" NEQ "" GOTO FoundJRE

SET KIT=Wow6432Node\JavaSoft\Java Development Kit
call:ReadRegValue VER "HKLM\Software\%KIT%" "CurrentVersion"
IF "%VER%" NEQ "" GOTO FoundJRE

ECHO Telepitett Java nem talalhato.
Echo SIKERTELEN Tanusitvany telepites.
TITLE KIRA - SIKERTELEN Tanúsítvány telepítés.
pause
GOTO :EOF

:FoundJRE
call:ReadRegValue JAVAPATH "HKLM\Software\%KIT%\%VER%" "JavaHome"
set javapath=%javapath%##
set javapath=%javapath: ##=##%
set javapath=%javapath:##=%

SET ktp=%JAVAPATH%\bin\keytool
set KEYSTORE_LOC=%USERPROFILE%\AppData\LocalLow\Sun\Java\Deployment\security

rem ELSO HIBAKEPHEZ

echo GOLD TANUSITVANY
"%ktp%" -importcert -alias NET_GOLD -file "gold.cer" -keystore %KEYSTORE_LOC%\trusted.jssecacerts -storepass "changeit" -noprompt
if not errorlevel 1 goto :cert1
"%ktp%" -importcert -alias NET_GOLD -file "gold.cer" -keystore %KEYSTORE_LOC%\trusted.jssecacerts -storepass "" -noprompt

:cert1
rem MASODIK HIBAKEPHEZ
echo Netlock CodeSign
"%ktp%" -importcert -alias NET_CODE -file "codesignca.cer" -keystore %KEYSTORE_LOC%\trusted.cacerts -storepass "changeit" -noprompt
if not errorlevel 1 goto :cert2
"%ktp%" -importcert -alias NET_CODE -file "codesignca.cer" -keystore %KEYSTORE_LOC%\trusted.cacerts -storepass "" -noprompt

:cert2
rem UJ ROOT TANUSITVANY
echo new root TRUSTEV
"%ktp%" -importcert -alias MAKtrustev3 -file "trustev3.cer" -keystore %KEYSTORE_LOC%\trusted.jssecacerts -storepass "changeit" -noprompt
if not errorlevel 1 goto :kesz
"%ktp%" -importcert -alias MAKtrustev3 -file "trustev3.cer" -keystore %KEYSTORE_LOC%\trusted.jssecacerts -storepass "" -noprompt

SET ktp=
SET KEYSTORE_LOC=

TITLE Tanusitvany telepites befejezve
GOTO :EOF

:kesz
SET ktp=
SET KEYSTORE_LOC=

TITLE Tanusitvany telepites befejezve
GOTO :EOF

:ReadRegValue
SET key=%2%
SET name=%3%
SET "%~1="
SET reg=reg
IF DEFINED ProgramFiles(x86) (
  IF EXIST %WINDIR%\sysnative\reg.exe SET reg=%WINDIR%\sysnative\reg.exe
)
FOR /F "usebackq tokens=3* skip=1" %%A IN (`%reg% QUERY %key% /v %name% 2^>NUL`) DO SET "%~1=%%A %%B"

