mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-30 10:47:55 +00:00
RUSTSEC-2021-0076 bump libsecp256k1 (#9391)
* 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 <bkchr@users.noreply.github.com>
This commit is contained in:
@@ -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)
|
||||
})
|
||||
@@ -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
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
@@ -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 {
|
||||
@@ -741,7 +741,7 @@ impl NetworkBehaviour for DiscoveryBehaviour {
|
||||
}
|
||||
},
|
||||
},
|
||||
KademliaEvent::QueryResult {
|
||||
KademliaEvent::OutboundQueryCompleted {
|
||||
result: QueryResult::GetRecord(res),
|
||||
stats,
|
||||
..
|
||||
@@ -778,7 +778,7 @@ impl NetworkBehaviour for DiscoveryBehaviour {
|
||||
};
|
||||
return Poll::Ready(NetworkBehaviourAction::GenerateEvent(ev))
|
||||
},
|
||||
KademliaEvent::QueryResult {
|
||||
KademliaEvent::OutboundQueryCompleted {
|
||||
result: QueryResult::PutRecord(res),
|
||||
stats,
|
||||
..
|
||||
@@ -799,7 +799,7 @@ impl NetworkBehaviour for DiscoveryBehaviour {
|
||||
};
|
||||
return Poll::Ready(NetworkBehaviourAction::GenerateEvent(ev))
|
||||
},
|
||||
KademliaEvent::QueryResult {
|
||||
KademliaEvent::OutboundQueryCompleted {
|
||||
result: QueryResult::RepublishRecord(res),
|
||||
..
|
||||
} => match res {
|
||||
@@ -830,6 +830,11 @@ impl NetworkBehaviour for DiscoveryBehaviour {
|
||||
address,
|
||||
score,
|
||||
}),
|
||||
NetworkBehaviourAction::CloseConnection { peer_id, connection } =>
|
||||
return Poll::Ready(NetworkBehaviourAction::CloseConnection {
|
||||
peer_id,
|
||||
connection,
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -862,6 +867,11 @@ impl NetworkBehaviour for DiscoveryBehaviour {
|
||||
address,
|
||||
score,
|
||||
}),
|
||||
NetworkBehaviourAction::CloseConnection { peer_id, connection } =>
|
||||
return Poll::Ready(NetworkBehaviourAction::CloseConnection {
|
||||
peer_id,
|
||||
connection,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -931,7 +941,7 @@ mod tests {
|
||||
},
|
||||
identity::Keypair,
|
||||
noise,
|
||||
swarm::Swarm,
|
||||
swarm::{Swarm, SwarmEvent},
|
||||
yamux, Multiaddr, PeerId,
|
||||
};
|
||||
use std::{collections::HashSet, task::Poll};
|
||||
@@ -1000,32 +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,
|
||||
);
|
||||
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)
|
||||
to_discover[swarm_n].remove(&other);
|
||||
},
|
||||
DiscoveryOut::RandomKademliaStarted(_) => {},
|
||||
e => {
|
||||
panic!("Unexpected event: {:?}", e)
|
||||
},
|
||||
}
|
||||
},
|
||||
// ignore non Behaviour events
|
||||
_ => {},
|
||||
}
|
||||
continue 'polling
|
||||
},
|
||||
|
||||
@@ -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,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -373,6 +378,11 @@ impl NetworkBehaviour for PeerInfoBehaviour {
|
||||
address,
|
||||
score,
|
||||
}),
|
||||
Poll::Ready(NetworkBehaviourAction::CloseConnection { peer_id, connection }) =>
|
||||
return Poll::Ready(NetworkBehaviourAction::CloseConnection {
|
||||
peer_id,
|
||||
connection,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -30,7 +30,7 @@ use libp2p::{
|
||||
identity, noise,
|
||||
swarm::{
|
||||
IntoProtocolsHandler, NetworkBehaviour, NetworkBehaviourAction, PollParameters,
|
||||
ProtocolsHandler, Swarm,
|
||||
ProtocolsHandler, Swarm, SwarmEvent,
|
||||
},
|
||||
yamux, Multiaddr, PeerId, Transport,
|
||||
};
|
||||
@@ -262,8 +262,8 @@ fn reconnect_after_disconnect() {
|
||||
loop {
|
||||
// Grab next event from services.
|
||||
let event = {
|
||||
let s1 = service1.next();
|
||||
let s2 = service2.next();
|
||||
let s1 = service1.select_next_some();
|
||||
let s2 = service2.select_next_some();
|
||||
futures::pin_mut!(s1, s2);
|
||||
match future::select(s1, s2).await {
|
||||
future::Either::Left((ev, _)) => future::Either::Left(ev),
|
||||
@@ -272,48 +272,52 @@ fn reconnect_after_disconnect() {
|
||||
};
|
||||
|
||||
match event {
|
||||
future::Either::Left(NotificationsOut::CustomProtocolOpen { .. }) =>
|
||||
match service1_state {
|
||||
ServiceState::NotConnected => {
|
||||
service1_state = ServiceState::FirstConnec;
|
||||
if service2_state == ServiceState::FirstConnec {
|
||||
service1.behaviour_mut().disconnect_peer(
|
||||
Swarm::local_peer_id(&service2),
|
||||
sc_peerset::SetId::from(0),
|
||||
);
|
||||
}
|
||||
},
|
||||
ServiceState::Disconnected => service1_state = ServiceState::ConnectedAgain,
|
||||
ServiceState::FirstConnec | ServiceState::ConnectedAgain => panic!(),
|
||||
future::Either::Left(SwarmEvent::Behaviour(
|
||||
NotificationsOut::CustomProtocolOpen { .. },
|
||||
)) => match service1_state {
|
||||
ServiceState::NotConnected => {
|
||||
service1_state = ServiceState::FirstConnec;
|
||||
if service2_state == ServiceState::FirstConnec {
|
||||
service1.behaviour_mut().disconnect_peer(
|
||||
Swarm::local_peer_id(&service2),
|
||||
sc_peerset::SetId::from(0),
|
||||
);
|
||||
}
|
||||
},
|
||||
future::Either::Left(NotificationsOut::CustomProtocolClosed { .. }) =>
|
||||
match service1_state {
|
||||
ServiceState::FirstConnec => service1_state = ServiceState::Disconnected,
|
||||
ServiceState::ConnectedAgain |
|
||||
ServiceState::NotConnected |
|
||||
ServiceState::Disconnected => panic!(),
|
||||
},
|
||||
future::Either::Right(NotificationsOut::CustomProtocolOpen { .. }) =>
|
||||
match service2_state {
|
||||
ServiceState::NotConnected => {
|
||||
service2_state = ServiceState::FirstConnec;
|
||||
if service1_state == ServiceState::FirstConnec {
|
||||
service1.behaviour_mut().disconnect_peer(
|
||||
Swarm::local_peer_id(&service2),
|
||||
sc_peerset::SetId::from(0),
|
||||
);
|
||||
}
|
||||
},
|
||||
ServiceState::Disconnected => service2_state = ServiceState::ConnectedAgain,
|
||||
ServiceState::FirstConnec | ServiceState::ConnectedAgain => panic!(),
|
||||
},
|
||||
future::Either::Right(NotificationsOut::CustomProtocolClosed { .. }) =>
|
||||
match service2_state {
|
||||
ServiceState::FirstConnec => service2_state = ServiceState::Disconnected,
|
||||
ServiceState::ConnectedAgain |
|
||||
ServiceState::NotConnected |
|
||||
ServiceState::Disconnected => panic!(),
|
||||
ServiceState::Disconnected => service1_state = ServiceState::ConnectedAgain,
|
||||
ServiceState::FirstConnec | ServiceState::ConnectedAgain => panic!(),
|
||||
},
|
||||
future::Either::Left(SwarmEvent::Behaviour(
|
||||
NotificationsOut::CustomProtocolClosed { .. },
|
||||
)) => match service1_state {
|
||||
ServiceState::FirstConnec => service1_state = ServiceState::Disconnected,
|
||||
ServiceState::ConnectedAgain |
|
||||
ServiceState::NotConnected |
|
||||
ServiceState::Disconnected => panic!(),
|
||||
},
|
||||
future::Either::Right(SwarmEvent::Behaviour(
|
||||
NotificationsOut::CustomProtocolOpen { .. },
|
||||
)) => match service2_state {
|
||||
ServiceState::NotConnected => {
|
||||
service2_state = ServiceState::FirstConnec;
|
||||
if service1_state == ServiceState::FirstConnec {
|
||||
service1.behaviour_mut().disconnect_peer(
|
||||
Swarm::local_peer_id(&service2),
|
||||
sc_peerset::SetId::from(0),
|
||||
);
|
||||
}
|
||||
},
|
||||
ServiceState::Disconnected => service2_state = ServiceState::ConnectedAgain,
|
||||
ServiceState::FirstConnec | ServiceState::ConnectedAgain => panic!(),
|
||||
},
|
||||
future::Either::Right(SwarmEvent::Behaviour(
|
||||
NotificationsOut::CustomProtocolClosed { .. },
|
||||
)) => match service2_state {
|
||||
ServiceState::FirstConnec => service2_state = ServiceState::Disconnected,
|
||||
ServiceState::ConnectedAgain |
|
||||
ServiceState::NotConnected |
|
||||
ServiceState::Disconnected => panic!(),
|
||||
},
|
||||
_ => {},
|
||||
}
|
||||
|
||||
@@ -331,8 +335,8 @@ fn reconnect_after_disconnect() {
|
||||
loop {
|
||||
// Grab next event from services.
|
||||
let event = {
|
||||
let s1 = service1.next();
|
||||
let s2 = service2.next();
|
||||
let s1 = service1.select_next_some();
|
||||
let s2 = service2.select_next_some();
|
||||
futures::pin_mut!(s1, s2);
|
||||
match future::select(future::select(s1, s2), &mut delay).await {
|
||||
future::Either::Right(_) => break, // success
|
||||
@@ -342,8 +346,8 @@ fn reconnect_after_disconnect() {
|
||||
};
|
||||
|
||||
match event {
|
||||
NotificationsOut::CustomProtocolOpen { .. } |
|
||||
NotificationsOut::CustomProtocolClosed { .. } => panic!(),
|
||||
SwarmEvent::Behaviour(NotificationsOut::CustomProtocolOpen { .. }) |
|
||||
SwarmEvent::Behaviour(NotificationsOut::CustomProtocolClosed { .. }) => panic!(),
|
||||
_ => {},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -385,7 +385,7 @@ where
|
||||
|
||||
fn upgrade_outbound(self, mut socket: TSubstream, negotiated_name: Self::Info) -> Self::Future {
|
||||
Box::pin(async move {
|
||||
upgrade::write_with_len_prefix(&mut socket, &self.initial_message).await?;
|
||||
upgrade::write_length_prefixed(&mut socket, &self.initial_message).await?;
|
||||
|
||||
// Reading handshake.
|
||||
let handshake_len = unsigned_varint::aio::read_usize(&mut socket).await?;
|
||||
|
||||
@@ -567,6 +567,11 @@ impl NetworkBehaviour for RequestResponsesBehaviour {
|
||||
address,
|
||||
score,
|
||||
}),
|
||||
NetworkBehaviourAction::CloseConnection { peer_id, connection } =>
|
||||
return Poll::Ready(NetworkBehaviourAction::CloseConnection {
|
||||
peer_id,
|
||||
connection,
|
||||
}),
|
||||
};
|
||||
|
||||
match ev {
|
||||
@@ -1009,7 +1014,7 @@ mod tests {
|
||||
let (mut swarm, _) = swarms.remove(0);
|
||||
async move {
|
||||
loop {
|
||||
match swarm.next_event().await {
|
||||
match swarm.select_next_some().await {
|
||||
SwarmEvent::Behaviour(Event::InboundRequest { result, .. }) => {
|
||||
result.unwrap();
|
||||
},
|
||||
@@ -1028,7 +1033,7 @@ mod tests {
|
||||
let mut response_receiver = None;
|
||||
|
||||
loop {
|
||||
match swarm.next_event().await {
|
||||
match swarm.select_next_some().await {
|
||||
SwarmEvent::ConnectionEstablished { peer_id, .. } => {
|
||||
let (sender, receiver) = oneshot::channel();
|
||||
swarm.behaviour_mut().send_request(
|
||||
@@ -1106,7 +1111,7 @@ mod tests {
|
||||
let (mut swarm, _) = swarms.remove(0);
|
||||
async move {
|
||||
loop {
|
||||
match swarm.next_event().await {
|
||||
match swarm.select_next_some().await {
|
||||
SwarmEvent::Behaviour(Event::InboundRequest { result, .. }) => {
|
||||
assert!(result.is_ok());
|
||||
break
|
||||
@@ -1126,7 +1131,7 @@ mod tests {
|
||||
let mut response_receiver = None;
|
||||
|
||||
loop {
|
||||
match swarm.next_event().await {
|
||||
match swarm.select_next_some().await {
|
||||
SwarmEvent::ConnectionEstablished { peer_id, .. } => {
|
||||
let (sender, receiver) = oneshot::channel();
|
||||
swarm.behaviour_mut().send_request(
|
||||
@@ -1226,7 +1231,7 @@ mod tests {
|
||||
.spawn_obj(
|
||||
async move {
|
||||
loop {
|
||||
match swarm_2.next_event().await {
|
||||
match swarm_2.select_next_some().await {
|
||||
SwarmEvent::Behaviour(Event::InboundRequest { result, .. }) => {
|
||||
result.unwrap();
|
||||
},
|
||||
@@ -1279,7 +1284,7 @@ mod tests {
|
||||
let mut num_responses = 0;
|
||||
|
||||
loop {
|
||||
match swarm_1.next_event().await {
|
||||
match swarm_1.select_next_some().await {
|
||||
SwarmEvent::ConnectionEstablished { peer_id, .. } => {
|
||||
let (sender_1, receiver_1) = oneshot::channel();
|
||||
let (sender_2, receiver_2) = oneshot::channel();
|
||||
|
||||
@@ -1631,7 +1631,7 @@ impl<B: BlockT + 'static, H: ExHashT> Future for NetworkWorker<B, H> {
|
||||
}
|
||||
|
||||
// Process the next action coming from the network.
|
||||
let next_event = this.network_service.next_event();
|
||||
let next_event = this.network_service.select_next_some();
|
||||
futures::pin_mut!(next_event);
|
||||
let poll_value = next_event.poll_unpin(cx);
|
||||
|
||||
@@ -1919,14 +1919,14 @@ impl<B: BlockT + 'static, H: ExHashT> Future for NetworkWorker<B, H> {
|
||||
}
|
||||
}
|
||||
},
|
||||
Poll::Ready(SwarmEvent::NewListenAddr(addr)) => {
|
||||
trace!(target: "sub-libp2p", "Libp2p => NewListenAddr({})", addr);
|
||||
Poll::Ready(SwarmEvent::NewListenAddr { address, .. }) => {
|
||||
trace!(target: "sub-libp2p", "Libp2p => NewListenAddr({})", address);
|
||||
if let Some(metrics) = this.metrics.as_ref() {
|
||||
metrics.listeners_local_addresses.inc();
|
||||
}
|
||||
},
|
||||
Poll::Ready(SwarmEvent::ExpiredListenAddr(addr)) => {
|
||||
info!(target: "sub-libp2p", "📪 No longer listening on {}", addr);
|
||||
Poll::Ready(SwarmEvent::ExpiredListenAddr { address, .. }) => {
|
||||
info!(target: "sub-libp2p", "📪 No longer listening on {}", address);
|
||||
if let Some(metrics) = this.metrics.as_ref() {
|
||||
metrics.listeners_local_addresses.dec();
|
||||
}
|
||||
@@ -2008,11 +2008,9 @@ impl<B: BlockT + 'static, H: ExHashT> Future for NetworkWorker<B, H> {
|
||||
.inc();
|
||||
}
|
||||
},
|
||||
Poll::Ready(SwarmEvent::UnknownPeerUnreachableAddr { address, error }) => {
|
||||
trace!(target: "sub-libp2p", "Libp2p => UnknownPeerUnreachableAddr({}): {}",
|
||||
address, error)
|
||||
},
|
||||
Poll::Ready(SwarmEvent::ListenerClosed { reason, addresses }) => {
|
||||
Poll::Ready(SwarmEvent::UnknownPeerUnreachableAddr { address, error }) =>
|
||||
trace!(target: "sub-libp2p", "Libp2p => UnknownPeerUnreachableAddr({}): {}", address, error),
|
||||
Poll::Ready(SwarmEvent::ListenerClosed { reason, addresses, .. }) => {
|
||||
if let Some(metrics) = this.metrics.as_ref() {
|
||||
metrics.listeners_local_addresses.sub(addresses.len() as u64);
|
||||
}
|
||||
@@ -2031,7 +2029,7 @@ impl<B: BlockT + 'static, H: ExHashT> Future for NetworkWorker<B, H> {
|
||||
),
|
||||
}
|
||||
},
|
||||
Poll::Ready(SwarmEvent::ListenerError { error }) => {
|
||||
Poll::Ready(SwarmEvent::ListenerError { error, .. }) => {
|
||||
debug!(target: "sub-libp2p", "Libp2p => ListenerError: {}", error);
|
||||
if let Some(metrics) = this.metrics.as_ref() {
|
||||
metrics.listeners_errors_total.inc();
|
||||
|
||||
Reference in New Issue
Block a user