Skip to content
This repository has been archived by the owner on Jun 3, 2020. It is now read-only.

Commit

Permalink
Merge pull request #391 from tendermint/zaki-prost-rename
Browse files Browse the repository at this point in the history
Update to tendermint-rs 0.12.0-rc0; prost-amino v0.5
  • Loading branch information
tarcieri authored Jan 20, 2020
2 parents 30a7550 + d16f1fe commit 052ca28
Show file tree
Hide file tree
Showing 9 changed files with 1,050 additions and 1,109 deletions.
2,029 changes: 1,007 additions & 1,022 deletions Cargo.lock

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ circle-ci = { repository = "tendermint/kms" }
abscissa_core = "0.5"
atomicwrites = "0.2"
byteorder = "1.2"
bytes = "0.4"
bytes = "0.5"
chacha20poly1305 = "0.3"
chrono = "0.4"
failure = "0.1"
Expand All @@ -27,25 +27,25 @@ hkdf = "0.7"
hmac = "0.7"
lazy_static = "1"
log = "0.4"
prost-amino = "0.4.0"
prost-amino-derive = "0.4.0"
prost-amino = "0.5"
prost-amino-derive = "0.5"
rand_os = "0.1"
rpassword = { version = "3", optional = true }
serde = { version = "1", features = ["serde_derive"] }
serde_json = "1"
sha2 = "0.8"
signatory = { version = "0.17", features = ["ecdsa", "ed25519", "encoding"] }
signatory-dalek = "0.17"
signatory-secp256k1 = "0.17"
signatory-ledger-tm = { version = "0.17", optional = true }
signatory = { version = "0.18", features = ["ecdsa", "ed25519", "encoding"] }
signatory-dalek = "0.18"
signatory-secp256k1 = "0.18"
signatory-ledger-tm = { version = "0.18", optional = true }
subtle = "2"
subtle-encoding = { version = "0.4", features = ["bech32-preview"] }
tendermint = "0.11"
tendermint = "0.12.0-rc0"
thiserror = "1"
tiny-bip39 = "0.6"
wait-timeout = "0.2"
x25519-dalek = "0.5"
yubihsm = { version = "0.30", features = ["setup", "usb"], optional = true }
yubihsm = { version = "0.31", features = ["setup", "usb"], optional = true }
zeroize = "1"

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion src/connection/secret_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ fn share_auth_signature<IoHandler: Read + Write + Send + Sync>(
sc.read_exact(&mut rbuf)?;

// TODO: proper error handling:
Ok(AuthSigMessage::decode_length_delimited(&rbuf)?)
Ok(AuthSigMessage::decode_length_delimited(rbuf.as_ref())?)
}

#[cfg(tests)]
Expand Down
4 changes: 2 additions & 2 deletions src/connection/secret_connection/amino_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ use prost_amino_derive::Message;
#[derive(Clone, PartialEq, Message)]
pub struct AuthSigMessage {
/// Public key
#[prost(bytes, tag = "1", amino_name = "tendermint/PubKeyEd25519")]
#[prost_amino(bytes, tag = "1", amino_name = "tendermint/PubKeyEd25519")]
pub key: Vec<u8>,

/// Signature
#[prost(bytes, tag = "2")]
#[prost_amino(bytes, tag = "2")]
pub sig: Vec<u8>,
}
7 changes: 6 additions & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,14 @@ pub enum ErrorKind {
#[error("attempted double sign")]
DoubleSign,

///Request a Signature above max height
/// Request a Signature above max height
#[error("requested signature above stop height")]
ExceedMaxHeight,

/// YubiHSM-related errors
#[cfg(feature = "yubihsm")]
#[error("YubiHSM error")]
YubihsmError,
}

impl ErrorKind {
Expand Down
30 changes: 17 additions & 13 deletions src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ use crate::{
prost::Message,
};

use bytes::IntoBuf;
use bytes::Bytes;
use lazy_static::lazy_static;
use sha2::{Digest, Sha256};
use std::io::Cursor;
use std::io::{self, Read};
use std::io::{Error, ErrorKind};
use tendermint::amino_types::*;
Expand Down Expand Up @@ -84,25 +83,30 @@ impl Request {
));
}

let buff: &mut Cursor<Vec<u8>> = &mut buf.into_buf();
let len = decode_varint(buff).unwrap();
let mut buf_amino: Bytes = Bytes::from(buf.clone());
let len = decode_varint(&mut buf_amino).unwrap();
if len > MAX_MSG_LEN as u64 {
return Err(Error::new(ErrorKind::InvalidData, "RPC message too large."));
}
let mut amino_pre = vec![0; 4];
buff.read_exact(&mut amino_pre)?;
buff.set_position(0);
let amino_pre = buf_amino.slice(0..4);

let buf: Bytes = Bytes::from(buf);

let total_len = encoded_len_varint(len).checked_add(len as usize).unwrap();
let rem = buff.get_ref()[..total_len].to_vec();
let rem = buf.as_ref()[..total_len].to_vec();
match amino_pre {
ref vt if *vt == *VOTE_PREFIX => Ok(Request::SignVote(SignVoteRequest::decode(&rem)?)),
ref pr if *pr == *PROPOSAL_PREFIX => {
Ok(Request::SignProposal(SignProposalRequest::decode(&rem)?))
ref vt if *vt == *VOTE_PREFIX => {
Ok(Request::SignVote(SignVoteRequest::decode(rem.as_ref())?))
}
ref pr if *pr == *PROPOSAL_PREFIX => Ok(Request::SignProposal(
SignProposalRequest::decode(rem.as_ref())?,
)),
ref pubk if *pubk == *PUBKEY_PREFIX => {
Ok(Request::ShowPublicKey(PubKeyRequest::decode(&rem)?))
Ok(Request::ShowPublicKey(PubKeyRequest::decode(rem.as_ref())?))
}
ref ping if *ping == *PING_PREFIX => {
Ok(Request::ReplyPing(PingRequest::decode(rem.as_ref())?))
}
ref ping if *ping == *PING_PREFIX => Ok(Request::ReplyPing(PingRequest::decode(&rem)?)),
_ => Err(Error::new(
ErrorKind::InvalidData,
"Received unknown RPC message.",
Expand Down
2 changes: 1 addition & 1 deletion src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ use crate::{
connection::{tcp, unix::UnixConnection, Connection},
error::{Error, ErrorKind::*},
prelude::*,
prost::Message,
rpc::{Request, Response, TendermintRequest},
};
use prost_amino::Message;
use std::{fmt::Debug, os::unix::net::UnixStream, time::Instant};
use tendermint::{
amino_types::{
Expand Down
55 changes: 1 addition & 54 deletions src/yubihsm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,59 +222,6 @@ fn run_connnector_server(config: HttpConfig, connector: Connector) {

impl From<yubihsm::client::Error> for Error {
fn from(other: yubihsm::client::Error) -> Error {
ErrorKind::from(other.kind()).context(other).into()
}
}

impl From<yubihsm::connector::ErrorKind> for ErrorKind {
fn from(other: yubihsm::connector::ErrorKind) -> ErrorKind {
match other {
yubihsm::connector::ErrorKind::AddrInvalid => ErrorKind::ConfigError,
yubihsm::connector::ErrorKind::AccessDenied => ErrorKind::AccessError,
yubihsm::connector::ErrorKind::IoError
| yubihsm::connector::ErrorKind::ConnectionFailed
| yubihsm::connector::ErrorKind::DeviceBusyError
| yubihsm::connector::ErrorKind::RequestError
| yubihsm::connector::ErrorKind::ResponseError
| yubihsm::connector::ErrorKind::UsbError => ErrorKind::IoError,
}
}
}

impl From<yubihsm::client::ErrorKind> for ErrorKind {
fn from(other: yubihsm::client::ErrorKind) -> ErrorKind {
match other {
yubihsm::client::ErrorKind::AuthenticationError => ErrorKind::AccessError,
yubihsm::client::ErrorKind::ConnectorError { kind } => kind.into(),
yubihsm::client::ErrorKind::DeviceError { kind } => kind.into(),
yubihsm::client::ErrorKind::CreateFailed
| yubihsm::client::ErrorKind::ProtocolError
| yubihsm::client::ErrorKind::ClosedSessionError
| yubihsm::client::ErrorKind::ResponseError => ErrorKind::IoError,
}
}
}

impl From<yubihsm::device::ErrorKind> for ErrorKind {
fn from(other: yubihsm::device::ErrorKind) -> ErrorKind {
// TODO(tarcieri): better map these to approriate KMS errors
match other {
yubihsm::device::ErrorKind::AuthenticationFailed => ErrorKind::AccessError,
yubihsm::device::ErrorKind::InvalidCommand
| yubihsm::device::ErrorKind::InvalidData
| yubihsm::device::ErrorKind::InvalidSession
| yubihsm::device::ErrorKind::SessionsFull
| yubihsm::device::ErrorKind::SessionFailed
| yubihsm::device::ErrorKind::StorageFailed
| yubihsm::device::ErrorKind::WrongLength
| yubihsm::device::ErrorKind::InsufficientPermissions
| yubihsm::device::ErrorKind::LogFull
| yubihsm::device::ErrorKind::ObjectNotFound
| yubihsm::device::ErrorKind::InvalidId
| yubihsm::device::ErrorKind::InvalidOtp
| yubihsm::device::ErrorKind::GenericError
| yubihsm::device::ErrorKind::ObjectExists => ErrorKind::SigningError,
_ => ErrorKind::SigningError,
}
ErrorKind::YubihsmError.context(other).into()
}
}
12 changes: 6 additions & 6 deletions tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,8 @@ fn test_handle_and_sign_proposal() {
let mut resp = vec![0u8; actual_len as usize];
resp.copy_from_slice(&mut resp_buf[..(actual_len as usize)]);

let p_req =
proposal::SignedProposalResponse::decode(&resp).expect("decoding proposal failed");
let p_req = proposal::SignedProposalResponse::decode(resp.as_ref())
.expect("decoding proposal failed");
let mut sign_bytes: Vec<u8> = vec![];
spr.sign_bytes(chain_id.into(), &mut sign_bytes).unwrap();

Expand Down Expand Up @@ -408,7 +408,7 @@ fn test_handle_and_sign_vote() {
let mut resp = vec![0u8; actual_len as usize];
resp.copy_from_slice(&resp_buf[..actual_len as usize]);

let v_resp = vote::SignedVoteResponse::decode(&resp).expect("decoding vote failed");
let v_resp = vote::SignedVoteResponse::decode(resp.as_ref()).expect("decoding vote failed");
let mut sign_bytes: Vec<u8> = vec![];
svr.sign_bytes(chain_id.into(), &mut sign_bytes).unwrap();

Expand Down Expand Up @@ -475,7 +475,7 @@ fn test_exceed_max_height() {
let mut resp = vec![0u8; actual_len as usize];
resp.copy_from_slice(&resp_buf[..actual_len as usize]);

let v_resp = vote::SignedVoteResponse::decode(&resp).expect("decoding vote failed");
let v_resp = vote::SignedVoteResponse::decode(resp.as_ref()).expect("decoding vote failed");
let mut sign_bytes: Vec<u8> = vec![];
svr.sign_bytes(chain_id.into(), &mut sign_bytes).unwrap();

Expand Down Expand Up @@ -511,7 +511,7 @@ fn test_handle_and_sign_get_publickey() {
let mut resp = vec![0u8; actual_len as usize];
resp.copy_from_slice(&resp_buf[..actual_len as usize]);

let pk_resp = PubKeyResponse::decode(&resp).expect("decoding public key failed");
let pk_resp = PubKeyResponse::decode(resp.as_ref()).expect("decoding public key failed");
assert_ne!(pk_resp.pub_key_ed25519.len(), 0);
});
}
Expand All @@ -530,6 +530,6 @@ fn test_handle_and_sign_ping_pong() {
let actual_len = extract_actual_len(&resp_buf).unwrap();
let mut resp = vec![0u8; actual_len as usize];
resp.copy_from_slice(&resp_buf[..actual_len as usize]);
PingResponse::decode(&resp).expect("decoding ping response failed");
PingResponse::decode(resp.as_ref()).expect("decoding ping response failed");
});
}

0 comments on commit 052ca28

Please sign in to comment.