Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src-node/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions src/document/DocumentCommandHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2310,8 +2310,7 @@ define(function (require, exports, module) {
});
}

let isTestWindow = (new window.URLSearchParams(window.location.search || "")).get("testEnvironment");
if (!isTestWindow) {
if (!Phoenix.isTestWindow) {
if(Phoenix.isNativeApp) {
_attachNativeUnloadHandler();
} else {
Expand Down
43 changes: 34 additions & 9 deletions src/phoenix/trust_ring.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,13 @@ const SIGNATURE_SALT_KEY = Phoenix.isTestWindow ? "SIGNATURE_SALT_KEY_TEST" : "S
const VERSION_PORTER_KEY = Phoenix.isTestWindow ? "VERSION_PORTER_TEST" : "VERSION_PORTER";
const { key, iv } = _selectKeys();

let _trustRingReadyResolve;
let _trustRingReady = new Promise(resolve => {
_trustRingReadyResolve = resolve;
});

async function setCredential(credKey, secret) {
await _trustRingReady;
if(!window.__IS_NATIVE_SHELL__){
throw new Error("Phoenix API key can only be set in native shell!");
}
Expand All @@ -200,6 +206,7 @@ async function setCredential(credKey, secret) {
}

async function getCredential(credKey) {
await _trustRingReady;
if(!window.__IS_NATIVE_SHELL__){
throw new Error("Phoenix API key can only be get in native shell!");
}
Expand All @@ -219,6 +226,7 @@ async function getCredential(credKey) {
}

async function removeCredential(credKey) {
await _trustRingReady;
if(!window.__IS_NATIVE_SHELL__){
throw new Error("Phoenix API key can only be removed in native shell!");
}
Expand All @@ -235,6 +243,7 @@ async function removeCredential(credKey) {

let _dismatled = false;
async function dismantleKeyring() {
await _trustRingReady;
if(_dismatled){
throw new Error("Keyring can only be dismantled once!");
// and once dismantled, the next line should be reload page. this is a strict security posture requirement to
Expand All @@ -249,25 +258,41 @@ async function dismantleKeyring() {
if(!window.__IS_NATIVE_SHELL__){
return;
}
let result;
if(window.__TAURI__) {
return window.__TAURI__.tauri.invoke("remove_trust_window_aes_key", {key, iv});
}
if(window.__ELECTRON__) {
return window.electronAPI.removeTrustWindowAesKey(key, iv);
result = await window.__TAURI__.tauri.invoke("remove_trust_window_aes_key", {key, iv});
} else if(window.__ELECTRON__) {
result = await window.electronAPI.removeTrustWindowAesKey(key, iv);
}
// After dismantling, reset the gate so credential APIs block until a new trust ring is established
_trustRingReady = new Promise(resolve => {
_trustRingReadyResolve = resolve;
});
return result;
}

export async function initTrustRing() {
if(!window.__IS_NATIVE_SHELL__){
_trustRingReadyResolve();
return;
}
// this will only work once in a window unless dismantleKeyring is called. So this is safe as
// a public export as essentially this is a fn that only works in the boot and shutdown phase.
if(window.__TAURI__) {
await window.__TAURI__.tauri.invoke("trust_window_aes_key", {key, iv});
} else if(window.__ELECTRON__) {
await window.electronAPI.trustWindowAesKey(key, iv);
}
try {
if(window.__TAURI__) {
await window.__TAURI__.tauri.invoke("trust_window_aes_key", {key, iv});
} else if(window.__ELECTRON__) {
await window.electronAPI.trustWindowAesKey(key, iv);
}
} catch(e) {
// Trust may already be established for this window (e.g., iframe reusing parent's trust).
// This is expected for tests and not an error - the trust ring is still functional. But for live this is
// a critical error that should never happen.
window.logger && window.logger.reportError(e, "Error establishing trust ring");
const Metrics = window.Metrics;
Metrics && Metrics.countEvent(Metrics.EVENT_TYPE.ERROR, "trustRing", "initFailed");
}
_trustRingReadyResolve();

await _portCredentials();
}
Expand Down
Loading