b2g-certificates/add-certificates-to-phone.bat

55 lines
1.3 KiB
Batchfile
Raw Normal View History

2021-10-07 08:02:48 +00:00
@echo off
:: Set environment variable
set CERT_DIR=certs
2021-10-07 09:35:32 +00:00
set TEMP=tmp
2021-10-07 08:02:48 +00:00
set CERT=cert9.db
set KEY=key4.db
set PKCS11=pkcs11.txt
for /f %%i in ('adb shell "ls -d /data/b2g/mozilla/*.default 2>/dev/null" ^|^| "bin/sed.exe" "s/default.*$/default/g"') do set DB_DIR=%%i
if DB_DIR == "" (
echo "Profile directory does not exists. Please start the b2g process at least once before running this script."
pause
)
:: Cleanup
2021-10-07 09:35:32 +00:00
rmdir /s /q %TEMP%
mkdir %TEMP%
2021-10-07 08:02:48 +00:00
:: Pull files from phone
@echo Getting %CERT%
2021-10-07 09:35:32 +00:00
adb pull %DB_DIR%/%CERT% ./%TEMP%/
2021-10-07 08:02:48 +00:00
@echo Getting %KEY%
2021-10-07 09:35:32 +00:00
adb pull %DB_DIR%/%KEY% ./%TEMP%/
2021-10-07 08:02:48 +00:00
@echo Getting %PKCS11%
2021-10-07 09:35:32 +00:00
adb pull %DB_DIR%/%PKCS11% ./%TEMP%/
2021-10-07 08:02:48 +00:00
:: Clear password and add certificates
@echo Set password (hit enter twice to set an empty password)
2021-10-07 09:35:32 +00:00
"bin/nss/certutil.exe" -d %TEMP% -N
2021-10-07 08:02:48 +00:00
@echo Adding certificats
for %%i in (%CERT_DIR%/*) do (
echo Adding certificate %%i
2021-10-07 09:35:32 +00:00
"bin/nss/certutil.exe" -d %TEMP% -A -n "`basename %%i`" -t "C,C,TC" -i %CERT_DIR%/%%i
2021-10-07 08:02:48 +00:00
)
:: Push files to phone
@echo Stopping B2G
adb shell stop b2g
@echo copying %CERT%
2021-10-07 09:35:32 +00:00
adb push ./%TEMP%/%CERT% %DB_DIR%/%CERT%
2021-10-07 08:02:48 +00:00
@echo copying %KEY%
2021-10-07 09:35:32 +00:00
adb push ./%TEMP%/%KEY% %DB_DIR%/%KEY%
2021-10-07 08:02:48 +00:00
@echo copying %PKCS11%
2021-10-07 09:35:32 +00:00
adb push ./%TEMP%/%PKCS11% %DB_DIR%/%PKCS11%
2021-10-07 08:02:48 +00:00
@echo Starting B2G
adb shell start b2g
@echo Finished.
pause