Bug 651596: eliminate IWeaveCrypto. r=philiKON
authorRichard Newman <rnewman@mozilla.com>
Wed, 20 Apr 2011 14:27:19 -0700
changeset 68642 d0cab65b9d4ea171f9f313b9562d8b1dae33d509
parent 68641 df65352d3fdc40b2c2217fc6a7be5bd43859b5c4
child 68643 c9dd5010ab78bb0b1b15127ba32045980cd9bfd3
push id19688
push userpweitershausen@mozilla.com
push dateWed, 27 Apr 2011 04:36:19 +0000
treeherdermozilla-central@47694c462622 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersphiliKON
bugs651596
milestone6.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 651596: eliminate IWeaveCrypto. r=philiKON
services/crypto/IWeaveCrypto.idl
services/crypto/Makefile.in
services/crypto/modules/WeaveCrypto.js
services/crypto/tests/unit/test_crypto_crypt.js
services/crypto/tests/unit/test_crypto_random.js
services/sync/tests/unit/head_helpers.js
services/sync/tests/unit/test_utils_deriveKey.js
deleted file mode 100644
--- a/services/crypto/IWeaveCrypto.idl
+++ /dev/null
@@ -1,224 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Weave code.
- *
- * The Initial Developer of the Original Code is
- * Mozilla Corporation
- * Portions created by the Initial Developer are Copyright (C) 2007
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Dan Mills <thunder@mozilla.com> (original author)
- *   Honza Bambas <honzab@allpeers.com>
- *   Justin Dolske <dolske@mozilla.com>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#include "nsISupports.idl"
-
-[scriptable, uuid(f4463043-315e-41f3-b779-82e900e6fffa)]
-interface IWeaveCrypto : nsISupports
-{
-  /**
-   * Shortcuts for some algorithm SEC OIDs.  Full list available here:
-   * http://lxr.mozilla.org/seamonkey/source/security/nss/lib/util/secoidt.h
-   */
-
-  const unsigned long DES_EDE3_CBC = 156;
-  const unsigned long AES_128_CBC  = 184;
-  const unsigned long AES_192_CBC  = 186;
-  const unsigned long AES_256_CBC  = 188;
-
-  /**
-   * One of the above constants. Used as the mechanism for encrypting bulk
-   * data and wrapping keys.
-   *
-   * Default is AES_256_CBC.
-   */
-  attribute unsigned long algorithm;
-
-  /**
-   * The size of the RSA key to create with generateKeypair().
-   *
-   * Default is 2048.
-   */
-  attribute unsigned long keypairBits;
-
-  /**
-   * Encrypt data using a symmetric key.
-   * The algorithm attribute specifies how the encryption is performed.
-   *
-   * @param   clearText
-   *          The data to be encrypted (not base64 encoded).
-   * @param   symmetricKey
-   *          A base64-encoded symmetric key (eg, one from generateRandomKey).
-   * @param   iv
-   *          A base64-encoded initialization vector
-   * @returns Encrypted data, base64 encoded
-   */
-  ACString encrypt(in AUTF8String clearText,
-                   in ACString symmetricKey, in ACString iv);
-
-  /**
-   * Encrypt data using a symmetric key.
-   * The algorithm attribute specifies how the encryption is performed.
-   *
-   * @param   cipherText
-   *          The base64-encoded data to be decrypted
-   * @param   symmetricKey
-   *          A base64-encoded symmetric key (eg, one from unwrapSymmetricKey)
-   * @param   iv
-   *          A base64-encoded initialization vector
-   * @returns Decrypted data (not base64-encoded)
-   */
-  AUTF8String decrypt(in ACString cipherText,
-                   in ACString symmetricKey, in ACString iv);
-
-  /**
-   * Generate a RSA public/private keypair.
-   *
-   * @param aPassphrase
-   *        User's passphrase. Used with PKCS#5 to generate a symmetric key
-   *        for wrapping the private key.
-   * @param aSalt
-   *        Salt for the user's passphrase.
-   * @param aIV
-   *        Random IV, used when wrapping the private key.
-   * @param aEncodedPublicKey
-   *        The public key, base-64 encoded.
-   * @param aWrappedPrivateKey
-   *        The public key, encrypted with the user's passphrase, and base-64 encoded.
-   */
-  void generateKeypair(in ACString aPassphrase, in ACString aSalt, in ACString aIV,
-                       out ACString aEncodedPublicKey, out ACString aWrappedPrivateKey);
-
-  /*
-   * Generate a random symmetric key.
-   *
-   * @returns The random key, base64 encoded
-   */
-  ACString generateRandomKey();
-
-  /*
-   * Generate a random IV.
-   *
-   * The IV will be sized for the algorithm specified in the algorithm
-   * attribute of IWeaveCrypto.
-   *
-   * @returns The random IV, base64 encoded
-   */
-  ACString generateRandomIV();
-
-  /*
-   * Generate random data.
-   *
-   * @param aByteCount
-   *        The number of bytes of random data to generate.
-   * @returns The random bytes, base64-encoded
-   */
-  ACString generateRandomBytes(in unsigned long aByteCount);
-
-
-  /**
-   * Encrypts a symmetric key with a user's public key.
-   *
-   * @param aSymmetricKey
-   *        The base64 encoded string holding a symmetric key.
-   * @param aEncodedPublicKey
-   *        The base64 encoded string holding a public key.
-   * @returns The wrapped symmetric key, base64 encoded
-   *
-   * For RSA, the unencoded public key is a PKCS#1 object.
-   */
-  ACString wrapSymmetricKey(in ACString aSymmetricKey,
-                            in ACString aEncodedPublicKey);
-
-  /**
-   * Decrypts a symmetric key with a user's private key.
-   *
-   * @param aWrappedSymmetricKey
-   *        The base64 encoded string holding an encrypted symmetric key.
-   * @param aWrappedPrivateKey
-   *        The base64 encoded string holdering an encrypted private key.
-   * @param aPassphrase
-   *        The passphrase to decrypt the private key.
-   * @param aSalt
-   *        The salt for the passphrase.
-   * @param aIV
-   *        The random IV used when unwrapping the private key.
-   * @returns The unwrapped symmetric key, base64 encoded
-   *
-   * For RSA, the unencoded, decrypted key is a PKCS#1 object.
-   */
-  ACString unwrapSymmetricKey(in ACString aWrappedSymmetricKey,
-                              in ACString aWrappedPrivateKey,
-                              in ACString aPassphrase,
-                              in ACString aSalt,
-                              in ACString aIV);
-                              
-  /**
-   * Rewrap a private key with a new user passphrase.
-   *
-   * @param aWrappedPrivateKey
-   *        The base64 encoded string holding an encrypted private key.
-   * @param aPassphrase
-   *        The passphrase to decrypt the private key.
-   * @param aSalt
-   *        The salt for the passphrase.
-   * @param aIV
-   *        The random IV used when unwrapping the private key.
-   * @param aNewPassphrase
-   *        The new passphrase to wrap the private key with.
-   * @returns The (re)wrapped private key, base64 encoded
-   *
-   */
-   ACString rewrapPrivateKey(in ACString aWrappedPrivateKey,
-                             in ACString aPassphrase,
-                             in ACString aSalt,
-                             in ACString aIV,
-                             in ACString aNewPassphrase);
-                             
-   /**
-    * Verify a user's passphrase against a private key.
-    *
-    * @param aWrappedPrivateKey
-    *        The base64 encoded string holding an encrypted private key.
-    * @param aPassphrase
-    *        The passphrase to decrypt the private key.
-    * @param aSalt
-    *        The salt for the passphrase.
-    * @param aIV
-    *        The random IV used when unwrapping the private key.
-    * @returns Boolean true if the passphrase decrypted the key correctly.
-    *
-    */
-   boolean verifyPassphrase(in ACString aWrappedPrivateKey,
-                            in ACString aPassphrase,
-                            in ACString aSalt,
-                            in ACString aIV);
-};
-
--- a/services/crypto/Makefile.in
+++ b/services/crypto/Makefile.in
@@ -39,21 +39,16 @@
 DEPTH     = ../..
 topsrcdir = @top_srcdir@
 srcdir    = @srcdir@
 VPATH     = @srcdir@
 
 include $(DEPTH)/config/autoconf.mk
 
 MODULE = services-crypto
-XPIDL_MODULE = services-crypto
-
-XPIDLSRCS = \
-  IWeaveCrypto.idl \
-  $(NULL)
 
 libs::
 	$(PYTHON) $(topsrcdir)/config/nsinstall.py $(srcdir)/modules/* $(FINAL_TARGET)/modules/services-crypto
 
 ifdef ENABLE_TESTS
 DIRS += tests
 endif
 
--- a/services/crypto/modules/WeaveCrypto.js
+++ b/services/crypto/modules/WeaveCrypto.js
@@ -40,28 +40,35 @@ const EXPORTED_SYMBOLS = ["WeaveCrypto"]
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 const Cr = Components.results;
 
 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
 Components.utils.import("resource://gre/modules/Services.jsm");
 Components.utils.import("resource://gre/modules/ctypes.jsm");
 
-const ALGORITHM                 = Ci.IWeaveCrypto.AES_256_CBC;
+/**
+ * Shortcuts for some algorithm SEC OIDs.  Full list available here:
+ * http://lxr.mozilla.org/seamonkey/source/security/nss/lib/util/secoidt.h
+ */
+const DES_EDE3_CBC = 156;
+const AES_128_CBC  = 184;
+const AES_192_CBC  = 186;
+const AES_256_CBC  = 188;
+
+const ALGORITHM                 = AES_256_CBC;
 const KEYSIZE_AES_256           = 32;
 const KEY_DERIVATION_ITERATIONS = 4096;   // PKCS#5 recommends at least 1000.
 const INITIAL_BUFFER_SIZE       = 1024;
 
 function WeaveCrypto() {
     this.init();
 }
 
 WeaveCrypto.prototype = {
-    QueryInterface: XPCOMUtils.generateQI([Ci.IWeaveCrypto]),
-
     prefBranch : null,
     debug      : true,  // services.sync.log.cryptoDebug
     nss        : null,
     nss_t      : null,
 
     observer : {
         _self : null,
 
@@ -374,20 +381,16 @@ WeaveCrypto.prototype = {
         // security/nss/lib/util/secoid.h#103
         // extern void SECOID_DestroyAlgorithmID(SECAlgorithmID *aid, PRBool freeit);
         this.nss.SECOID_DestroyAlgorithmID = nsslib.declare("SECOID_DestroyAlgorithmID",
                                                             ctypes.default_abi, ctypes.void_t,
                                                             this.nss_t.SECAlgorithmID.ptr, this.nss_t.PRBool);
     },
 
 
-    //
-    // IWeaveCrypto interfaces
-    //
-
     _sharedInputBuffer:      null,
     _sharedInputBufferInts:  null,
     _sharedInputBufferSize:  0,
     _sharedOutputBuffer:     null,
     _sharedOutputBufferSize: 0,
     _randomByteBuffer:       null,
     _randomByteBufferAddr:   null,
     _randomByteBufferSize:   0,
--- a/services/crypto/tests/unit/test_crypto_crypt.js
+++ b/services/crypto/tests/unit/test_crypto_crypt.js
@@ -1,17 +1,11 @@
-let cryptoSvc;
-try {
-  Components.utils.import("resource://services-crypto/WeaveCrypto.js");
-  cryptoSvc = new WeaveCrypto();
-} catch (ex) {
-  // Fallback to binary WeaveCrypto
-  cryptoSvc = Cc["@labs.mozilla.com/Weave/Crypto;1"]
-                .getService(Ci.IWeaveCrypto);
-}
+Cu.import("resource://services-crypto/WeaveCrypto.js");
+
+let cryptoSvc = new WeaveCrypto();
 
 function run_test() {
   
   if ("makeSECItem" in cryptoSvc)   // Only for js-ctypes WeaveCrypto.
     test_makeSECItem();
   
   if (this.gczeal) {
     _("Running crypto tests with gczeal(2).");
--- a/services/crypto/tests/unit/test_crypto_random.js
+++ b/services/crypto/tests/unit/test_crypto_random.js
@@ -1,17 +1,11 @@
-let cryptoSvc;
-try {
-  Components.utils.import("resource://services-crypto/WeaveCrypto.js");
-  cryptoSvc = new WeaveCrypto();
-} catch (ex) {
-  // Fallback to binary WeaveCrypto
-  cryptoSvc = Cc["@labs.mozilla.com/Weave/Crypto;1"]
-                .getService(Ci.IWeaveCrypto);
-}
+let WeaveCryptoModule = Cu.import("resource://services-crypto/WeaveCrypto.js");
+
+let cryptoSvc = new WeaveCrypto();
 
 function run_test() {
   if (this.gczeal) {
     _("Running crypto random tests with gczeal(2).");
     gczeal(2);
   }
 
   // Test salt generation.
@@ -46,17 +40,17 @@ function run_test() {
 
   keydata  = cryptoSvc.generateRandomKey();
   do_check_eq(keydata.length, 44);
   keydata2 = cryptoSvc.generateRandomKey();
   do_check_neq(keydata, keydata2); // sanity check for randomness
   iv = cryptoSvc.generateRandomIV();
   do_check_eq(iv.length, 24);
 
-  cryptoSvc.algorithm = Ci.IWeaveCrypto.AES_256_CBC;
+  cryptoSvc.algorithm = WeaveCryptoModule.AES_256_CBC;
   keydata  = cryptoSvc.generateRandomKey();
   do_check_eq(keydata.length, 44);
   keydata2 = cryptoSvc.generateRandomKey();
   do_check_neq(keydata, keydata2); // sanity check for randomness
   iv = cryptoSvc.generateRandomIV();
   do_check_eq(iv.length, 24);
 
   if (this.gczeal)
--- a/services/sync/tests/unit/head_helpers.js
+++ b/services/sync/tests/unit/head_helpers.js
@@ -174,18 +174,18 @@ function FakeGUIDService() {
 
   Utils.makeGUID = function fake_makeGUID() {
     return "fake-guid-" + latestGUID++;
   };
 }
 
 
 /*
- * Mock implementation of IWeaveCrypto.  It does not encrypt or
- * decrypt, just returns the input verbatimly.
+ * Mock implementation of WeaveCrypto. It does not encrypt or
+ * decrypt, merely returning the input verbatim.
  */
 function FakeCryptoService() {
   this.counter = 0;
 
   delete Svc.Crypto;  // get rid of the getter first
   Svc.Crypto = this;
   Utils.sha256HMAC = this.sha256HMAC;
 
--- a/services/sync/tests/unit/test_utils_deriveKey.js
+++ b/services/sync/tests/unit/test_utils_deriveKey.js
@@ -1,19 +1,12 @@
-let cryptoSvc;
-try {
-  Components.utils.import("resource://services-crypto/WeaveCrypto.js");
-  cryptoSvc = new WeaveCrypto();
-} catch (ex) {
-  // Fallback to binary WeaveCrypto
-  cryptoSvc = Cc["@labs.mozilla.com/Weave/Crypto;1"]
-                .getService(Ci.IWeaveCrypto);
-}
+Cu.import("resource://services-crypto/WeaveCrypto.js");
+Cu.import("resource://services-sync/util.js");
 
-Cu.import("resource://services-sync/util.js");
+let cryptoSvc = new WeaveCrypto();
 
 function run_test() {
   if (this.gczeal) {
     _("Running deriveKey tests with gczeal(2).");
     gczeal(2);
   } else {
     _("Running deriveKey tests with default gczeal.");
   }