diff options
Diffstat (limited to 'client')
-rw-r--r-- | client/package.json | 2 | ||||
-rw-r--r-- | client/src/assets/player/p2p-media-loader/segment-validator.ts | 15 | ||||
-rw-r--r-- | client/yarn.lock | 7 |
3 files changed, 20 insertions, 4 deletions
diff --git a/client/package.json b/client/package.json index 152f8445f..5147ca86c 100644 --- a/client/package.json +++ b/client/package.json | |||
@@ -63,6 +63,7 @@ | |||
63 | "@types/markdown-it": "^10.0.1", | 63 | "@types/markdown-it": "^10.0.1", |
64 | "@types/node": "^14.0.14", | 64 | "@types/node": "^14.0.14", |
65 | "@types/sanitize-html": "1.23.3", | 65 | "@types/sanitize-html": "1.23.3", |
66 | "@types/sha.js": "^2.4.0", | ||
66 | "@types/socket.io-client": "^1.4.32", | 67 | "@types/socket.io-client": "^1.4.32", |
67 | "@types/video.js": "^7.3.8", | 68 | "@types/video.js": "^7.3.8", |
68 | "@types/webtorrent": "^0.107.0", | 69 | "@types/webtorrent": "^0.107.0", |
@@ -110,6 +111,7 @@ | |||
110 | "sass-lint": "^1.13.1", | 111 | "sass-lint": "^1.13.1", |
111 | "sass-loader": "8.0.2", | 112 | "sass-loader": "8.0.2", |
112 | "sass-resources-loader": "^2.0.0", | 113 | "sass-resources-loader": "^2.0.0", |
114 | "sha.js": "^2.4.11", | ||
113 | "socket.io-client": "^2.2.0", | 115 | "socket.io-client": "^2.2.0", |
114 | "stream-browserify": "^3.0.0", | 116 | "stream-browserify": "^3.0.0", |
115 | "stream-http": "^3.0.0", | 117 | "stream-http": "^3.0.0", |
diff --git a/client/src/assets/player/p2p-media-loader/segment-validator.ts b/client/src/assets/player/p2p-media-loader/segment-validator.ts index 0614f73d2..fa6e6df1d 100644 --- a/client/src/assets/player/p2p-media-loader/segment-validator.ts +++ b/client/src/assets/player/p2p-media-loader/segment-validator.ts | |||
@@ -41,7 +41,7 @@ function segmentValidatorFactory (segmentsSha256Url: string) { | |||
41 | throw new Error(`Unknown segment name ${filename}/${range} in segment validator`) | 41 | throw new Error(`Unknown segment name ${filename}/${range} in segment validator`) |
42 | } | 42 | } |
43 | 43 | ||
44 | const calculatedSha = bufferToEx(await sha256(segment.data)) | 44 | const calculatedSha = await sha256Hex(segment.data) |
45 | if (calculatedSha !== hashShouldBe) { | 45 | if (calculatedSha !== hashShouldBe) { |
46 | throw new Error( | 46 | throw new Error( |
47 | `Hashes does not correspond for segment ${filename}/${range}` + | 47 | `Hashes does not correspond for segment ${filename}/${range}` + |
@@ -68,14 +68,21 @@ function fetchSha256Segments (url: string) { | |||
68 | }) | 68 | }) |
69 | } | 69 | } |
70 | 70 | ||
71 | function sha256 (data?: ArrayBuffer) { | 71 | async function sha256Hex (data?: ArrayBuffer) { |
72 | if (!data) return undefined | 72 | if (!data) return undefined |
73 | 73 | ||
74 | return window.crypto.subtle.digest('SHA-256', data) | 74 | if (window.crypto.subtle) { |
75 | return window.crypto.subtle.digest('SHA-256', data) | ||
76 | .then(data => bufferToHex(data)) | ||
77 | } | ||
78 | |||
79 | // Fallback for non HTTPS context | ||
80 | const shaModule = await import('sha.js') | ||
81 | return new shaModule.sha256().update(Buffer.from(data)).digest('hex') | ||
75 | } | 82 | } |
76 | 83 | ||
77 | // Thanks: https://stackoverflow.com/a/53307879 | 84 | // Thanks: https://stackoverflow.com/a/53307879 |
78 | function bufferToEx (buffer?: ArrayBuffer) { | 85 | function bufferToHex (buffer?: ArrayBuffer) { |
79 | if (!buffer) return '' | 86 | if (!buffer) return '' |
80 | 87 | ||
81 | let s = '' | 88 | let s = '' |
diff --git a/client/yarn.lock b/client/yarn.lock index d3603a4a9..0efcabe8c 100644 --- a/client/yarn.lock +++ b/client/yarn.lock | |||
@@ -1495,6 +1495,13 @@ | |||
1495 | resolved "https://registry.yarnpkg.com/@types/selenium-webdriver/-/selenium-webdriver-3.0.17.tgz#50bea0c3c2acc31c959c5b1e747798b3b3d06d4b" | 1495 | resolved "https://registry.yarnpkg.com/@types/selenium-webdriver/-/selenium-webdriver-3.0.17.tgz#50bea0c3c2acc31c959c5b1e747798b3b3d06d4b" |
1496 | integrity sha512-tGomyEuzSC1H28y2zlW6XPCaDaXFaD6soTdb4GNdmte2qfHtrKqhy0ZFs4r/1hpazCfEZqeTSRLvSasmEx89uw== | 1496 | integrity sha512-tGomyEuzSC1H28y2zlW6XPCaDaXFaD6soTdb4GNdmte2qfHtrKqhy0ZFs4r/1hpazCfEZqeTSRLvSasmEx89uw== |
1497 | 1497 | ||
1498 | "@types/sha.js@^2.4.0": | ||
1499 | version "2.4.0" | ||
1500 | resolved "https://registry.yarnpkg.com/@types/sha.js/-/sha.js-2.4.0.tgz#bce682ef860b40f419d024fa08600c3b8d24bb01" | ||
1501 | integrity sha512-amxKgPy6WJTKuw8mpUwjX2BSxuBtBmZfRwIUDIuPJKNwGN8CWDli8JTg5ONTWOtcTkHIstvT7oAhhYXqEjStHQ== | ||
1502 | dependencies: | ||
1503 | "@types/node" "*" | ||
1504 | |||
1498 | "@types/simple-peer@*": | 1505 | "@types/simple-peer@*": |
1499 | version "9.6.0" | 1506 | version "9.6.0" |
1500 | resolved "https://registry.yarnpkg.com/@types/simple-peer/-/simple-peer-9.6.0.tgz#b5828d835b7f42dde27db584ba127e7a9f9072f4" | 1507 | resolved "https://registry.yarnpkg.com/@types/simple-peer/-/simple-peer-9.6.0.tgz#b5828d835b7f42dde27db584ba127e7a9f9072f4" |