original files of m241
This commit is contained in:
@@ -0,0 +1,321 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
* INTERPEAK SOURCE FILE
|
||||
*
|
||||
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: ipeap_tls.c,v $ $Revision: 1.20.12.1 $
|
||||
* $Source: /home/interpeak/CVSRoot/ipeap/src/ipeap_tls.c,v $
|
||||
* $Author: hxu4 $
|
||||
* $State: Exp $ $Locker: $
|
||||
*
|
||||
* INTERPEAK_COPYRIGHT_STRING
|
||||
* Design and implementation by Roger Boden <roger@interpeak.se>
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 1 DESCRIPTION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 2 CONFIGURATION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#include "ipeap_config.h"
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 3 INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#define IPCOM_USE_CLIB_PROTO
|
||||
#include <ipcom_type.h>
|
||||
#include <ipcom_cstyle.h>
|
||||
#include <ipcom_clib.h>
|
||||
#include <ipcom_err.h>
|
||||
#include <ipcom_syslog.h>
|
||||
|
||||
#include <openssl/ssl.h>
|
||||
|
||||
#include "ipeap.h"
|
||||
#include "ipeap_h.h"
|
||||
#include "ipeap_common_tls.h"
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 4 DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 5 TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 6 EXTERN PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 7 LOCAL PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
IP_STATIC Ip_err ipeap_tls_suppl_process_msg(struct Ipeap_ctx_st *ctx,
|
||||
struct Ipeap_pkt_st *in_pkt,
|
||||
struct Ipeap_pkt_st *reply_pkt);
|
||||
|
||||
IP_STATIC Ip_err ipeap_tls_suppl_get_key(struct Ipeap_ctx_st* ctx, Ip_u8* key, int key_len);
|
||||
|
||||
IP_STATIC Ip_err ipeap_tls_suppl_init(struct Ipeap_ctx_st *ctx);
|
||||
IP_STATIC Ip_err ipeap_tls_suppl_free(Ipeap_ctx *ctx);
|
||||
IP_STATIC Ip_err ipeap_tls_suppl_get_session_id(Ipeap_ctx *ctx,Ip_u8 *session_id,Ip_u32 *session_id_len);
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 8 DATA
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
IP_STATIC Ipeap_methods ipeap_tls_suppl_methods =
|
||||
{
|
||||
ipeap_tls_suppl_process_msg,
|
||||
ipeap_tls_suppl_init,
|
||||
ipeap_tls_suppl_free,
|
||||
ipeap_tls_suppl_get_key,
|
||||
IP_NULL,
|
||||
IP_NULL,
|
||||
ipeap_tls_suppl_get_session_id
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 9 STATIC FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* ipeap_tls_suppl_init
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_STATIC Ip_err
|
||||
ipeap_tls_suppl_init(Ipeap_ctx *ctx)
|
||||
{
|
||||
Ipeap_tls_suppl_ctx* tls_ctx;
|
||||
|
||||
tls_ctx = ipeap_common_tls_ctx_new();
|
||||
if(!tls_ctx)
|
||||
return IPCOM_ERR_FAILED;
|
||||
|
||||
ctx->mech_data = tls_ctx;
|
||||
return IPCOM_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* ipeap_tls_suppl_free
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_STATIC Ip_err
|
||||
ipeap_tls_suppl_free(Ipeap_ctx *ctx)
|
||||
{
|
||||
Ipeap_tls_suppl_ctx* tls_ctx;
|
||||
|
||||
tls_ctx = (Ipeap_tls_suppl_ctx*)ctx->mech_data;
|
||||
|
||||
ipeap_common_tls_ctx_free(tls_ctx);
|
||||
|
||||
return IPCOM_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* ipeap_tls_suppl_get_key
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_STATIC Ip_err
|
||||
ipeap_tls_suppl_get_key(struct Ipeap_ctx_st* ctx, Ip_u8* key, int key_len)
|
||||
{
|
||||
Ipeap_tls_suppl_ctx *tls_ctx;
|
||||
|
||||
tls_ctx = (Ipeap_tls_suppl_ctx*)ctx->mech_data;
|
||||
|
||||
return ipeap_tls_common_generate_key(tls_ctx, "client EAP encryption", key, key_len);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* ipeap_tls_suppl_process_msg
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_STATIC Ip_err
|
||||
ipeap_tls_suppl_process_msg(Ipeap_ctx *ctx, Ipeap_pkt *in_pkt, Ipeap_pkt *out_pkt)
|
||||
{
|
||||
Ip_err rc;
|
||||
Ipeap_tls_msg *msg;
|
||||
Ipeap_tls_suppl_ctx* tls_ctx;
|
||||
|
||||
msg = IPEAP_PKT2TLSMSG(in_pkt);
|
||||
tls_ctx = (Ipeap_tls_suppl_ctx*)ctx->mech_data;
|
||||
|
||||
switch(msg->code)
|
||||
{
|
||||
case IPEAP_MSG_REQUEST:
|
||||
rc = ipeap_common_tls_handle_frag_and_handshake(ctx, tls_ctx, in_pkt, out_pkt);
|
||||
|
||||
switch(rc)
|
||||
{
|
||||
case IPEAP_PENDING_SEND_OUT_PKT:
|
||||
break;
|
||||
case IPEAP_TLS_HANDSHAKE_COMPLETE:
|
||||
rc = ipeap_tls_pkt_set_header(out_pkt, IPEAP_PKT_RESPONSE, msg->id, 6, ctx->meth_id, 0);
|
||||
out_pkt->end += 6;
|
||||
if(rc != IPCOM_SUCCESS)
|
||||
return rc;
|
||||
return IPEAP_PENDING_SEND_OUT_PKT;
|
||||
|
||||
case IPEAP_TLS_DATA_AVAILABLE:
|
||||
IPCOM_LOG0(ERR, "EAP-TLS :: Application data received in TLS handshake");
|
||||
return IPCOM_ERR_FAILED;
|
||||
|
||||
default:
|
||||
IPCOM_LOG1(ERR, "EAP-TLS :: Unexpected return code from ipeap_common_tls_handle_frag_and_handshake(): %d", rc);
|
||||
return IPCOM_ERR_FAILED;
|
||||
}
|
||||
break;
|
||||
case IPEAP_MSG_RESPONSE:
|
||||
IPCOM_LOG0(ERR, "EAP-TLS :: received response msg, dropping msg");
|
||||
return IPEAP_DROPPED_PKT;
|
||||
|
||||
case IPEAP_MSG_FAILURE:
|
||||
IPCOM_LOG0(ERR, "EAP-TLS :: received EAP failure");
|
||||
return IPEAP_FAILURE;
|
||||
|
||||
case IPEAP_MSG_SUCCESS:
|
||||
ctx->state = IPEAP_STATE_AUTHENTICATED;
|
||||
IPCOM_LOG0(INFO, "EAP-TLS ::Received EAP success");
|
||||
return IPEAP_SUCCESS;
|
||||
|
||||
default:
|
||||
IPCOM_LOG1(ERR, "EAP-TLS :: received unknown msg type: %d, dropping msg", msg->code);
|
||||
return IPEAP_DROPPED_PKT;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* ipeap_tls_suppl_get_session_id
|
||||
*===========================================================================
|
||||
*
|
||||
*/
|
||||
|
||||
IP_STATIC Ip_err
|
||||
ipeap_tls_suppl_get_session_id(
|
||||
Ipeap_ctx *ctx,
|
||||
Ip_u8 *session_id,
|
||||
Ip_u32 *session_id_len
|
||||
)
|
||||
{
|
||||
|
||||
Ip_err rc = IPCOM_SUCCESS;
|
||||
Ipeap_tls_suppl_ctx *tls_ctx = IP_NULL;
|
||||
|
||||
|
||||
IPCOM_LOG0(DEBUG, "IPEAP-TLS :: Get Session-Id :: ");
|
||||
|
||||
if(!ctx)
|
||||
{
|
||||
IPCOM_LOG0(ERR, "ipeap_tls_suppl_get_session_id - NULL EAP ctx");
|
||||
return IPCOM_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
tls_ctx = (Ipeap_tls_suppl_ctx*)ctx->mech_data;
|
||||
|
||||
if(!tls_ctx)
|
||||
{
|
||||
IPCOM_LOG0(ERR, "ipeap_tls_suppl_get_session_id - NULL EAP-TLS ctx");
|
||||
return IPCOM_ERR_FAILED;
|
||||
}
|
||||
|
||||
|
||||
rc = ipeap_tls_common_generate_session_id(tls_ctx,IPEAP_TYPE_TLS,session_id,session_id_len);
|
||||
|
||||
return rc;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 10 GLOBAL FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 11 PUBLIC FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* ipeap_tls_suppl_methods_get
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_PUBLIC Ipeap_methods*
|
||||
ipeap_tls_suppl_methods_get(void)
|
||||
{
|
||||
return &ipeap_tls_suppl_methods;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user