Test on wasm32-unknown-unknown (#806)

* Test on wasm32-unknown-unknown

* Fix compilation
This commit is contained in:
Pierre Krieger
2019-01-02 15:50:08 +01:00
committed by GitHub
parent ad7a3b94ba
commit 9ca215b1a3
12 changed files with 56 additions and 80 deletions

View File

@ -34,9 +34,9 @@ use log::{debug, trace};
use protobuf::parse_from_bytes as protobuf_parse_from_bytes;
use protobuf::Message as ProtobufMessage;
use rand::{self, RngCore};
#[cfg(all(feature = "ring", not(target_os = "emscripten")))]
#[cfg(all(feature = "ring", not(any(target_os = "emscripten", target_os = "unknown"))))]
use ring::signature::{RSASigningState, RSA_PKCS1_2048_8192_SHA256, RSA_PKCS1_SHA256, verify as ring_verify};
#[cfg(all(feature = "ring", not(target_os = "emscripten")))]
#[cfg(all(feature = "ring", not(any(target_os = "emscripten", target_os = "unknown"))))]
use ring::rand::SystemRandom;
#[cfg(feature = "secp256k1")]
use secp256k1;
@ -46,7 +46,7 @@ use std::io::{Error as IoError, ErrorKind as IoErrorKind};
use crate::structs_proto::{Exchange, Propose};
use tokio_io::codec::length_delimited;
use tokio_io::{AsyncRead, AsyncWrite};
#[cfg(all(feature = "ring", not(target_os = "emscripten")))]
#[cfg(all(feature = "ring", not(any(target_os = "emscripten", target_os = "unknown"))))]
use untrusted::Input as UntrustedInput;
use crate::{KeyAgreement, SecioConfig, SecioKeyPairInner};
@ -368,7 +368,7 @@ where
exchange.set_epubkey(tmp_pub_key);
exchange.set_signature({
match context.config.key.inner {
#[cfg(all(feature = "ring", not(target_os = "emscripten")))]
#[cfg(all(feature = "ring", not(any(target_os = "emscripten", target_os = "unknown"))))]
SecioKeyPairInner::Rsa { ref private, .. } => {
let mut state = match RSASigningState::new(private.clone()) {
Ok(s) => s,
@ -401,7 +401,7 @@ where
let secp256k1 = secp256k1::Secp256k1::signing_only();
secp256k1
.sign(&message, private)
.serialize_der(&secp256k1)
.serialize_der()
},
}
});
@ -452,7 +452,7 @@ where
data_to_verify.extend_from_slice(remote_exch.get_epubkey());
match context.state.remote.public_key {
#[cfg(all(feature = "ring", not(target_os = "emscripten")))]
#[cfg(all(feature = "ring", not(any(target_os = "emscripten", target_os = "unknown"))))]
PublicKey::Rsa(ref remote_public_key) => {
// TODO: The ring library doesn't like some stuff in our DER public key,
// therefore we scrap the first 24 bytes of the key. A proper fix would
@ -492,8 +492,8 @@ where
let message = secp256k1::Message::from_slice(data_to_verify.as_ref())
.expect("digest output length doesn't match secp256k1 input length");
let secp256k1 = secp256k1::Secp256k1::verification_only();
let signature = secp256k1::Signature::from_der(&secp256k1, remote_exch.get_signature());
let remote_public_key = secp256k1::key::PublicKey::from_slice(&secp256k1, remote_public_key);
let signature = secp256k1::Signature::from_der(remote_exch.get_signature());
let remote_public_key = secp256k1::key::PublicKey::from_slice(remote_public_key);
if let (Ok(signature), Ok(remote_public_key)) = (signature, remote_public_key) {
match secp256k1.verify(&message, &signature, &remote_public_key) {
Ok(()) => (),
@ -507,7 +507,7 @@ where
return Err(SecioError::SignatureVerificationFailed)
}
},
#[cfg(not(all(feature = "ring", not(target_os = "emscripten"))))]
#[cfg(not(all(feature = "ring", not(any(target_os = "emscripten", target_os = "unknown")))))]
PublicKey::Rsa(_) => {
debug!("support for RSA was disabled at compile-time");
return Err(SecioError::SignatureVerificationFailed);
@ -640,7 +640,7 @@ mod tests {
use crate::{SecioConfig, SecioKeyPair};
#[test]
#[cfg(all(feature = "ring", not(target_os = "emscripten")))]
#[cfg(all(feature = "ring", not(any(target_os = "emscripten", target_os = "unknown"))))]
fn handshake_with_self_succeeds_rsa() {
let key1 = {
let private = include_bytes!("../tests/test-rsa-private-key.pk8");