Skip to content

Commit 2d75c35

Browse files
committed
feat(p2p/webrtc): signal encryption
re: #772
1 parent c749df2 commit 2d75c35

File tree

15 files changed

+175
-52
lines changed

15 files changed

+175
-52
lines changed

Cargo.lock

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node/native/src/http_server.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ pub async fn run(port: u16, rpc_sender: RpcSender) {
6565
false => StatusCode::OK,
6666
true => StatusCode::BAD_REQUEST,
6767
},
68+
P2pConnectionResponse::SignalDecryptionFailed => {
69+
StatusCode::BAD_REQUEST
70+
}
6871
P2pConnectionResponse::InternalError => {
6972
StatusCode::INTERNAL_SERVER_ERROR
7073
}

node/src/event_source/event_source_effects.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,12 @@ pub fn event_source_effects<S: Service>(store: &mut Store<S>, action: EventSourc
158158
error: P2pConnectionErrorResponse::Rejected(reason),
159159
});
160160
}
161+
P2pConnectionResponse::SignalDecryptionFailed => {
162+
store.dispatch(P2pConnectionOutgoingAction::AnswerRecvError {
163+
peer_id,
164+
error: P2pConnectionErrorResponse::SignalDecryptionFailed,
165+
});
166+
}
161167
P2pConnectionResponse::InternalError => {
162168
store.dispatch(P2pConnectionOutgoingAction::AnswerRecvError {
163169
peer_id,

node/src/rpc/rpc_effects.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,11 @@ pub fn rpc_effects<S: Service>(store: &mut Store<S>, action: RpcActionWithMeta)
293293
RpcAction::P2pConnectionIncomingRespond { rpc_id, response } => {
294294
let error = match &response {
295295
P2pConnectionResponse::Accepted(_) => None,
296-
P2pConnectionResponse::InternalError => Some("RemoteInternalError".to_owned()),
297296
P2pConnectionResponse::Rejected(reason) => Some(format!("Rejected({:?})", reason)),
297+
P2pConnectionResponse::SignalDecryptionFailed => {
298+
Some("RemoteSignalDecryptionFailed".to_owned())
299+
}
300+
P2pConnectionResponse::InternalError => Some("RemoteInternalError".to_owned()),
298301
};
299302
let _ = store
300303
.service

p2p/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ cfg-if = "1.0.0"
2323
url = "2.3.1"
2424
multihash = "0.18.1"
2525
sha2 = "0.10.6"
26-
# ecies-ed25519 = "0.5.1"
2726
ed25519-dalek = { version = "2.1.1", features = ["serde"] }
27+
x25519-dalek = { version = "2.0.1", features = ["static_secrets"] }
28+
aes-gcm = "0.10.3"
2829
faster-stun = { version = "1.0.1", optional = true }
2930
reqwest = { version = "0.11.22", optional = true }
3031
unsigned-varint = { version = "0.8.0" }

p2p/src/connection/mod.rs

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -17,55 +17,14 @@ pub use p2p_connection_service::*;
1717

1818
use serde::{Deserialize, Serialize};
1919

20-
use crate::webrtc;
21-
22-
#[derive(Serialize, Deserialize, Eq, PartialEq, Debug, Clone, Copy, thiserror::Error)]
23-
pub enum RejectionReason {
24-
#[error("peer_id does not match peer's public key")]
25-
PeerIdAndPublicKeyMismatch,
26-
#[error("target peer_id is not local node's peer_id")]
27-
TargetPeerIdNotMe,
28-
#[error("too many peers")]
29-
PeerCapacityFull,
30-
#[error("peer already connected")]
31-
AlreadyConnected,
32-
#[error("self connection detected")]
33-
ConnectingToSelf,
34-
}
35-
36-
impl RejectionReason {
37-
pub fn is_bad(&self) -> bool {
38-
match self {
39-
Self::PeerIdAndPublicKeyMismatch => true,
40-
Self::TargetPeerIdNotMe => true,
41-
Self::PeerCapacityFull => false,
42-
Self::AlreadyConnected => true,
43-
Self::ConnectingToSelf => false,
44-
}
45-
}
46-
}
20+
pub use crate::webrtc::{Answer, Offer, P2pConnectionResponse, RejectionReason};
4721

4822
#[derive(Serialize, Deserialize, Debug, Clone, thiserror::Error)]
4923
pub enum P2pConnectionErrorResponse {
5024
#[error("connection rejected: {0}")]
5125
Rejected(RejectionReason),
26+
#[error("signal decryption failed")]
27+
SignalDecryptionFailed,
5228
#[error("internal error")]
5329
InternalError,
5430
}
55-
56-
#[derive(Serialize, Deserialize, Debug, Clone)]
57-
pub enum P2pConnectionResponse {
58-
Accepted(Box<webrtc::Answer>),
59-
Rejected(RejectionReason),
60-
InternalError,
61-
}
62-
63-
impl P2pConnectionResponse {
64-
pub fn internal_error_str() -> &'static str {
65-
"InternalError"
66-
}
67-
68-
pub fn internal_error_json_str() -> &'static str {
69-
"\"InternalError\""
70-
}
71-
}

p2p/src/connection/outgoing/p2p_connection_outgoing_actions.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ impl redux::EnablingCondition<P2pState> for P2pConnectionOutgoingAction {
189189
matches!(s, P2pConnectionOutgoingState::OfferSdpCreatePending { .. })
190190
}
191191
P2pConnectionOutgoingError::Rejected(_)
192+
| P2pConnectionOutgoingError::RemoteSignalDecryptionFailed
192193
| P2pConnectionOutgoingError::RemoteInternalError => {
193194
matches!(s, P2pConnectionOutgoingState::AnswerRecvPending { .. })
194195
}

p2p/src/connection/outgoing/p2p_connection_outgoing_reducer.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,9 @@ impl P2pConnectionOutgoingState {
276276
P2pConnectionErrorResponse::Rejected(reason) => {
277277
P2pConnectionOutgoingError::Rejected(*reason)
278278
}
279+
P2pConnectionErrorResponse::SignalDecryptionFailed => {
280+
P2pConnectionOutgoingError::RemoteSignalDecryptionFailed
281+
}
279282
P2pConnectionErrorResponse::InternalError => {
280283
P2pConnectionOutgoingError::RemoteInternalError
281284
}

p2p/src/connection/outgoing/p2p_connection_outgoing_state.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ pub enum P2pConnectionOutgoingError {
125125
SdpCreateError(String),
126126
#[error("rejected: {0}")]
127127
Rejected(RejectionReason),
128+
#[error("remote signal decryption failed")]
129+
RemoteSignalDecryptionFailed,
128130
#[error("remote internal error")]
129131
RemoteInternalError,
130132
#[error("finalization error: {0}")]

p2p/src/identity/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ mod public_key;
55
pub use public_key::PublicKey;
66

77
mod secret_key;
8-
pub use secret_key::SecretKey;
8+
pub use secret_key::{EncryptableType, SecretKey};

0 commit comments

Comments
 (0)