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

63 lines
1.5 KiB
Batchfile
Raw Normal View History

2021-10-07 08:02:48 +00:00
@echo off
:: Set environment variable
@echo Enter the NSS DB root directory ( Such as Nokia, enter /data/b2g/mozilla )
@echo Some phones may be different.
@echo For more information, please visit: https://github.com/openGiraffes/b2g-certificates
@echo:
set /p ROOT_DIR_DB=
2021-10-07 08:02:48 +00:00
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 %ROOT_DIR_DB%/*.default 2>/dev/null" ^|^| "bin/sed.exe" "s/default.*$/default/g"') do set DB_DIR=%%i
@echo %DB_DIR%
2021-10-07 08:02:48 +00:00
if DB_DIR == "" (
@echo:
2021-10-07 08:02:48 +00:00
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 certificates
2021-10-07 08:02:48 +00:00
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