Crate sawp_ike

source
Expand description

An Internet Key Exchange (IKE) v1 and v2 parser.

Given bytes and a sawp::parser::Direction, it will attempt to parse the bytes and return a Message. The parser will inform the caller about errors if no message is returned and warnings if it was parsed but had nonstandard or erroneous data (see sawp::parser::Parse for details on possible return types).

This parser keeps state for the current session so it is expected to create one parser per session.

The following references were used to create this module:

ISAKMP

IKE v1

IKE v2 Fibre Channel

IKE v2

Group Key Management using IKEv2

§Example

use sawp::parser::{Direction, Parse};
use sawp::error::Error;
use sawp::error::ErrorKind;
use sawp_ike::{Ike, Message};

fn parse_bytes(input: &[u8]) -> std::result::Result<&[u8], Error> {
    let ike = Ike::default();
    let mut bytes = input;
    while bytes.len() > 0 {
        // If we know that this is a request or response, change the Direction
        // for a more accurate parsing
        match ike.parse(bytes, Direction::Unknown) {
            // The parser succeeded and returned the remaining bytes and the parsed ike message
            Ok((rest, Some(message))) => {
                println!("IKE message: {:?}", message);
                bytes = rest;
            }
            // The parser recognized that this might be ike and made some progress,
            // but more bytes are needed to parse a full message
            Ok((rest, None)) => return Ok(rest),
            // The parser was unable to determine whether this was ike or not and more
            // bytes are needed
            Err(Error { kind: ErrorKind::Incomplete(_) }) => return Ok(bytes),
            // The parser determined that this was not ike
            Err(e) => return Err(e)
        }
    }

    Ok(bytes)
}

Modules§

Structs§

  • If UDP encapsulation is present, the metadata associated with it is parsed.
  • Parser handle.
  • The parsed IKEv1 or v2 message

Enums§

  • Classes of errors that can be returned by this parser.
  • The parsed message.