From de2dfd1355a8a351ed6ae69c4bc0d945f8e31b47 Mon Sep 17 00:00:00 2001 From: Ruben De Smet Date: Thu, 9 Jul 2020 18:56:16 +0200 Subject: [PATCH] Add is_signal_key_encrypted, is_signal_service_envelope. --- libsignal-service/src/proto.rs | 38 ++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/libsignal-service/src/proto.rs b/libsignal-service/src/proto.rs index af7dd6d2f..ec11cd659 100644 --- a/libsignal-service/src/proto.rs +++ b/libsignal-service/src/proto.rs @@ -1 +1,39 @@ include!(concat!(env!("OUT_DIR"), "/signalservice.rs")); + +impl WebSocketRequestMessage { + /// Equivalent of + /// `SignalServiceMessagePipe::isSignalServiceEnvelope(WebSocketMessage)`. + fn is_signal_service_envelope(&self) -> bool { + self.verb.as_ref().map(std::ops::Deref::deref) == Some("PUT") + && self.path.as_ref().map(std::ops::Deref::deref) + == Some("/api/v1/message") + } + + /// Equivalent of + /// `SignalServiceMessagePipe::isSignalKeyEncrypted(WebSocketMessage)`. + fn is_signal_key_encrypted(&self) -> bool { + if self.headers.len() == 0 { + return true; + } + + for header in &self.headers { + let parts: Vec<_> = header.split(':').collect(); + if parts.len() != 2 { + log::warn!( + "Got a weird header: {:?}, split in {:?}", + header, + parts + ); + continue; + } + + if parts[0].trim().eq_ignore_ascii_case("X-Signal-Key") { + if parts[1].trim().eq_ignore_ascii_case("false") { + return false; + } + } + } + + false + } +}