Skip to content

Commit

Permalink
more fixes after @xla review
Browse files Browse the repository at this point in the history
  • Loading branch information
melekes committed Nov 24, 2020
1 parent 5ae53f6 commit 9e253df
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 22 deletions.
1 change: 0 additions & 1 deletion p2p/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! Error types

pub use eyre::{Report, Result};
use thiserror::Error;

/// Kinds of errors
Expand Down
1 change: 0 additions & 1 deletion p2p/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#![forbid(unsafe_code)]
#![deny(
warnings,

This comment has been minimized.

Copy link
@xla

xla Nov 24, 2020

This one as well, we should make sure they are enforced on CI.

missing_docs,
trivial_casts,
trivial_numeric_casts,
unused_import_braces,
Expand Down
36 changes: 20 additions & 16 deletions p2p/src/secret_connection.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//! `SecretConnection`: Transport layer encryption for Tendermint P2P connections.

mod amino_types;
mod kdf;
mod nonce;
mod protocol;
mod public_key;
use std::{
cmp,
convert::{TryFrom, TryInto},
io::{self, Read, Write},
marker::{Send, Sync},
slice,
};

pub use self::{kdf::Kdf, nonce::Nonce, protocol::Version, public_key::PublicKey};
use crate::error::Error;
use chacha20poly1305::{
aead::{generic_array::GenericArray, AeadInPlace, NewAead},
ChaCha20Poly1305,
Expand All @@ -16,17 +16,20 @@ use ed25519_dalek::{self as ed25519, Signer, Verifier};
use eyre::{Result, WrapErr};
use merlin::Transcript;
use rand_core::OsRng;
use std::{
cmp,
convert::{TryFrom, TryInto},
io::{self, Read, Write},
marker::{Send, Sync},
slice,
};
use subtle::ConstantTimeEq;
use tendermint_proto as proto;
use x25519_dalek::{EphemeralSecret, PublicKey as EphemeralPublic};

use tendermint_proto as proto;

pub use self::{kdf::Kdf, nonce::Nonce, protocol::Version, public_key::PublicKey};
use crate::error::Error;

mod amino_types;
mod kdf;
mod nonce;
mod protocol;
mod public_key;

/// Size of the MAC tag
pub const TAG_SIZE: usize = 16;

Expand Down Expand Up @@ -83,7 +86,8 @@ impl<IoHandler: Read + Write + Send + Sync> SecretConnection<IoHandler> {
// - https://github.com/tendermint/kms/issues/142
// - https://eprint.iacr.org/2019/526.pdf
if shared_secret.as_bytes().ct_eq(&[0x00; 32]).unwrap_u8() == 1 {
return Err(Error::InvalidKey).wrap_err("low-order points found (potential MitM attack!)");
return Err(Error::InvalidKey)
.wrap_err("low-order points found (potential MitM attack!)");
}

// Sort by lexical order.
Expand Down
11 changes: 7 additions & 4 deletions p2p/src/secret_connection/protocol.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
//! Secret Connection Protocol: message framing and versioning

use super::amino_types;
use crate::error::Error;
use std::convert::TryInto;

use ed25519_dalek as ed25519;
use eyre::{Report, Result, WrapErr};
use prost::Message as _;
use prost_amino::Message as _;
use std::convert::TryInto;
use tendermint_proto as proto;
use x25519_dalek::PublicKey as EphemeralPublic;

use tendermint_proto as proto;

use super::amino_types;
use crate::error::Error;

/// Size of an X25519 or Ed25519 public key
const PUBLIC_KEY_SIZE: usize = 32;

Expand Down

0 comments on commit 9e253df

Please sign in to comment.