-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Open trusted browser link in normal browser
Add chromium extension to trusted browser that allows opening links in normal browser. Signed-off-by: Tero Tervala <[email protected]>
- Loading branch information
1 parent
83951aa
commit 8005b3d
Showing
10 changed files
with
198 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,6 +115,7 @@ let | |
runWaypipe | ||
pkgs.tpm2-tools | ||
pkgs.opensc | ||
pkgs.givc-cli | ||
]; | ||
|
||
security.tpm2 = { | ||
|
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Copyright 2022-2023 TII (SSRC) and the Ghaf contributors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
(final: _prev: { open-normal-extension = final.callPackage ../../../packages/open-normal-extension { }; }) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Copyright 2022-2024 TII (SSRC) and the Ghaf contributors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
{ | ||
stdenvNoCC, | ||
pkgs, | ||
lib, | ||
config, | ||
... | ||
}: | ||
stdenvNoCC.mkDerivation { | ||
name = "open-normal-extension"; | ||
|
||
src = ./.; | ||
|
||
buildInputs = [pkgs.gettext]; | ||
|
||
postInstall = '' | ||
mkdir -p "$out" | ||
cp -v ./manifest.json ./open_normal.js ./open_normal.sh "$out" | ||
chmod a+x "$out/open_normal.sh" | ||
${pkgs.gettext}/bin/envsubst < "./fi.ssrc.open_normal.json" > "$out/fi.ssrc.open_normal.json" | ||
''; | ||
|
||
meta = with lib; { | ||
description = "Browser extension for Chromium to launch trusted browser"; | ||
platforms = [ | ||
"x86_64-linux" | ||
"aarch64-linux" | ||
]; | ||
}; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"__comment1__": "SPDX-FileCopyrightText: 2022-2024 TII (SSRC) and the Ghaf contributors", | ||
"__comment2__": "SPDX-License-Identifier: Apache-2.0", | ||
"name": "fi.ssrc.open_normal", | ||
"description": "Open link in normal browser", | ||
"path": "${out}/open_normal.sh", | ||
"type": "stdio", | ||
"allowed_origins": [ | ||
"chrome-extension://ehlgfonodkljjbpedhnphehcflbohngk/" | ||
] | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// SPDX-FileCopyrightText: 2022-2024 TII (SSRC) and the Ghaf contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
{ | ||
"manifest_version": 3, | ||
"name": "Open in normal browser", | ||
"version": "1.0", | ||
"permissions": ["nativeMessaging", "contextMenus"], | ||
"background": { | ||
"service_worker": "open_normal.js" | ||
}, | ||
"key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwDuuaHrpJGYZyXylG9Ag+mA4MbZPUZWhteMR9VpsHmblziD+Q02QA1z67H7FbnmsAIjY/yI+m0Q7lC4iFyksLyvJKlM8pMtBhMQxOwr9x+f+bUak2BmmQO4MFX/O2+k5viGF7kTzfp2KNBzpzUYMr9BrTuxyZ76z7abPohobYAA6spDHZW5DXOsBoXZ4+zg7G5R8Rg/MV+U9mobmyPsa9RGgpLX4KB8ysgJu4wpPGOyXdxf+Pp7h7NhP2Hk9PBl05DHEHTzoJMz0bGxGmAYBxjS95PfI4hC0Dr0YfUmIwY6IOTIvpY4qnqGHr6Qc4aeAwZDncFKj0xVx5nHsNze9WwIDAQAB" | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// SPDX-FileCopyrightText: 2022-2024 TII (SSRC) and the Ghaf contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
chrome.contextMenus.create({ | ||
id: "openNormal", | ||
title: "Open in normal browser", | ||
contexts: ["link"] | ||
}); | ||
|
||
chrome.contextMenus.onClicked.addListener((info, tab) => { | ||
if (info.menuItemId === "openNormal") { | ||
sendNativeMessage(info.linkUrl); | ||
} | ||
}); | ||
|
||
function sendNativeMessage(linkUrl) { | ||
chrome.runtime.sendNativeMessage('fi.ssrc.open_normal', { "URL": linkUrl }, | ||
(response) => { | ||
if (chrome.runtime.lastError) { | ||
console.error(chrome.runtime.lastError); | ||
} else { | ||
console.log("open_normal:", response); | ||
} | ||
}); | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
#!/usr/bin/env bash | ||
# SPDX-FileCopyrightText: 2022-2024 TII (SSRC) and the Ghaf contributors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
CFGF="/etc/open-normal-extension.cfg" | ||
|
||
function Ord { | ||
printf "%d" "\"$1" | ||
} | ||
|
||
function Chr { | ||
printf "%b" "$(printf "\\\\x%02x" "$1")" | ||
} | ||
|
||
function Msg { | ||
local len b1 b2 b3 b4 | ||
|
||
len="${#1}" | ||
b1="$(( len & 255 ))" | ||
b2="$(( (len >> 8) & 255 ))" | ||
b3="$(( (len >> 16) & 255 ))" | ||
b4="$(( (len >> 24) & 255 ))" | ||
Chr "$b1" | ||
Chr "$b2" | ||
Chr "$b3" | ||
Chr "$b4" | ||
printf "%s" "$1" | ||
} | ||
|
||
LANG=C IFS= read -r -d '' -n 1 B1 | ||
LANG=C IFS= read -r -d '' -n 1 B2 | ||
LANG=C IFS= read -r -d '' -n 1 B3 | ||
LANG=C IFS= read -r -d '' -n 1 B4 | ||
|
||
if [ -z "$B1" ]; then | ||
B1=0 | ||
else | ||
B1="$(Ord "$B1")" | ||
fi | ||
if [ -z "$B2" ]; then | ||
B2=0 | ||
else | ||
B2="$(Ord "$B2")" | ||
fi | ||
if [ -z "$B3" ]; then | ||
B3=0 | ||
else | ||
B3="$(Ord "$B3")" | ||
fi | ||
if [ -z "$B4" ]; then | ||
B4=0 | ||
else | ||
B4="$(Ord "$B4")" | ||
fi | ||
|
||
LEN="$((B1+(B2*256)+(B3*65536)+(B4*16777216)))" | ||
|
||
if [ "$LEN" -lt 0 ] || [ "$LEN" -gt 4096 ]; then | ||
Msg "{\"status\":\"Failed to read parameters from API\"}" | ||
exit 1 | ||
fi | ||
|
||
LANG=C IFS= read -r -d '' -n "$LEN" JSON | ||
PFX="{\"URL\":\"" | ||
URL="${JSON##"$PFX"}" | ||
SFX="\"}" | ||
URL="${URL%%"$SFX"}" | ||
|
||
if [ -r "$CFGF" ]; then | ||
# Do not complain about not being able to follow non-constant source | ||
# shellcheck disable=SC1090 | ||
. "$CFGF" | ||
if [ -z "$GIVC_PATH" ] || [ -z "$GIVC_OPTS" ] || [ ! -x "${GIVC_PATH}/bin/givc-cli" ]; then | ||
Msg "{\"status\":\"Invalid config in ${CFGF}\"}" | ||
exit 1 | ||
else | ||
# Do not complain about double quotes, $GIVC_OPTS is purposefully unquoted here | ||
# shellcheck disable=SC2086 | ||
"${GIVC_PATH}/bin/givc-cli" $GIVC_OPTS start chromium -- "${URL}" > /dev/null 2>&1 | ||
RES=$? | ||
Msg "{\"status\":\"${RES}\"}" | ||
exit "$RES" | ||
fi | ||
else | ||
Msg "{\"status\":\"Failed to read ${CFGF}\"}" | ||
exit 1 | ||
fi |