From 313011ca5b56a36ad1cbfe01535a096ca9cc7e80 Mon Sep 17 00:00:00 2001 From: megumish Date: Mon, 5 Sep 2022 12:06:29 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=E3=83=91=E3=82=B1=E3=83=83=E3=83=88?= =?UTF-8?q?=E3=82=92=E8=AA=AD=E3=81=BF=E8=BE=BC=E3=81=BF=E3=81=8A=E3=82=8F?= =?UTF-8?q?=E3=81=A3=E3=81=9F=E3=82=89=E7=A0=B4=E6=A3=84=E3=81=99=E3=82=8B?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/refuic-endpoint/src/crypto_kit.rs | 4 +++- crates/refuic-endpoint/src/lib.rs | 4 ++-- crates/refuic-frame/src/frame.rs | 8 ++++++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/crates/refuic-endpoint/src/crypto_kit.rs b/crates/refuic-endpoint/src/crypto_kit.rs index 22c73a2..a83cce2 100644 --- a/crates/refuic-endpoint/src/crypto_kit.rs +++ b/crates/refuic-endpoint/src/crypto_kit.rs @@ -111,7 +111,9 @@ impl CryptoKit { self.client_server_names = Vec::new(); return Ok(()); } - Err(NegotiationError::NoCertificateServerName) + // client_server_names が空の場合は空の文字列を詰めておく + self.server_name = Some(b"".to_vec()); + Ok(()) } pub(crate) fn is_negotiated_server_name(&self) -> bool { self.client_server_names.is_empty() && self.server_name.is_some() diff --git a/crates/refuic-endpoint/src/lib.rs b/crates/refuic-endpoint/src/lib.rs index 8004cb0..f38a3e7 100644 --- a/crates/refuic-endpoint/src/lib.rs +++ b/crates/refuic-endpoint/src/lib.rs @@ -104,9 +104,9 @@ where unimplemented!("recv no support version packet") } Err(e) => return Err(e).map_err(Into::into), - Ok(packet_length) => { + Ok(_) => { // bufを消費して次のパケットに進む - let _ = buf.drain(..packet_length); + buf = Vec::new(); continue; } } diff --git a/crates/refuic-frame/src/frame.rs b/crates/refuic-frame/src/frame.rs index 35c2dad..8510f48 100644 --- a/crates/refuic-frame/src/frame.rs +++ b/crates/refuic-frame/src/frame.rs @@ -50,6 +50,8 @@ pub enum FrameRfc9000 { impl FrameRfc9000 { pub fn to_vec(&self) -> Vec { match self { + Self::Padding => vec![0x00], + Self::Ping => vec![0x01], Self::Crypto(f) => { let frame_type = VarInt::try_new(6).unwrap(); [frame_type.to_vec(), f.to_vec()].concat() @@ -64,6 +66,8 @@ impl FrameRfc9000 { pub fn vec_len(&self) -> usize { match self { + Self::Padding => 1, + Self::Ping => 1, Self::Crypto(f) => { let frame_type = VarInt::try_new(6).unwrap(); frame_type.len() + f.vec_len() @@ -72,7 +76,6 @@ impl FrameRfc9000 { let frame_type = f.frame_type(); frame_type.len() + f.vec_len() } - Self::Padding => 1, _ => unimplemented!(), } } @@ -86,8 +89,9 @@ pub fn parse_from_bytes_v1(bytes: &[u8]) -> Result, ParseFrame while sum_of_length < length { let frame_type = input.read_var_int()?; let frame = match frame_type.u64() { - 6 => FrameRfc9000::Crypto(read_crypto_frame(&mut input)?), 0 => FrameRfc9000::Padding, + 1 => FrameRfc9000::Ping, + 6 => FrameRfc9000::Crypto(read_crypto_frame(&mut input)?), _ => unimplemented!(), }; sum_of_length += frame_type.len() + frame.vec_len();