| skipped 22 lines |
23 | 23 | | } |
24 | 24 | | |
25 | 25 | | // Run when the <body> loads |
26 | | - | function main() { |
| 26 | + | async function main() { |
27 | 27 | | if (window.location.hash) { |
28 | 28 | | // Fail if the b64 library or API was not loaded |
29 | 29 | | if (!("b64" in window)) { |
| skipped 28 lines |
58 | 58 | | } |
59 | 59 | | |
60 | 60 | | const api = apiVersions[params["v"]]; |
| 61 | + | |
| 62 | + | // Get values for decryption |
| 63 | + | const encrypted = b64.base64ToBinary(params["e"]); |
| 64 | + | const salt = "s" in params ? b64.base64ToBinary(params["s"]) : null; |
| 65 | + | const iv = "i" in params ? b64.base64ToBinary(params["i"]) : null; |
| 66 | + | |
| 67 | + | let hint, password; |
| 68 | + | if ("h" in params) { |
| 69 | + | hint = params["h"]; |
| 70 | + | password = prompt(`Please enter the password\n\nHint: ${hint}`); |
| 71 | + | } else { |
| 72 | + | password = prompt("Please enter the password"); |
| 73 | + | } |
| 74 | + | |
| 75 | + | // Decrypt and redirect if possible |
| 76 | + | let url; |
| 77 | + | try { |
| 78 | + | url = await api.decrypt(encrypted, password, salt, iv); |
| 79 | + | } catch { |
| 80 | + | // Password is incorrect. |
| 81 | + | error("Password is incorrect."); |
| 82 | + | return; |
| 83 | + | } |
| 84 | + | |
| 85 | + | try { |
| 86 | + | // Extra check to make sure the URL is valid. Probably shouldn't fail. |
| 87 | + | new URL(url); |
| 88 | + | window.location.replace(url); |
| 89 | + | } catch { |
| 90 | + | error("A corrupted URL was encrypted. Cannot redirect."); |
| 91 | + | console.log(url); |
| 92 | + | return; |
| 93 | + | } |
61 | 94 | | } else { |
62 | 95 | | // Otherwise redirect to the creator |
63 | 96 | | window.location.replace("./create"); |
| skipped 26 lines |