Made cross-origin use case and issued non-goal caveat
author"arangana <arun@mozilla.com>"
Wed, 03 Jul 2013 14:20:59 -0400
changeset 31 cc4724a8d1f6
parent 30 4f81f389188c
child 32 4ee6bd222b1c
Made cross-origin use case and issued non-goal caveat
Overview.html
--- a/Overview.html	Thu May 16 17:05:26 2013 -0400
+++ b/Overview.html	Wed Jul 03 14:20:59 2013 -0400
@@ -70,12 +70,20 @@
   </head>
   <body>
     <section id='abstract'>
-      This document is NOT a recommendation track document, and should be read as an informative overview of the target use cases for a cryptographic API for the web. These use cases, described as scenarios, represent some of the set of expected functionality that may be achieved by the Web Cryptography API [WEBCRYPTO]  which provides an API for cryptographic operations such as encryption and decryption, and the Key Discovery API [KEY-DISCOVERY], which specifically covers the ability to access cryptographic keys that have been pre-provisioned. As both APIs are under construction, the reader should consult each specification for changes, and should treat sample code provided here as illustrative only. Presented here are primary use cases, showing what the working group hopes to achieve first. Other use cases are marked as secondary. 
+      This document is NOT a recommendation track document, and should be read as an informative overview of the target use cases for a cryptographic API for the web. These use cases, described as scenarios, represent some of the set of expected functionality that may be achieved by the Web Cryptography API [[!WEBCRYPTO]]  which provides an API for cryptographic operations such as encryption and decryption, and the Key Discovery API [[!KEY-DISCOVERY]], which specifically covers the ability to access cryptographic keys that have been pre-provisioned. As both APIs are under construction, the reader should consult each specification for changes, and should treat sample code provided here as illustrative only. Presented here are primary use cases, showing what the working group hopes to achieve first. 
     </section>
-    
-    <section>
-      <h2>Requirements</h2>
-      <p>This section presents required features of a cryptographic API.  It is possible that there is more than one algorithm and more than one mechanism to accomplish each of these features.  The section presents code names for each of the features, which will be used alongside each scenario, illustrating which feature is used.</p>
+    <section id='nonGoals'>
+      <h2>Some Non-Goals</h2>
+      <p>Certain popular use cases for cryptography on the web do not correspond to the combined capabilities of the Key Discovery API [[!KEY-DISCOVERY]] or the Web Cryptography API [[!WEBCRYPTO]], and these use cases are not addressed here.  These include:
+      </p>
+      <ol>
+        <li><p>Any use case requiring a relaxation or violation of the same-origin policy in JavaScript, implemented by all the major web browsers.  This includes use cases that require direct access to cryptographic material that is not domain-specific from a key store that is not domain specific.  Currently, certain banking transactions require citizens to obtain certificates that are centrally issued, and that are user specific yet not domain specific, and that are used by multiple institutions, each having separate domains, each of which can call upon a hardware-based cryptographic material store.  Such use cases aren't directly addressed by the combination of the Web Cryptography API [[!WEBCRYPTO]] or the Key Discovery API [[!KEY-DISCOVERY]].  Instead, use cases that require cryptographic material to be shared between domains can leverage cross-origin messaging and the structured clonability of keys, or the importing and exporting of cryptographic keys across domains; such use cases are covered in this document.  Another use case not addressed here for the same reason is the case of a centrally issued electronic identity (eID) that exposes a certificate chain to web applications for use with digital signatures.</p> </li>
+        <li><p>Any use case that expressly requires the use of auxiliary cryptographic hardware, including smart cards or USB dongles.  Other standardization activities may provide mechanisms for these technologies to interact with web applications, but such use cases fall beyond the scope of this document.  Examples of this type of use case include "advanced electronic signatures" which rely on certificates issued on secure hardware by certifying authorities, typically acting under the aegis of state governments.</p></li>
+      </ol>
+    </section>
+    <section id='reqs'>
+      <h2>Requirements Covered By Use Cases</h2>
+      <p>This section presents required features of a cryptographic API, particularly the features that this use cases document will rely on.  It is possible that there is more than one algorithm and more than one mechanism to accomplish each of these features.  The section presents code names for each of the features, which will be used alongside each scenario, illustrating which feature is used.</p>
     <ul>
       <li><p><dfn title="digest" id="digest">DIGEST</dfn>, the ability to perform a cryptographic hash, where an algorithm that takes an arbitrary block of data returns a fixed-size bit sequence, called the <dfn id="hash-value">hash value</dfn>, such that any change to the block of data changes the hash value.</p></li>
       <li><p><dfn title="mac" id="mac">MAC</dfn>, the ability to generate a <em>message authentication code</em>, using an algorithm, with <dfn id="hmac">HMAC</dfn> being a specific kind of message authentication code, with a specific algorithm.</p></li>
@@ -83,35 +91,35 @@
       <li><p><dfn title="verify" id="verify">VERIFY</dfn>, the ability to verify a digitally signed document, as well as verify a MAC or HMAC.</p></li>
       <li><p><dfn title="encrypt" id="encrypt">ENCRYPT</dfn>, the ability to encode a document using an encryption algorithm.  <dfn id="encrypt-sym">ENCRYPT-SYM</dfn> is a specific type of encryption using symmetric cryptographic keys, and <dfn id="encrypt-assym">ENCRYPT-ASSYM</dfn> is a specific type of encryption using assymetric cryptographic keys, typically a public and private key pair.</p></li> 
       <li><p><dfn title="decrypt" id="decrypt">DECRYPT</dfn>, the ability to decrypt a digitally signed document.  <dfn id="decrypt-sym">DECRYPT-SYM</dfn> is a specific type of decryption using symmetric keys, and <dfn id="decrypt-assym">DECRYPT-ASSYM</dfn> is a specific type of decryption using assymetric keys, typically a public and private key pair.</p></li>
-      <li><p><dfn title="derive" id="derive">DERIVE</dfn>, the ability to derive a key or key pair used in cryptographic operations; <dfn id="derive-assym">DERIVE-ASSYM</dfn> is the ability to derive assymetric keys, typically a public and private key pair, for use with assymetric cryptographic operations, and <dfn id="derive-sym">DERIVE-SYM</dfn> is the ability to derive a symmetric key for use with symmetric cryptographic operations.</p></li>
-      <li><p><dfn title="import" id="import">IMPORT</dfn>, the ability to import a key or key pair that have already been created elsewhere, for use within the web application that is invoking the import function, for use within the importing web application's origin.  This necessiates an interoperable key format, which may be represented as octets.</p></li>
-      <li><p><dfn title="export" id="export">EXPORT</dfn>, the ability to export a key or key pair that can be accessed from within the application that is invoking the export function.  This necessiates an interoperable key format, which may be represented as octets, that other web applications can then import.</p></li>
-      <li><p><dfn title="keyex" id="keyex">KEYEX</dfn>, the ability for two entities to exchange key(s) without interception by a third party, with <dfn id="keyex-dh">KEYEX-DH</dfn> representing Diffie-Hellman key exchange, a common application of safe key exchange.</p></li>
-      <li><p><dfn title="keycall" id="keycall">KEYCALL</dfn>, the ability to access a particular key (or key pair) from within a web application's key storage, which is within the web application's origin only.  Here, the key storage might be IndexedDB or localStorage, and the key or key pair might have been created by the web application or imported by the web application.</p></li>
+      <li><p><dfn title="derive" id="derive">DERIVE</dfn>, the ability to derive a key or key pair used in cryptographic operations, starting with a base key, and factors such as algorithms appropriate for key derivation; <dfn id="derive-assym">DERIVE-ASSYM</dfn> is the ability to derive assymetric keys, typically a public and private key pair, for use with assymetric cryptographic operations, and <dfn id="derive-sym">DERIVE-SYM</dfn> is the ability to derive a symmetric key for use with symmetric cryptographic operations.</p></li>
+      <li><p><dfn title="keygen" id="keygen">KEYGEN</dfn>, the ability to generate a key or key pair used in cryptographic operations, without an initial base key, and using factors such as the entropy of the computing system and algorithms appropriate for key or key pair generation; <dfn id="keygen-assym">KEYGEN-ASSYM</dfn> is the ability to generate assymetric keys, typically a public and private key pair, for use with assymetric cryptographic operations, and <dfn id="keygen-sym">KEYGEN-SYM</dfn> is the ability to derive a symmetric key for use with symmetric cryptographic operations.</p></li>
+      <li><p><dfn title="import" id="import">IMPORT</dfn>, the ability to import a key or key pair that have already been created elsewhere, for use within the web application that is invoking the import function, for use within the importing web application's origin.  This necessiates an interoperable key format, such as JSON Web Key [[!JWK]] which may be represented as octets.</p></li>
+      <li><p><dfn title="export" id="export">EXPORT</dfn>, the ability to export a key or key pair that can be accessed from within the application that is invoking the export function.  This necessiates an interoperable key format, such as JSON Web Key [[!JWK]] which may be represented as octets, that other web applications can then import.</p></li>
+      <li><p><dfn title="keyex" id="keyex">KEYEX</dfn>, the ability for two entities to exchange key(s) without interception by a third party, with <dfn id="keyex-dh">KEYEX-DH</dfn> representing Diffie-Hellman key exchange, a common application of safe key exchange. </p>
+      <div class="note">This feature doesn't imply that every aspect of key exchange is covered, since much of key exchange often includes a network component, which isn't covered by the API.  The <a title="derive">DERIVE</a> feature, coupled with an a network exchange of key data outside the scope of this API, may be all that is required.</div>
+      </li>
+      <li><p><dfn title="keycall" id="keycall">KEYCALL</dfn>, the ability to access a particular key (or key pair) from within a web application's key storage, which is within the web application's origin only, and has been generated, derived, or imported by that web application.  Here, the key storage might be IndexedDB [[INDEXEDDB]] or <code>localStorage</code>.  This feature should be compared and contrasted with <a title="namedkey">NAMEDKEY</a>.</p></li>
       <li><p><dfn title="sym" id="sym">-SYM</dfn>, an abbreviation for <em>symmetric key cryptographic operations</em>, used in this document as a suffix to other features to specifically clarify the feature being invoked by the web application.</p></li>
       <li><p><dfn title="assym" id="assym">-ASSYM</dfn>, an abbreviation for <em>assymetric key cryptographic operations</em>, typically involving a public and private key pair, used in this document as a suffix to other features to specifically clarify the feature being invoked by the web application.</p></li>
       <li><p><dfn title="random" id="random">RANDOM</dfn>, the ability to generate cryptographically secure random numbers.</p></li>
-    </ul> 
-    <p>Additionally, the Web Cryptography WG is actively discussing three other features:</p>
-    <ul>
-      <li><p><dfn title="wrap" id="wrap">WRAP</dfn> which allows a web application to use a key to <em>wrap another key</em>, so that the wrapped key can be unwrapped by a party with the corresponding wrapping key, but is hard to obtain or unwrap by anyone without the corresponding wrapping key.  While it is possible to create a key-wrapping and unwrapping mechanism with the other features listed, this feature provides a way to do so without exposing the key to be wrapped to JavaScript. <dfn title="wrap-sym" id="wrap-sym">WRAP-SYM</dfn> refers to symmetric key wrapping, and <dfn title="wrap-assym">WRAP-ASSYM</dfn> refers to assymetric key wrapping.</p>
+      <li><p><dfn title="JSONWebKey" id="JSONWebKey">JWK</dfn>, the ability to represent public keys in the JSON Web Key format [[!JWK]].  JWK keys can be imported [<a title="import">IMPORT</a>] and exported [<a title="export">EXPORT</a>].</p></li>
+      <li><p><dfn title="wrap" id="wrap">WRAP</dfn> which allows a web application to use a key to <em>wrap another key</em>, so that the wrapped key can be unwrapped by a party with the corresponding wrapping key.  While it is possible to create a key-wrapping and unwrapping mechanism with the other features listed, this feature provides a way to do so without exposing the key to be wrapped to JavaScript. <dfn title="wrap-sym" id="wrap-sym">WRAP-SYM</dfn> refers to symmetric key wrapping, and <dfn title="wrap-assym">WRAP-ASSYM</dfn> refers to assymetric key wrapping.</p>
       <li><p><dfn id="unwrap">UNWRAP</dfn> which allows a web application to use a key to unwrap another encrypted key or key pair, which can then be used in standard cryptographic operations.  While it is possible to create a key-wrapping and unwrapping mechanism with the other features listed, this feature provides a way to do so without exposing the key to be wrapped to JavaScript.  <dfn id="unwrap-sym" title="unwrap-sym">UNWRAP-SYM</dfn> refers to symmetric unwrapping, and <dfn id="unwrap-assym" title="unwrap-assym">UNWRAP-ASSYM</dfn> refers to assymetric unwrapping.</p>
-      <div class="issue"><p>This feature is subject to discussion, including further work by JOSE [JOSE].  See <a href="https://www.w3.org/2012/webcrypto/track/issues/35">ISSUE-35</a> logged by the WebCrypto WG.</p></div>
+      <div class="issue"><p>This feature is subject to discussion. See <a href="https://www.w3.org/2012/webcrypto/track/issues/35">ISSUE-35</a> logged by the WebCrypto WG.</p></div>
     </li>
-
       <li><p><dfn id="namedkey">NAMEDKEY</dfn> which allows an application in JavaScript to discover a <dfn id="pre-prov">pre-provisioned</dfn> key within the scope of the application's origin, which exists at the time of the application's first invocation, and has not been derived, generated or imported by the application using any of the features listed above; such keys may have been provisioned by a device manufacturer, for example, and the JavaSript application can access them for initial authorization and authentication at time of first invocation. </p>
-      <div class="note"><p>This feature is developed in the Key Discovery API [KEY-DISCOVERY].</p></div>
+      <div class="note"><p>This feature is developed in the Key Discovery API [[!KEY-DISCOVERY]].</p></div>
     </li>
   </ul>
     </section>
     <section>
       <h2>Use Case Scenarios</h2>
-      <p>This section collates use case scenarios that leverages the WebCrypto API [WEBCRYPTO] or the Key Discovery API [KEY-DISCOVERY].  Where possible, sample code is provided, and should be considered illustrative only, since the underlying API specifications are changing.</p>
+      <p>This section collates use case scenarios that leverages the WebCrypto API [[!WEBCRYPTO]] or the Key Discovery API [[!KEY-DISCOVERY]]; in particular, these use cases leverage all the features listed above as <a href="#reqs">requirements</a>.  Where possible, sample code is provided, and should be considered illustrative only, since the underlying API specifications are changing.</p>
     
       <section>
       <h3>Banking Transactions</h3>
-      <p>Park Jae-sang opens up a bank account with Gangnam Bank, and wishes to log-in and engage in online transactions, including account balance checking, online payments (with some automated scheduled payments), and account transfers between domestic and investment accounts.  The first time Park logs in to the Gangnam Bank website (Gangnam Bank's website from now on will be abbreviated "GB") with a temporary verification code sent to his cell phone, the bank asks him to ascertain if the browser he is using is not at a kiosk; moreover, he is asked if it is a web browser and machine configuration he will use often.</p>
-      <p>He confirms that it is.  The GB web site then asks him to generate a public key/private key pair.  Park consents, and the web page creates the key pair, storing his private key in the browser's designated key store, along with a one-time key escrow by the bank.  Additionally, Jae-sang is presented with the bank's public key, such that documents issued by the bank can be verified and decrypted; Jae-sang presents the derived public key to GB.  Jae-sang is also presented with a user guide that explains the validity period of the key pair, and for how long they will persist.  [<a title="derive">DERIVE</a> | <a title="keyex">KEYEX</a>].</p>
+      <p>Park Jae-sang opens up a bank account with Gangnam Bank, and wishes to log-in and engage in online transactions, including account balance checking, online payments (with some automated scheduled payments), and account transfers between domestic and investment accounts.  The first time Park logs in to the Gangnam Bank website (abbreviated "GB") with a temporary verification code sent to his cell phone, the bank asks him to ascertain if the browser he is using is not at a kiosk; moreover, he is asked if it is a web browser and machine configuration he will use often.</p>
+      <p>He confirms that it is.  The GB web site then asks him to generate a public key/private key pair.  Park consents, and the web page creates the key pair, storing his private key in the browser's designated key store, along with a one-time key escrow by the bank.  Additionally, Jae-sang is presented with the bank's public key, such that documents issued by the bank can be verified and decrypted; Jae-sang presents the derived public key to GB.  Jae-sang is also presented with a user guide that explains the validity period of the key pair, and for how long they will persist.  [<a title="keygen">KEYGEN-ASSYM</a> .</p>
       <p>GB may first generate some key pair for Jae-sang.  These include the public key/private key which will be used for digital signatures. </p>
 
       <pre class="example hightlight prettyprint">
@@ -127,42 +135,37 @@
 };
 
 
-var keyGen = window.crypto.generateKey(algorithmKeyGen,
-                                       false, // extractable
-                                       ["sign"]);
-
-keyGen.oncomplete = function(event) {
-
-  // Store the key pair in IndexedDB
-  // Perform a signing operation
-}
- 
+window.crypto.subtle.generateKey(algorithmKeyGen, false, ["sign"]).then(
+  function(key)
+  {
+    // Store the key pair in IndexedDB
+  },
+  console.error.bind(console, "Unable to generate key -- call your Banker or retry later.")); 
 
       </pre>
 <p>GB may then use a key exchange mechanism to exchange keys with the server over TLS. This includes making sure that the client (Jae-sang) obtains a copy of GB's public key, and that GB obtains a copy of Jae-sang's public key, which were generated in the preceding step. </p>
-<pre class="example highlight prettyprint">
-  /** 
-          TODO add some Diffie-Hellman key exchange code which results in
-          1. Jae-sang having GB's public key
-          2. GB having Jae-sang's public key
-  **/
-</pre>  
+ 
 <p>Subsequent access to the GB website -- always over TLS -- is triggered via use of the key that Jae-sang generated when he first accessed the website. JavaScript initially loaded by GB contains a message that only Jae-sang can decipher, since it is encrypted with his public key; moreover, that message is signed by GB, which gives the client confidence that the message originates from GB. The message is deciphered, and the deciphered message is then digitally signed and sent back to the GB server. </p>
 <p>  [<a title="keycall">KEYCALL</a> | <a title="verify">VERIFY</a> | <a title="decrypt-assym">DECRYPT-ASSYM</a> | <a title="sign">SIGN</a>]</p>  
-<p>In the example below, an encrypted message is signed by GB. The signature is verified, and upon successful verfication, is decrypted. The decrypted message is then signed and sent to GB. This example should be seen as a simplification for illustrative purposes only. </p>  
+<p>In the example below, an encrypted message is signed by GB. The signature is verified, and upon successful verfication, is decrypted. The decrypted message is then processed. This example should be seen as a simplification for illustrative purposes only. </p>
+<div class="issue"><p>Semantics of the verify operation are still TBD in the group.  TODO: create another example using WRAP/UNWRAP.</p></div>
 <pre class="example highlight prettyprint">
 
-        // Message generated by GB... the ellipsis are added. 
+        // Encrypted and Signed Message generated by GB... the ellipsis are added. 
+        // This could be in a parsable JWT format such that portions with signature and message are easily understood
+
         var cat = "qANQR1DBw04Dk2uPpEjcJT8QD/0VCfFK2XDM5Cg4iTRwmXrB+Pp8SMK5x09WkYqc... ";
 
         /** 
           1. Generate an ArrayBufferView of the overall message.
           2. Bit-manipulate this with the ArrayBufferView API to obtain the portion of bytes 
           constituting the signature as an ArrayBufferView, and the message as an ArrayBufferView.
+          This could be based on an understood JWT paradigm.
           3. Obtain the public key of GB from IndexedDB -- pubGBKeySign -- a step not shown here.
-          4. Verify the signature ... assume GB provides a method getSignature() to obtain a signature
-             from the server against which the message's signature can be verified.
-          **/
+          4. Verify the signature.
+          5. Upon verification, decrypt the message.  This message can be decrypted only by Jae-Sang, using his private key          
+
+        **/
 
         var data = createArrayBufferView(cat);
         var signature = extractSignature(data);
@@ -172,53 +175,38 @@
                             hash: "SHA-256"
                         }
         };
-        verifier = window.crypto.verify(mRSARFC3447, pubGBKeySign, signature);
-        verifier.oncomplete = function(e){
+        // Verify GB signature
+        window.crypto.subtle.verify(mRSARFC3447, pubGBKeySign, signature).then(
+        function(verified){
+
         /* 
           If verified, obtain a prvKeyEncrypt from IndexedDB representing Jae-sang's private key and:
           1. Decrypt the message.  Note that here, typically the encryption key might be symmetric
              and wrapped.  This sample simplifies this by not demonstrating key wrapping.
-          2. Sign it
-          3. Send it back
+          2. Do further operations, like sign the decrypted message and send it back
           Else the signature is invalid -- abort
         */
-        
-          if (e.target.result == true)
-          {
-            var decrypter = window.crypto.decrypt("RSAES-PKCS1-v1_5", prvKeyEncrypt);
-            decrypter.process(pMessage);
-            decrypter.onprogress = function(e){e.target.finish()};
-            decrypter.oncomplete = function(evt)
-            { 
-
-            // If successfully decrypted send a signed version back
-
-            message = evt.target.result;
 
-            /* Assume key retrieval code from IndexedDB that results in pubKeySign */
-        
-            var signer = window.crypto.sign(mRSARFC3447, pubKeySign, message);
-            signer.onprogress = function(e){e.target.finish();}
-            signer.oncomplete = function(evt)
-            {
-            /* 
-                                     Combine signature and signed data into an ArrayBuffer
-                                     Use XHR to send signed data back...
-                                     Wait for auth token...
-                                  */ 
-            }
-        }
-        else
-        {
-          // Unverified signature -- ABORT 
-        }
-      }
+          return window.crypto.subtle.decrypt("RSAES-PKCS1-v1_5", prvKeyEncrypt, pMessage);
+
+        },
+        console.log.bind(console, "Verification Error!  Contact Bank.")).then(
+        function decrypted(message){
+
+          // Conduct operations on GB message
+          // This could include signing the decrypted message and sending it back to GB
+
+        },
+        console.error.bind(console, "Decryption Error!  Contact Bank.")
+
+        );
 </pre>
 <p>
-His browser presents this key every time he accesses the website and enters his password, which effectively binds his username and password to the generated private key. Additionally, Jae-sang can digitally sign online checks, authorize payments, and sign tax forms that he submits to the bank site using this generated key [SIGN]. He can also perform the following tasks, following an authentication cycle such as the one described above:</p>
+His browser presents this key every time he accesses the website and enters his password, which effectively binds his username and password to the generated private key. Additionally, Jae-sang can digitally sign online checks, authorize payments, and sign tax forms that he submits to the bank site using this generated key [<a href="sign">SIGN</a>]. He can also perform the following tasks, following an authentication cycle such as the one described above:</p>
 <ol>
-  <li>Receive encrypted documents from GB that only he can read, with the assurance that they have come from GB and only GB. These include his private bank statements and tax documents, which are signed with his public key, already obtained in a previous step. [<a title="verify">VERIFY</a> | <a title="unwrap">UNWRAP</a> | <a title="decrypt-sym">DECRYPT-SYM</a>]</li>
-  <li>Submit documents to GB that only GB can read, with the assurance that these have come from Jae-sang. Such documents include confidential financial information, and may be encrypted at submission. [<a title="sign">SIGN</a> | <a title="derive-sym">DERIVE-SYM</a> | <a title="encrypt-sym">ENCRYPT-SYM</a> | <a title="wrap">WRAP</a>]</li>
+    <li>Submit documents to GB that only GB can read, with the assurance that these have come from Jae-sang. Such documents include confidential financial information, and may be encrypted at submission. This can follow the well-understood pattern of wrapping keys using assymetric encryption, but encrypting and decrypting larger documents using symmetric encryption. [<a title="sign">SIGN</a> | <a title="derive-sym">DERIVE-SYM</a> | <a title="encrypt-sym">ENCRYPT-SYM</a> | <a title="wrap">WRAP-ASSYM</a>]</li>
+  <li>Receive encrypted documents from GB that only he can read, with the assurance that they have come from GB and only GB. These include his private bank statements and tax documents, which are signed with his public key, already generated and obtained by GB in a previous step. [<a title="verify">VERIFY</a> | <a title="unwrap">UNWRAP-ASSYM</a> | <a title="decrypt-sym">DECRYPT-SYM</a>]</li>
+
 </ol>
      </section>
 <section>
@@ -249,11 +237,11 @@
 </section>
 <section>
   <h2>Code Sanctity and Bandwidth Saver</h2>
-<p>A major social networking site wishes to optimize website performance by storing JavaScript libraries that are served from a CDN in <code>localStorage</code> or in <code>IndexedDB</code>, preventing server rountrips to the CDN.  When the code in the libraries has undergone critical modifications, the social networking site wishes to determine whether the version stored in the client needs updating.  </p>
-<p>Using the Web Crypto API, the social networking site might verify a digest of the code from the CDN and compare it to a digest of the code in <code>localStorage</code>.</p>
+<p>A major social networking site wishes to optimize website performance by storing JavaScript libraries that are served from a CDN in <code>localStorage</code> or in <code>IndexedDB</code> [[INDEXEDDB]], preventing server rountrips to the CDN.  When the code in the libraries has undergone critical modifications, the social networking site wishes to determine whether the version stored in the client needs updating.  </p>
+<p>Using the Web Crypto API, the social networking site might verify a digest of the code from the CDN and compare it to a digest of the code in <code>localStorage</code>.  The social network can generate a digest of the material extracted from the client storage, and compare this to a pristine version of the digest that the social networking site makes available to the client. If the two digests match, the code is deemed the latest from the CDN, and does not need to be refreshed. [<a title="digest">DIGEST</a>]</p>
 <pre class="example highlight prettyprint">
-// Synchronously retrieve a SHA-256 digest of the pristine version of the code
-      // This is retrieved from the server
+// Retrieve a SHA-256 digest of the pristine version of the code
+// This is retrieved from the server
         var src_hash = getHashFromCDN();
         function init()
         {
@@ -264,37 +252,37 @@
             1. Assume utility function createArrayBufferView that creates an ArrayBufferView of the src
             (and note that the comparison does depend on this being consistent on client and server).
 
-            2. Compare the two values after hashing is successfully completed.
+            2. Compare the two values after digest is successfully generated.
 
             In practice including an onprogress handler and onerror handler is recommended - the code here
             is terse for readability.
 
             */
-          
+          bufferData = createArrayBufferView(src);  
+          window.crypto.subtle.digest("SHA-256", bufferData).then(
+          function(digest){
+            if(digest == src_hash)
+            {
+              var transformed = JSON.parse(src);
+        
+              /* Now do stuff with transformed -- it is legitimately from the mothership */
 
-          bufferData = createArrayBufferView(src);
-          var digest = window.crypto.digest("SHA-256", bufferData);
-          digest.finish();
-          digest.oncomplete = function(e)
-          {
-            if(e.target.result === src_hash)
-            {
-                JSON.parse(src);
-            }
-            else
-            {
-                // Fetch the code using XHR and repopulate localStorage
-            }
-          }
+
+            }  
+           },
+           function(error){
+           // Fetch the code anew 
+
+            request.pull("http://cdn.example/src.js");
+
+           // Put it in localStore
+
+         });
+
         }
 <div class="note">The conversion to an <code>ArrayBufferView</code> must be consistent with the conversion to the bits on the server-side, so that the SHA-256 digests can be compared accurately.</div>
 </pre>
-<p>In this case, <code>getHashFromServer()</code> runs within the origin of the page of the social networking site, accessed through TLS.</p>
-<ol>
-<li>As in the example above, the social network can generate a digest of the material extracted from the client storage, and compare this to a pristine version of the digest that the social networking site makes available to the client. If the two digests match, the code is deemed safe. [<a title="digest">DIGEST</a>]</li>
-<li>They can improve on the model above by "signing with an HMAC" (or "signed hash") and then verifying the HMAC. This model offers one level more robustness, since the verification occurs within the WebCrypto API, as opposed to within the application. [<a title="sign">SIGN</a> | <a title="hmac">HMAC</a> | <a title="verify">VERIFY</a>]</li>
-</ol>
-
+<p>In this case, <code>getHashFromCDN()</code> runs within the origin of the page of the social networking site, accessed through TLS, and allows the CDN to transform the code blob into an ArrayBufferView, perform a digest operation, and then allow client-side code to do the same with what is in <code>localStorage</code>; if the two digests are exactly equivalent, the code in <code>localStorage</code> is sanctioned for use, and if not, code is fetched anew from the CDN.</p>
 </section>
 <section>
   <h2>Encrypted Communications via Webmail</h2>
@@ -315,7 +303,7 @@
   
 </pre>
 <p>Logging on to EWA, Tantek is prompted to import Ryan's contact information from his web page, and is notified that Ryan's public key will also be imported. EWA then begins the process of importing Ryan's PGP key, since it understands how to parse public keys within hCard content (see also key examples). In order to import the key for storage under EWA's origin, it must first "scrub" the key format to be in one of the accepted import formats of the WebCrypto API.</p>
-<p>Here, the Contacts API [cf. Mozilla][cf. Google][cf. DAP] could be used to procure Ryan's contact information, and can be one way of importing the key for use by an application such as EWA. Due the same origin policy [cf. HTML], EWA must import the key, so that operations conducted with it fall under the domain of EWA. Convert the key to JSON Web Key format, which the WebCrypto API accepts if converted to octets, and then import it for use within the web application.</p>
+<p>Here, a standardized Contacts API could be used to procure Ryan's contact information, and can be one way of importing the key for use by an application such as EWA. Due the same origin policy [[!HTML]], EWA must import the key, so that operations conducted with it fall under the domain of EWA. The key is converted to JSON Web Key format [[!JWK]], which the WebCrypto API accepts and then import it for use within the web application.</p>
 <pre class="example highlight prettyprint">
 /**
   1. First convert the PGP key format into an "importable" format by the WebCrypto API; assume "keyString" is the PGP format
@@ -329,29 +317,32 @@
 
 var jwkKeyObject = JSON.parse(jwkKey);
 
-// Convert to ArrayBufferView
-var octetsKey = mByteArray(jwkKey);
-
-
-var importer = window.crypto.importKey("jwk", octetsKey, "RSAES-PKCS1-v1_5", false, ["encrypt", "verify"]);
+/**
 
-importer.oncomplete() = function(evt){
-  var keyImported = evt.target.result;
+  Key import syntax is still undefined in the spec.
 
-  /**
-    1. Store the new object keyImported in IndexedDB
-    2. The Key ID used to store the public key may be Ryan's contact
-    3. Or it could be jkwKeyObject.kid
-    **/
-}
+  1. The key gets imported, and is used to sign messages.
+  2. The key can also be used to WRAP-ASSYM a symmetric key
+  3. The symmetric key from 2. above can be used to encrypt messages
+
+**/
+
+  window.crypto.subtle.importKey("jwk", jwkKey, "RSAES-PKCS1-v1_5", "true", ["encrypt", "verify"]).then(handleImport);
+
+  function handleImport(bool)
+  {
+    // If successfully imported, store key in IndexedDB
+    // Retrieve key later for encypted communications and signature verification
+    // If not, console.error.bind(console, "Error Importing Key")
+  }
 
 </pre>
-<p>Following the key import and storage sequence, the key now serves as a key within the origin of EWA. EWA can then offer Tantek the option of encrypting messages to Ryan, which may follow the pattern below:</p>
+<p>The key now serves as a key within the origin of EWA. EWA can then offer Tantek the option of encrypting messages to Ryan, which may follow the pattern below:</p>
 <ol>
-  <li>Tantek composes a message that he wishes to send only to Ryan.</li>
-  <li>EWA generates a symmetric key on Tantek's behalf, and uses Ryan's public key, just imported, to wrap that key. [<a title="derive-sym">DERIVE-SYM</a> | <a title="keycall">KEYCALL</a> | <a title="wrap">WRAP</a>].</li>
+  <li>Tantek imports the key into the EWA, and composes a message that he wishes to send only to Ryan. [<a title="JSONWebKey">JWK</a>]</li>
+  <li>EWA generates a symmetric key on Tantek's behalf, and uses Ryan's public key, just imported, to wrap that key. [<a title="derive-sym">DERIVE-SYM</a> | <a title="keycall">KEYCALL</a> | <a title="wrap">WRAP-ASSYM</a>].</li>
   <li>EWA then signs the encrypted message and wrapped key, and sends them from Tantek's email account on Tantek's behalf [<a title="sign">SIGN</a> | <a title="encrypt-sym">ENCRYPT-SYM</a>].</li>
-  <li>Ryan also logs into EWA. Separately, he has also imported Tantek's public key to EWA using a similar mechanism that Ryan did. In this case, as long as Ryan has Tantek's public key, he does not strictly need to log into the same EWA as Tantek does; instead, Ryan may choose another email web application with a different origin, but with similar functionality, such that the public key is imported to be used within the origin of the web application. Ryan receives the message, verifies that it is indeed from Tantek, decrypts and reads the message using his corresponding private key. [<a title="keycall">KEYCALL</a> | <a title="verify">VERIFY</a> | <a title="unwrap">UNWRAP</a> | <a title="decrypt-sym">DECRYPT-SYM</a>].</li>
+  <li>Ryan also logs into EWA. Separately, he has also imported Tantek's public key to EWA using a similar mechanism that Ryan did. In this case, as long as Ryan has Tantek's public key, he does not strictly need to log into the same EWA as Tantek does; instead, Ryan may choose another email web application with a different origin, but with similar functionality, such that the public key is imported to be used within the origin of the web application. Ryan receives the message, verifies that it is indeed from Tantek, decrypts and reads the message using his corresponding private key. [<a title="keycall">KEYCALL</a> | <a title="verify">VERIFY</a> | <a title="unwrap">UNWRAP-ASSYM</a> | <a title="decrypt-sym">DECRYPT-SYM</a>].</li>
 </ol>
 <div class="note">Importing keys from across the web is safest when the provenance of the keys is known.</div>
 </section>
@@ -375,6 +366,164 @@
 </ol>
 
     </section>
+    <section>
+<h2>BrowserID: Use of Cryptography for Identity Protocols</h2>
+<p>
+Karen, an avid photographer, has been looking for a site to store all the photos that she posts on various websites.  Instead of creating yet another online identity for another photo storage website, Karen is pleased to find a photo-storage service that uses the BrowserID protocol [[!BrowserID]], allowing her to use any email address as an identity.  The photo-storage service (PSS) is a <em>Relying Party</em> of the protocol, and Karen elects to use Persona.org as an <em>Identity Provider</em>, since she sees a "log-in with Persona" button on the PSS website.  She notes that her preferred email provider is not yet an Identity Provider for use with BrowserID [[!BrowserID]], and thus uses Persona.org as a fallback option.
+</p>
+<p>
+Karen first creates a "verified email" identity with Persona.org.  Persona.org sends out an email with a hyperlink in it to an email address that she chooses to use as one of her identities (she chooses "[email protected]"), especially for use with PSS.  She then logs in to this email account and clicks on the verification link sent by Persona.org.  Persona.org is thus able to determine that Karen owns this email address.  The following now happens:</p>
+<ol>
+<li><p>Persona.org creates assymetric keys, public and private, on behalf of the user. [<a title="keygen-assym">KEYGEN-ASSYM</a>]</p></li>
+<li><p>Persona.org's web page then sends the public key just created over TLS for storage on Persona.org's servers, and stores the keypair in the browser's client-side storage.  This could include [[!INDEXEDDB]] and <code>localStorage</code>, although in browsers with a native implementation of BrowserID [[!BrowserID]], this might include another key store.</p></li>
+<li><p>Persona.org then generates a certificate, which involves signing the public key just created, the email address, and a validity interval; the signature here is performed by Persona.org.  This certificate takes the form of a [[!JWT]] object. The [[!JWT]] object -- the certificate created above -- is itself stored in the browser's client storage, which can be [[!INDEXEDDB]] or <code>localStore</code>; if the browser implementation has a native implementation of [[!BrowserID]], another key and certificate store could exist. [<a title="keycall">KEYCALL</a> | <a title="sign">SIGN</a>]</p></li>
+</ol>
+<p>Karen now has at least one identity, namely her email of choice, verified on Persona.org, along with a certificate issued by Persona.org.  She then decides to log in to the PSS website using that identity.  The following sequence then takes place:</p>
+<ol>
+<li><p>Karen accesses the website of the PSS, and then clicks on the "Log in with Persona" link.  The log-in link loads script from Persona.org in an <code>iframe</code>, which creates an assertion structure as a JWT [[!JWT]].  The assertion consists of the name of the Relying Party, also referred to as an <em>audience</em>, and a validity period.  This assertion is signed using the private key that was created previously. [<a title="keycall">KEYCALL</a> | <a title="sign">SIGN</a>]</p></li>
+<li>The signed assertion is then combined with the certificate created previously into a new [[!JWT]] structure, which might look like this:
+  <pre class="example highlight prettyprint">
+  // This is for illustrative purposes only
+  // Proper use of JWT uses Base64 
+
+  assertionPlusCert = 
+  {
+    "assertion": {
+      "audience": "photosharingsite.example",
+      "valid-until": 1308859352261,
+    }, // signed using Karen's private key minted by Persona.org for [email protected]
+    "certificate": {
+        "email": "[email protected]",
+        "public-key": "<karens-public-key>",
+        "valid-until": 1308860561861,
+    } // certificate is signed by Persona.org
+  };
+
+  </pre>
+</li>
+<li><p>Persona.org then sends this over to script hosted by PSS using cross-origin messaging.</p>
+
+<pre class="example highlight prettyprint">
+/** 
+   This code is for illustrative purposes only and runs on Persona.org.
+
+   1. Assume a combined assertion and certificate structure in JWT format for use with postMessage()
+      var assertionPlusCert is a JWT like above
+   2. Extract [email protected] public key for use with postMessage()
+   3. Send the certificate structure assertionPlusCert over for verification
+   
+   Caveat emptor: step 3 can be made more efficient in terms of Web Crypto API usage if
+   Karen's public key can be sent over using the structured clone algorithm.  Currently
+   we proceed with it as a JWK embedded in a JWT.
+
+**/
+
+
+transaction.objectStore("publicBrowserIDKeys").get("[email protected]").onsuccess = function(evt) {
+  var publicKey = event.target.result;
+
+// Send the assertionPlusCert structure to script on photosharingsite.example
+
+  pssHandle.postMessage(assertionPlusCert, "http://photosharingsite.example");
+  
+  window.addEventListener("message", receiveCallBackFromPSS, false);
+
+
+  function receveCallBackFromPSS(event)
+  {
+    if(event.origin != "http://photosharingsite.example")
+      return;
+    if(event.data == "OK") 
+      // Auth was successful
+    else
+      // Auth Fail on PSS side
+  }
+
+/** 
+  On the receiving end, namely http://photosharingsite.example:
+
+  0. Register to receive message events
+  1. Obtain the public key from Persona.org to verify the signed certificate
+  2. Use [email protected]'s public key to verify the signature on the assertion
+
+**/
+
+window.addEventListener("message", receiveCryptoFromIDP, false);
+
+function receiveCryptoFromIDP(event)
+{
+
+  if(event.origin!="http://login.persona.org/")
+  {
+    event.source.postMessage("authFail", event.origin);
+    return "authFail";
+  }
+
+  
+  /* 
+     Note that event.data is assertionPlusCert with two signatures
+     JWT specifies a way this can be represented, following use of
+     Base64 encoding and "." as a delimiter separating components
+
+     1. Assume a utility function to obtain a JWK from a well-known location
+        Import the JWK key from Persona.org -- see Example 6
+     2. Verify the part signed by Persona.org
+     3. Assume utility functions to parse the event.data into subcomponents
+     4. Extract Karen's public key from event.data using utility function
+     5. Import Karen's public key for use within PSS
+     6. Verify the assertion signed by Karen's private key
+     7. Step 2. and 6. succeeding allow authentication to occur
+  */
+  
+  var mRSARFC3447 = 
+  {
+    name: "RSASSA-PKCS1-v1_5", params: {
+                            hash: "SHA-256"
+                        }
+  };
+
+  var JWKIDPKey = createJWK("https://login.persona.org/.well-known/browserid");
+
+  var certificateSignature = parseCertSignature(event.data);
+
+  var assertionSignature = parseAssertionSignature(event.data);
+  // Import the JWK key -- see Example 6 -- this results in publicKeyIDP
+
+  var JWKuserPubKey = parseUserPublicKey(event.data);
+  // Import the user public key -- see Example 6 -- this results in userPublicKey
+  
+  window.crypto.subtle.verify(mRSARFC3447, publicKeyIDP, certificateSignature).then(
+  function(successCert)
+  {
+    window.crypto.subtle.verify(mRSARFC3447, userPublicKey, assertionSignature).then(
+    function(successUserClaim)
+    {
+      event.source.postMessage("OK", event.origin);
+      return "OK";
+    },
+    function(failUserClaim)
+    {
+      event.source.postMessage("authFail", event.origin);
+      return "authFail";
+    }
+    );
+  },
+  function(failCert)
+  {
+    event.source.postMessage("authFail", event.origin);
+    return "authFail";
+  }
+  );
+}
+</pre>
+</li>
+<li><p>The PSS website receives the message, sent via cross-origin messaging, and proceeds to validate the assertion.  In order to do this, the PSS website first obtains Persona.org's public key, hosted at a well-known location, and verifies the signature on the certificate.  The script at PSS may choose to "import" the public key of Persona.org in order to verify the signature, and store it within PSS's application storage. [<a title="import">IMPORT</a> | <a title="verify">VERIFY</a>]</p>
+</li>
+<li><p>The PSS website then verifies the signature of the user on the assertion.  Karen's public key has also been sent to script hosted on PSS via a structured clone using cross-document messaging. [<a title="verify">VERIFY</a>]</p></li>
+<li>Upon successful verification of both signatures, Karen is granted access to PSS, which now identifies her and considers her authenticated.</li>
+</ol>
+
+    </section>
   </section>
 
     <section class='appendix'>