00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifndef __message_h
00038 #define __message_h
00039
00040 #ifdef __cplusplus
00041 extern "C" {
00042 #endif
00043
00044 #include"common.h"
00045
00046 #include"session.h"
00047
00048
00049
00050 #define IKEv2_MAJOR_VERSION 2
00051 #define IKEv2_MINOR_VERSION 0
00052
00053
00054 #define NONCE_LEN 128 // should be variable???
00055 #define TB_SIZE 4092
00056
00057
00058
00059 #define IKEv2_EXT_IKE_SA_INIT 34
00060 #define IKEv2_EXT_IKE_AUTH 35
00061 #define IKEv2_EXT_CREATE_CHILD_SA 36
00062 #define IKEv2_EXT_INFORMATIONAL 37
00063
00064
00065 #define IKEv2_HDF_INITIATOR (1<<3)
00066 #define IKEv2_HDF_VERSION (1<<4)
00067 #define IKEv2_HDF_RESPONSE (1<<5)
00068
00069
00070
00074 struct CertList
00075 {
00076 struct CertList *next;
00077 uint8_t *cdata;
00078 uint32_t cdlen;
00079 uint8_t ctype;
00080 };
00081
00089 struct ParseMsgResult
00090 {
00091 struct Proposal *SA;
00092 BIGNUM *KE;
00093 uint16_t DHGroup;
00094 BIGNUM *Nonce;
00095 uint8_t *IDiData;
00096 uint16_t IDiLen;
00097 uint8_t *IDrData;
00098 uint16_t IDrLen;
00099 uint8_t *authData;
00100 uint32_t adlen;
00101 uint8_t authMeth;
00102
00103
00104
00105 struct CertList *cert;
00106
00107 uint8_t enc;
00108 uint8_t failed;
00109
00110 uint8_t error;
00111 uint8_t unsuppCritPl;
00112 uint8_t plType;
00113 uint8_t Authfailed;
00114 uint8_t NoPropAcceptable;
00115 uint8_t KEInvalid;
00116 uint16_t ChosenDHGroup;
00117 };
00118
00141 struct IKEv2Header
00142 {
00143 uint64_t InitiatorSPI;
00144 uint64_t ResponderSPI;
00145 uint8_t NextPayload;
00146 union
00147 {
00148 struct
00149 {
00150 uint8_t MjVersion:4;
00151 uint8_t MnVersion:4;
00152 }__attribute__((packed));
00153 uint8_t Version;
00154 }__attribute__((packed));
00155 uint8_t ExchangeType;
00156 uint8_t Flags;
00157 uint32_t MessageID;
00158 uint32_t Length;
00159 }__attribute__((packed));
00160
00161
00162
00163 int IKEv2IBuild_SA_Init( const struct ikev2_ctx *i2, uint8_t **out, uint32_t *olen, struct IKEv2Session *session, uint16_t DHGroup );
00164 int IKEv2RBuild_SA_Init( const struct ikev2_ctx *i2, uint8_t *oldMsg, uint8_t **out, uint32_t *olen,
00165 struct Proposal *selTrans, struct IKEv2Session *session, BIGNUM *pubk );
00166 int IKEv2IBuild_Auth( const struct ikev2_ctx *i2, uint8_t **out, uint32_t *olen, struct IKEv2Session *session );
00167 int IKEv2RBuild_Auth( const struct ikev2_ctx *i2, uint8_t **out, uint32_t *olen, uint8_t *in, struct IKEv2Session *session );
00168 int IKEv2Build_Informational( uint8_t **out, uint32_t *olen, struct IKEv2Session *session,
00169 uint8_t first, uint8_t *payloads, uint32_t plsize );
00170 int IKEv2RespondInformational( uint8_t **out, uint32_t *olen, uint8_t *inf );
00171 #if 0
00172 int IKEv2BuildEndSession( uint8_t **out, uint32_t *olen, struct IKEv2Session *session, uint64_t SPI );
00173 #endif
00174 int IKEv2BuildErrorMsg( uint8_t **out, uint32_t *olen, struct IKEv2Session *session,
00175 struct ParseMsgResult *res );
00176 int IKEv2BuildErrorResponseMsg( uint8_t **out, uint32_t *olen, uint8_t *in, struct ParseMsgResult *res,
00177 struct IKEv2Session *session, int enc );
00178 int IKEv2ICreateChildSA( const struct ikev2_ctx *i2, uint8_t **out, uint32_t *olen, struct IKEv2Session *session, int DHGroup );
00179 int IKEv2RCreateChildSA( uint8_t *oldMsg, uint8_t **out, uint32_t *olen, struct IKEv2Session *session,
00180 struct Proposal *selTrans, int DHGroup );
00181
00182 struct ParseMsgResult *ParseSAInitMsg( const struct ikev2_ctx *i2, struct IKEv2Session *session, uint8_t *p );
00183 struct ParseMsgResult *ParseAuthMsg( const struct ikev2_ctx *i2, struct IKEv2Session *session, uint8_t *p );
00184 struct ParseMsgResult *ParseInformationalMsg( const struct ikev2_ctx *i2, struct IKEv2Session *session, uint8_t *p );
00185 struct ParseMsgResult *ParseChildSAMsg( const struct ikev2_ctx *i2, struct IKEv2Session *session, uint8_t *p );
00186 void FreeMsgResult(struct ParseMsgResult *res);
00187
00188 #ifdef __cplusplus
00189 }
00190 #endif
00191
00192 #endif