diff options
Diffstat (limited to 'gnu/packages/patches/anubis-use-the-browser-native-web-crypto-api.patch')
| -rw-r--r-- | gnu/packages/patches/anubis-use-the-browser-native-web-crypto-api.patch | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/gnu/packages/patches/anubis-use-the-browser-native-web-crypto-api.patch b/gnu/packages/patches/anubis-use-the-browser-native-web-crypto-api.patch new file mode 100644 index 00000000000..c6bbae2f75f --- /dev/null +++ b/gnu/packages/patches/anubis-use-the-browser-native-web-crypto-api.patch | |||
| @@ -0,0 +1,60 @@ | |||
| 1 | From c29172faf8b57450317f6d29ac9ff4c5dfe69d77 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Sharlatan Hellseher <sharlatanus@gmail.com> | ||
| 3 | Date: Tue, 18 Aug 2026 19:26:53 +0100 | ||
| 4 | Subject: [PATCH] chore: Use the browser-native Web Crypto API. | ||
| 5 | |||
| 6 | Use the browser-native Web Crypto API instead of @aws-crypto/sha256-js. | ||
| 7 | |||
| 8 | * lib/challenge/preact/js/app.jsx (useEffect): Switch to browser native hasher. | ||
| 9 | * web/js/worker/sha256-purejs.mjs (calculateSHA256): Likewise. | ||
| 10 | --- | ||
| 11 | lib/challenge/preact/js/app.jsx | 7 +++---- | ||
| 12 | web/js/worker/sha256-purejs.mjs | 10 ++++------ | ||
| 13 | 2 files changed, 7 insertions(+), 10 deletions(-) | ||
| 14 | |||
| 15 | diff --git a/lib/challenge/preact/js/app.jsx b/lib/challenge/preact/js/app.jsx | ||
| 16 | index f1321b8..96352b0 100644 | ||
| 17 | --- a/lib/challenge/preact/js/app.jsx | ||
| 18 | +++ b/lib/challenge/preact/js/app.jsx | ||
| 19 | @@ -1,7 +1,6 @@ | ||
| 20 | import { render, h, Fragment } from 'preact'; | ||
| 21 | import { useState, useEffect } from 'preact/hooks'; | ||
| 22 | import { g, j, u, x } from "./xeact.js"; | ||
| 23 | -import { Sha256 } from '@aws-crypto/sha256-js'; | ||
| 24 | |||
| 25 | /** @jsx h */ | ||
| 26 | /** @jsxFrag Fragment */ | ||
| 27 | @@ -24,9 +23,9 @@ const App = () => { | ||
| 28 | |||
| 29 | useEffect(() => { | ||
| 30 | setImageURL(state.pensive_url); | ||
| 31 | - const hash = new Sha256(''); | ||
| 32 | - hash.update(state.challenge); | ||
| 33 | - setChallenge(toHexString(hash.digestSync())); | ||
| 34 | + crypto.subtle | ||
| 35 | + .digest("SHA-256", new TextEncoder().encode(state.challenge)) | ||
| 36 | + .then((buf) => setChallenge(toHexString(new Uint8Array(buf)))); | ||
| 37 | }, [state]); | ||
| 38 | |||
| 39 | useEffect(() => { | ||
| 40 | diff --git a/web/js/worker/sha256-purejs.mjs b/web/js/worker/sha256-purejs.mjs | ||
| 41 | index 3211b44..08072c6 100644 | ||
| 42 | --- a/web/js/worker/sha256-purejs.mjs | ||
| 43 | +++ b/web/js/worker/sha256-purejs.mjs | ||
| 44 | @@ -1,9 +1,7 @@ | ||
| 45 | -import { Sha256 } from '@aws-crypto/sha256-js'; | ||
| 46 | - | ||
| 47 | -const calculateSHA256 = (text) => { | ||
| 48 | - const hash = new Sha256(); | ||
| 49 | - hash.update(text); | ||
| 50 | - return hash.digest(); | ||
| 51 | +const calculateSHA256 = async (text) => { | ||
| 52 | + return new Uint8Array( | ||
| 53 | + await crypto.subtle.digest("SHA-256", | ||
| 54 | + new TextEncoder().encode(text))); | ||
| 55 | }; | ||
| 56 | |||
| 57 | function toHexString(arr) { | ||
| 58 | -- | ||
| 59 | 2.54.0 | ||
| 60 | |||
