suricata
util-decode-asn1.c File Reference
#include "suricata.h"
#include "suricata-common.h"
#include "decode.h"
#include "util-debug.h"
#include "util-unittest.h"
#include "util-print.h"
#include "util-decode-asn1.h"
#include "conf.h"
Include dependency graph for util-decode-asn1.c:

Go to the source code of this file.

Functions

void SCAsn1LoadConfig ()
 
uint8_t SCAsn1DecodeContent (Asn1Ctx *ac)
 Check the content length and perform other inspections and decodings if necessary. More...
 
uint8_t SCAsn1DecodeLength (Asn1Ctx *ac)
 Decode and check the length, of the current node that we are parsing, also check invalid opts. More...
 
uint8_t SCAsn1DecodeIdentifier (Asn1Ctx *ac)
 Decode and check the identifier information of the current node that we are parsing, also check invalid opts. More...
 
void SCPrintByteBin (uint8_t byte)
 Helper function that print the bits of a byte to check encoding internals. More...
 
uint8_t SCAsn1CheckBounds (Asn1Ctx *ac)
 check if we have remaining data available, otherwise the parser should stop More...
 
Asn1CtxSCAsn1CtxNew (void)
 Create a new ASN1 Parsing context. More...
 
void SCAsn1CtxDestroy (Asn1Ctx *ac)
 Destroy an ASN1 Parsing context. More...
 
void SCAsn1CtxInit (Asn1Ctx *ac, uint8_t *data, uint16_t length)
 Initialize the data of the ASN1 parser ctx with the asn1 raw buffer. More...
 
uint8_t SCAsn1Decode (Asn1Ctx *ac, uint16_t node_id)
 Decode the nodes/frames located at certain position/level. More...
 
void DecodeAsn1RegisterTests (void)
 

Variables

uint16_t asn1_max_frames_config = ASN1_MAX_FRAMES
 

Detailed Description

Author
Pablo Rincon Crespo pablo.nosp@m..rin.nosp@m.con.c.nosp@m.resp.nosp@m.o@gma.nosp@m.il.c.nosp@m.om

Implements ASN1 decoding (needed for the asn1 keyword, BER, CER & DER)

Definition in file util-decode-asn1.c.

Function Documentation

void DecodeAsn1RegisterTests ( void  )

Definition at line 888 of file util-decode-asn1.c.

References UtRegisterTest().

Here is the call graph for this function:

uint8_t SCAsn1CheckBounds ( Asn1Ctx ac)

check if we have remaining data available, otherwise the parser should stop

Parameters
acAsn1Ctx pointer initialized
Return values
1if we are out of bounds, 0 if not

Definition at line 335 of file util-decode-asn1.c.

References ASN1_PARSER_ERR, ASN1_PARSER_OK, Asn1Ctx_::data, Asn1Ctx_::end, and Asn1Ctx_::iter.

Referenced by SCAsn1Decode(), SCAsn1DecodeIdentifier(), SCAsn1DecodeLength(), and SCAsn1LoadConfig().

Here is the caller graph for this function:

void SCAsn1CtxDestroy ( Asn1Ctx ac)

Destroy an ASN1 Parsing context.

Parameters
Asn1Ctxpointer to the new ctx

Definition at line 371 of file util-decode-asn1.c.

References asn1_max_frames_config, Asn1Ctx_::asn1_stack, ASN1CTX_GET_NODE, SCFree, and SCMalloc.

Referenced by DetectAsn1Register(), and SCAsn1Decode().

Here is the caller graph for this function:

void SCAsn1CtxInit ( Asn1Ctx ac,
uint8_t *  data,
uint16_t  length 
)

Initialize the data of the ASN1 parser ctx with the asn1 raw buffer.

Parameters
acpointer to the ASN1 ctx
datapointer to the data to process (binary raw of asn1)
lengthlength of the asn1 raw buffer
Return values
void

Definition at line 422 of file util-decode-asn1.c.

References ASN1_STATUS_OK, Asn1Ctx_::data, Asn1Ctx_::end, Asn1Ctx_::iter, Asn1Ctx_::len, length, and Asn1Ctx_::parser_status.

Referenced by DetectAsn1Register(), and SCAsn1Decode().

Here is the caller graph for this function:

Asn1Ctx* SCAsn1CtxNew ( void  )

Create a new ASN1 Parsing context.

Return values
Asn1Ctxpointer to the new ctx

Definition at line 346 of file util-decode-asn1.c.

References asn1_max_frames_config, Asn1Ctx_::asn1_stack, SC_ERR_MEM_ALLOC, SCFree, SCLogError, SCMalloc, and unlikely.

Referenced by DetectAsn1Register(), and SCAsn1Decode().

Here is the caller graph for this function:

uint8_t SCAsn1Decode ( Asn1Ctx ac,
uint16_t  node_id 
)
uint8_t SCAsn1DecodeContent ( Asn1Ctx ac)

Check the content length and perform other inspections and decodings if necessary.

Parameters
acpointer to the ASN1 Context data
Return values
byteof the status of the parser

Definition at line 175 of file util-decode-asn1.c.

References ASN1_BER_LEN_INDEFINITE, ASN1_NODE_IS_EOC, ASN1_PARSER_OK, ASN1CTX_CUR_NODE, Asn1Node_::data, Asn1Ctx_::end, Asn1Node_::flags, Asn1Len_::form, Asn1Ctx_::iter, Asn1Len_::len, Asn1Data_::len, Asn1Node_::len, and Asn1Data_::ptr.

Referenced by SCAsn1Decode().

Here is the caller graph for this function:

uint8_t SCAsn1DecodeIdentifier ( Asn1Ctx ac)

Decode and check the identifier information of the current node that we are parsing, also check invalid opts.

Parameters
acpointer to the ASN1 Context data
Return values
byteof the status of the parser

Definition at line 285 of file util-decode-asn1.c.

References ASN1_BER_GET_CLASS_TAG, ASN1_BER_GET_LOW_TAG_NUM, ASN1_BER_IS_CONSTRUCTED, ASN1_BER_IS_HIGH_TAG, ASN1_PARSER_ERR, ASN1_PARSER_OK, ASN1_STATUS_INVALID, ASN1_STATUS_OOB, ASN1CTX_CUR_NODE, Asn1Id_::class_tag, Asn1Node_::id, Asn1Ctx_::iter, Asn1Ctx_::parser_status, Asn1Id_::ptr, SCAsn1CheckBounds(), Asn1Id_::tag_num, and Asn1Id_::tag_type.

Referenced by SCAsn1Decode().

Here is the call graph for this function:

Here is the caller graph for this function:

uint8_t SCAsn1DecodeLength ( Asn1Ctx ac)

Decode and check the length, of the current node that we are parsing, also check invalid opts.

Parameters
acpointer to the ASN1 Context data
Return values
byteof the status of the parser

Definition at line 215 of file util-decode-asn1.c.

References ASN1_BER_EVENT_EOC_NOT_FOUND, ASN1_BER_GET_SHORT_LEN, ASN1_BER_IS_EOC, ASN1_BER_IS_INDEFINITE_LEN, ASN1_BER_IS_SHORT_LEN, ASN1_BER_LEN_INDEFINITE, ASN1_BER_LEN_LONG, ASN1_BER_LEN_SHORT, ASN1_NODE_IS_EOC, ASN1_PARSER_ERR, ASN1_PARSER_OK, ASN1_STATUS_INVALID, ASN1_STATUS_OOB, ASN1CTX_CUR_NODE, Asn1Node_::data, Asn1Ctx_::end, Asn1Node_::flags, Asn1Len_::form, Asn1Node_::id, Asn1Ctx_::iter, Asn1Len_::len, Asn1Data_::len, Asn1Node_::len, Asn1Ctx_::parser_status, Asn1Len_::ptr, Asn1Id_::ptr, and SCAsn1CheckBounds().

Referenced by SCAsn1Decode().

Here is the call graph for this function:

Here is the caller graph for this function:

void SCPrintByteBin ( uint8_t  byte)

Helper function that print the bits of a byte to check encoding internals.

Parameters
bytevalue of the byte

Definition at line 318 of file util-decode-asn1.c.

Variable Documentation

uint16_t asn1_max_frames_config = ASN1_MAX_FRAMES

Definition at line 36 of file util-decode-asn1.c.

Referenced by SCAsn1CtxDestroy(), SCAsn1CtxNew(), SCAsn1Decode(), and SCAsn1LoadConfig().