Skip to content

Commit

Permalink
ldap: add support for STARTTLS to make certificate information available
Browse files Browse the repository at this point in the history
Ticket: OISF#7394.
  • Loading branch information
chifflier authored and victorjulien committed Nov 26, 2024
1 parent 3341907 commit bd7d38e
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions rust/src/ldap/ldap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ static mut LDAP_MAX_TX: usize = LDAP_MAX_TX_DEFAULT;

static mut ALPROTO_LDAP: AppProto = ALPROTO_UNKNOWN;

const STARTTLS_OID: &str = "1.3.6.1.4.1.1466.20037";

#[derive(AppLayerFrameType)]
pub enum LdapFrameType {
Pdu,
Expand Down Expand Up @@ -92,6 +94,8 @@ pub struct LdapState {
response_frame: Option<Frame>,
request_gap: bool,
response_gap: bool,
request_tls: bool,
has_starttls: bool,
}

impl State<LdapTransaction> for LdapState {
Expand All @@ -115,6 +119,8 @@ impl LdapState {
response_frame: None,
request_gap: false,
response_gap: false,
request_tls: false,
has_starttls: false,
}
}

Expand Down Expand Up @@ -182,6 +188,13 @@ impl LdapState {
return AppLayerResult::ok();
}

if self.has_starttls {
unsafe {
AppLayerRequestProtocolTLSUpgrade(flow);
}
return AppLayerResult::ok();
}

if self.request_gap {
match ldap_parse_msg(input) {
Ok((_, msg)) => {
Expand Down Expand Up @@ -216,6 +229,12 @@ impl LdapState {
let mut tx = self.new_tx();
let tx_id = tx.id();
let request = LdapMessage::from(msg);
// check if STARTTLS was requested
if let ProtocolOp::ExtendedRequest(request) = &request.protocol_op {
if request.request_name.0 == STARTTLS_OID {
self.request_tls = true;
}
}
tx.complete = tx_is_complete(&request.protocol_op, Direction::ToServer);
tx.request = Some(request);
self.transactions.push_back(tx);
Expand Down Expand Up @@ -275,6 +294,17 @@ impl LdapState {
match ldap_parse_msg(start) {
Ok((rem, msg)) => {
let response = LdapMessage::from(msg);
// check if STARTTLS was requested
if self.request_tls {
if let ProtocolOp::ExtendedResponse(response) = &response.protocol_op
{
if response.result.result_code == ResultCode(0) {
SCLogDebug!("LDAP: STARTTLS detected");
self.has_starttls = true;
}
self.request_tls = false;
}
}
if let Some(tx) = self.find_request(response.message_id) {
tx.complete = tx_is_complete(&response.protocol_op, Direction::ToClient);
let tx_id = tx.id();
Expand Down

0 comments on commit bd7d38e

Please sign in to comment.