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 #170 from tendermint/signatory-update
Browse files Browse the repository at this point in the history
Update all `signatory` dependencies to v0.11 (and 2018 edition fixups)
  • Loading branch information
tarcieri committed Feb 13, 2019
2 parents 84812b2 + 4c8dd19 commit 752184b
Show file tree
Hide file tree
Showing 27 changed files with 416 additions and 458 deletions.
521 changes: 275 additions & 246 deletions Cargo.lock

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ homepage = "https://github.com/tendermint/kms/"
readme = "README.md"
categories = ["cryptography"]
keywords = ["cosmos", "ed25519", "kms", "key-management", "yubihsm"]
edition = "2018"

[workspace]
members = [".", "tendermint-rs"]
Expand All @@ -26,20 +27,20 @@ failure_derive = "0.1"
lazy_static = "1"
prost-amino = "0.4.0"
prost-amino-derive = "0.4.0"
rand = "0.6"
serde = "1"
serde_derive = "1"
serde_json = "1"
sha2 = "0.8"
signal-hook = "0.1.7"
signatory = { version = "0.10", features = ["ed25519"] }
signatory-dalek = "0.10"
signatory-yubihsm = { version = "0.10", optional = true }
signatory = { version = "0.11", features = ["ed25519"] }
signatory-dalek = "0.11"
signatory-yubihsm = { version = "0.11", optional = true }
subtle-encoding = "0.3"
tendermint = { version = "0.2,0", path = "tendermint-rs" }
tendermint = { version = "0.2", path = "tendermint-rs" }

[dev-dependencies]
tempfile = "3"
rand = "0.6"

[features]
default = ["softsign", "yubihsm"]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ prerequisites for support.

You will need the following prerequisites:

- **Rust** (stable; 1.27+): https://rustup.rs/
- **Rust** (stable; 1.31+): https://rustup.rs/
- **C compiler**: e.g. gcc, clang
- **pkg-config**
- **libusb** (1.0+). Install instructions for common platforms:
Expand Down
2 changes: 1 addition & 1 deletion src/commands/yubihsm/detect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub struct DetectCommand {
impl Callable for DetectCommand {
/// Detect all YubiHSM2 devices connected via USB
fn call(&self) {
let devices = Devices::new(Default::default()).unwrap_or_else(|e| {
let devices = Devices::detect(Default::default()).unwrap_or_else(|e| {
status_err!("couldn't detect USB devices: {}", e);

// TODO: handle exits via abscissa
Expand Down
2 changes: 1 addition & 1 deletion src/commands/yubihsm/keys/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl Callable for GenerateCommand {
}

let public_key =
ed25519::PublicKey::from_bytes(hsm.get_pubkey(*key_id).unwrap_or_else(|e| {
ed25519::PublicKey::from_bytes(hsm.get_public_key(*key_id).unwrap_or_else(|e| {
status_err!("couldn't get public key for key #{}: {}", key_id, e);
process::exit(1);
}))
Expand Down
17 changes: 9 additions & 8 deletions src/commands/yubihsm/keys/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,15 @@ impl Callable for ImportCommand {
}

let public_key = ed25519::PublicKey::from_bytes(
hsm.get_pubkey(self.key_id.unwrap()).unwrap_or_else(|e| {
status_err!(
"couldn't get public key for key #{}: {}",
self.key_id.unwrap(),
e
);
process::exit(1);
}),
hsm.get_public_key(self.key_id.unwrap())
.unwrap_or_else(|e| {
status_err!(
"couldn't get public key for key #{}: {}",
self.key_id.unwrap(),
e
);
process::exit(1);
}),
)
.unwrap();

Expand Down
2 changes: 1 addition & 1 deletion src/commands/yubihsm/keys/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl Callable for ListCommand {
println!("Listing keys in YubiHSM #{}:", serial_number);

for key in &keys {
let public_key = hsm.get_pubkey(key.object_id).unwrap_or_else(|e| {
let public_key = hsm.get_public_key(key.object_id).unwrap_or_else(|e| {
status_err!(
"couldn't get public key for asymmetric key #{}: {}",
key.object_id,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/yubihsm/keys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub const DEFAULT_KEY_TYPE: &str = "ed25519";
pub const DEFAULT_DOMAINS: yubihsm::Domain = yubihsm::Domain::DOM1;

/// Default YubiHSM2 permissions for generated keys
pub const DEFAULT_CAPABILITIES: yubihsm::Capability = yubihsm::Capability::ASYMMETRIC_SIGN_EDDSA;
pub const DEFAULT_CAPABILITIES: yubihsm::Capability = yubihsm::Capability::SIGN_EDDSA;

/// The `yubihsm keys` subcommand
#[derive(Debug, Options)]
Expand Down
2 changes: 1 addition & 1 deletion src/keyring/ed25519/yubihsm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub fn init(keyring: &mut KeyRing, yubihsm_configs: &[YubihsmConfig]) -> Result<
}

let yubihsm_config = &yubihsm_configs[0];
let connector = signatory_yubihsm::yubihsm::UsbConnector::new(&yubihsm_config.usb_config())?;
let connector = signatory_yubihsm::yubihsm::UsbConnector::create(&yubihsm_config.usb_config())?;
let session = signatory_yubihsm::Session::create(connector, yubihsm_config.auth.credentials())?;

for key_config in &yubihsm_config.keys {
Expand Down
17 changes: 7 additions & 10 deletions src/yubihsm.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
use crate::{
abscissa::GlobalConfig,
config::{provider::yubihsm::YubihsmConfig, KmsConfig},
std::{
process,
sync::{Mutex, MutexGuard},
},
};

use crate::config::{provider::yubihsm::YubihsmConfig, KmsConfig};
use abscissa::GlobalConfig;
pub use signatory_yubihsm::yubihsm::*;
use std::{
process,
sync::{Mutex, MutexGuard},
};

lazy_static! {
static ref HSM_CLIENT: Mutex<Client> = Mutex::new(create_hsm_client());
Expand Down Expand Up @@ -49,7 +46,7 @@ pub fn get_config() -> YubihsmConfig {
#[cfg(not(feature = "yubihsm-mock"))]
pub fn create_hsm_connector() -> Box<dyn Connector> {
// TODO: `HttpConnector` support
let connector = UsbConnector::new(&get_config().usb_config()).unwrap_or_else(|e| {
let connector = UsbConnector::create(&get_config().usb_config()).unwrap_or_else(|e| {
status_err!("error opening USB connection to YubiHSM2: {}", e);
process::exit(1);
});
Expand Down
11 changes: 6 additions & 5 deletions tendermint-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ repository = "https://github.com/tendermint/kms/tree/master/crates/tendermint"
readme = "README.md"
categories = ["cryptography", "database"]
keywords = ["blockchain", "bft", "consensus", "cosmos", "tendermint"]
edition = "2018"

description = """
Tendermint is a high-performance blockchain consensus engine that powers
Expand Down Expand Up @@ -35,12 +36,12 @@ failure_derive = "0.1"
hkdf = { version = "0.7", optional = true }
prost-amino = { version = "0.4.0", optional = true }
prost-amino-derive = { version = "0.4.0", optional = true }
rand = { version = "0.6", optional = true }
ring = { version = "0.13", optional = true }
rand_os = { version = "0.1", optional = true }
ring = { version = "0.14", optional = true }
serde = { version = "1", optional = true }
serde_derive = { version = "1", optional = true }
signatory = { version = "0.10", optional = true, features = ["ed25519"] }
signatory-dalek = { version = "0.10", optional = true }
signatory = { version = "0.11", optional = true, features = ["ed25519"] }
signatory-dalek = { version = "0.11", optional = true }
sha2 = { version = "0.8", optional = true, default-features = false }
subtle-encoding = { version = "0.3", features = ["bech32-preview"] }
tai64 = { version = "1", optional = true, features = ["chrono"] }
Expand All @@ -54,7 +55,7 @@ secret-connection = [
"hkdf",
"prost-amino",
"prost-amino-derive",
"rand",
"rand_os",
"ring",
"signatory",
"signatory-dalek",
Expand Down
3 changes: 2 additions & 1 deletion tendermint-rs/src/amino_types/ed25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ impl Into<PubKeyResponse> for PublicKey {
#[cfg(test)]
mod tests {
use super::*;
use crate::{prost::Message, std::error::Error};
use prost::Message;
use std::error::Error;

#[test]
fn test_empty_pubkey_msg() {
Expand Down
23 changes: 8 additions & 15 deletions tendermint-rs/src/amino_types/proposal.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
use crate::{
block,
bytes::BufMut,
chain,
error::Error,
prost::{EncodeError, Message},
signatory::{ed25519, Signature},
};

use super::{
block_id::{BlockId, CanonicalBlockId, CanonicalPartSetHeader},
remote_error::RemoteError,
signature::{SignableMsg, SignedMsgType},
time::TimeMsg,
validate::{ConsensusMessage, ValidationError, ValidationErrorKind::*},
};
use crate::{block, chain, error::Error};
use bytes::BufMut;
use prost::{EncodeError, Message};
use signatory::{ed25519, Signature};

#[derive(Clone, PartialEq, Message)]
pub struct Proposal {
Expand Down Expand Up @@ -161,12 +156,10 @@ impl ConsensusMessage for Proposal {
#[cfg(test)]
mod tests {
use super::*;
use crate::{
amino_types::block_id::PartsSetHeader,
chrono::{DateTime, Utc},
prost::Message,
std::error::Error,
};
use crate::amino_types::block_id::PartsSetHeader;
use chrono::{DateTime, Utc};
use prost::Message;
use std::error::Error;

#[test]
fn test_serialization() {
Expand Down
12 changes: 5 additions & 7 deletions tendermint-rs/src/amino_types/signature.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use crate::{
amino_types::validate::ValidationError,
bytes::BufMut,
chain,
prost::{DecodeError, EncodeError},
signatory::ed25519,
};
use super::validate::ValidationError;
use crate::chain;
use bytes::BufMut;
use prost::{DecodeError, EncodeError};
use signatory::ed25519;

/// Amino messages which are signable within a Tendermint network
pub trait SignableMsg {
Expand Down
4 changes: 2 additions & 2 deletions tendermint-rs/src/amino_types/time.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//! Timestamps

use crate::{
chrono::{TimeZone, Utc},
error::Error,
std::time::{Duration, SystemTime, UNIX_EPOCH},
timestamp::{ParseTimestamp, Timestamp},
};
use chrono::{TimeZone, Utc};
use std::time::{Duration, SystemTime, UNIX_EPOCH};

#[derive(Clone, PartialEq, Message)]
pub struct TimeMsg {
Expand Down
21 changes: 7 additions & 14 deletions tendermint-rs/src/amino_types/vote.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
use crate::{
block,
bytes::BufMut,
chain,
error::Error,
prost::{error::EncodeError, Message},
signatory::{ed25519, Signature},
};

use super::{
block_id::{BlockId, CanonicalBlockId, CanonicalPartSetHeader},
remote_error::RemoteError,
Expand All @@ -15,6 +6,10 @@ use super::{
validate::{ConsensusMessage, ValidationError, ValidationErrorKind::*},
SignedMsgType,
};
use crate::{block, chain, error::Error};
use bytes::BufMut;
use prost::{error::EncodeError, Message};
use signatory::{ed25519, Signature};

const VALIDATOR_ADDR_SIZE: usize = 20;

Expand Down Expand Up @@ -187,11 +182,9 @@ impl ConsensusMessage for Vote {
mod tests {
use super::super::PartsSetHeader;
use super::*;
use crate::{
amino_types::SignedMsgType,
chrono::{DateTime, Utc},
prost::Message,
};
use crate::amino_types::SignedMsgType;
use chrono::{DateTime, Utc};
use prost::Message;

#[test]
fn test_vote_serialization() {
Expand Down
6 changes: 2 additions & 4 deletions tendermint-rs/src/block/height.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use crate::{
error::Error,
std::fmt::{self, Debug, Display},
};
use crate::error::Error;
use std::fmt::{self, Debug, Display};

/// Block height for a particular chain (i.e. number of blocks created since
/// the chain began)
Expand Down
3 changes: 1 addition & 2 deletions tendermint-rs/src/chain/id.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Tendermint blockchain identifiers

use crate::error::Error;
#[cfg(feature = "serializers")]
use serde::{de::Error as DeError, Deserialize, Deserializer, Serialize, Serializer};
use std::{
Expand All @@ -9,8 +10,6 @@ use std::{
str::{self, FromStr},
};

use crate::error::Error;

/// Maximum length of a `chain::Id` name. Matches `MaxChainIDLen` from:
/// <https://github.com/tendermint/tendermint/blob/develop/types/genesis.go>
// TODO: update this when `chain::Id` is derived from a digest output
Expand Down
2 changes: 1 addition & 1 deletion tendermint-rs/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Error types

#[cfg(feature = "secret-connection")]
use crate::{
use {
chrono, prost, signatory,
std::{self, io},
subtle_encoding,
Expand Down
9 changes: 3 additions & 6 deletions tendermint-rs/src/hash.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
//! Hash functions and their outputs

use crate::{
algorithm::HashAlgorithm,
error::Error,
std::fmt::{self, Display},
subtle_encoding::{Encoding, Hex},
};
use crate::{algorithm::HashAlgorithm, error::Error};
use std::fmt::{self, Display};
use subtle_encoding::{Encoding, Hex};

/// Output size for the SHA-256 hash function
pub const SHA256_HASH_SIZE: usize = 32;
Expand Down
21 changes: 0 additions & 21 deletions tendermint-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
//! This crate provides types for representing information about Tendermint
//! blockchain networks, including chain IDs, block IDs, and block heights.

#![crate_name = "tendermint"]
#![crate_type = "rlib"]
#![deny(
warnings,
missing_docs,
Expand All @@ -21,12 +19,6 @@
html_root_url = "https://docs.rs/tendermint/0.2.0"
)]

#[cfg(feature = "secret-connection")]
extern crate byteorder;
extern crate bytes;
extern crate chrono;
pub extern crate digest;
extern crate failure;
#[macro_use]
extern crate failure_derive;
#[cfg(feature = "secret-connection")]
Expand All @@ -35,21 +27,8 @@ extern crate prost_amino as prost;
#[macro_use]
extern crate prost_amino_derive as prost_derive;
#[cfg(feature = "serializers")]
extern crate serde;
#[cfg(feature = "serializers")]
#[macro_use]
extern crate serde_derive;
#[cfg(feature = "secret-connection")]
pub extern crate sha2;
#[cfg(feature = "secret-connection")]
pub extern crate signatory;
#[cfg(feature = "secret-connection")]
extern crate signatory_dalek;
extern crate subtle_encoding;
#[cfg(feature = "tai64")]
extern crate tai64;
#[cfg(feature = "secret-connection")]
extern crate zeroize;

pub mod algorithm;
pub mod amino_types;
Expand Down
Loading

0 comments on commit 752184b

Please sign in to comment.