Skip to content

Commit

Permalink
Merge #11: Connection and message processing fixes
Browse files Browse the repository at this point in the history
09130c4 processing: append the sighash type to the signature (Antoine Poinsot)
9ff4ccb cosignerd: accept connection once! (Antoine Poinsot)
4fcd3eb cosignerd: log Noise key at startup (Antoine Poinsot)

Pull request description:

  After implementation in revaultd

ACKs for top commit:
  darosior:
    ACK 09130c4

Tree-SHA512: 8306449dfe1ed1fd0d83dc98456e48332ee9f1a6a238d9a25d4b2cca7798b7b48cc4c9985b628ef38f35b0a02f37d2a97fde2b2dae4c7d52f001fac0d6bc95af
  • Loading branch information
darosior committed Mar 23, 2021
2 parents 069bcac + 09130c4 commit 52d7aea
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
20 changes: 10 additions & 10 deletions src/bin/cosignerd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ use cosignerd::{
use revault_net::{
message::cosigner::SignRequest,
noise::{PublicKey as NoisePubkey, SecretKey as NoisePrivkey},
sodiumoxide::crypto::scalarmult::curve25519,
};
use revault_tx::bitcoin::secp256k1;
use revault_tx::bitcoin::{hashes::hex::ToHex, secp256k1};
use std::{env, fs, net::TcpListener, os::unix::fs::DirBuilderExt, path::PathBuf, process};

fn parse_args(args: Vec<String>) -> Option<PathBuf> {
Expand Down Expand Up @@ -60,13 +61,7 @@ fn daemon_main(

// We expect a single connection once in a while, there is *no need* for complexity here so
// just treat incoming connections sequentially.
for stream in listener.incoming() {
log::trace!("Got a new connection: '{:?}'", stream);
let stream = match stream {
Ok(s) => s,
Err(_) => continue,
};
// This does the Noise KK handshake.
loop {
let mut kk_stream = match revault_net::transport::KKTransport::accept(
&listener,
noise_privkey,
Expand All @@ -82,7 +77,7 @@ fn daemon_main(
let buf = match kk_stream.read() {
Ok(buf) => buf,
Err(e) => {
log::error!("Error reading from stream '{:?}': '{}'", stream, e);
log::error!("Error reading from stream '{:?}': '{}'", kk_stream, e);
continue;
}
};
Expand Down Expand Up @@ -187,7 +182,12 @@ fn main() {
);
}
}
log::info!("Started cosignerd daemon.");
log::info!(
"Started cosignerd daemon with Noise pubkey: {}",
NoisePubkey(curve25519::scalarmult_base(&curve25519::Scalar(noise_privkey.0)).0)
.0
.to_hex()
);

daemon_main(config, &noise_privkey, &bitcoin_privkey);
}
3 changes: 2 additions & 1 deletion src/processing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,11 @@ pub fn process_sign_message(
.signature_hash_internal_input(i, SigHashType::All)
.map_err(SignProcessingError::InsanePsbtMissingInput)?;
let sighash = secp256k1::Message::from_slice(&sighash).expect("Sighash is 32 bytes");
let signature = secp
let mut signature = secp
.sign(&sighash, bitcoin_privkey)
.serialize_der()
.to_vec();
signature.push(SigHashType::All as u8);
assert!(
psbtin.partial_sigs.insert(our_pubkey, signature).is_none(),
"If there was a signature for our pubkey already and we didn't return \
Expand Down

0 comments on commit 52d7aea

Please sign in to comment.