Main Page | Data Structures | File List | Data Fields | Globals | Related Pages

payload.c File Reference

#include "common.h"
#include <assert.h>
#include <netinet/in.h>
#include <openssl/rand.h>
#include <string.h>
#include "payload.h"
#include "transforms.h"
#include "session.h"
#include "encr.h"
#include "message.h"
#include "auth.h"
#include "dh.h"
#include "conf_utils.h"
#include "enums.h"
#include "integ.h"

Functions

static void fillFixedPayloadHdr (uint8_t **next, uint8_t type, uint8_t *p)
 Auxiliary function used to set next field value of previous payload and initialize current payload header.
uint32_t CreateEncryptedPayload (uint8_t **next, uint8_t inner_next, uint8_t *data, uint32_t dlen, uint8_t *sigdata, struct IKEv2Session *session, uint8_t *p)
 Create an encrypted payload.
uint32_t CreateKEPayload (uint8_t **next, uint16_t DHGroup, struct IKEv2Session *session, uint8_t *p)
 Function creates an KE-Payload.
uint32_t CreateSAPayload (uint8_t **next, struct Proposal *suppProp, uint8_t *p)
 Creates SA payload.
uint32_t CreateNoncePayload (uint8_t **next, struct IKEv2Session *s, uint32_t len, uint8_t *p)
 Creates a Nonce payload.
uint32_t CreateIDPayload (uint8_t **next, uint8_t initiator, uint8_t type, uint8_t *id, uint16_t idlen, uint8_t *p)
 Creating IDR or IDI payload (depends on initiator param value).
uint32_t CreateAuthPayload (const struct ikev2_ctx *i2, uint8_t **next, struct IKEv2Session *session, uint8_t *id, uint16_t idlen, uint8_t *p)
 Creating an AUTH payload.
uint32_t CreateCertPayload (const struct ikev2_ctx *i2, uint8_t **next, uint8_t type, uint8_t *p)
 Create an CERT payload.
uint32_t CreateNotifyPayload (uint8_t **next, uint16_t type, uint8_t *ndata, uint16_t ndlen, uint8_t *p)
 Creating an notify payload.
uint32_t CreateDeletePayload (uint8_t **next, uint8_t SProtocolID, uint8_t *SPIs, uint16_t count, uint8_t *p)
 Creating an DELETE payload.
uint32_t CreateCertReqPayload (const struct ikev2_ctx *i2, uint8_t **next, uint8_t *p)
 Creates an Certification Request Payload (CERT REQ).
uint32_t ParseEncryptedPayload (uint8_t **data, struct IKEv2Session *session, uint8_t *p)
 Parses an encryption payload (without integrity checksum!!).
ProposalParseSAPayload (uint8_t *p)
 Parse SA payload.
BIGNUM * ParseKEPayload (uint16_t *DHGroup, uint8_t *p)
 Parse KE Payload. Extract KE data an DH group information from payload.
BIGNUM * ParseNoncePayload (uint8_t *p)
 Parse nonce payload and extract nonce data.
uint16_t ParseIDPayload (uint8_t **data, uint8_t *p)
 Parse an ID payload.
int ParseAuthPayload (uint8_t *AuthMethod, uint8_t **data, uint8_t *p)
 Parses an AUTH payload.
int ParseCertPayload (uint8_t **cdata, uint32_t *cdlen, uint8_t *ctype, uint8_t *p)
 Parse certificate payload.
int ParseNotifyPayload (uint8_t *p, uint16_t *data)
 Parse notify payload.
void ParseCertReqPayload (const struct ikev2_ctx *i2, uint8_t *p)
 Parse Certificate Request Parse.

Function Documentation

uint32_t CreateAuthPayload const struct ikev2_ctx i2,
uint8_t **  next,
struct IKEv2Session session,
uint8_t *  id,
uint16_t  idlen,
uint8_t *  p
 

Creating an AUTH payload.

IKEv2 context date carry necessary info about used authentication type.

Parameters:
*i2 IKEv2 context data
next next payload type.
*session IKEv2 session data
*id ptr to ID data
idlen ID data length
*p destination buffer
Returns:
size of created payload (in bytes)
See also:
For more details about 'next' param usage see CreateKEPayload description.

uint32_t CreateCertPayload const struct ikev2_ctx i2,
uint8_t **  next,
uint8_t  type,
uint8_t *  p
 

Create an CERT payload.

Parameters:
*i2 IKEv2 context data
next next payload type.
type type of certificate
*p destination buffer
Returns:
size of created payload (in bytes)
See also:
For more details about 'next' param usage see CreateKEPayload description.

uint32_t CreateCertReqPayload const struct ikev2_ctx i2,
uint8_t **  next,
uint8_t *  p
 

Creates an Certification Request Payload (CERT REQ).

Parameters:
*i2 IKEv2 context data
next next payload type
*p destination buffer
Returns:
size of created payload (in bytes)
See also:
For more details about 'next' param usage see CreateKEPayload description.

uint32_t CreateDeletePayload uint8_t **  next,
uint8_t  SProtocolID,
uint8_t *  SPIs,
uint16_t  count,
uint8_t *  p
 

Creating an DELETE payload.

Parameters:
next next payload type
SProtocolID protocol for which sessions should be deleted
*SPIs ptr to an array of SPIs
count # of SPIs
*p destination buffer
Returns:
size of created payload (in bytes)
See also:
For more details about 'next' param usage see CreateKEPayload description.

uint32_t CreateEncryptedPayload uint8_t **  next,
uint8_t  inner_next,
uint8_t *  data,
uint32_t  dlen,
uint8_t *  sigdata,
struct IKEv2Session session,
uint8_t *  p
 

Create an encrypted payload.

This is the most complex payload creation function. The work is performed in three main steps:

  • encrypt given data,
  • setup all remainig fields of IKEv2 message (hdr length, next payload field),
  • compute and attach integrity checksum of whole IKEv2 message. This function is ALWAYS called as last when chain of payloads is builded.

Parameters:
next next payload type.
inner_next value for 'NextPayload' field
*sigdata ptr to the begining of the IKEv2 message
*data payloads to be encrypted
dlen length of data
*session IKEv2 session data
*p destination buffer
Returns:
size of created payload (in bytes)
See also:
For more details about 'next' param usage see CreateKEPayload description.

uint32_t CreateIDPayload uint8_t **  next,
uint8_t  initiator,
uint8_t  type,
uint8_t *  id,
uint16_t  idlen,
uint8_t *  p
 

Creating IDR or IDI payload (depends on initiator param value).

Parameters:
next next payload type.
initiator if true create IDI payload else IDR payload
type type of ID
*id ptr to ID data
idlen ID data length
*p destination buffer
Returns:
size of created payload (in bytes)
See also:
For more details about 'next' param usage see CreateKEPayload description.

uint32_t CreateKEPayload uint8_t **  next,
uint16_t  DHGroup,
struct IKEv2Session session,
uint8_t *  p
 

Function creates an KE-Payload.

Parameters:
next next payload type. This variable is used as input/output data. On input *next must contain ptr to the 'next' field of the previous payload. After function execution *next will contain ptr to the 'next' field of current payload. This sollution is very useful when creating a chain of payloads.
DHGroup group ID for DH
*session IKEv2 session data
*p destination buffer
Returns:
length of created payload

uint32_t CreateNoncePayload uint8_t **  next,
struct IKEv2Session s,
uint32_t  len,
uint8_t *  p
 

Creates a Nonce payload.

As a side effect session->Ni (for initiator) or session->Nr (for responder) field will be filled. Old value will be lost.

Parameters:
next next payload type.
*s current IKEv2 session data
len length of nonce data
*p destination buffer
Returns:
size of created payload (in bytes)
See also:
For more details about 'next' param usage see CreateKEPayload description.

uint32_t CreateNotifyPayload uint8_t **  next,
uint16_t  type,
uint8_t *  ndata,
uint16_t  ndlen,
uint8_t *  p
 

Creating an notify payload.

Parameters:
next next payload type
type type of notify payload
*ndata notify payload data
ndlen ndata length
*p destination buffer
Returns:
size of created payload (in bytes)
See also:
For more details about 'next' param usage see CreateKEPayload description.

uint32_t CreateSAPayload uint8_t **  next,
struct Proposal suppProp,
uint8_t *  p
 

Creates SA payload.

Parameters:
next next payload type.
*suppProp list of supported transforms
*p destination buffer
Returns:
size of created payload (in bytes)
See also:
For more details about 'next' param usage see CreateKEPayload description.

static void fillFixedPayloadHdr uint8_t **  next,
uint8_t  type,
uint8_t *  p
[static]
 

Auxiliary function used to set next field value of previous payload and initialize current payload header.

Parameters:
**next *next must point to the previous payload 'next' field. After function execution *next will contain ptr to the current payload 'next' * field.
type payload type
*p payload header in raw format

int ParseAuthPayload uint8_t *  AuthMethod,
uint8_t **  data,
uint8_t *  p
 

Parses an AUTH payload.

Parameters:
*AuthMethod result ptr for auth method
**data result ptr for authentication data
*p ptr to payload
Returns:
length of data

int ParseCertPayload uint8_t **  cdata,
uint32_t *  cdlen,
uint8_t *  ctype,
uint8_t *  p
 

Parse certificate payload.

Parameters:
**cdata result ptr for certificate data
*cdlen result ptr for cdata length
*ctype result ptr for certificate type
*p ptr to payload
Returns:
0 on success, 1 otherwise

void ParseCertReqPayload const struct ikev2_ctx i2,
uint8_t *  p
 

Parse Certificate Request Parse.

Todo:
Current implementation only print payload data
Parameters:
*i2 IKEv2 context data
*p ptr to payload

uint32_t ParseEncryptedPayload uint8_t **  data,
struct IKEv2Session session,
uint8_t *  p
 

Parses an encryption payload (without integrity checksum!!).

Warning:
length field in header MUST be without integrity checksum!
Parameters:
**data decrypted payloads
*session IKEv2 session data
*p ptr to payload
Returns:
length of decrypted data without padding and padlen field

uint16_t ParseIDPayload uint8_t **  data,
uint8_t *  p
 

Parse an ID payload.

Parameters:
**data result ptr to ID data
*p ptr to payload
Returns:
length of payload body

BIGNUM* ParseKEPayload uint16_t *  DHGroup,
uint8_t *  p
 

Parse KE Payload. Extract KE data an DH group information from payload.

Parameters:
*DHGroup result ptr for DH group id
*p ptr to payload
Returns:
KE data

BIGNUM* ParseNoncePayload uint8_t *  p  ) 
 

Parse nonce payload and extract nonce data.

Parameters:
*p ptr to payload
Returns:
nonce data

int ParseNotifyPayload uint8_t *  p,
uint16_t *  data
 

Parse notify payload.

Parameters:
*p ptr to payload
*data result ptr for notification data
Returns:
0 on success, 1 otherwise

struct Proposal* ParseSAPayload uint8_t *  p  ) 
 

Parse SA payload.

Parameters:
*p ptr to payload
Returns:
Proposal structure which contains SA algorithms


Project hosted by: SourceForge.net Logo