Skip to content

Commit d2e8a48

Browse files
committed
Auto merge of #394 - pietroalbini:remove-ring, r=pietroalbini
Switch from ring to openssl The ring update policy is awful (see briansmith/ring#774), so this switches to a crate that doesn't break existing builds every time a new version is released.
2 parents 2c96710 + 7b58b55 commit d2e8a48

File tree

3 files changed

+32
-40
lines changed

3 files changed

+32
-40
lines changed

Cargo.lock

Lines changed: 12 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ rand = "0.5"
3939
ref_slice = "1.1.1"
4040
regex = "1.0"
4141
reqwest = "0.9"
42-
ring = "0.13"
4342
rusoto_core = "0.35.0"
4443
rusoto_credential = "0.14.0"
4544
rusoto_s3 = "0.35.0"
@@ -63,6 +62,7 @@ warp = "0.1.9"
6362
winapi = "0.3"
6463
log = "0.4.6"
6564
env_logger = "0.6.0"
65+
openssl = "0.10.16"
6666

6767
[dev-dependencies]
6868
assert_cmd = "0.10.1"

src/server/routes/webhooks/mod.rs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ use crate::server::Data;
99
use bytes::buf::Buf;
1010
use http::{HeaderMap, Response, StatusCode};
1111
use hyper::Body;
12-
use ring;
1312
use serde_json;
1413
use std::str::FromStr;
1514
use std::sync::Arc;
15+
use openssl::{hash::MessageDigest, pkey::PKey, sign::Signer};
1616
use warp::{self, filters::body::FullBody, Filter, Rejection};
1717

1818
fn process_webhook(
@@ -131,6 +131,15 @@ fn process_command(
131131
}
132132

133133
fn verify_signature(secret: &str, payload: &[u8], raw_signature: &str) -> bool {
134+
macro_rules! try_false {
135+
($expr:expr) => {
136+
match $expr {
137+
Ok(res) => res,
138+
Err(_) => return false,
139+
}
140+
}
141+
};
142+
134143
// The signature must have a =
135144
if !raw_signature.contains('=') {
136145
return false;
@@ -156,16 +165,17 @@ fn verify_signature(secret: &str, payload: &[u8], raw_signature: &str) -> bool {
156165

157166
// Get the correct digest
158167
let digest = match *algorithm {
159-
"sha1" => &ring::digest::SHA1,
160-
_ => {
161-
// Unknown digest, return false
162-
return false;
163-
}
168+
"sha1" => MessageDigest::sha1(),
169+
// Unknown digest, return false
170+
_ => return false,
164171
};
165172

166-
// Verify the HMAC signature
167-
let key = ring::hmac::VerificationKey::new(digest, secret.as_bytes());
168-
ring::hmac::verify(&key, payload, &signature).is_ok()
173+
// Verify the HMAC using OpenSSL
174+
let key = try_false!(PKey::hmac(secret.as_bytes()));
175+
let mut signer = try_false!(Signer::new(digest, &key));
176+
try_false!(signer.update(payload));
177+
let hmac = try_false!(signer.sign_to_vec());
178+
openssl::memcmp::eq(&hmac, &signature)
169179
}
170180

171181
fn receive_endpoint(data: Arc<Data>, headers: HeaderMap, body: FullBody) -> Fallible<()> {

0 commit comments

Comments
 (0)