Privacy/Features/DOMCryptAPI/UseCases

From MozillaWiki
< Privacy‎ | Features‎ | DOMCryptAPI
Revision as of 23:05, 31 May 2011 by Ddahl (talk | contribs)
Jump to navigation Jump to search

DOMCrypt API Use Cases

Messaging

  • Natasha and Boris would like to message one another privately via a web application. The server is untrusted and all message data that Natasha sends to the server should be encrypted so only Boris can read it after downloading. A server compromise will net the server's attacker only blobs of useless data. This web application will use the Public Key API.

Example Code:

var publicKey = messagingApp.getPublicKey("boris");

var plainText = "Hey, wanna grab a root beer with me after work?";

window.cipher.pk.encrypt(plainText, publicKey, function callback(aCipherMessage) {
  // Asynchronous crypto API - the plainText is encrypted and the CipherMessage object is returned to this callback function
  // aCipherMessage is a JS object literal: 
  //   { content: <ENCRYPTED, BASE64 Encoded String>, 
  //     pubKey: <PUBLICKEY used to encrypt the a symmetric key>, 
  //     wrappedKey: <SYMMETRIC KEY wrapped with the recipient's public key>,
  //     iv: <Initialization Vector> 
  //   }
  messagingApp.sendMessage(aCipherMessage, {from: 'natasha', to: 'boris'});
});

General Purpose Symmetric Crypto

  • A web developer would like to use localStorage or IndexedDB in her diary web application, but would really like all data stored locally to be encrypted should the machine get stolen or 'borrowed' by an unauthorized user.

Example Code:

// create an encryption key and keep it around for later use - perhaps it is also saved to the server...

window.cipher.sym.generateKey(function callback(key){
  document.currentKey = key;
  diaryApp.saveKeyToServer(key);
});

// save the current diary entry:
var diaryEntry = document.getElementById("diary-entry").textContent;

window.cipher.sym.encrypt(diaryEntry, document.currentKey, function callback(cipherText) {
  var entryID = diaryApp.getSequence();
  localStorage.setItem(entryID, cipherText);
  alert("Diary entry saved successfully");
});

// decryption

window.cipher.sym.decrypt(localStorage.getItem(entryID), document.currentKey, function callback(plainText) {
  document.getElementById("diary-entry").textContent = plainText;
});

Hashing

SHA 256 hashes are handy for storing passwords and generating checksums (among other uses)

Example code:

var myPassword = "5ekr3tPa55w0rd";

window.cipher.hash.SHA256(myPassword, function callback(aHash) {
  myApp.doSomethingWithAHash(aHash);  
});

// Another idea: generating a file checksum in conjunction with the FileAPI

New Ideas

  • Some ideas that have been mentioned via mailing lists, etc.

An API to make <keygen> easier

  • Jonas Sicking mentioned this to me during a Mozilla All-hands DOMCrypt presentation
    • NEED EXAMPLE

Signing APIs that would allow S. Korean web users to use any browser for online banking

  • on the WHAT-WG mailing list, this was brought up. The API as spec'd is part of the way there, but needs additional research and API methods
    • NEED EXAMPLES