Browse Source

removed unused crypto functions

Danny Coates 6 years ago
parent
commit
976fd61f23
3 changed files with 1 additions and 53 deletions
  1. 0 1
      app/fileReceiver.js
  2. 1 39
      app/keychain.js
  3. 0 13
      test/frontend/tests/keychain-tests.js

+ 0 - 1
app/fileReceiver.js

@@ -45,7 +45,6 @@ export default class FileReceiver extends Nanobus {
 
   async getMetadata() {
     const meta = await metadata(this.fileInfo.id, this.keychain);
-    this.keychain.setIV(meta.iv);
     this.fileInfo.name = meta.name;
     this.fileInfo.type = meta.type;
     this.fileInfo.iv = meta.iv;

+ 1 - 39
app/keychain.js

@@ -4,13 +4,8 @@ const encoder = new TextEncoder();
 const decoder = new TextDecoder();
 
 export default class Keychain {
-  constructor(secretKeyB64, nonce, ivB64) {
+  constructor(secretKeyB64, nonce) {
     this._nonce = nonce || 'yRCdyQ1EMSA3mo4rqSkuNQ==';
-    if (ivB64) {
-      this.iv = b64ToArray(ivB64);
-    } else {
-      this.iv = crypto.getRandomValues(new Uint8Array(12));
-    }
     if (secretKeyB64) {
       this.rawSecret = b64ToArray(secretKeyB64);
     } else {
@@ -86,10 +81,6 @@ export default class Keychain {
     }
   }
 
-  setIV(ivB64) {
-    this.iv = b64ToArray(ivB64);
-  }
-
   setPassword(password, shareUrl) {
     this.authKeyPromise = crypto.subtle
       .importKey('raw', encoder.encode(password), { name: 'PBKDF2' }, false, [
@@ -145,20 +136,6 @@ export default class Keychain {
     return `send-v1 ${arrayToB64(new Uint8Array(sig))}`;
   }
 
-  async encryptFile(plaintext) {
-    const encryptKey = await this.encryptKeyPromise;
-    const ciphertext = await crypto.subtle.encrypt(
-      {
-        name: 'AES-GCM',
-        iv: this.iv,
-        tagLength: 128
-      },
-      encryptKey,
-      plaintext
-    );
-    return ciphertext;
-  }
-
   async encryptMetadata(metadata) {
     const metaKey = await this.metaKeyPromise;
     const ciphertext = await crypto.subtle.encrypt(
@@ -170,7 +147,6 @@ export default class Keychain {
       metaKey,
       encoder.encode(
         JSON.stringify({
-          iv: arrayToB64(this.iv),
           name: metadata.name,
           size: metadata.size,
           type: metadata.type || 'application/octet-stream',
@@ -189,20 +165,6 @@ export default class Keychain {
     return decryptStream(cryptotext, this.rawSecret);
   }
 
-  async decryptFile(ciphertext) {
-    const encryptKey = await this.encryptKeyPromise;
-    const plaintext = await crypto.subtle.decrypt(
-      {
-        name: 'AES-GCM',
-        iv: this.iv,
-        tagLength: 128
-      },
-      encryptKey,
-      ciphertext
-    );
-    return plaintext;
-  }
-
   async decryptMetadata(ciphertext) {
     const metaKey = await this.metaKeyPromise;
     const plaintext = await crypto.subtle.decrypt(

+ 0 - 13
test/frontend/tests/keychain-tests.js

@@ -12,19 +12,6 @@ describe('Keychain', function() {
     });
   });
 
-  describe('encrypt / decrypt file', function() {
-    it('can decrypt text it encrypts', async function() {
-      const enc = new TextEncoder();
-      const dec = new TextDecoder();
-      const text = 'hello world!';
-      const k = new Keychain();
-      const ciphertext = await k.encryptFile(enc.encode(text));
-      assert.notEqual(dec.decode(ciphertext), text);
-      const plaintext = await k.decryptFile(ciphertext);
-      assert.equal(dec.decode(plaintext), text);
-    });
-  });
-
   describe('encrypt / decrypt metadata', function() {
     it('can decrypt metadata it encrypts', async function() {
       const k = new Keychain();