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

SecretStore: servers set change session api #6925

Merged
merged 53 commits into from
Nov 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
81b97c1
SecretStore: first key versions flush
svyatonik Oct 10, 2017
cb3af63
SecretStore: key versions in encryption session
svyatonik Oct 10, 2017
dedf03b
SecretStore: flush key versions negotiation session
svyatonik Oct 11, 2017
a748a0b
SecretStore: connected key version negotiation session to cluster
svyatonik Oct 11, 2017
402a8e0
SecretStore: cluster sessions container refactoring
svyatonik Oct 12, 2017
b03a43a
SecretStore: flush
svyatonik Oct 13, 2017
3f443f0
SecretStore: flush key versions
svyatonik Oct 16, 2017
187e1fd
SecretStore: flush
svyatonik Oct 16, 2017
782080a
SecretStore: delegation proto
svyatonik Oct 16, 2017
5c448b2
Merge branch 'master' into secretstore_key_version
svyatonik Oct 16, 2017
45c7637
SecretStore: decryption_session_is_delegated_when_node_does_not_have_…
svyatonik Oct 17, 2017
d7a4b03
SecretStore: fixed version in decryption session
svyatonik Oct 17, 2017
0f61db3
SecretStore: signing_session_is_delegated_when_node_does_not_have_key…
svyatonik Oct 17, 2017
7a98951
SecretStore: started restoring admin sessions
svyatonik Oct 18, 2017
9036b17
SecretStore: restoring admin sessions
svyatonik Oct 19, 2017
18cbea8
SecretStore: removed obsolete ShareRemove && ShareMove sessions
svyatonik Oct 19, 2017
4f535f4
SecretStore: ShareAdd math tests only require old_t+1 nodes
svyatonik Oct 23, 2017
117cbb6
SecretStore: ShareAdd revamp using new math backend
svyatonik Oct 24, 2017
6a5144a
SecretStore: do not include isolated nodes into consensus_group
svyatonik Oct 24, 2017
873b185
SecretStore: ServersSetChange + ShareAdd revamp
svyatonik Oct 24, 2017
f1f6fa4
removed debug printlns
svyatonik Oct 24, 2017
cb403b9
SecretStore: key version negotiation tests
svyatonik Oct 24, 2017
9ad693c
SecretStore: removed debug/merge artifacts
svyatonik Oct 24, 2017
4d2b29a
SecretStore: fixed master node selection
svyatonik Oct 24, 2017
c35b9bd
SecretStore: cleanup + tests + fixes
svyatonik Oct 25, 2017
1093393
SecretStore: uncommented tests
svyatonik Oct 25, 2017
232b3d0
SecretStore: cleaning up
svyatonik Oct 25, 2017
9972832
SecretStore: cleaning up + tests
svyatonik Oct 25, 2017
e74774c
SecretStore: cleaning up
svyatonik Oct 25, 2017
07f1bf3
SecretStore: cleaning up && tests
svyatonik Oct 25, 2017
1a6a6f5
SecretStore: fixing TODOs
svyatonik Oct 25, 2017
0c52239
SecretStore: fixing TODOs + cleanup
svyatonik Oct 25, 2017
5328d5e
SecretStore: fixing TODOs
svyatonik Oct 25, 2017
646bb7b
SecretStore: nodes_add_to_the_node_with_obsolete_version
svyatonik Oct 26, 2017
811e01c
SecretStore: nodes_add_fails_when_not_enough_share_owners_are_connected
svyatonik Oct 26, 2017
cd3cdf5
SecretStore: tests
svyatonik Oct 26, 2017
705e4a1
SecretStore: signing && delegation tests
svyatonik Oct 26, 2017
f5a13f1
SecretStore: signing && decryption tests when some nodes are isolated
svyatonik Oct 26, 2017
580ab02
SecretStore: sessions_are_removed_when_initialization_fails
svyatonik Oct 26, 2017
aed908a
SecretStore: ceaning up
svyatonik Oct 26, 2017
56de751
Merge branch 'master' into secretstore_key_version
svyatonik Oct 26, 2017
e76ea31
SecretStore: removed obsolete comments
svyatonik Oct 26, 2017
eb55573
SecretStore: signing_session_completes_if_node_does_not_have_a_share
svyatonik Oct 27, 2017
2e21d63
SecretStore: initial ServersSetChange API
svyatonik Oct 30, 2017
75dcc48
SecretStore: added secretstore_signServersSet RPC
svyatonik Oct 30, 2017
41d92f2
SecretStore: ChangeServersSet parse tests
svyatonik Oct 30, 2017
5d6ab84
SecretStore: fixes after manual ServersSetChange tests
svyatonik Oct 31, 2017
73566d5
Merge branch 'master' into servers_set_change_api
svyatonik Nov 6, 2017
e2aea0e
lost file
svyatonik Nov 6, 2017
f303afb
fixed network ports overlap in tests
svyatonik Nov 6, 2017
79c10a7
Merge branch 'master' into servers_set_change_api
svyatonik Nov 16, 2017
5bc1656
Merge branch 'master' into servers_set_change_api
svyatonik Nov 16, 2017
0680f42
lost files
svyatonik Nov 16, 2017
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
time = "0.1"
tiny-keccak = "1.3"
tokio-timer = "0.1"
transient-hashmap = "0.4"
itertools = "0.5"
Expand Down
1 change: 1 addition & 0 deletions rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ extern crate semver;
extern crate serde;
extern crate serde_json;
extern crate time;
extern crate tiny_keccak;
extern crate tokio_timer;
extern crate transient_hashmap;

Expand Down
17 changes: 17 additions & 0 deletions rpc/src/v1/helpers/secretstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

use std::collections::BTreeSet;
use rand::{Rng, OsRng};
use ethkey::{Public, Secret, math};
use crypto;
use bytes::Bytes;
use jsonrpc_core::Error;
use v1::helpers::errors;
use v1::types::{H256, H512};
use tiny_keccak::Keccak;

/// Initialization vector length.
const INIT_VEC_LEN: usize = 16;
Expand Down Expand Up @@ -61,11 +64,25 @@ pub fn decrypt_document(key: Bytes, mut encrypted_document: Bytes) -> Result<Byt
Ok(document)
}

/// Decrypt document given secret shadow.
pub fn decrypt_document_with_shadow(decrypted_secret: Public, common_point: Public, shadows: Vec<Secret>, encrypted_document: Bytes) -> Result<Bytes, Error> {
let key = decrypt_with_shadow_coefficients(decrypted_secret, common_point, shadows)?;
decrypt_document(key.to_vec(), encrypted_document)
}

/// Calculate Keccak(ordered servers set)
pub fn ordered_servers_keccak(servers_set: BTreeSet<H512>) -> H256 {
let mut servers_set_keccak = Keccak::new_keccak256();
for server in servers_set {
servers_set_keccak.update(&server.0);
}

let mut servers_set_keccak_value = [0u8; 32];
servers_set_keccak.finalize(&mut servers_set_keccak_value);

servers_set_keccak_value.into()
}

fn into_document_key(key: Bytes) -> Result<Bytes, Error> {
// key is a previously distributely generated Public
if key.len() != 64 {
Expand Down
12 changes: 11 additions & 1 deletion rpc/src/v1/impls/secretstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

//! SecretStore-specific rpc implementation.

use std::collections::BTreeSet;
use std::sync::Arc;

use crypto::DEFAULT_MAC;
Expand All @@ -25,7 +26,7 @@ use ethcore::account_provider::AccountProvider;
use jsonrpc_core::Result;
use v1::helpers::errors;
use v1::helpers::accounts::unwrap_provider;
use v1::helpers::secretstore::{encrypt_document, decrypt_document, decrypt_document_with_shadow};
use v1::helpers::secretstore::{encrypt_document, decrypt_document, decrypt_document_with_shadow, ordered_servers_keccak};
use v1::traits::SecretStore;
use v1::types::{H160, H512, Bytes};

Expand Down Expand Up @@ -82,4 +83,13 @@ impl SecretStore for SecretStoreClient {
decrypt_document_with_shadow(decrypted_secret.into(), common_point.into(), shadows, data.0)
.map(Into::into)
}

fn sign_servers_set(&self, address: H160, password: String, servers_set: BTreeSet<H512>) -> Result<Bytes> {
let servers_set_keccak_value = ordered_servers_keccak(servers_set);
let store = self.account_provider()?;
store
.sign(address.into(), Some(password), servers_set_keccak_value.into())
.map(|s| Bytes::new((*s).to_vec()))
.map_err(|e| errors::account("Could not sign servers set.", e))
}
}
34 changes: 32 additions & 2 deletions rpc/src/v1/tests/mocked/secretstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
use std::sync::Arc;

use ethcore::account_provider::AccountProvider;
use ethkey::{KeyPair, Signature, verify_public};

use serde_json;
use jsonrpc_core::{IoHandler, Success};
use v1::metadata::Metadata;
use v1::SecretStoreClient;
use v1::traits::secretstore::SecretStore;
use v1::helpers::secretstore::ordered_servers_keccak;

struct Dependencies {
pub accounts: Arc<AccountProvider>,
Expand Down Expand Up @@ -51,7 +53,7 @@ fn rpc_secretstore_encrypt_and_decrypt() {
let deps = Dependencies::new();
let io = deps.default_client();

// insert new account && unlock it
// insert new account
let secret = "c1f1cfe279a5c350d13795bce162941967340c8a228e6ba175489afc564a5bef".parse().unwrap();
deps.accounts.insert_account(secret, "password").unwrap();

Expand Down Expand Up @@ -81,7 +83,7 @@ fn rpc_secretstore_shadow_decrypt() {
let deps = Dependencies::new();
let io = deps.default_client();

// insert new account && unlock it
// insert new account
let secret = "82758356bf46b42710d3946a8efa612b7bf5e125e4d49f28facf1139db4a46f4".parse().unwrap();
deps.accounts.insert_account(secret, "password").unwrap();

Expand All @@ -96,3 +98,31 @@ fn rpc_secretstore_shadow_decrypt() {
let decryption_response = io.handle_request_sync(&decryption_request).unwrap();
assert_eq!(decryption_response, r#"{"jsonrpc":"2.0","result":"0xdeadbeef","id":1}"#);
}

#[test]
fn rpc_secretstore_sign_servers_set() {
let deps = Dependencies::new();
let io = deps.default_client();

// insert new account
let secret = "82758356bf46b42710d3946a8efa612b7bf5e125e4d49f28facf1139db4a46f4".parse().unwrap();
let key_pair = KeyPair::from_secret(secret).unwrap();
deps.accounts.insert_account(key_pair.secret().clone(), "password").unwrap();

// execute signing request
let signing_request = r#"{"jsonrpc": "2.0", "method": "secretstore_signServersSet", "params":[
"0x00dfE63B22312ab4329aD0d28CaD8Af987A01932", "password",
["0x843645726384530ffb0c52f175278143b5a93959af7864460f5a4fec9afd1450cfb8aef63dec90657f43f55b13e0a73c7524d4e9a13c051b4e5f1e53f39ecd91",
"0x07230e34ebfe41337d3ed53b186b3861751f2401ee74b988bba55694e2a6f60c757677e194be2e53c3523cc8548694e636e6acb35c4e8fdc5e29d28679b9b2f3"]
], "id": 1}"#;
let signing_response = io.handle_request_sync(&signing_request).unwrap();
let signing_response = signing_response.replace(r#"{"jsonrpc":"2.0","result":"0x"#, "");
let signing_response = signing_response.replace(r#"","id":1}"#, "");
let signature: Signature = signing_response.parse().unwrap();

let servers_set_keccak = ordered_servers_keccak(vec![
"843645726384530ffb0c52f175278143b5a93959af7864460f5a4fec9afd1450cfb8aef63dec90657f43f55b13e0a73c7524d4e9a13c051b4e5f1e53f39ecd91".parse().unwrap(),
"07230e34ebfe41337d3ed53b186b3861751f2401ee74b988bba55694e2a6f60c757677e194be2e53c3523cc8548694e636e6acb35c4e8fdc5e29d28679b9b2f3".parse().unwrap()
].into_iter().collect());
assert!(verify_public(key_pair.public(), &signature, &servers_set_keccak.into()).unwrap());
}
6 changes: 6 additions & 0 deletions rpc/src/v1/traits/secretstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

//! SecretStore-specific rpc interface.

use std::collections::BTreeSet;
use jsonrpc_core::Result;

use v1::types::{H160, H512, Bytes};
Expand All @@ -37,5 +38,10 @@ build_rpc_trait! {
/// Arguments: `account`, `password`, `decrypted_secret`, `common_point`, `decrypt_shadows`, `data`.
#[rpc(name = "secretstore_shadowDecrypt")]
fn shadow_decrypt(&self, H160, String, H512, H512, Vec<Bytes>, Bytes) -> Result<Bytes>;

/// Sign servers set for use in ServersSetChange session.
/// Arguments: `account`, `password`, `servers_set`.
#[rpc(name = "secretstore_signServersSet")]
fn sign_servers_set(&self, H160, String, BTreeSet<H512>) -> Result<Bytes>;
}
}
Loading