Skip to content

Commit a3c0c80

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 e39d131 + f35ed45 commit a3c0c80

File tree

4 files changed

+33
-40
lines changed

4 files changed

+33
-40
lines changed

.appveyor.yml

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ cache:
1414
install:
1515
- appveyor-retry appveyor DownloadFile https://win.rustup.rs/ -FileName rustup-init.exe
1616
- rustup-init.exe -y --default-toolchain %CHANNEL% --default-host %TARGET%
17+
- set OPENSSL_DIR=C:\OpenSSL-v111-Win64
1718
- set PATH=%PATH%;C:\Users\appveyor\.cargo\bin
1819
- rustc -V
1920
- cargo -V

Cargo.lock

+12-30
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
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

+19-9
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::server::Data;
99
use bytes::buf::Buf;
1010
use http::{HeaderMap, Response, StatusCode};
1111
use hyper::Body;
12-
use ring;
12+
use openssl::{hash::MessageDigest, pkey::PKey, sign::Signer};
1313
use serde_json;
1414
use std::str::FromStr;
1515
use std::sync::Arc;
@@ -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)