I am trying to write a bash script to update set Max TLS version to 1.3 in Chrome. This is what my script currently looks like:
#!/bin/bash -x
consoleuser=`ls -la /dev/console | cut -d " " -f4`
string='browser.*max@2'
echo "Current user: ${consoleuser}"
echo "Closing Google Chrome.."
sleep 2
pkill Chrome
cd /Users/$consoleuser/Library/Application\ Support/Google/Chrome
echo "Current directory: " && pwd
if [ ! -f "/Users/"$consoleuser"/Library/Application Support/Google/Chrome/Local State" ]; then
echo "Local State file not found. Relaunch Chrome to create the file"
else
while true; do
if grep -q "$string" "/Users/"$consoleuser"/Library/Application Support/Google/Chrome/Local State"; then
echo "Max TLS set to 1.3"
break
else
sed -i '.bak' -e 's|\(\"browser\"\):{\(\".*origin\":\"\"\)}|\1:{\"enabled_labs_experiments\":[\"ssl-version-max@2\"],\2}|' /Users/$consoleuser/Library/Application\ Support/Google/Chrome/Local\ State
if ! grep -q "$string" "/Users/"$consoleuser"/Library/Application Support/Google/Chrome/Local State"; then
echo "TLS configuration not found. Retrying.."
fi
fi
done
fi
sleep 2
exit
The goal is to append
"enabled_labs_experiments":["ssl-version-max@2"]
to this
{"browser":{"last_redirect_origin":""}
to make it looks like this
{"browser":{"enabled_labs_experiments":["ssl-version-max@2"],"last_redirect_origin":""}
The reason to put sed in a loop is that it needs to run sed at least twice on some machines to make actual changes to the file. However, for some reason, this script runs on some machines and fails to make changes on others. Not really sure what I am doing wrong here.
Any insights/help/directions/articles to make this script work or to achieve a similar result will be highly appreciated!
For reference: @1=TLS1.2 and @2=TLS1.3
Thank you!
EDIT
After reading comments below, I learned that python can be used to edit JSON files as jq is not native to Macs. However, I have no idea for where to start. I would really appreciate it if anyone could help me with this or point me in right direction.