-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontentscript_common.js
54 lines (44 loc) · 1.63 KB
/
contentscript_common.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
const ACCOUNT_TYPE_PUPIL = 0;
const ACCOUNT_TYPE_PARENT = 1;
const ACCOUNT_TYPE_TEACHER = 2;
//#region ENCRYPTION
// better to encrypt with a statically embedded key than to store in storage in plaintext
let keyJWK = {"alg":"A256CTR","ext":true,"k":"cFQapcrsDni7TtMw9IMIvWqQqOf6DPFnWxsHt-uGtrg","key_ops":["encrypt","decrypt"],"kty":"oct"};
/** @type {CryptoKey} */ let key;
let keyPromise = crypto.subtle.importKey('jwk', keyJWK, {name: "AES-CTR"}, true, ['encrypt', 'decrypt']).then(k => key = k);
let counter = new Uint8Array([223,4,183,186,65,15,14,174,251,45,102,133,60,63,18,113]); // mmm secure af
// doesn't really matter, if someone had access to the source code, they could decrypt anyways
async function encryptPassword(pass) {
await keyPromise;
let enc = new TextEncoder();
let encoded = enc.encode(pass);
//let counter = window.crypto.getRandomValues(new Uint8Array(16));
let ciphertext = await window.crypto.subtle.encrypt(
{
name: "AES-CTR",
counter,
length: 64
},
key,
encoded
);
return new Uint8Array(ciphertext).toString();
}
async function decryptPassword(passEncrypted) {
let ciphertext = new Uint8Array(passEncrypted.split(',')).buffer;
let decrypted = await window.crypto.subtle.decrypt(
{
name: "AES-CTR",
counter,
length: 64
},
key,
ciphertext
);
let dec = new TextDecoder();
return dec.decode(decrypted);
}
//#endregion ENCRYPTION
/** @type {browser.storage.StorageArea} */
//let storage = browser.storage.sync;
let storage = browser.storage.local;