Skip to content
This repository was archived by the owner on Jun 25, 2021. It is now read-only.

Commit 7f8a059

Browse files
authored
Merge pull request #2240 from madadam/protect-secret-key-share
Do not expose BLS secret key share
2 parents 7d67efe + e8fa12e commit 7f8a059

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

src/error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ pub enum Error {
3737
UntrustedMessage,
3838
#[error(display = "A signature share is invalid.")]
3939
InvalidSignatureShare,
40-
#[error(display = "An Elder DKG result is invalid.")]
41-
InvalidElderDkgResult,
40+
#[error(display = "The secret key share is missing.")]
41+
MissingSecretKeyShare,
4242
#[error(display = "Failed to send a message.")]
4343
FailedSend,
4444
#[error(display = "Invalid vote.")]

src/routing/mod.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -148,17 +148,17 @@ impl Routing {
148148
self.stage.state.lock().await.node().age
149149
}
150150

151-
/// Returns the `PublicKey` of this node.
151+
/// Returns the ed25519 public key of this node.
152152
pub async fn public_key(&self) -> PublicKey {
153153
self.stage.state.lock().await.node().keypair.public
154154
}
155155

156-
/// Sign any data with the key of this node.
156+
/// Signs any data with the ed25519 key of this node.
157157
pub async fn sign(&self, data: &[u8]) -> Signature {
158158
self.stage.state.lock().await.node().keypair.sign(data)
159159
}
160160

161-
/// Verify any signed data with the key of this node.
161+
/// Verifies `signature` on `data` with the ed25519 public key of this node.
162162
pub async fn verify(&self, data: &[u8], signature: &Signature) -> bool {
163163
self.stage
164164
.state
@@ -291,45 +291,45 @@ impl Routing {
291291
self.stage.clone().handle_commands(command).await
292292
}
293293

294-
/// Returns the current BLS public key set or `Error::InvalidState` if we are not joined
295-
/// yet.
294+
/// Returns the current BLS public key set if this node has one, or
295+
/// `Error::MissingSecretKeyShare` otherwise.
296296
pub async fn public_key_set(&self) -> Result<bls::PublicKeySet> {
297297
self.stage
298298
.state
299299
.lock()
300300
.await
301301
.section_key_share()
302302
.map(|share| share.public_key_set.clone())
303-
.ok_or(Error::InvalidState)
303+
.ok_or(Error::MissingSecretKeyShare)
304304
}
305305

306-
/// Returns the current BLS secret key share or `Error::InvalidState` if we are not
307-
/// elder.
308-
pub async fn secret_key_share(&self) -> Result<bls::SecretKeyShare> {
306+
/// Signs `data` with the BLS secret key share of this node, if it has any. Returns
307+
// `Error::MissingSecretKeyShare` otherwise.
308+
pub async fn sign_with_secret_key_share(&self, data: &[u8]) -> Result<bls::SignatureShare> {
309309
self.stage
310310
.state
311311
.lock()
312312
.await
313313
.section_key_share()
314-
.map(|share| share.secret_key_share.clone())
315-
.ok_or(Error::InvalidState)
314+
.map(|share| share.secret_key_share.sign(data))
315+
.ok_or(Error::MissingSecretKeyShare)
316316
}
317317

318-
/// Returns our section proof chain, or `None` if we are not joined yet.
318+
/// Returns our section proof chain.
319319
pub async fn our_history(&self) -> SectionProofChain {
320320
self.stage.state.lock().await.section().chain().clone()
321321
}
322322

323-
/// Returns our index in the current BLS group or `Error::InvalidState` if section key was
324-
/// not generated yet.
323+
/// Returns our index in the current BLS group if this node is a member of one, or
324+
/// `Error::MissingSecretKeyShare` otherwise.
325325
pub async fn our_index(&self) -> Result<usize> {
326326
self.stage
327327
.state
328328
.lock()
329329
.await
330330
.section_key_share()
331331
.map(|share| share.index)
332-
.ok_or(Error::InvalidState)
332+
.ok_or(Error::MissingSecretKeyShare)
333333
}
334334
}
335335

src/section/section_keys.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use bls_dkg::key_gen::outcome::Outcome;
1212
use xor_name::XorName;
1313

1414
/// All the key material needed to sign or combine signature for our section key.
15-
#[derive(Clone, Debug)]
15+
#[derive(Debug)]
1616
pub struct SectionKeyShare {
1717
/// Public key set to verify threshold signatures and combine shares.
1818
pub public_key_set: bls::PublicKeySet,
@@ -40,7 +40,7 @@ impl SectionKeysProvider {
4040
}
4141

4242
pub fn key_share(&self) -> Result<&SectionKeyShare> {
43-
self.current.as_ref().ok_or(Error::InvalidElderDkgResult)
43+
self.current.as_ref().ok_or(Error::MissingSecretKeyShare)
4444
}
4545

4646
pub fn insert_dkg_outcome(

0 commit comments

Comments
 (0)