Skip to content

Commit

Permalink
util: warn in non-secure context for crypto.subtle
Browse files Browse the repository at this point in the history
  • Loading branch information
yoursunny committed Jun 26, 2023
1 parent 654ca6c commit c87341b
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/util/src/platform_browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@ import assert from "minimalistic-assert";
export const console = globalThis.console;
export const crypto = globalThis.crypto;

if (!crypto.subtle && !globalThis.isSecureContext) {
Object.defineProperty(crypto, "subtle", {
configurable: true,
get() {
console.error("NDNts depends on Web Crypto but it is unavailable because this webpage is not delivered securely, " +
"see https://mdn.io/SecureContext");
return undefined;
},
});
}

// https://codahale.com/a-lesson-in-timing-attacks/
export function timingSafeEqual(a: Uint8Array, b: Uint8Array): boolean {
// length has been checked by caller
Expand Down

0 comments on commit c87341b

Please sign in to comment.