rust: Update der, kerberos and snmp parser dependencies

- The update to der-parser allows us to use the latest API changes
pull/5149/head
Emmanuel Thompson 5 years ago committed by Victor Julien
parent dfcc8a88f6
commit 6b8517dc12

@ -30,12 +30,12 @@ num-traits = "0.2"
widestring = "0.4" widestring = "0.4"
md5 = "0.7.0" md5 = "0.7.0"
der-parser = "3.0" der-parser = "4.0"
kerberos-parser = "0.4" kerberos-parser = "0.5"
ntp-parser = "0.4" ntp-parser = "0.4"
ipsec-parser = "0.5" ipsec-parser = "0.5"
snmp-parser = "0.5" snmp-parser = "0.6"
tls-parser = "0.9" tls-parser = "0.9"
x509-parser = "0.6.5" x509-parser = "0.6.5"
libc = "0.2.67" libc = "0.2.67"

@ -23,6 +23,7 @@ use nom;
use nom::IResult; use nom::IResult;
use nom::number::streaming::be_u32; use nom::number::streaming::be_u32;
use der_parser::der::der_read_element_header; use der_parser::der::der_read_element_header;
use der_parser::ber::BerClass;
use kerberos_parser::krb5_parser; use kerberos_parser::krb5_parser;
use kerberos_parser::krb5::{EncryptionType,ErrorCode,MessageType,PrincipalName,Realm}; use kerberos_parser::krb5::{EncryptionType,ErrorCode,MessageType,PrincipalName,Realm};
use crate::applayer::{self, *}; use crate::applayer::{self, *};
@ -120,7 +121,7 @@ impl KRB5State {
match der_read_element_header(i) { match der_read_element_header(i) {
Ok((_rem,hdr)) => { Ok((_rem,hdr)) => {
// Kerberos messages start with an APPLICATION header // Kerberos messages start with an APPLICATION header
if hdr.class != 0b01 { return 0; } if hdr.class != BerClass::Application { return 0; }
match hdr.tag.0 { match hdr.tag.0 {
10 => { 10 => {
self.req_id = 10; self.req_id = 10;
@ -443,7 +444,7 @@ pub extern "C" fn rs_krb5_probing_parser(_flow: *const Flow,
match der_read_element_header(slice) { match der_read_element_header(slice) {
Ok((rem, ref hdr)) => { Ok((rem, ref hdr)) => {
// Kerberos messages start with an APPLICATION header // Kerberos messages start with an APPLICATION header
if hdr.class != 0b01 { return unsafe{ALPROTO_FAILED}; } if hdr.class != BerClass::Application { return unsafe{ALPROTO_FAILED}; }
// Tag number should be <= 30 // Tag number should be <= 30
if hdr.tag.0 >= 30 { return unsafe{ALPROTO_FAILED}; } if hdr.tag.0 >= 30 { return unsafe{ALPROTO_FAILED}; }
// Kerberos messages contain sequences // Kerberos messages contain sequences

@ -51,33 +51,33 @@ impl SNMPEvent {
} }
} }
pub struct SNMPState { pub struct SNMPState<'a> {
/// SNMP protocol version /// SNMP protocol version
pub version: u32, pub version: u32,
/// List of transactions for this session /// List of transactions for this session
transactions: Vec<SNMPTransaction>, transactions: Vec<SNMPTransaction<'a>>,
/// tx counter for assigning incrementing id's to tx's /// tx counter for assigning incrementing id's to tx's
tx_id: u64, tx_id: u64,
} }
pub struct SNMPPduInfo { pub struct SNMPPduInfo<'a> {
pub pdu_type: PduType, pub pdu_type: PduType,
pub err: ErrorStatus, pub err: ErrorStatus,
pub trap_type: Option<(TrapType,Oid,NetworkAddress)>, pub trap_type: Option<(TrapType,Oid<'a>,NetworkAddress)>,
pub vars: Vec<Oid>, pub vars: Vec<Oid<'a>>,
} }
pub struct SNMPTransaction { pub struct SNMPTransaction<'a> {
/// PDU version /// PDU version
pub version: u32, pub version: u32,
/// PDU info, if present (and cleartext) /// PDU info, if present (and cleartext)
pub info: Option<SNMPPduInfo>, pub info: Option<SNMPPduInfo<'a>>,
/// Community, if present (SNMPv2) /// Community, if present (SNMPv2)
pub community: Option<String>, pub community: Option<String>,
@ -103,8 +103,8 @@ pub struct SNMPTransaction {
impl SNMPState { impl<'a> SNMPState<'a> {
pub fn new() -> SNMPState { pub fn new() -> SNMPState<'a> {
SNMPState{ SNMPState{
version: 0, version: 0,
transactions: Vec::new(), transactions: Vec::new(),
@ -113,8 +113,8 @@ impl SNMPState {
} }
} }
impl Default for SNMPPduInfo { impl<'a> Default for SNMPPduInfo<'a> {
fn default() -> SNMPPduInfo { fn default() -> SNMPPduInfo<'a> {
SNMPPduInfo{ SNMPPduInfo{
pdu_type: PduType(0), pdu_type: PduType(0),
err: ErrorStatus::NoError, err: ErrorStatus::NoError,
@ -124,8 +124,8 @@ impl Default for SNMPPduInfo {
} }
} }
impl SNMPState { impl<'a> SNMPState<'a> {
fn add_pdu_info(&mut self, pdu: &SnmpPdu, tx: &mut SNMPTransaction) { fn add_pdu_info(&mut self, pdu: &SnmpPdu<'a>, tx: &mut SNMPTransaction<'a>) {
let mut pdu_info = SNMPPduInfo::default(); let mut pdu_info = SNMPPduInfo::default();
pdu_info.pdu_type = pdu.pdu_type(); pdu_info.pdu_type = pdu.pdu_type();
match *pdu { match *pdu {
@ -138,13 +138,14 @@ impl SNMPState {
pdu_info.trap_type = Some((t.generic_trap,t.enterprise.clone(),t.agent_addr.clone())); pdu_info.trap_type = Some((t.generic_trap,t.enterprise.clone(),t.agent_addr.clone()));
} }
} }
for ref var in pdu.vars_iter() {
pdu_info.vars.push(var.oid.clone()); for var in pdu.vars_iter() {
pdu_info.vars.push(var.oid.to_owned());
} }
tx.info = Some(pdu_info); tx.info = Some(pdu_info);
} }
fn handle_snmp_v12(&mut self, msg:SnmpMessage, _direction: u8) -> i32 { fn handle_snmp_v12(&mut self, msg: SnmpMessage<'a>, _direction: u8) -> i32 {
let mut tx = self.new_tx(); let mut tx = self.new_tx();
// in the message, version is encoded as 0 (version 1) or 1 (version 2) // in the message, version is encoded as 0 (version 1) or 1 (version 2)
if self.version != msg.version + 1 { if self.version != msg.version + 1 {
@ -157,7 +158,7 @@ impl SNMPState {
0 0
} }
fn handle_snmp_v3(&mut self, msg: SnmpV3Message, _direction: u8) -> i32 { fn handle_snmp_v3(&mut self, msg: SnmpV3Message<'a>, _direction: u8) -> i32 {
let mut tx = self.new_tx(); let mut tx = self.new_tx();
if self.version != msg.version { if self.version != msg.version {
SCLogDebug!("SNMP version mismatch: expected {}, received {}", self.version, msg.version); SCLogDebug!("SNMP version mismatch: expected {}, received {}", self.version, msg.version);
@ -186,7 +187,7 @@ impl SNMPState {
/// Parse an SNMP request message /// Parse an SNMP request message
/// ///
/// Returns 0 if successful, or -1 on error /// Returns 0 if successful, or -1 on error
fn parse(&mut self, i: &[u8], direction: u8) -> i32 { fn parse(&mut self, i: &'a [u8], direction: u8) -> i32 {
if self.version == 0 { if self.version == 0 {
match parse_pdu_enveloppe_version(i) { match parse_pdu_enveloppe_version(i) {
Ok((_,x)) => self.version = x, Ok((_,x)) => self.version = x,
@ -211,7 +212,7 @@ impl SNMPState {
self.transactions.clear(); self.transactions.clear();
} }
fn new_tx(&mut self) -> SNMPTransaction { fn new_tx(&mut self) -> SNMPTransaction<'a> {
self.tx_id += 1; self.tx_id += 1;
SNMPTransaction::new(self.version, self.tx_id) SNMPTransaction::new(self.version, self.tx_id)
} }
@ -264,8 +265,8 @@ impl SNMPState {
} }
} }
impl SNMPTransaction { impl<'a> SNMPTransaction<'a> {
pub fn new(version: u32, id: u64) -> SNMPTransaction { pub fn new(version: u32, id: u64) -> SNMPTransaction<'a> {
SNMPTransaction { SNMPTransaction {
version, version,
info: None, info: None,
@ -287,7 +288,7 @@ impl SNMPTransaction {
} }
} }
impl Drop for SNMPTransaction { impl<'a> Drop for SNMPTransaction<'a> {
fn drop(&mut self) { fn drop(&mut self) {
self.free(); self.free();
} }

Loading…
Cancel
Save