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

Commit

Permalink
RUSTSEC-2021-0076 bump libsecp256k1 (#9391)
Browse files Browse the repository at this point in the history
* RUSTSEC-2021-0076 bump libsecp256k1

libsecp256k1 allows overflowing signatures
https://rustsec.org/advisories/RUSTSEC-2021-0076

Changes were made to conform to libsecp256k1 version differences.

Closes #9356

* parse_standard_slice() -> parse_overflowing_slice()

* Added v2 host function for ecdsa_verify

* Add feature tag over helpers

* Added ecdsa_verify v2 to test runner

* PR feedback

- Spaces -> tabs
- renamed two helper functions

* Fixed imports after rebasing

* Bump rest of libsecp256k1 (and libp2p)

libp2p also uses libsecp256k1 so it is required to be bumped too, along
with all the version difference changes.

* Add version2 for ecdsa pubkey recovery

* libp2p rebase master fixes

* Fix test panic when non Behaviour event is returned

* Update bin/node/browser-testing/Cargo.toml

* Update primitives/core/src/ecdsa.rs

* Update primitives/core/src/ecdsa.rs

* Update Cargo.lock

Co-authored-by: Bastian Köcher <[email protected]>
  • Loading branch information
2 people authored and apopiak committed Sep 13, 2021
1 parent 91061a7 commit 6ac80d3
Show file tree
Hide file tree
Showing 26 changed files with 720 additions and 367 deletions.
639 changes: 436 additions & 203 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,6 @@ members = [
#
# This list is ordered alphabetically.
[profile.dev.package]
aes-soft = { opt-level = 3 }
aesni = { opt-level = 3 }
blake2 = { opt-level = 3 }
blake2-rfc = { opt-level = 3 }
blake2b_simd = { opt-level = 3 }
Expand Down
2 changes: 1 addition & 1 deletion bin/node/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ try-runtime-cli = { version = "0.10.0-dev", optional = true, path = "../../../ut
wasm-bindgen = { version = "0.2.73", optional = true }
wasm-bindgen-futures = { version = "0.4.18", optional = true }
browser-utils = { package = "substrate-browser-utils", path = "../../../utils/browser", optional = true, version = "0.10.0-dev"}
libp2p-wasm-ext = { version = "0.28", features = ["websocket"], optional = true }
libp2p-wasm-ext = { version = "0.29", features = ["websocket"], optional = true }

[target.'cfg(target_arch="x86_64")'.dependencies]
node-executor = { version = "3.0.0-dev", path = "../executor", features = [ "wasmtime" ] }
Expand Down
4 changes: 2 additions & 2 deletions client/authority-discovery/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ derive_more = "0.99.2"
either = "1.5.3"
futures = "0.3.9"
futures-timer = "3.0.1"
ip_network = "0.3.4"
libp2p = { version = "0.37.1", default-features = false, features = ["kad"] }
ip_network = "0.4.0"
libp2p = { version = "0.39.1", default-features = false, features = ["kad"] }
log = "0.4.8"
prometheus-endpoint = { package = "substrate-prometheus-endpoint", path = "../../utils/prometheus", version = "0.9.0"}
prost = "0.7"
Expand Down
2 changes: 1 addition & 1 deletion client/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ regex = "1.4.2"
tokio = { version = "0.2.21", features = [ "signal", "rt-core", "rt-threaded", "blocking" ] }
futures = "0.3.9"
fdlimit = "0.2.1"
libp2p = "0.37.1"
libp2p = "0.39.1"
parity-scale-codec = "2.0.0"
hex = "0.4.2"
rand = "0.7.3"
Expand Down
2 changes: 1 addition & 1 deletion client/consensus/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
thiserror = "1.0.21"
libp2p = { version = "0.37.1", default-features = false }
libp2p = { version = "0.39.1", default-features = false }
log = "0.4.8"
futures = { version = "0.3.1", features = ["thread-pool"] }
futures-timer = "3.0.1"
Expand Down
2 changes: 1 addition & 1 deletion client/executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ sc-executor-wasmi = { version = "0.10.0-dev", path = "wasmi" }
sc-executor-wasmtime = { version = "0.10.0-dev", path = "wasmtime", optional = true }
parking_lot = "0.11.1"
log = "0.4.8"
libsecp256k1 = "0.3.4"
libsecp256k1 = "0.6"

[dev-dependencies]
assert_matches = "1.3.0"
Expand Down
2 changes: 1 addition & 1 deletion client/network-gossip/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
futures = "0.3.9"
futures-timer = "3.0.1"
libp2p = { version = "0.37.1", default-features = false }
libp2p = { version = "0.39.1", default-features = false }
log = "0.4.8"
lru = "0.6.5"
prometheus-endpoint = { package = "substrate-prometheus-endpoint", version = "0.9.0", path = "../../utils/prometheus" }
Expand Down
6 changes: 3 additions & 3 deletions client/network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,17 @@ wasm-timer = "0.2"
zeroize = "1.2.0"

[dependencies.libp2p]
version = "0.37.1"
version = "0.39.1"

[target.'cfg(target_os = "unknown")'.dependencies.libp2p]
version = "0.37.1"
version = "0.39.1"
default-features = false
features = ["identify", "kad", "mdns", "mplex", "noise", "ping", "request-response", "tcp-async-io", "websocket", "yamux"]


[dev-dependencies]
assert_matches = "1.3"
libp2p = { version = "0.37.1", default-features = false }
libp2p = { version = "0.39.1", default-features = false }
quickcheck = "1.0.3"
rand = "0.7.2"
sp-keyring = { version = "4.0.0-dev", path = "../../primitives/keyring" }
Expand Down
6 changes: 3 additions & 3 deletions client/network/src/bitswap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ where

fn upgrade_inbound(self, mut socket: TSocket, _info: Self::Info) -> Self::Future {
Box::pin(async move {
let packet = upgrade::read_one(&mut socket, MAX_PACKET_SIZE).await?;
let packet = upgrade::read_length_prefixed(&mut socket, MAX_PACKET_SIZE).await?;
let message: BitswapMessage = Message::decode(packet.as_slice())?;
Ok(message)
})
Expand Down Expand Up @@ -122,7 +122,7 @@ where
Box::pin(async move {
let mut data = Vec::with_capacity(self.encoded_len());
self.encode(&mut data)?;
upgrade::write_one(&mut socket, data).await
upgrade::write_length_prefixed(&mut socket, data).await
})
}
}
Expand Down Expand Up @@ -328,7 +328,7 @@ pub enum BitswapError {
/// Error parsing CID
BadCid(cid::Error),
/// Packet read error.
Read(upgrade::ReadOneError),
Read(io::Error),
/// Error sending response.
#[display(fmt = "Failed to send response.")]
SendResponse,
Expand Down
79 changes: 50 additions & 29 deletions client/network/src/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ impl NetworkBehaviour for DiscoveryBehaviour {
KademliaEvent::PendingRoutablePeer { .. } => {
// We are not interested in this event at the moment.
},
KademliaEvent::QueryResult {
KademliaEvent::OutboundQueryCompleted {
result: QueryResult::GetClosestPeers(res),
..
} => match res {
Expand All @@ -741,7 +741,7 @@ impl NetworkBehaviour for DiscoveryBehaviour {
}
},
},
KademliaEvent::QueryResult {
KademliaEvent::OutboundQueryCompleted {
result: QueryResult::GetRecord(res),
stats,
..
Expand Down Expand Up @@ -778,7 +778,7 @@ impl NetworkBehaviour for DiscoveryBehaviour {
};
return Poll::Ready(NetworkBehaviourAction::GenerateEvent(ev))
},
KademliaEvent::QueryResult {
KademliaEvent::OutboundQueryCompleted {
result: QueryResult::PutRecord(res),
stats,
..
Expand All @@ -799,7 +799,7 @@ impl NetworkBehaviour for DiscoveryBehaviour {
};
return Poll::Ready(NetworkBehaviourAction::GenerateEvent(ev))
},
KademliaEvent::QueryResult {
KademliaEvent::OutboundQueryCompleted {
result: QueryResult::RepublishRecord(res),
..
} => match res {
Expand Down Expand Up @@ -830,6 +830,11 @@ impl NetworkBehaviour for DiscoveryBehaviour {
address,
score,
}),
NetworkBehaviourAction::CloseConnection { peer_id, connection } =>
return Poll::Ready(NetworkBehaviourAction::CloseConnection {
peer_id,
connection,
}),
}
}
}
Expand Down Expand Up @@ -862,6 +867,11 @@ impl NetworkBehaviour for DiscoveryBehaviour {
address,
score,
}),
NetworkBehaviourAction::CloseConnection { peer_id, connection } =>
return Poll::Ready(NetworkBehaviourAction::CloseConnection {
peer_id,
connection,
}),
}
}

Expand Down Expand Up @@ -931,7 +941,7 @@ mod tests {
},
identity::Keypair,
noise,
swarm::Swarm,
swarm::{Swarm, SwarmEvent},
yamux, Multiaddr, PeerId,
};
use std::{collections::HashSet, task::Poll};
Expand Down Expand Up @@ -1000,31 +1010,42 @@ mod tests {
match swarms[swarm_n].0.poll_next_unpin(cx) {
Poll::Ready(Some(e)) => {
match e {
DiscoveryOut::UnroutablePeer(other) |
DiscoveryOut::Discovered(other) => {
// Call `add_self_reported_address` to simulate identify happening.
let addr = swarms
.iter()
.find_map(|(s, a)| {
if s.behaviour().local_peer_id == other {
Some(a.clone())
} else {
None
}
})
.unwrap();
swarms[swarm_n].0.behaviour_mut().add_self_reported_address(
&other,
[protocol_name_from_protocol_id(&protocol_id)].iter(),
addr,
);

to_discover[swarm_n].remove(&other);
},
DiscoveryOut::RandomKademliaStarted(_) => {},
e => {
panic!("Unexpected event: {:?}", e)
SwarmEvent::Behaviour(behavior) => {
match behavior {
DiscoveryOut::UnroutablePeer(other) |
DiscoveryOut::Discovered(other) => {
// Call `add_self_reported_address` to simulate identify
// happening.
let addr = swarms
.iter()
.find_map(|(s, a)| {
if s.behaviour().local_peer_id == other {
Some(a.clone())
} else {
None
}
})
.unwrap();
swarms[swarm_n]
.0
.behaviour_mut()
.add_self_reported_address(
&other,
[protocol_name_from_protocol_id(&protocol_id)]
.iter(),
addr,
);

to_discover[swarm_n].remove(&other);
},
DiscoveryOut::RandomKademliaStarted(_) => {},
e => {
panic!("Unexpected event: {:?}", e)
},
}
},
// ignore non Behaviour events
_ => {},
}
continue 'polling
},
Expand Down
10 changes: 10 additions & 0 deletions client/network/src/peer_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,11 @@ impl NetworkBehaviour for PeerInfoBehaviour {
address,
score,
}),
Poll::Ready(NetworkBehaviourAction::CloseConnection { peer_id, connection }) =>
return Poll::Ready(NetworkBehaviourAction::CloseConnection {
peer_id,
connection,
}),
}
}

Expand Down Expand Up @@ -372,6 +377,11 @@ impl NetworkBehaviour for PeerInfoBehaviour {
address,
score,
}),
Poll::Ready(NetworkBehaviourAction::CloseConnection { peer_id, connection }) =>
return Poll::Ready(NetworkBehaviourAction::CloseConnection {
peer_id,
connection,
}),
}
}

Expand Down
2 changes: 2 additions & 0 deletions client/network/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1575,6 +1575,8 @@ impl<B: BlockT> NetworkBehaviour for Protocol<B> {
}),
Poll::Ready(NetworkBehaviourAction::ReportObservedAddr { address, score }) =>
return Poll::Ready(NetworkBehaviourAction::ReportObservedAddr { address, score }),
Poll::Ready(NetworkBehaviourAction::CloseConnection { peer_id, connection }) =>
return Poll::Ready(NetworkBehaviourAction::CloseConnection { peer_id, connection }),
};

let outcome = match event {
Expand Down
Loading

0 comments on commit 6ac80d3

Please sign in to comment.