SecretStore: removed obsolete traits
This commit is contained in:
parent
5a7e065e41
commit
fc7f3433b7
@ -31,10 +31,6 @@ use traits::{AdminSessionsServer, ServerKeyGenerator, DocumentKeyServer, Message
|
||||
use types::all::{Error, Public, RequestSignature, ServerKeyId, EncryptedDocumentKey, EncryptedDocumentKeyShadow,
|
||||
ClusterConfiguration, MessageHash, EncryptedMessageSignature, NodeId};
|
||||
use key_server_cluster::{ClusterClient, ClusterConfiguration as NetClusterConfiguration};
|
||||
use key_server_cluster::generation_session::Session as GenerationSession;
|
||||
use key_server_cluster::encryption_session::Session as EncryptionSession;
|
||||
use key_server_cluster::decryption_session::Session as DecryptionSession;
|
||||
use key_server_cluster::signing_session::Session as SigningSession;
|
||||
|
||||
/// Secret store key server implementation
|
||||
pub struct KeyServerImpl {
|
||||
@ -68,7 +64,9 @@ impl AdminSessionsServer for KeyServerImpl {
|
||||
fn change_servers_set(&self, old_set_signature: RequestSignature, new_set_signature: RequestSignature, new_servers_set: BTreeSet<NodeId>) -> Result<(), Error> {
|
||||
let servers_set_change_session = self.data.lock().cluster
|
||||
.new_servers_set_change_session(None, new_servers_set, old_set_signature, new_set_signature)?;
|
||||
servers_set_change_session.wait().map_err(Into::into)
|
||||
servers_set_change_session.as_servers_set_change()
|
||||
.expect("new_servers_set_change_session creates servers_set_change_session; qed")
|
||||
.wait().map_err(Into::into)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,16 +31,6 @@ use key_server_cluster::admin_sessions::ShareChangeSessionMeta;
|
||||
/// Number of versions sent in single message.
|
||||
const VERSIONS_PER_MESSAGE: usize = 32;
|
||||
|
||||
/// Key version negotiation session API.
|
||||
pub trait Session: Send + Sync + 'static {
|
||||
/// Set continue action.
|
||||
fn set_continue_action(&self, action: ContinueAction);
|
||||
/// Get continue action.
|
||||
fn continue_action(&self) -> Option<ContinueAction>;
|
||||
/// Wait until session is completed.
|
||||
fn wait(&self) -> Result<(H256, NodeId), Error>;
|
||||
}
|
||||
|
||||
/// Key version negotiation transport.
|
||||
pub trait SessionTransport {
|
||||
/// Send message to given node.
|
||||
@ -196,6 +186,28 @@ impl<T> SessionImpl<T> where T: SessionTransport {
|
||||
.clone())
|
||||
}
|
||||
|
||||
/// Set continue action.
|
||||
pub fn set_continue_action(&self, action: ContinueAction) {
|
||||
self.data.lock().continue_with = Some(action);
|
||||
}
|
||||
|
||||
/// Get continue action.
|
||||
pub fn continue_action(&self) -> Option<ContinueAction> {
|
||||
self.data.lock().continue_with.clone()
|
||||
}
|
||||
|
||||
/// Wait for session completion.
|
||||
pub fn wait(&self) -> Result<(H256, NodeId), Error> {
|
||||
let mut data = self.data.lock();
|
||||
if !data.result.is_some() {
|
||||
self.core.completed.wait(&mut data);
|
||||
}
|
||||
|
||||
data.result.as_ref()
|
||||
.expect("checked above or waited for completed; completed is only signaled when result.is_some(); qed")
|
||||
.clone()
|
||||
}
|
||||
|
||||
/// Initialize session.
|
||||
pub fn initialize(&self, connected_nodes: BTreeSet<NodeId>) -> Result<(), Error> {
|
||||
// check state
|
||||
@ -355,27 +367,6 @@ impl<T> SessionImpl<T> where T: SessionTransport {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Session for SessionImpl<T> where T: SessionTransport + Send + Sync + 'static {
|
||||
fn set_continue_action(&self, action: ContinueAction) {
|
||||
self.data.lock().continue_with = Some(action);
|
||||
}
|
||||
|
||||
fn continue_action(&self) -> Option<ContinueAction> {
|
||||
self.data.lock().continue_with.clone()
|
||||
}
|
||||
|
||||
fn wait(&self) -> Result<(H256, NodeId), Error> {
|
||||
let mut data = self.data.lock();
|
||||
if !data.result.is_some() {
|
||||
self.core.completed.wait(&mut data);
|
||||
}
|
||||
|
||||
data.result.as_ref()
|
||||
.expect("checked above or waited for completed; completed is only signaled when result.is_some(); qed")
|
||||
.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> ClusterSession for SessionImpl<T> where T: SessionTransport {
|
||||
type Id = SessionIdWithSubSession;
|
||||
|
||||
|
@ -33,7 +33,7 @@ use key_server_cluster::share_change_session::{ShareChangeSession, ShareChangeSe
|
||||
prepare_share_change_session_plan};
|
||||
use key_server_cluster::key_version_negotiation_session::{SessionImpl as KeyVersionNegotiationSessionImpl,
|
||||
SessionParams as KeyVersionNegotiationSessionParams, LargestSupportResultComputer,
|
||||
SessionTransport as KeyVersionNegotiationTransport, Session as KeyVersionNegotiationSession};
|
||||
SessionTransport as KeyVersionNegotiationTransport};
|
||||
use key_server_cluster::jobs::job_session::JobTransport;
|
||||
use key_server_cluster::jobs::servers_set_change_access_job::{ServersSetChangeAccessJob, ServersSetChangeAccessRequest};
|
||||
use key_server_cluster::jobs::unknown_sessions_job::{UnknownSessionsJob};
|
||||
@ -44,12 +44,6 @@ use key_server_cluster::admin_sessions::ShareChangeSessionMeta;
|
||||
/// Maximal number of active share change sessions.
|
||||
const MAX_ACTIVE_KEY_SESSIONS: usize = 64;
|
||||
|
||||
/// Servers set change session API.
|
||||
pub trait Session: Send + Sync + 'static {
|
||||
/// Wait until session is completed.
|
||||
fn wait(&self) -> Result<(), Error>;
|
||||
}
|
||||
|
||||
/// Servers set change session.
|
||||
/// Brief overview:
|
||||
/// 1) consensus establishing
|
||||
@ -211,6 +205,17 @@ impl SessionImpl {
|
||||
&self.core.meta.id
|
||||
}
|
||||
|
||||
/// Wait for session completion.
|
||||
pub fn wait(&self) -> Result<(), Error> {
|
||||
let mut data = self.data.lock();
|
||||
if !data.result.is_some() {
|
||||
self.core.completed.wait(&mut data);
|
||||
}
|
||||
|
||||
data.result.clone()
|
||||
.expect("checked above or waited for completed; completed is only signaled when result.is_some(); qed")
|
||||
}
|
||||
|
||||
/// Initialize servers set change session on master node.
|
||||
pub fn initialize(&self, new_nodes_set: BTreeSet<NodeId>, all_set_signature: Signature, new_set_signature: Signature) -> Result<(), Error> {
|
||||
check_nodes_set(&self.core.all_nodes_set, &new_nodes_set)?;
|
||||
@ -877,18 +882,6 @@ impl SessionImpl {
|
||||
}
|
||||
}
|
||||
|
||||
impl Session for SessionImpl {
|
||||
fn wait(&self) -> Result<(), Error> {
|
||||
let mut data = self.data.lock();
|
||||
if !data.result.is_some() {
|
||||
self.core.completed.wait(&mut data);
|
||||
}
|
||||
|
||||
data.result.clone()
|
||||
.expect("checked above or waited for completed; completed is only signaled when result.is_some(); qed")
|
||||
}
|
||||
}
|
||||
|
||||
impl ClusterSession for SessionImpl {
|
||||
type Id = SessionId;
|
||||
|
||||
|
@ -32,12 +32,6 @@ use key_server_cluster::jobs::servers_set_change_access_job::{ServersSetChangeAc
|
||||
use key_server_cluster::jobs::consensus_session::{ConsensusSessionParams, ConsensusSessionState, ConsensusSession};
|
||||
use key_server_cluster::admin_sessions::ShareChangeSessionMeta;
|
||||
|
||||
/// Share addition session API.
|
||||
pub trait Session: Send + Sync + 'static {
|
||||
/// Wait until session is completed.
|
||||
fn wait(&self) -> Result<(), Error>;
|
||||
}
|
||||
|
||||
/// Share addition session transport.
|
||||
pub trait SessionTransport: Clone + JobTransport<PartialJobRequest=ServersSetChangeAccessRequest, PartialJobResponse=bool> {
|
||||
/// Get all connected nodes. Since ShareAdd session requires all cluster nodes to be connected, this set equals to all known cluster nodes set.
|
||||
@ -182,6 +176,17 @@ impl<T> SessionImpl<T> where T: SessionTransport {
|
||||
})
|
||||
}
|
||||
|
||||
/// Wait for session completion.
|
||||
pub fn wait(&self) -> Result<(), Error> {
|
||||
let mut data = self.data.lock();
|
||||
if !data.result.is_some() {
|
||||
self.core.completed.wait(&mut data);
|
||||
}
|
||||
|
||||
data.result.clone()
|
||||
.expect("checked above or waited for completed; completed is only signaled when result.is_some(); qed")
|
||||
}
|
||||
|
||||
/// Set pre-established consensus data.
|
||||
pub fn set_consensus_output(&self, version: &H256, consensus_group: BTreeSet<NodeId>, mut new_nodes_map: BTreeMap<NodeId, Option<Secret>>) -> Result<(), Error> {
|
||||
let mut data = self.data.lock();
|
||||
@ -721,18 +726,6 @@ impl<T> SessionImpl<T> where T: SessionTransport {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Session for SessionImpl<T> where T: SessionTransport + Send + Sync + 'static {
|
||||
fn wait(&self) -> Result<(), Error> {
|
||||
let mut data = self.data.lock();
|
||||
if !data.result.is_some() {
|
||||
self.core.completed.wait(&mut data);
|
||||
}
|
||||
|
||||
data.result.clone()
|
||||
.expect("checked above or waited for completed; completed is only signaled when result.is_some(); qed")
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> ClusterSession for SessionImpl<T> where T: SessionTransport {
|
||||
type Id = SessionId;
|
||||
|
||||
|
@ -30,12 +30,6 @@ use key_server_cluster::jobs::key_access_job::KeyAccessJob;
|
||||
use key_server_cluster::jobs::decryption_job::{PartialDecryptionRequest, PartialDecryptionResponse, DecryptionJob};
|
||||
use key_server_cluster::jobs::consensus_session::{ConsensusSessionParams, ConsensusSessionState, ConsensusSession};
|
||||
|
||||
/// Decryption session API.
|
||||
pub trait Session: Send + Sync + 'static {
|
||||
/// Wait until session is completed. Returns distributely restored secret key.
|
||||
fn wait(&self) -> Result<EncryptedDocumentKeyShadow, Error>;
|
||||
}
|
||||
|
||||
/// Distributed decryption session.
|
||||
/// Based on "ECDKG: A Distributed Key Generation Protocol Based on Elliptic Curve Discrete Logarithm" paper:
|
||||
/// http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.124.4128&rep=rep1&type=pdf
|
||||
@ -206,6 +200,18 @@ impl SessionImpl {
|
||||
self.data.lock().result.clone()
|
||||
}
|
||||
|
||||
/// Wait for session completion.
|
||||
pub fn wait(&self) -> Result<EncryptedDocumentKeyShadow, Error> {
|
||||
let mut data = self.data.lock();
|
||||
if !data.result.is_some() {
|
||||
self.core.completed.wait(&mut data);
|
||||
}
|
||||
|
||||
data.result.as_ref()
|
||||
.expect("checked above or waited for completed; completed is only signaled when result.is_some(); qed")
|
||||
.clone()
|
||||
}
|
||||
|
||||
/// Delegate session to other node.
|
||||
pub fn delegate(&self, master: NodeId, version: H256, is_shadow_decryption: bool) -> Result<(), Error> {
|
||||
if self.core.meta.master_node_id != self.core.meta.self_node_id {
|
||||
@ -555,19 +561,6 @@ impl ClusterSession for SessionImpl {
|
||||
}
|
||||
}
|
||||
|
||||
impl Session for SessionImpl {
|
||||
fn wait(&self) -> Result<EncryptedDocumentKeyShadow, Error> {
|
||||
let mut data = self.data.lock();
|
||||
if !data.result.is_some() {
|
||||
self.core.completed.wait(&mut data);
|
||||
}
|
||||
|
||||
data.result.as_ref()
|
||||
.expect("checked above or waited for completed; completed is only signaled when result.is_some(); qed")
|
||||
.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl SessionCore {
|
||||
pub fn decryption_transport(&self) -> DecryptionJobTransport {
|
||||
DecryptionJobTransport {
|
||||
|
@ -26,14 +26,6 @@ use key_server_cluster::cluster_sessions::ClusterSession;
|
||||
use key_server_cluster::message::{Message, EncryptionMessage, InitializeEncryptionSession,
|
||||
ConfirmEncryptionInitialization, EncryptionSessionError};
|
||||
|
||||
/// Encryption session API.
|
||||
pub trait Session: Send + Sync + 'static {
|
||||
/// Get encryption session state.
|
||||
fn state(&self) -> SessionState;
|
||||
/// Wait until session is completed. Returns distributely generated secret key.
|
||||
fn wait(&self, timeout: Option<time::Duration>) -> Result<(), Error>;
|
||||
}
|
||||
|
||||
/// Encryption (distributed key generation) session.
|
||||
/// Based on "ECDKG: A Distributed Key Generation Protocol Based on Elliptic Curve Discrete Logarithm" paper:
|
||||
/// http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.124.4128&rep=rep1&type=pdf
|
||||
@ -138,6 +130,27 @@ impl SessionImpl {
|
||||
&self.self_node_id
|
||||
}
|
||||
|
||||
/// Get session state.
|
||||
pub fn state(&self) -> SessionState {
|
||||
self.data.lock().state.clone()
|
||||
}
|
||||
|
||||
/// Wait for session completion.
|
||||
pub fn wait(&self, timeout: Option<time::Duration>) -> Result<(), Error> {
|
||||
let mut data = self.data.lock();
|
||||
if !data.result.is_some() {
|
||||
match timeout {
|
||||
None => self.completed.wait(&mut data),
|
||||
Some(timeout) => { self.completed.wait_for(&mut data, timeout); },
|
||||
}
|
||||
}
|
||||
|
||||
data.result.as_ref()
|
||||
.expect("checked above or waited for completed; completed is only signaled when result.is_some(); qed")
|
||||
.clone()
|
||||
}
|
||||
|
||||
|
||||
/// Start new session initialization. This must be called on master node.
|
||||
pub fn initialize(&self, requestor_signature: Signature, common_point: Public, encrypted_point: Public) -> Result<(), Error> {
|
||||
let mut data = self.data.lock();
|
||||
@ -328,26 +341,6 @@ impl ClusterSession for SessionImpl {
|
||||
}
|
||||
}
|
||||
|
||||
impl Session for SessionImpl {
|
||||
fn state(&self) -> SessionState {
|
||||
self.data.lock().state.clone()
|
||||
}
|
||||
|
||||
fn wait(&self, timeout: Option<time::Duration>) -> Result<(), Error> {
|
||||
let mut data = self.data.lock();
|
||||
if !data.result.is_some() {
|
||||
match timeout {
|
||||
None => self.completed.wait(&mut data),
|
||||
Some(timeout) => { self.completed.wait_for(&mut data, timeout); },
|
||||
}
|
||||
}
|
||||
|
||||
data.result.as_ref()
|
||||
.expect("checked above or waited for completed; completed is only signaled when result.is_some(); qed")
|
||||
.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for SessionImpl {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result<(), FmtError> {
|
||||
write!(f, "Encryption session {} on {}", self.id, self.self_node_id)
|
||||
|
@ -27,16 +27,6 @@ use key_server_cluster::cluster_sessions::ClusterSession;
|
||||
use key_server_cluster::message::{Message, GenerationMessage, InitializeSession, ConfirmInitialization, CompleteInitialization,
|
||||
KeysDissemination, PublicKeyShare, SessionError, SessionCompleted};
|
||||
|
||||
/// Key generation session API.
|
||||
pub trait Session: Send + Sync + 'static {
|
||||
/// Get generation session state.
|
||||
fn state(&self) -> SessionState;
|
||||
/// Wait until session is completed. Returns public portion of generated server key.
|
||||
fn wait(&self, timeout: Option<time::Duration>) -> Result<Public, Error>;
|
||||
/// Get joint public key (if it is known).
|
||||
fn joint_public_and_secret(&self) -> Option<Result<(Public, Secret), Error>>;
|
||||
}
|
||||
|
||||
/// Distributed key generation session.
|
||||
/// Based on "ECDKG: A Distributed Key Generation Protocol Based on Elliptic Curve Discrete Logarithm" paper:
|
||||
/// http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.124.4128&rep=rep1&type=pdf
|
||||
@ -226,6 +216,31 @@ impl SessionImpl {
|
||||
self.data.lock().simulate_faulty_behaviour = true;
|
||||
}
|
||||
|
||||
/// Get session state.
|
||||
pub fn state(&self) -> SessionState {
|
||||
self.data.lock().state.clone()
|
||||
}
|
||||
|
||||
/// Wait for session completion.
|
||||
pub fn wait(&self, timeout: Option<time::Duration>) -> Result<Public, Error> {
|
||||
let mut data = self.data.lock();
|
||||
if !data.joint_public_and_secret.is_some() {
|
||||
match timeout {
|
||||
None => self.completed.wait(&mut data),
|
||||
Some(timeout) => { self.completed.wait_for(&mut data, timeout); },
|
||||
}
|
||||
}
|
||||
|
||||
data.joint_public_and_secret.clone()
|
||||
.expect("checked above or waited for completed; completed is only signaled when joint_public.is_some(); qed")
|
||||
.map(|p| p.0)
|
||||
}
|
||||
|
||||
/// Get generated public and secret (if any).
|
||||
pub fn joint_public_and_secret(&self) -> Option<Result<(Public, Secret), Error>> {
|
||||
self.data.lock().joint_public_and_secret.clone()
|
||||
}
|
||||
|
||||
/// Start new session initialization. This must be called on master node.
|
||||
pub fn initialize(&self, author: Public, threshold: usize, nodes: BTreeSet<NodeId>) -> Result<(), Error> {
|
||||
check_cluster_nodes(self.node(), &nodes)?;
|
||||
@ -782,30 +797,6 @@ impl ClusterSession for SessionImpl {
|
||||
}
|
||||
}
|
||||
|
||||
impl Session for SessionImpl {
|
||||
fn state(&self) -> SessionState {
|
||||
self.data.lock().state.clone()
|
||||
}
|
||||
|
||||
fn wait(&self, timeout: Option<time::Duration>) -> Result<Public, Error> {
|
||||
let mut data = self.data.lock();
|
||||
if !data.joint_public_and_secret.is_some() {
|
||||
match timeout {
|
||||
None => self.completed.wait(&mut data),
|
||||
Some(timeout) => { self.completed.wait_for(&mut data, timeout); },
|
||||
}
|
||||
}
|
||||
|
||||
data.joint_public_and_secret.clone()
|
||||
.expect("checked above or waited for completed; completed is only signaled when joint_public.is_some(); qed")
|
||||
.map(|p| p.0)
|
||||
}
|
||||
|
||||
fn joint_public_and_secret(&self) -> Option<Result<(Public, Secret), Error>> {
|
||||
self.data.lock().joint_public_and_secret.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl EveryOtherNodeVisitor {
|
||||
pub fn new<I>(self_id: &NodeId, nodes: I) -> Self where I: Iterator<Item=NodeId> {
|
||||
EveryOtherNodeVisitor {
|
||||
@ -883,7 +874,7 @@ pub mod tests {
|
||||
use key_server_cluster::message::{self, Message, GenerationMessage};
|
||||
use key_server_cluster::cluster::tests::{DummyCluster, make_clusters, run_clusters, loop_until, all_connections_established};
|
||||
use key_server_cluster::cluster_sessions::ClusterSession;
|
||||
use key_server_cluster::generation_session::{Session, SessionImpl, SessionState, SessionParams};
|
||||
use key_server_cluster::generation_session::{SessionImpl, SessionState, SessionParams};
|
||||
use key_server_cluster::math;
|
||||
use key_server_cluster::math::tests::do_encryption_and_decryption;
|
||||
|
||||
|
@ -23,7 +23,7 @@ use key_server_cluster::{Error, NodeId, SessionId, SessionMeta, AclStorage, Docu
|
||||
use key_server_cluster::cluster::{Cluster};
|
||||
use key_server_cluster::cluster_sessions::{SessionIdWithSubSession, ClusterSession};
|
||||
use key_server_cluster::generation_session::{SessionImpl as GenerationSession, SessionParams as GenerationSessionParams,
|
||||
Session as GenerationSessionApi, SessionState as GenerationSessionState};
|
||||
SessionState as GenerationSessionState};
|
||||
use key_server_cluster::message::{Message, SigningMessage, SigningConsensusMessage, SigningGenerationMessage,
|
||||
RequestPartialSignature, PartialSignature, SigningSessionCompleted, GenerationMessage, ConsensusMessage, SigningSessionError,
|
||||
InitializeConsensusSession, ConfirmConsensusInitialization, SigningSessionDelegation, SigningSessionDelegationCompleted};
|
||||
@ -32,12 +32,6 @@ use key_server_cluster::jobs::key_access_job::KeyAccessJob;
|
||||
use key_server_cluster::jobs::signing_job::{PartialSigningRequest, PartialSigningResponse, SigningJob};
|
||||
use key_server_cluster::jobs::consensus_session::{ConsensusSessionParams, ConsensusSessionState, ConsensusSession};
|
||||
|
||||
/// Signing session API.
|
||||
pub trait Session: Send + Sync + 'static {
|
||||
/// Wait until session is completed. Returns signed message.
|
||||
fn wait(&self) -> Result<(Secret, Secret), Error>;
|
||||
}
|
||||
|
||||
/// Distributed signing session.
|
||||
/// Based on "Efficient Multi-Party Digital Signature using Adaptive Secret Sharing for Low-Power Devices in Wireless Network" paper.
|
||||
/// Brief overview:
|
||||
@ -211,6 +205,18 @@ impl SessionImpl {
|
||||
self.data.lock().state
|
||||
}
|
||||
|
||||
/// Wait for session completion.
|
||||
pub fn wait(&self) -> Result<(Secret, Secret), Error> {
|
||||
let mut data = self.data.lock();
|
||||
if !data.result.is_some() {
|
||||
self.core.completed.wait(&mut data);
|
||||
}
|
||||
|
||||
data.result.as_ref()
|
||||
.expect("checked above or waited for completed; completed is only signaled when result.is_some(); qed")
|
||||
.clone()
|
||||
}
|
||||
|
||||
/// Delegate session to other node.
|
||||
pub fn delegate(&self, master: NodeId, version: H256, message_hash: H256) -> Result<(), Error> {
|
||||
if self.core.meta.master_node_id != self.core.meta.self_node_id {
|
||||
@ -680,19 +686,6 @@ impl ClusterSession for SessionImpl {
|
||||
}
|
||||
}
|
||||
|
||||
impl Session for SessionImpl {
|
||||
fn wait(&self) -> Result<(Secret, Secret), Error> {
|
||||
let mut data = self.data.lock();
|
||||
if !data.result.is_some() {
|
||||
self.core.completed.wait(&mut data);
|
||||
}
|
||||
|
||||
data.result.as_ref()
|
||||
.expect("checked above or waited for completed; completed is only signaled when result.is_some(); qed")
|
||||
.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl SessionKeyGenerationTransport {
|
||||
fn map_message(&self, message: Message) -> Result<Message, Error> {
|
||||
match message {
|
||||
@ -819,12 +812,11 @@ mod tests {
|
||||
use key_server_cluster::{NodeId, DummyKeyStorage, DocumentKeyShare, DocumentKeyShareVersion, SessionId, SessionMeta, Error, KeyStorage};
|
||||
use key_server_cluster::cluster_sessions::ClusterSession;
|
||||
use key_server_cluster::cluster::tests::DummyCluster;
|
||||
use key_server_cluster::generation_session::{Session as GenerationSession};
|
||||
use key_server_cluster::generation_session::tests::MessageLoop as KeyGenerationMessageLoop;
|
||||
use key_server_cluster::math;
|
||||
use key_server_cluster::message::{Message, SigningMessage, SigningConsensusMessage, ConsensusMessage, ConfirmConsensusInitialization,
|
||||
SigningGenerationMessage, GenerationMessage, ConfirmInitialization, InitializeSession, RequestPartialSignature};
|
||||
use key_server_cluster::signing_session::{Session, SessionImpl, SessionState, SessionParams};
|
||||
use key_server_cluster::signing_session::{SessionImpl, SessionState, SessionParams};
|
||||
|
||||
struct Node {
|
||||
pub node_id: NodeId,
|
||||
|
@ -29,17 +29,16 @@ use tokio_core::net::{TcpListener, TcpStream};
|
||||
use ethkey::{Public, KeyPair, Signature, Random, Generator};
|
||||
use bigint::hash::H256;
|
||||
use key_server_cluster::{Error, NodeId, SessionId, AclStorage, KeyStorage, KeyServerSet, NodeKeyPair};
|
||||
use key_server_cluster::cluster_sessions::{ClusterSession, ClusterSessions, GenerationSessionWrapper, EncryptionSessionWrapper,
|
||||
DecryptionSessionWrapper, SigningSessionWrapper, AdminSessionWrapper, KeyNegotiationSessionWrapper, SessionIdWithSubSession,
|
||||
use key_server_cluster::cluster_sessions::{ClusterSession, AdminSession, ClusterSessions, SessionIdWithSubSession,
|
||||
ClusterSessionsContainer, SERVERS_SET_CHANGE_SESSION_ID, create_cluster_view, AdminSessionCreationData, ClusterSessionsListener};
|
||||
use key_server_cluster::cluster_sessions_creator::{ClusterSessionCreator, IntoSessionId};
|
||||
use key_server_cluster::message::{self, Message, ClusterMessage};
|
||||
use key_server_cluster::generation_session::{SessionImpl as GenerationSession, Session as GenerationSessionTrait};
|
||||
use key_server_cluster::decryption_session::{SessionImpl as DecryptionSession, Session as DecryptionSessionTrait};
|
||||
use key_server_cluster::encryption_session::{SessionImpl as EncryptionSession, Session as EncryptionSessionTrait};
|
||||
use key_server_cluster::signing_session::{SessionImpl as SigningSession, Session as SigningSessionTrait};
|
||||
use key_server_cluster::generation_session::{SessionImpl as GenerationSession};
|
||||
use key_server_cluster::decryption_session::{SessionImpl as DecryptionSession};
|
||||
use key_server_cluster::encryption_session::{SessionImpl as EncryptionSession};
|
||||
use key_server_cluster::signing_session::{SessionImpl as SigningSession};
|
||||
use key_server_cluster::key_version_negotiation_session::{SessionImpl as KeyVersionNegotiationSession,
|
||||
IsolatedSessionTransport as KeyVersionNegotiationSessionTransport, ContinueAction, Session as KeyVersionNegotiationSessionTrait};
|
||||
IsolatedSessionTransport as KeyVersionNegotiationSessionTransport, ContinueAction};
|
||||
use key_server_cluster::io::{DeadlineStatus, ReadMessage, SharedTcpStream, read_encrypted_message, WriteMessage, write_encrypted_message};
|
||||
use key_server_cluster::net::{accept_connection as net_accept_connection, connect as net_connect, Connection as NetConnection};
|
||||
|
||||
@ -74,7 +73,7 @@ pub trait ClusterClient: Send + Sync {
|
||||
/// Start new key version negotiation session.
|
||||
fn new_key_version_negotiation_session(&self, session_id: SessionId) -> Result<Arc<KeyVersionNegotiationSession<KeyVersionNegotiationSessionTransport>>, Error>;
|
||||
/// Start new servers set change session.
|
||||
fn new_servers_set_change_session(&self, session_id: Option<SessionId>, new_nodes_set: BTreeSet<NodeId>, old_set_signature: Signature, new_set_signature: Signature) -> Result<Arc<AdminSessionWrapper>, Error>;
|
||||
fn new_servers_set_change_session(&self, session_id: Option<SessionId>, new_nodes_set: BTreeSet<NodeId>, old_set_signature: Signature, new_set_signature: Signature) -> Result<Arc<AdminSession>, Error>;
|
||||
|
||||
/// Listen for new generation sessions.
|
||||
fn add_generation_listener(&self, listener: Arc<ClusterSessionsListener<GenerationSession>>);
|
||||
@ -959,7 +958,7 @@ impl ClusterClient for ClusterClientImpl {
|
||||
Ok(session)
|
||||
}
|
||||
|
||||
fn new_servers_set_change_session(&self, session_id: Option<SessionId>, new_nodes_set: BTreeSet<NodeId>, old_set_signature: Signature, new_set_signature: Signature) -> Result<Arc<AdminSessionWrapper>, Error> {
|
||||
fn new_servers_set_change_session(&self, session_id: Option<SessionId>, new_nodes_set: BTreeSet<NodeId>, old_set_signature: Signature, new_set_signature: Signature) -> Result<Arc<AdminSession>, Error> {
|
||||
let mut connected_nodes = self.data.connections.connected_nodes();
|
||||
connected_nodes.insert(self.data.self_key_pair.public().clone());
|
||||
|
||||
@ -975,7 +974,7 @@ impl ClusterClient for ClusterClientImpl {
|
||||
.initialize(new_nodes_set, old_set_signature, new_set_signature);
|
||||
|
||||
match initialization_result {
|
||||
Ok(()) => Ok(AdminSessionWrapper::new(Arc::downgrade(&self.data), session_id, session)),
|
||||
Ok(()) => Ok(session),
|
||||
Err(error) => {
|
||||
self.data.sessions.admin_sessions.remove(&session.id());
|
||||
Err(error)
|
||||
@ -1025,8 +1024,7 @@ pub mod tests {
|
||||
use key_server_cluster::message::Message;
|
||||
use key_server_cluster::cluster::{Cluster, ClusterCore, ClusterConfiguration};
|
||||
use key_server_cluster::cluster_sessions::ClusterSession;
|
||||
use key_server_cluster::generation_session::{Session as GenerationSession, SessionState as GenerationSessionState};
|
||||
use key_server_cluster::signing_session::Session as SigningSession;
|
||||
use key_server_cluster::generation_session::SessionState as GenerationSessionState;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct DummyCluster {
|
||||
|
@ -24,16 +24,13 @@ use ethkey::{Public, Secret, Signature};
|
||||
use key_server_cluster::{Error, NodeId, SessionId, EncryptedDocumentKeyShadow};
|
||||
use key_server_cluster::cluster::{Cluster, ClusterData, ClusterConfiguration, ClusterView};
|
||||
use key_server_cluster::message::{self, Message};
|
||||
use key_server_cluster::generation_session::{Session as GenerationSession, SessionImpl as GenerationSessionImpl,
|
||||
SessionState as GenerationSessionState};
|
||||
use key_server_cluster::decryption_session::{Session as DecryptionSession, SessionImpl as DecryptionSessionImpl};
|
||||
use key_server_cluster::encryption_session::{Session as EncryptionSession, SessionImpl as EncryptionSessionImpl,
|
||||
SessionState as EncryptionSessionState};
|
||||
use key_server_cluster::signing_session::{Session as SigningSession, SessionImpl as SigningSessionImpl};
|
||||
use key_server_cluster::share_add_session::{Session as ShareAddSession, SessionImpl as ShareAddSessionImpl,
|
||||
IsolatedSessionTransport as ShareAddTransport};
|
||||
use key_server_cluster::servers_set_change_session::{Session as ServersSetChangeSession, SessionImpl as ServersSetChangeSessionImpl};
|
||||
use key_server_cluster::key_version_negotiation_session::{Session as KeyVersionNegotiationSession, SessionImpl as KeyVersionNegotiationSessionImpl,
|
||||
use key_server_cluster::generation_session::{SessionImpl as GenerationSessionImpl, SessionState as GenerationSessionState};
|
||||
use key_server_cluster::decryption_session::{SessionImpl as DecryptionSessionImpl};
|
||||
use key_server_cluster::encryption_session::{SessionImpl as EncryptionSessionImpl, SessionState as EncryptionSessionState};
|
||||
use key_server_cluster::signing_session::{SessionImpl as SigningSessionImpl};
|
||||
use key_server_cluster::share_add_session::{SessionImpl as ShareAddSessionImpl, IsolatedSessionTransport as ShareAddTransport};
|
||||
use key_server_cluster::servers_set_change_session::{SessionImpl as ServersSetChangeSessionImpl};
|
||||
use key_server_cluster::key_version_negotiation_session::{SessionImpl as KeyVersionNegotiationSessionImpl,
|
||||
IsolatedSessionTransport as VersionNegotiationTransport, ContinueAction};
|
||||
|
||||
use key_server_cluster::cluster_sessions_creator::{GenerationSessionCreator, EncryptionSessionCreator, DecryptionSessionCreator, SigningSessionCreator,
|
||||
@ -169,66 +166,6 @@ pub enum ClusterSessionsContainerState {
|
||||
Exclusive,
|
||||
}
|
||||
|
||||
/// Generation session implementation, which removes session from cluster on drop.
|
||||
pub struct GenerationSessionWrapper {
|
||||
/// Wrapped session.
|
||||
session: Arc<GenerationSession>,
|
||||
/// Session Id.
|
||||
session_id: SessionId,
|
||||
/// Cluster data reference.
|
||||
cluster: Weak<ClusterData>,
|
||||
}
|
||||
|
||||
/// Encryption session implementation, which removes session from cluster on drop.
|
||||
pub struct EncryptionSessionWrapper {
|
||||
/// Wrapped session.
|
||||
session: Arc<EncryptionSession>,
|
||||
/// Session Id.
|
||||
session_id: SessionId,
|
||||
/// Cluster data reference.
|
||||
cluster: Weak<ClusterData>,
|
||||
}
|
||||
|
||||
/// Decryption session implementation, which removes session from cluster on drop.
|
||||
pub struct DecryptionSessionWrapper {
|
||||
/// Wrapped session.
|
||||
session: Arc<DecryptionSession>,
|
||||
/// Session Id.
|
||||
session_id: SessionIdWithSubSession,
|
||||
/// Cluster data reference.
|
||||
cluster: Weak<ClusterData>,
|
||||
}
|
||||
|
||||
/// Signing session implementation, which removes session from cluster on drop.
|
||||
pub struct SigningSessionWrapper {
|
||||
/// Wrapped session.
|
||||
session: Arc<SigningSession>,
|
||||
/// Session Id.
|
||||
session_id: SessionIdWithSubSession,
|
||||
/// Cluster data reference.
|
||||
cluster: Weak<ClusterData>,
|
||||
}
|
||||
|
||||
/// Admin session implementation, which removes session from cluster on drop.
|
||||
pub struct AdminSessionWrapper {
|
||||
/// Wrapped session.
|
||||
session: Arc<AdminSession>,
|
||||
/// Session Id.
|
||||
session_id: SessionId,
|
||||
/// Cluster data reference.
|
||||
cluster: Weak<ClusterData>,
|
||||
}
|
||||
|
||||
/// Key server version negotiation session implementation, which removes session from cluster on drop.
|
||||
pub struct KeyNegotiationSessionWrapper {
|
||||
/// Wrapped session.
|
||||
session: Arc<KeyVersionNegotiationSession>,
|
||||
/// Session Id.
|
||||
session_id: SessionIdWithSubSession,
|
||||
/// Cluster data reference.
|
||||
cluster: Weak<ClusterData>,
|
||||
}
|
||||
|
||||
impl ClusterSessions {
|
||||
/// Create new cluster sessions container.
|
||||
pub fn new(config: &ClusterConfiguration) -> Self {
|
||||
@ -599,158 +536,6 @@ impl ClusterSession for AdminSession {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl GenerationSessionWrapper {
|
||||
pub fn new(cluster: Weak<ClusterData>, session_id: SessionId, session: Arc<GenerationSession>) -> Arc<Self> {
|
||||
Arc::new(GenerationSessionWrapper {
|
||||
session: session,
|
||||
session_id: session_id,
|
||||
cluster: cluster,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl GenerationSession for GenerationSessionWrapper {
|
||||
fn state(&self) -> GenerationSessionState {
|
||||
self.session.state()
|
||||
}
|
||||
|
||||
fn wait(&self, timeout: Option<time::Duration>) -> Result<Public, Error> {
|
||||
self.session.wait(timeout)
|
||||
}
|
||||
|
||||
fn joint_public_and_secret(&self) -> Option<Result<(Public, Secret), Error>> {
|
||||
self.session.joint_public_and_secret()
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for GenerationSessionWrapper {
|
||||
fn drop(&mut self) {
|
||||
if let Some(cluster) = self.cluster.upgrade() {
|
||||
cluster.sessions().generation_sessions.remove(&self.session_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl EncryptionSessionWrapper {
|
||||
pub fn new(cluster: Weak<ClusterData>, session_id: SessionId, session: Arc<EncryptionSession>) -> Arc<Self> {
|
||||
Arc::new(EncryptionSessionWrapper {
|
||||
session: session,
|
||||
session_id: session_id,
|
||||
cluster: cluster,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl EncryptionSession for EncryptionSessionWrapper {
|
||||
fn state(&self) -> EncryptionSessionState {
|
||||
self.session.state()
|
||||
}
|
||||
|
||||
fn wait(&self, timeout: Option<time::Duration>) -> Result<(), Error> {
|
||||
self.session.wait(timeout)
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for EncryptionSessionWrapper {
|
||||
fn drop(&mut self) {
|
||||
if let Some(cluster) = self.cluster.upgrade() {
|
||||
cluster.sessions().encryption_sessions.remove(&self.session_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl DecryptionSessionWrapper {
|
||||
pub fn new(cluster: Weak<ClusterData>, session_id: SessionIdWithSubSession, session: Arc<DecryptionSession>) -> Arc<Self> {
|
||||
Arc::new(DecryptionSessionWrapper {
|
||||
session: session,
|
||||
session_id: session_id,
|
||||
cluster: cluster,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl DecryptionSession for DecryptionSessionWrapper {
|
||||
fn wait(&self) -> Result<EncryptedDocumentKeyShadow, Error> {
|
||||
self.session.wait()
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for DecryptionSessionWrapper {
|
||||
fn drop(&mut self) {
|
||||
if let Some(cluster) = self.cluster.upgrade() {
|
||||
cluster.sessions().decryption_sessions.remove(&self.session_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl SigningSessionWrapper {
|
||||
pub fn new(cluster: Weak<ClusterData>, session_id: SessionIdWithSubSession, session: Arc<SigningSession>) -> Arc<Self> {
|
||||
Arc::new(SigningSessionWrapper {
|
||||
session: session,
|
||||
session_id: session_id,
|
||||
cluster: cluster,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl SigningSession for SigningSessionWrapper {
|
||||
fn wait(&self) -> Result<(Secret, Secret), Error> {
|
||||
self.session.wait()
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for SigningSessionWrapper {
|
||||
fn drop(&mut self) {
|
||||
if let Some(cluster) = self.cluster.upgrade() {
|
||||
cluster.sessions().signing_sessions.remove(&self.session_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AdminSessionWrapper {
|
||||
pub fn new(cluster: Weak<ClusterData>, session_id: SessionId, session: Arc<AdminSession>) -> Arc<Self> {
|
||||
Arc::new(AdminSessionWrapper {
|
||||
session: session,
|
||||
session_id: session_id,
|
||||
cluster: cluster,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn wait(&self) -> Result<(), Error> {
|
||||
match *self.session {
|
||||
AdminSession::ShareAdd(ref session) => session.wait(),
|
||||
AdminSession::ServersSetChange(ref session) => session.wait(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ShareAddSession for AdminSessionWrapper {
|
||||
fn wait(&self) -> Result<(), Error> {
|
||||
match *self.session {
|
||||
AdminSession::ShareAdd(ref session) => session.wait(),
|
||||
_ => Err(Error::InvalidMessage),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ServersSetChangeSession for AdminSessionWrapper {
|
||||
fn wait(&self) -> Result<(), Error> {
|
||||
match *self.session {
|
||||
AdminSession::ServersSetChange(ref session) => session.wait(),
|
||||
_ => Err(Error::InvalidMessage),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for AdminSessionWrapper {
|
||||
fn drop(&mut self) {
|
||||
if let Some(cluster) = self.cluster.upgrade() {
|
||||
cluster.sessions().admin_sessions.remove(&self.session_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn create_cluster_view(data: &Arc<ClusterData>, requires_all_connections: bool) -> Result<Arc<Cluster>, Error> {
|
||||
if requires_all_connections {
|
||||
if !data.connections.disconnected_nodes().is_empty() {
|
||||
@ -764,38 +549,6 @@ pub fn create_cluster_view(data: &Arc<ClusterData>, requires_all_connections: bo
|
||||
Ok(Arc::new(ClusterView::new(data.clone(), connected_nodes)))
|
||||
}
|
||||
|
||||
impl KeyNegotiationSessionWrapper {
|
||||
pub fn new(cluster: Weak<ClusterData>, session_id: SessionIdWithSubSession, session: Arc<KeyVersionNegotiationSession>) -> Arc<Self> {
|
||||
Arc::new(KeyNegotiationSessionWrapper {
|
||||
session: session,
|
||||
session_id: session_id,
|
||||
cluster: cluster,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl KeyVersionNegotiationSession for KeyNegotiationSessionWrapper {
|
||||
fn set_continue_action(&self, action: ContinueAction) {
|
||||
self.session.set_continue_action(action)
|
||||
}
|
||||
|
||||
fn continue_action(&self) -> Option<ContinueAction> {
|
||||
self.session.continue_action()
|
||||
}
|
||||
|
||||
fn wait(&self) -> Result<(H256, NodeId), Error> {
|
||||
self.session.wait()
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for KeyNegotiationSessionWrapper {
|
||||
fn drop(&mut self) {
|
||||
if let Some(cluster) = self.cluster.upgrade() {
|
||||
cluster.sessions().negotiation_sessions.remove(&self.session_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
@ -28,9 +28,6 @@ pub use super::key_server_set::KeyServerSet;
|
||||
pub use super::serialization::{SerializableSignature, SerializableH256, SerializableSecret, SerializablePublic, SerializableMessageHash};
|
||||
pub use self::cluster::{ClusterCore, ClusterConfiguration, ClusterClient};
|
||||
pub use self::cluster_sessions::{ClusterSession, ClusterSessionsListener};
|
||||
pub use self::generation_session::Session as GenerationSession;
|
||||
pub use self::encryption_session::Session as EncryptionSession;
|
||||
pub use self::decryption_session::Session as DecryptionSession;
|
||||
|
||||
#[cfg(test)]
|
||||
pub use super::node_key_pair::PlainNodeKeyPair;
|
||||
|
@ -32,7 +32,7 @@ use bigint::prelude::U256;
|
||||
use util::Address;
|
||||
use key_server_set::KeyServerSet;
|
||||
use key_server_cluster::{ClusterClient, ClusterSessionsListener, ClusterSession};
|
||||
use key_server_cluster::generation_session::{SessionImpl as GenerationSession, Session as GenerationSessionTrait};
|
||||
use key_server_cluster::generation_session::SessionImpl as GenerationSession;
|
||||
use {ServerKeyId, NodeKeyPair, KeyServer};
|
||||
|
||||
/// Name of the SecretStore contract in the registry.
|
||||
|
Loading…
Reference in New Issue
Block a user