mirror of
https://github.com/Noratrieb/tls.git
synced 2026-01-14 08:35:03 +01:00
getting rejected :(
This commit is contained in:
parent
c71fc68d8e
commit
29057b8e92
3 changed files with 92 additions and 8 deletions
|
|
@ -15,9 +15,6 @@
|
||||||
llvmPackages_16.bintools
|
llvmPackages_16.bintools
|
||||||
llvmPackages_16.libllvm
|
llvmPackages_16.libllvm
|
||||||
rustup
|
rustup
|
||||||
pkg-config
|
|
||||||
sqlite
|
|
||||||
# openssl Explicitly no openssl!
|
|
||||||
];
|
];
|
||||||
# https://github.com/rust-lang/rust-bindgen#environment-variables
|
# https://github.com/rust-lang/rust-bindgen#environment-variables
|
||||||
LIBCLANG_PATH = pkgs.lib.makeLibraryPath [ pkgs.llvmPackages_latest.libclang.lib ];
|
LIBCLANG_PATH = pkgs.lib.makeLibraryPath [ pkgs.llvmPackages_latest.libclang.lib ];
|
||||||
|
|
@ -37,6 +34,7 @@
|
||||||
''-I${pkgs.glib.out}/lib/glib-2.0/include/''
|
''-I${pkgs.glib.out}/lib/glib-2.0/include/''
|
||||||
];
|
];
|
||||||
packages = (with pkgs; [
|
packages = (with pkgs; [
|
||||||
|
wireshark
|
||||||
]);
|
]);
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,9 @@ impl ClientSetupConnection {
|
||||||
plaintext.write(&mut stream)?;
|
plaintext.write(&mut stream)?;
|
||||||
stream.flush()?;
|
stream.flush()?;
|
||||||
|
|
||||||
|
let out = proto::TLSPlaintext::read(stream.get_mut())?;
|
||||||
|
dbg!(out);
|
||||||
|
|
||||||
// let res: proto::TLSPlaintext = proto::Value::read(&mut stream.get_mut())?;
|
// let res: proto::TLSPlaintext = proto::Value::read(&mut stream.get_mut())?;
|
||||||
// dbg!(res);
|
// dbg!(res);
|
||||||
|
|
||||||
|
|
@ -54,7 +57,7 @@ pub struct Error {
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum ErrorKind {
|
pub enum ErrorKind {
|
||||||
InvalidHandshake(Box<dyn Debug>),
|
InvalidFrame(Box<dyn Debug>),
|
||||||
Io(io::Error),
|
Io(io::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
91
src/proto.rs
91
src/proto.rs
|
|
@ -15,7 +15,9 @@ pub enum TLSPlaintext {
|
||||||
fragment: List<u8, u16>,
|
fragment: List<u8, u16>,
|
||||||
},
|
},
|
||||||
ChangeCipherSpec,
|
ChangeCipherSpec,
|
||||||
Alert,
|
Alert {
|
||||||
|
alert: Alert,
|
||||||
|
},
|
||||||
Handshake {
|
Handshake {
|
||||||
handshake: Handshake,
|
handshake: Handshake,
|
||||||
},
|
},
|
||||||
|
|
@ -23,6 +25,12 @@ pub enum TLSPlaintext {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TLSPlaintext {
|
impl TLSPlaintext {
|
||||||
|
const INVALID: u8 = 0;
|
||||||
|
const CHANGE_CIPHER_SPEC: u8 = 20;
|
||||||
|
const ALERT: u8 = 21;
|
||||||
|
const HANDSHAKE: u8 = 22;
|
||||||
|
const APPLICATION_DATA: u8 = 23;
|
||||||
|
|
||||||
pub fn write(&self, w: &mut impl Write) -> io::Result<()> {
|
pub fn write(&self, w: &mut impl Write) -> io::Result<()> {
|
||||||
match self {
|
match self {
|
||||||
TLSPlaintext::Invalid {
|
TLSPlaintext::Invalid {
|
||||||
|
|
@ -30,9 +38,9 @@ impl TLSPlaintext {
|
||||||
fragment,
|
fragment,
|
||||||
} => todo!(),
|
} => todo!(),
|
||||||
TLSPlaintext::ChangeCipherSpec => todo!(),
|
TLSPlaintext::ChangeCipherSpec => todo!(),
|
||||||
TLSPlaintext::Alert => todo!(),
|
TLSPlaintext::Alert { alert } => todo!(),
|
||||||
TLSPlaintext::Handshake { handshake } => {
|
TLSPlaintext::Handshake { handshake } => {
|
||||||
22u8.write(w)?; // handshake
|
Self::HANDSHAKE.write(w)?; // handshake
|
||||||
LEGACY_VERSION.write(w)?;
|
LEGACY_VERSION.write(w)?;
|
||||||
let len: u16 = handshake.byte_size().try_into().unwrap();
|
let len: u16 = handshake.byte_size().try_into().unwrap();
|
||||||
len.write(w)?;
|
len.write(w)?;
|
||||||
|
|
@ -42,6 +50,28 @@ impl TLSPlaintext {
|
||||||
TLSPlaintext::ApplicationData => todo!(),
|
TLSPlaintext::ApplicationData => todo!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn read(r: &mut impl Read) -> crate::Result<Self> {
|
||||||
|
let discr = u8::read(r)?;
|
||||||
|
let _legacy_version = ProtocolVersion::read(r)?;
|
||||||
|
let _len = u16::read(r)?;
|
||||||
|
match discr {
|
||||||
|
Self::INVALID => todo!(),
|
||||||
|
Self::CHANGE_CIPHER_SPEC => todo!(),
|
||||||
|
Self::ALERT => {
|
||||||
|
let alert = Alert::read(r)?;
|
||||||
|
Ok(Self::Alert { alert })
|
||||||
|
}
|
||||||
|
Self::HANDSHAKE => todo!(),
|
||||||
|
Self::APPLICATION_DATA => todo!(),
|
||||||
|
_ => {
|
||||||
|
return Err(crate::ErrorKind::InvalidFrame(Box::new(format!(
|
||||||
|
"Invalid record discriminant: {discr}"
|
||||||
|
)))
|
||||||
|
.into())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type ProtocolVersion = u16;
|
pub type ProtocolVersion = u16;
|
||||||
|
|
@ -134,6 +164,55 @@ proto_enum! {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
proto_struct! {
|
||||||
|
#[derive(Debug, Clone, Copy)]
|
||||||
|
pub struct Alert {
|
||||||
|
level: AlertLevel,
|
||||||
|
description: AlertDescription,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
proto_enum! {
|
||||||
|
#[derive(Debug, Clone, Copy)]
|
||||||
|
pub enum AlertLevel: u8 {
|
||||||
|
Warning = 1,
|
||||||
|
Fatal = 2,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
proto_enum! {
|
||||||
|
#[derive(Debug, Clone, Copy)]
|
||||||
|
pub enum AlertDescription: u8 {
|
||||||
|
CloseNotify = 0,
|
||||||
|
UnexpectedMessage = 10,
|
||||||
|
BadRecordMac = 20,
|
||||||
|
RecordOverflow = 22,
|
||||||
|
HandshakeFailure = 40,
|
||||||
|
BadCertificate = 42,
|
||||||
|
UnsupportedCertificate = 43,
|
||||||
|
CertificateRevoked = 44,
|
||||||
|
CertificateExpired = 45,
|
||||||
|
CertificateUnknown = 46,
|
||||||
|
IllegalParameter = 47,
|
||||||
|
UnknownCa = 48,
|
||||||
|
AccessDenied = 49,
|
||||||
|
DecodeError = 50,
|
||||||
|
DecryptError = 51,
|
||||||
|
ProtocolVersion = 70,
|
||||||
|
InsufficientSecurity = 71,
|
||||||
|
InternalError = 80,
|
||||||
|
InappropriateFallback = 86,
|
||||||
|
UserCanceled = 90,
|
||||||
|
MissingExtension = 109,
|
||||||
|
UnsupportedExtension = 110,
|
||||||
|
UnrecognizedName = 112,
|
||||||
|
BadCertificateStatusResponse = 113,
|
||||||
|
UnknownPskIdentity = 115,
|
||||||
|
CertificateRequired = 116,
|
||||||
|
NoApplicationProtocol = 120,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
macro_rules! proto_struct {
|
macro_rules! proto_struct {
|
||||||
{$(#[$meta:meta])* pub struct $name:ident {
|
{$(#[$meta:meta])* pub struct $name:ident {
|
||||||
$(
|
$(
|
||||||
|
|
@ -165,6 +244,10 @@ macro_rules! proto_struct {
|
||||||
)*
|
)*
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn byte_size(&self) -> usize {
|
||||||
|
$( self.$field_name.byte_size() + )* 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -238,7 +321,7 @@ macro_rules! proto_enum {
|
||||||
},
|
},
|
||||||
)*
|
)*
|
||||||
|
|
||||||
_ => Err(ErrorKind::InvalidHandshake(Box::new(kind)).into()),
|
_ => Err(ErrorKind::InvalidFrame(Box::new(kind)).into()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue