Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ring requirement from 0.14.6 to 0.16.0 #37

Merged
merged 3 commits into from
Jul 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .taskcluster.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ tasks:
- pull_request.synchronize
payload:
maxRunTime: 3600
image: djmitche/rust-hawk-test:1.35.0@sha256:b4d60deff348ed8091fd1e431ac7d497aa6881b7fcbee56bf6272cb540f4b35a
image: djmitche/rust-hawk-test:1.36.0@sha256:b4040d92f34183cf218d222f90e91206ff4fc6ed94d68222fb2b2042a53373a0
command:
- /bin/bash
- '-c'
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use_openssl = ["openssl"]

[dependencies]
base64 = "0.10.1"
ring = { version = "0.14.6", optional = true }
ring = { version = "0.16.0", optional = true }
openssl = { version = "0.10.20", optional = true }
url = "1.7.2"
rand = "0.7.0"
Expand Down
2 changes: 1 addition & 1 deletion docker/rust-hawk-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

set -e

docker build -t djmitche/rust-hawk-test:1.34.0 rust-hawk-test
docker build -t djmitche/rust-hawk-test:1.36.0 rust-hawk-test
2 changes: 1 addition & 1 deletion docker/rust-hawk-test/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ chmod +x rustup-init
./rustup-init -y --no-modify-path

# install stable
/root/.cargo/bin/rustup install 1.34.0
/root/.cargo/bin/rustup install 1.36.0
/root/.cargo/bin/rustup component add clippy
/root/.cargo/bin/rustup component add rustfmt

Expand Down
27 changes: 23 additions & 4 deletions src/crypto/ring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,20 @@ impl From<ring::error::Unspecified> for CryptoError {
}
}

impl From<std::convert::Infallible> for CryptoError {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For completeness, why did we add this?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The most accurate answer is "the compiler told me to". I tried looking through the ring commits to see what breaking changes had occurred, and 50 commits in I had no idea.

But more precisely, one of those try_from()?'s returns Result<, Infallible>, and this impl made the types check out in that case. If there's a better approach I'm all 👀 :)

fn from(_: std::convert::Infallible) -> Self {
unreachable!()
}
}

pub struct RingCryptographer;

struct RingHmacKey(hmac::SigningKey);
struct RingHmacKey(hmac::Key);

impl HmacKey for RingHmacKey {
fn sign(&self, data: &[u8]) -> Result<Vec<u8>, CryptoError> {
let digest = hmac::sign(&self.0, data);
let mut mac = vec![0; self.0.digest_algorithm().output_len];
let mut mac = vec![0; self.0.algorithm().digest_algorithm().output_len];
mac.copy_from_slice(digest.as_ref());
Ok(mac)
}
Expand All @@ -45,7 +51,8 @@ impl Hasher for RingHasher {
impl Cryptographer for RingCryptographer {
fn rand_bytes(&self, output: &mut [u8]) -> Result<(), CryptoError> {
use ring::rand::SecureRandom;
ring::rand::SystemRandom.fill(output)?;
let rnd = ring::rand::SystemRandom::new();
rnd.fill(output)?;
Ok(())
}

Expand All @@ -54,7 +61,7 @@ impl Cryptographer for RingCryptographer {
algorithm: DigestAlgorithm,
key: &[u8],
) -> Result<Box<dyn HmacKey>, CryptoError> {
let k = hmac::SigningKey::new(algorithm.try_into()?, key);
let k = hmac::Key::new(algorithm.try_into()?, key);
Ok(Box::new(RingHmacKey(k)))
}

Expand All @@ -79,3 +86,15 @@ impl TryFrom<DigestAlgorithm> for &'static digest::Algorithm {
}
}
}

impl TryFrom<DigestAlgorithm> for hmac::Algorithm {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need the TryFrom impl bellow?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, both are used.

type Error = CryptoError;
fn try_from(algorithm: DigestAlgorithm) -> Result<Self, CryptoError> {
match algorithm {
DigestAlgorithm::Sha256 => Ok(hmac::HMAC_SHA256),
DigestAlgorithm::Sha384 => Ok(hmac::HMAC_SHA384),
DigestAlgorithm::Sha512 => Ok(hmac::HMAC_SHA512),
algo => Err(CryptoError::UnsupportedDigest(algo)),
}
}
}