Skip to content

Commit

Permalink
Merge pull request #1570 from mozilla/use-rustece-dyn
Browse files Browse the repository at this point in the history
Use rust-ece with rc_crypto dynamic backend
  • Loading branch information
eoger committed Aug 14, 2019
2 parents fe9c866 + 31dfb84 commit c729bed
Show file tree
Hide file tree
Showing 12 changed files with 172 additions and 1,422 deletions.
129 changes: 11 additions & 118 deletions Cargo.lock

Large diffs are not rendered by default.

79 changes: 0 additions & 79 deletions DEPENDENCIES.md
Expand Up @@ -13,7 +13,6 @@ the details of which are reproduced below.
* [MIT License: bytes](#mit-license-bytes)
* [MIT License: caseless](#mit-license-caseless)
* [MIT License: clap](#mit-license-clap)
* [MIT License: generic-array](#mit-license-generic-array)
* [MIT License: h2](#mit-license-h2)
* [MIT License: http-body](#mit-license-http-body)
* [MIT License: hyper](#mit-license-hyper)
Expand Down Expand Up @@ -49,7 +48,6 @@ the details of which are reproduced below.
* [BSD-3-Clause License: bindgen](#bsd-3-clause-license-bindgen)
* [BSD-3-Clause License: protobuf](#bsd-3-clause-license-protobuf)
* [BSD-3-Clause License: sqlcipher](#bsd-3-clause-license-sqlcipher)
* [BSD-3-Clause License: subtle](#bsd-3-clause-license-subtle)
* [OpenSSL License](#openssl-license)
* [Optional Notice: SQlite](#optional-notice-sqlite)
* [Optional Notice: zlib](#optional-notice-zlib)
Expand Down Expand Up @@ -448,9 +446,6 @@ The following text applies to code linked from these dependendencies:
[backtrace](https://github.com/rust-lang/backtrace-rs),
[base64](https://github.com/alicemaz/rust-base64),
[bitflags](https://github.com/bitflags/bitflags),
[block-buffer](https://github.com/RustCrypto/utils),
[block-padding](https://github.com/RustCrypto/utils),
[byte-tools](https://github.com/RustCrypto/utils),
[c2-chacha](https://github.com/cryptocorrosion/cryptocorrosion),
[cc](https://github.com/alexcrichton/cc-rs),
[cexpr](https://github.com/jethrogb/rust-cexpr),
Expand All @@ -465,8 +460,6 @@ The following text applies to code linked from these dependendencies:
[crossbeam-epoch](https://github.com/crossbeam-rs/crossbeam),
[crossbeam-queue](https://github.com/crossbeam-rs/crossbeam),
[crossbeam-utils](https://github.com/crossbeam-rs/crossbeam),
[crypto-mac](https://github.com/RustCrypto/traits),
[digest](https://github.com/RustCrypto/traits),
[dogear](https://github.com/mozilla/dogear),
[dtoa](https://github.com/dtolnay/dtoa),
[either](https://github.com/bluss/either),
Expand All @@ -475,7 +468,6 @@ The following text applies to code linked from these dependendencies:
[error-chain](https://github.com/rust-lang-nursery/error-chain),
[failure](https://github.com/rust-lang-nursery/failure),
[failure_derive](https://github.com/withoutboats/failure_derive),
[fake-simd](https://github.com/RustCrypto/utils),
[fallible-iterator](https://github.com/sfackler/rust-fallible-iterator),
[fallible-streaming-iterator](https://github.com/sfackler/fallible-streaming-iterator),
[fixedbitset](https://github.com/bluss/fixedbitset),
Expand All @@ -490,8 +482,6 @@ The following text applies to code linked from these dependendencies:
[glob](https://github.com/rust-lang/glob),
[heck](https://github.com/withoutboats/heck),
[hex](https://github.com/KokaKiwi/rust-hex),
[hkdf](https://github.com/RustCrypto/KDFs/),
[hmac](https://github.com/RustCrypto/MACs),
[http](https://github.com/hyperium/http),
[httparse](https://github.com/seanmonstar/httparse),
[humantime](None),
Expand All @@ -516,7 +506,6 @@ The following text applies to code linked from these dependendencies:
[nodrop](https://github.com/bluss/arrayvec),
[num_cpus](https://github.com/seanmonstar/num_cpus),
[once_cell](https://github.com/matklad/once_cell),
[opaque-debug](https://github.com/RustCrypto/utils),
[openssl-probe](https://github.com/alexcrichton/openssl-probe),
[openssl](https://github.com/sfackler/rust-openssl),
[parking_lot](https://github.com/Amanieu/parking_lot),
Expand Down Expand Up @@ -560,7 +549,6 @@ The following text applies to code linked from these dependendencies:
[serde_derive](https://github.com/serde-rs/serde),
[serde_json](https://github.com/serde-rs/json),
[serde_urlencoded](https://github.com/nox/serde_urlencoded),
[sha2](https://github.com/RustCrypto/hashes),
[shlex](https://github.com/comex/rust-shlex),
[siphasher](https://github.com/jedisct1/rust-siphash),
[smallbitvec](https://github.com/servo/smallbitvec),
Expand All @@ -572,7 +560,6 @@ The following text applies to code linked from these dependendencies:
[thread_local](https://github.com/Amanieu/thread_local-rs),
[time](https://github.com/rust-lang/time),
[toml](https://github.com/alexcrichton/toml-rs),
[typenum](https://github.com/paholg/typenum),
[ucd-util](https://github.com/BurntSushi/ucd-generate),
[unicase](https://github.com/seanmonstar/unicase),
[unicode-bidi](https://github.com/servo/unicode-bidi),
Expand Down Expand Up @@ -1009,35 +996,6 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
```
-------------
## MIT License: generic-array

The following text applies to code linked from these dependendencies:
[generic-array](https://github.com/fizyk20/generic-array.git)

```
The MIT License (MIT)
Copyright (c) 2015 Bartłomiej Kamiński
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
```
-------------
## MIT License: h2
Expand Down Expand Up @@ -2197,43 +2155,6 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
```
-------------
## BSD-3-Clause License: subtle

The following text applies to code linked from these dependendencies:
[subtle](https://github.com/dalek-cryptography/subtle)

```
Copyright (c) 2016-2017 Isis Agora Lovecruft, Henry de Valence. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
```
-------------
## OpenSSL License
Expand Down
1 change: 0 additions & 1 deletion components/fxa-client/Cargo.toml
Expand Up @@ -13,7 +13,6 @@ failure = "0.1.3"
hex = "0.3.2"
lazy_static = "1.0.0"
log = "0.4"
openssl = { version = "0.10.24", optional = true }
prost = "0.5"
prost-derive = "0.5"
serde = { version = "1.0.98", features = ["rc"] }
Expand Down
18 changes: 9 additions & 9 deletions components/fxa-client/src/commands/send_tab.rs
Expand Up @@ -15,10 +15,8 @@
/// then sent to the target device.
use crate::{device::Device, error::*, scoped_keys::ScopedKey, scopes};
use hex;
use rc_crypto::ece::{
self, Aes128GcmEceWebPushImpl, EcKeyComponents, LocalKeyPair, LocalKeyPairImpl,
RemotePublicKey, RemotePublicKeyImpl, WebPushParams,
};
use rc_crypto::ece::{self, Aes128GcmEceWebPush, EcKeyComponents, WebPushParams};
use rc_crypto::ece_crypto::{RcCryptoLocalKeyPair, RcCryptoRemotePublicKey};
use serde_derive::*;
use sync15::{EncryptedPayload, KeyBundle};

Expand All @@ -32,10 +30,10 @@ pub struct EncryptedSendTabPayload {

impl EncryptedSendTabPayload {
pub(crate) fn decrypt(self, keys: &PrivateSendTabKeysV1) -> Result<SendTabPayload> {
rc_crypto::ensure_initialized();
let encrypted = base64::decode_config(&self.encrypted, base64::URL_SAFE_NO_PAD)?;
let private_key = LocalKeyPairImpl::from_raw_components(&keys.p256key)?;
let decrypted =
Aes128GcmEceWebPushImpl::decrypt(&private_key, &keys.auth_secret, &encrypted)?;
let private_key = RcCryptoLocalKeyPair::from_raw_components(&keys.p256key)?;
let decrypted = Aes128GcmEceWebPush::decrypt(&private_key, &keys.auth_secret, &encrypted)?;
Ok(serde_json::from_slice(&decrypted)?)
}
}
Expand All @@ -55,11 +53,12 @@ impl SendTabPayload {
}
}
fn encrypt(&self, keys: PublicSendTabKeys) -> Result<EncryptedSendTabPayload> {
rc_crypto::ensure_initialized();
let bytes = serde_json::to_vec(&self)?;
let public_key = base64::decode_config(&keys.public_key, base64::URL_SAFE_NO_PAD)?;
let public_key = RemotePublicKeyImpl::from_raw(&public_key)?;
let public_key = RcCryptoRemotePublicKey::from_raw(&public_key)?;
let auth_secret = base64::decode_config(&keys.auth_secret, base64::URL_SAFE_NO_PAD)?;
let encrypted = Aes128GcmEceWebPushImpl::encrypt(
let encrypted = Aes128GcmEceWebPush::encrypt(
&public_key,
&auth_secret,
&bytes,
Expand Down Expand Up @@ -109,6 +108,7 @@ impl PrivateSendTabKeys {

impl PrivateSendTabKeys {
pub fn from_random() -> Result<Self> {
rc_crypto::ensure_initialized();
let (key_pair, auth_secret) = ece::generate_keypair_and_auth_secret()?;
Ok(Self {
p256key: key_pair.raw_components()?,
Expand Down
15 changes: 8 additions & 7 deletions components/push/src/crypto.rs
Expand Up @@ -4,9 +4,9 @@

use crate::error;
use rc_crypto::ece::{
Aes128GcmEceWebPushImpl, AesGcmEceWebPushImpl, AesGcmEncryptedBlock, EcKeyComponents,
LocalKeyPair, LocalKeyPairImpl,
Aes128GcmEceWebPush, AesGcmEceWebPush, AesGcmEncryptedBlock, EcKeyComponents, LocalKeyPair,
};
use rc_crypto::ece_crypto::RcCryptoLocalKeyPair;
use rc_crypto::rand;
use serde_derive::*;

Expand Down Expand Up @@ -50,8 +50,8 @@ impl Key {
}
}

pub fn key_pair(&self) -> error::Result<LocalKeyPairImpl> {
LocalKeyPairImpl::from_raw_components(&self.p256key).map_err(|e| {
pub fn key_pair(&self) -> error::Result<RcCryptoLocalKeyPair> {
RcCryptoLocalKeyPair::from_raw_components(&self.p256key).map_err(|e| {
error::ErrorKind::CryptoError(format!(
"Could not re-create key from components: {:?}",
e
Expand Down Expand Up @@ -139,7 +139,7 @@ fn extract_value(string: Option<&str>, target: &str) -> Option<Vec<u8>> {
impl Cryptography for Crypto {
/// Generate a new cryptographic Key
fn generate_key() -> error::Result<Key> {
let key = LocalKeyPairImpl::generate_random().map_err(|e| {
let key = RcCryptoLocalKeyPair::generate_random().map_err(|e| {
error::ErrorKind::CryptoError(format!("Could not generate key: {:?}", e))
})?;
let components = key.raw_components().map_err(|e| {
Expand Down Expand Up @@ -173,6 +173,7 @@ impl Cryptography for Crypto {
salt: Option<&str>,
dh: Option<&str>,
) -> error::Result<Decrypted> {
rc_crypto::ensure_initialized();
// convert the private key into something useful.
let d_salt = extract_value(salt, "salt");
let d_dh = extract_value(dh, "dh");
Expand Down Expand Up @@ -216,12 +217,12 @@ impl Cryptography for Crypto {
.into());
}
};
AesGcmEceWebPushImpl::decrypt(&key.key_pair()?, &key.auth, &block)
AesGcmEceWebPush::decrypt(&key.key_pair()?, &key.auth, &block)
.map_err(|_| error::ErrorKind::CryptoError("Decryption error".to_owned()).into())
}

fn decrypt_aes128gcm(key: &Key, content: &[u8]) -> error::Result<Vec<u8>> {
Aes128GcmEceWebPushImpl::decrypt(&key.key_pair()?, &key.auth, &content)
Aes128GcmEceWebPush::decrypt(&key.key_pair()?, &key.auth, &content)
.map_err(|_| error::ErrorKind::CryptoError("Decryption error".to_owned()).into())
}
}
Expand Down
3 changes: 1 addition & 2 deletions components/support/rc_crypto/Cargo.toml
Expand Up @@ -16,8 +16,7 @@ error-support = { path = "../error" }
nss = { path = "nss" }
libsqlite3-sys = { version = "0.15.0", features = ["bundled"] }
hawk = { version = "3.0.0", default-features = false, optional = true }
ece = { version = "1.0.1", optional = true }
ece = { version = "1.1.0", default-features = false, features = ["serializable-keys"], optional = true }

[dev-dependencies]
hex = "0.3.2"
openssl-sys = "0.9.48"

0 comments on commit c729bed

Please sign in to comment.