Bug 651596: eliminate IWeaveCrypto. r=philiKON

This commit is contained in:
Richard Newman 2011-04-20 14:27:19 -07:00
parent 72c45263fa
commit 1f647fc550
7 changed files with 22 additions and 267 deletions

View File

@ -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);
};

View File

@ -44,11 +44,6 @@ 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

View File

@ -45,7 +45,16 @@ 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;
@ -55,8 +64,6 @@ function WeaveCrypto() {
}
WeaveCrypto.prototype = {
QueryInterface: XPCOMUtils.generateQI([Ci.IWeaveCrypto]),
prefBranch : null,
debug : true, // services.sync.log.cryptoDebug
nss : null,
@ -379,10 +386,6 @@ WeaveCrypto.prototype = {
},
//
// IWeaveCrypto interfaces
//
_sharedInputBuffer: null,
_sharedInputBufferInts: null,
_sharedInputBufferSize: 0,

View File

@ -1,12 +1,6 @@
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() {

View File

@ -1,12 +1,6 @@
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) {
@ -51,7 +45,7 @@ function run_test() {
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();

View File

@ -179,8 +179,8 @@ function FakeGUIDService() {
/*
* 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;

View File

@ -1,15 +1,8 @@
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");
let cryptoSvc = new WeaveCrypto();
function run_test() {
if (this.gczeal) {
_("Running deriveKey tests with gczeal(2).");