Merge pull request #3 from ente-io/shared_collections
Decrypt shared collection files
This commit is contained in:
commit
274b45fa0f
4 changed files with 19 additions and 6 deletions
|
@ -58,7 +58,7 @@ export default function Generate() {
|
|||
const kekHash = await cryptoWorker.hash(kek);
|
||||
const encryptedKeyAttributes = await cryptoWorker.encrypt(key, kek);
|
||||
const keyPair = await cryptoWorker.generateKeyPair();
|
||||
const encryptedKeyPairAttributes = await cryptoWorker.encrypt(keyPair.privateKey, kek);
|
||||
const encryptedKeyPairAttributes = await cryptoWorker.encrypt(keyPair.privateKey, key);
|
||||
const keyAttributes = {
|
||||
kekSalt: await cryptoWorker.toB64(kekSalt),
|
||||
kekHash: kekHash,
|
||||
|
|
|
@ -54,8 +54,15 @@ const getCollectionKey = async (collection: collection, key: Uint8Array) => {
|
|||
await worker.fromB64(collection.keyDecryptionNonce),
|
||||
key);
|
||||
} else {
|
||||
// TODO
|
||||
decryptedKey = null;
|
||||
const keyAttributes = getData(LS_KEYS.KEY_ATTRIBUTES);
|
||||
const secretKey = await worker.decrypt(
|
||||
await worker.fromB64(keyAttributes.encryptedSecretKey),
|
||||
await worker.fromB64(keyAttributes.secretKeyDecryptionNonce),
|
||||
key);
|
||||
decryptedKey = await worker.boxSealOpen(
|
||||
await worker.fromB64(collection.encryptedKey),
|
||||
await worker.fromB64(keyAttributes.publicKey),
|
||||
secretKey);
|
||||
}
|
||||
return {
|
||||
...collection,
|
||||
|
@ -81,9 +88,6 @@ export const getFiles = async (sinceTime: string, token: string, limit: string,
|
|||
var files: Array<file> = [];
|
||||
for (const index in collections) {
|
||||
const collection = collections[index];
|
||||
if (collection.key == null) {
|
||||
continue;
|
||||
}
|
||||
const resp = await HTTPService.get(`${ENDPOINT}/collections/diff`, {
|
||||
'collectionID': collection.id.toString(), sinceTime, token, limit,
|
||||
});
|
||||
|
|
|
@ -92,6 +92,11 @@ export async function generateKeyPair() {
|
|||
return sodium.crypto_box_keypair();
|
||||
}
|
||||
|
||||
export async function boxSealOpen(input: Uint8Array, publicKey: Uint8Array, secretKey: Uint8Array) {
|
||||
await sodium.ready;
|
||||
return sodium.crypto_box_seal_open(input, publicKey, secretKey);
|
||||
}
|
||||
|
||||
export async function fromB64(input: string) {
|
||||
await sodium.ready;
|
||||
return sodium.from_base64(input, sodium.base64_variants.ORIGINAL);
|
||||
|
|
|
@ -57,6 +57,10 @@ export class Crypto {
|
|||
return libsodium.generateKeyPair();
|
||||
}
|
||||
|
||||
async boxSealOpen(input, publicKey, secretKey) {
|
||||
return libsodium.boxSealOpen(input, publicKey, secretKey)
|
||||
}
|
||||
|
||||
async fromString(string) {
|
||||
return libsodium.fromString(string);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue