Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
246 changes: 206 additions & 40 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ edition = "2018"
app_dirs = "^1.2.1"
clap = { version = "2", features = ["yaml"] }
codechain-core = { path = "core" }
codechain-crypto = { git = "https://github.com/CodeChain-io/rust-codechain-crypto.git", version = "0.1" }
codechain-crypto = { git = "https://github.com/CodeChain-io/rust-codechain-crypto.git", version = "0.2" }
codechain-discovery = { path = "discovery" }
codechain-logger = { path = "util/logger" }
codechain-key = { path = "key" }
Expand Down
6 changes: 3 additions & 3 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ authors = ["CodeChain Team <hi@codechain.io>"]
edition = "2018"

[dependencies]
codechain-crypto = { git = "https://github.com/CodeChain-io/rust-codechain-crypto.git", version = "0.1" }
codechain-db = { git = "https://github.com/CodeChain-io/rust-codechain-db.git", version = "0.1" }
codechain-crypto = { git = "https://github.com/CodeChain-io/rust-codechain-crypto.git", version = "0.2" }
codechain-db = { git = "https://github.com/CodeChain-io/rust-codechain-db.git", version = "0.2" }
codechain-io = { path = "../util/io" }
codechain-json = { path = "../json" }
codechain-key = { path = "../key" }
Expand All @@ -25,7 +25,7 @@ kvdb-memorydb = "0.1"
linked-hash-map = "0.5"
log = "0.4.6"
lru-cache = "0.1.2"
merkle-trie = { git = "https://github.com/CodeChain-io/rust-merkle-trie.git", version = "0.2" }
merkle-trie = { git = "https://github.com/CodeChain-io/rust-merkle-trie.git", version = "0.4" }
num-rational = "0.2.1"
parking_lot = "0.6.0"
primitives = { git = "https://github.com/CodeChain-io/rust-codechain-primitives.git", version = "0.4" }
Expand Down
2 changes: 1 addition & 1 deletion discovery/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ authors = ["CodeChain Team <hi@codechain.io>"]
edition = "2018"

[dependencies]
codechain-crypto = { git = "https://github.com/CodeChain-io/rust-codechain-crypto.git", version = "0.1" }
codechain-crypto = { git = "https://github.com/CodeChain-io/rust-codechain-crypto.git", version = "0.2" }
codechain-key = { path = "../key" }
codechain-logger = { path = "../util/logger" }
codechain-network = { path = "../network" }
Expand Down
2 changes: 1 addition & 1 deletion key/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ rustc-hex = "1.0"
rustc-serialize = "0.3"
lazy_static = "1.2"
bech32 = "0.2.2"
codechain-crypto = { git = "https://github.com/CodeChain-io/rust-codechain-crypto.git", version = "0.1" }
codechain-crypto = { git = "https://github.com/CodeChain-io/rust-codechain-crypto.git", version = "0.2" }
never-type = "0.1.0"
parking_lot = "0.6.0"
primitives = { git = "https://github.com/CodeChain-io/rust-codechain-primitives.git", version = "0.4" }
Expand Down
2 changes: 1 addition & 1 deletion keystore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ serde_derive = "1.0"
rustc-hex = "1.0"
time = "0.1.34"
parking_lot = "0.6.0"
codechain-crypto = { git = "https://github.com/CodeChain-io/rust-codechain-crypto.git", version = "0.1" }
codechain-crypto = { git = "https://github.com/CodeChain-io/rust-codechain-crypto.git", version = "0.2" }
smallvec = "0.4"
tempdir = "0.3"

Expand Down
2 changes: 1 addition & 1 deletion network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ authors = ["CodeChain Team <hi@codechain.io>"]
edition = "2018"

[dependencies]
codechain-crypto = { git = "https://github.com/CodeChain-io/rust-codechain-crypto.git", version = "0.1" }
codechain-crypto = { git = "https://github.com/CodeChain-io/rust-codechain-crypto.git", version = "0.2" }
codechain-io = { path = "../util/io" }
codechain-key = { path = "../key" }
codechain-logger = { path = "../util/logger" }
Expand Down
10 changes: 5 additions & 5 deletions network/src/p2p/connection/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2019 Kodebox, Inc.
// Copyright 2019-2020 Kodebox, Inc.
// This file is part of CodeChain.
//
// This program is free software: you can redistribute it and/or modify
Expand All @@ -19,7 +19,7 @@ mod incoming;
mod message;
mod outgoing;

use ccrypto::aes::SymmetricCipherError;
use ccrypto::error::SymmError;
use rlp::DecoderError;
use std::fmt;
use std::io;
Expand All @@ -35,7 +35,7 @@ use super::stream::Error as P2pStreamError;

#[derive(Debug)]
pub enum Error {
SymmetricCipher(SymmetricCipherError),
SymmetricCipher(SymmError),
IoError(io::Error),
Decoder(DecoderError),
InvalidSign,
Expand Down Expand Up @@ -77,8 +77,8 @@ impl From<P2pStreamError> for Error {
}
}

impl From<SymmetricCipherError> for Error {
fn from(err: SymmetricCipherError) -> Self {
impl From<SymmError> for Error {
fn from(err: SymmError) -> Self {
Error::SymmetricCipher(err)
}
}
Expand Down
10 changes: 5 additions & 5 deletions network/src/p2p/handler.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2018-2019 Kodebox, Inc.
// Copyright 2018-2020 Kodebox, Inc.
// This file is part of CodeChain.
//
// This program is free software: you can redistribute it and/or modify
Expand All @@ -23,7 +23,7 @@ use crate::client::Client;
use crate::session::Session;
use crate::stream::Stream;
use crate::{FiltersControl, NodeId, RoutingTable, SocketAddr};
use ccrypto::aes::SymmetricCipherError;
use ccrypto::error::SymmError;
use cio::{IoChannel, IoContext, IoHandler, IoHandlerResult, IoManager, StreamToken, TimerToken};
use ckey::NetworkId;
use finally_block::finally;
Expand Down Expand Up @@ -1155,8 +1155,8 @@ impl IoHandler<Message> for Handler {
}
}

impl From<SymmetricCipherError> for Error {
fn from(err: SymmetricCipherError) -> Self {
impl From<SymmError> for Error {
fn from(err: SymmError) -> Self {
Error::SymmetricCipher(err)
}
}
Expand Down Expand Up @@ -1186,7 +1186,7 @@ pub enum Message {
#[derive(Debug)]
enum Error {
InvalidNode(NodeId),
SymmetricCipher(SymmetricCipherError),
SymmetricCipher(SymmError),
}

impl ::std::fmt::Display for Error {
Expand Down
9 changes: 5 additions & 4 deletions network/src/p2p/message/extension.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2018-2019 Kodebox, Inc.
// Copyright 2018-2020 Kodebox, Inc.
// This file is part of CodeChain.
//
// This program is free software: you can redistribute it and/or modify
Expand All @@ -17,7 +17,8 @@
use super::ENCRYPTED_ID;
use super::UNENCRYPTED_ID;
use crate::session::Session;
use ccrypto::aes::{self, SymmetricCipherError};
use ccrypto::aes;
use ccrypto::error::SymmError;
use primitives::Bytes;
use rlp::{Decodable, DecoderError, Encodable, Rlp, RlpStream};
use std::sync::Arc;
Expand Down Expand Up @@ -46,7 +47,7 @@ impl Message {
extension_name: String,
unencrypted_data: &[u8],
session: &Session,
) -> Result<Self, SymmetricCipherError> {
) -> Result<Self, SymmError> {
let encrypted = aes::encrypt(unencrypted_data, session.secret(), &session.nonce())?;
Ok(Self::encrypted(extension_name, encrypted))
}
Expand All @@ -72,7 +73,7 @@ impl Message {
}
}

pub fn unencrypted_data(&self, session: &Session) -> Result<Arc<Bytes>, SymmetricCipherError> {
pub fn unencrypted_data(&self, session: &Session) -> Result<Arc<Bytes>, SymmError> {
match self {
Message::Encrypted {
encrypted,
Expand Down
23 changes: 13 additions & 10 deletions network/src/routing_table.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2018-2019 Kodebox, Inc.
// Copyright 2018-2020 Kodebox, Inc.
// This file is part of CodeChain.
//
// This program is free software: you can redistribute it and/or modify
Expand All @@ -16,7 +16,8 @@

use crate::session::{Nonce, Session};
use crate::SocketAddr;
use ccrypto::aes::{self, SymmetricCipherError};
use ccrypto::aes;
use ccrypto::error::SymmError;
use ckey::{exchange, Generator, KeyPair, Public, Random, Secret};
use parking_lot::{Mutex, RwLock};
use primitives::Bytes;
Expand Down Expand Up @@ -506,8 +507,7 @@ impl RoutingTable {
State::Establishing1(local_key_pair) => {
let shared_secret = exchange(&remote_public, local_key_pair.private())
.map_err(|e| format!("Cannot exchange key: {:?}", e))?;
let nonce = decrypt_nonce(encrypted_nonce, &shared_secret)
.map_err(|e| format!("Cannot decrypt nonce: {:?}", e))?;
let nonce = decrypt_nonce(encrypted_nonce, &shared_secret)?;
State::Established {
local_key_pair: *local_key_pair,
remote_public,
Expand All @@ -529,8 +529,7 @@ impl RoutingTable {
))
}
debug_assert_eq!(*shared_secret, exchange(&remote_public, local_key_pair.private()).unwrap());
let nonce = decrypt_nonce(encrypted_nonce, &shared_secret)
.map_err(|e| format!("Cannot decrypt nonce: {:?}", e))?;
let nonce = decrypt_nonce(encrypted_nonce, &shared_secret)?;
State::Established {
local_key_pair: *local_key_pair,
remote_public,
Expand Down Expand Up @@ -618,19 +617,23 @@ impl RoutingTable {
}
}

fn decrypt_nonce(encrypted_bytes: &[u8], shared_secret: &Secret) -> Result<Nonce, SymmetricCipherError> {
fn decrypt_nonce(encrypted_bytes: &[u8], shared_secret: &Secret) -> Result<Nonce, String> {
let iv = 0; // FIXME: Use proper iv
let unecrypted = aes::decrypt(encrypted_bytes, shared_secret, &iv)?;
let unecrypted =
aes::decrypt(encrypted_bytes, shared_secret, &iv).map_err(|e| format!("Cannot decrypt nonce: {:?}", e))?;
debug_assert_eq!(std::mem::size_of::<Nonce>(), 16);
if unecrypted.len() != 16 {
return Err(SymmetricCipherError::InvalidLength) // FIXME
return Err(format!(
"Cannot decrpyt nonce: 16 length bytes expected but, {} length bytes received",
unecrypted.len()
)) // FIXME
}
let mut nonce_bytes = [0u8; 16];
nonce_bytes.copy_from_slice(&unecrypted);
Ok(Nonce::from_be_bytes(nonce_bytes))
}

fn encrypt_nonce(nonce: Nonce, shared_secret: &Secret) -> Result<Bytes, SymmetricCipherError> {
fn encrypt_nonce(nonce: Nonce, shared_secret: &Secret) -> Result<Bytes, SymmError> {
let iv = 0; // FIXME: Use proper iv
Ok(aes::encrypt(&nonce.to_be_bytes(), shared_secret, &iv)?)
}
Expand Down
11 changes: 5 additions & 6 deletions network/src/session/session.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2018-2019 Kodebox, Inc.
// Copyright 2018-2020 Kodebox, Inc.
// This file is part of CodeChain.
//
// This program is free software: you can redistribute it and/or modify
Expand All @@ -15,7 +15,8 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use super::Nonce;
use ccrypto::aes::{self, SymmetricCipherError};
use ccrypto::aes;
use ccrypto::error::SymmError;
use ccrypto::Blake;
use ckey::Secret;
use primitives::H256;
Expand All @@ -26,8 +27,6 @@ pub struct Session {
nonce: Nonce,
}

type Error = SymmetricCipherError;

impl Session {
pub fn new_with_zero_nonce(secret: Secret) -> Self {
Self::new(secret, 0)
Expand All @@ -52,11 +51,11 @@ impl Session {
self.nonce
}

pub fn encrypt(&self, data: &[u8]) -> Result<Vec<u8>, Error> {
pub fn encrypt(&self, data: &[u8]) -> Result<Vec<u8>, SymmError> {
Ok(aes::encrypt(&data, &self.secret, &self.nonce())?)
}

pub fn decrypt(&self, data: &[u8]) -> Result<Vec<u8>, Error> {
pub fn decrypt(&self, data: &[u8]) -> Result<Vec<u8>, SymmError> {
Ok(aes::decrypt(&data, &self.secret, &self.nonce())?)
}

Expand Down
6 changes: 3 additions & 3 deletions state/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ authors = ["CodeChain Team <hi@codechain.io>"]
edition = "2018"

[dependencies]
codechain-crypto = { git = "https://github.com/CodeChain-io/rust-codechain-crypto.git", version = "0.1" }
codechain-db = { git = "https://github.com/CodeChain-io/rust-codechain-db.git", version = "0.1" }
codechain-crypto = { git = "https://github.com/CodeChain-io/rust-codechain-crypto.git", version = "0.2" }
codechain-db = { git = "https://github.com/CodeChain-io/rust-codechain-db.git", version = "0.2" }
codechain-logger = { path = "../util/logger" }
codechain-key = { path = "../key" }
codechain-types = { path = "../types" }
Expand All @@ -15,7 +15,7 @@ kvdb = "0.1"
kvdb-memorydb = "0.1"
log = "0.4.6"
lru-cache = "0.1.1"
merkle-trie = { git = "https://github.com/CodeChain-io/rust-merkle-trie.git", version = "0.2" }
merkle-trie = { git = "https://github.com/CodeChain-io/rust-merkle-trie.git", version = "0.4" }
parking_lot = "0.6.0"
primitives = { git = "https://github.com/CodeChain-io/rust-codechain-primitives.git", version = "0.4" }
rlp = { git = "https://github.com/CodeChain-io/rlp.git", version = "0.4" }
Expand Down
8 changes: 4 additions & 4 deletions sync/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ edition = "2018"

[dependencies]
codechain-core = { path = "../core" }
codechain-crypto = { git = "https://github.com/CodeChain-io/rust-codechain-crypto.git", version = "0.1" }
codechain-db = { git = "https://github.com/CodeChain-io/rust-codechain-db.git", version = "0.1" }
codechain-crypto = { git = "https://github.com/CodeChain-io/rust-codechain-crypto.git", version = "0.2" }
codechain-db = { git = "https://github.com/CodeChain-io/rust-codechain-db.git", version = "0.2" }
codechain-key = { path = "../key" }
codechain-logger = { path = "../util/logger" }
codechain-network = { path = "../network" }
Expand All @@ -18,7 +18,7 @@ codechain-timer = { path = "../util/timer" }
codechain-types = { path = "../types" }
kvdb = "0.1"
log = "0.4.6"
merkle-trie = { git = "https://github.com/CodeChain-io/rust-merkle-trie.git", version = "0.2" }
merkle-trie = { git = "https://github.com/CodeChain-io/rust-merkle-trie.git", version = "0.4" }
never-type = "0.1.0"
parking_lot = "0.6.0"
primitives = { git = "https://github.com/CodeChain-io/rust-codechain-primitives.git", version = "0.4" }
Expand All @@ -31,4 +31,4 @@ token-generator = "0.1.0"
[dev-dependencies]
kvdb-memorydb = "0.1"
tempfile = "3.0.4"
trie-standardmap = { git = "https://github.com/CodeChain-io/trie-standardmap.git", version = "0.2" }
trie-standardmap = { git = "https://github.com/CodeChain-io/trie-standardmap.git", version = "0.3" }
2 changes: 1 addition & 1 deletion types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ authors = ["CodeChain Team <hi@codechain.io>"]
edition = "2018"

[dependencies]
codechain-crypto = { git = "https://github.com/CodeChain-io/rust-codechain-crypto.git", version = "0.1" }
codechain-crypto = { git = "https://github.com/CodeChain-io/rust-codechain-crypto.git", version = "0.2" }
codechain-json = { path = "../json" }
codechain-key = { path = "../key" }
primitives = { git = "https://github.com/CodeChain-io/rust-codechain-primitives.git", version = "0.4" }
Expand Down
2 changes: 1 addition & 1 deletion vm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2018"
[lib]

[dependencies]
codechain-crypto = { git = "https://github.com/CodeChain-io/rust-codechain-crypto.git", version = "0.1" }
codechain-crypto = { git = "https://github.com/CodeChain-io/rust-codechain-crypto.git", version = "0.2" }
codechain-key = { path = "../key" }
codechain-types = { path = "../types" }
primitives = { git = "https://github.com/CodeChain-io/rust-codechain-primitives.git", version = "0.4" }
Expand Down