--- /dev/null
+#include "ssl_protocol_module_base.h"
+
+namespace l7vs
+{
+
+ ssl_protocol_module_base::ssl_protocol_module_base(std::string in_modulename)
+ :protocol_module_base(in_modulename)
+ {
+ //ctor
+ }
+
+ ssl_protocol_module_base::~ssl_protocol_module_base()
+ {
+ //dtor
+ }
+ /*
+ * get ssl session id
+ * @param[in] const char* record_data ssl record data pointer
+ * @param[in] int recv_length ssl record data length
+ * @param[out] std::string& session_id ssl session id
+ */
+ int ssl_protocol_module_base::get_ssl_session_id(const char* record_data, int recv_length, std::string& session_id)
+ {
+ //check the ssl record data length
+ if (recv_length >= 76 && record_data != NULL)
+ {
+ //check the length of ssl session id (session id length is 32 bytes)
+ if (record_data[43] == 0x20)
+ {
+ //get session id
+ session_id.assign(record_data + 44, record_data + 76);
+ return 0;
+ }
+ else
+ {
+ //the length of ssl session id is 0, the ssl record data dose not have a session id.
+ return -1;
+ }
+ }
+ else
+ {
+ //the ssl record data length < 76, error!
+ return -1;
+ }
+ }
+ /*
+ * check the ssl record data whether is able to send, or not.
+ * @param[in] bool is_message_form_client is message from client
+ * @param[in] const char* record_data ssl record data pointer
+ * @param[out] int& all_length ssl record data length
+ * @param[out] bool& is_hello_message is ssl client/server hello record data
+ */
+ int ssl_protocol_module_base::check_ssl_record_sendable( bool is_message_form_client,
+ const char* record_data,
+ int recv_length,
+ int& all_length,
+ bool& is_hello_message)
+ {
+ //check record_data pointer
+ if (record_data == NULL) {
+ return -1;
+ }
+ //is_hello_messageを FALSEで設定する
+ is_hello_message = false;
+ //data_size≧6(SSL record のminimalサイズ)
+ if (recv_length >= 6)
+ {
+ // SSL recordチェック
+ // SSLレコードデータの1バイト目が「20」、「21」、「22」、「23」で、
+ // 2バイト目が「0x03」で、3バイト目が「0x00」、又は「0x01」の場合、
+ // チェック結果がOKで、その以外の場合、チェック結果がNGとして処理を行う。
+ if((record_data[0] == 0x14 ||
+ record_data[0] == 0x15 ||
+ record_data[0] == 0x16 ||
+ record_data[0] == 0x17) && (
+ record_data[1] == 0x03) && (
+ record_data[2] == 0x00 || record_data[2] == 0x01))
+ {//チェック結果 = OK
+ // handshake helloチェック
+ // SSLレコードデータの1バイト目が「22」、且つ6バイト目が「0x01」、「0x02」の場合、
+ // チェック結果がhandshake helloとして処理を行う。
+ if(record_data[0] == 0x16 && (record_data[5] == 0x01 || record_data[5] == 0x02))
+ {//handshake helloの場合
+ if(recv_length >= 76)
+ {//data_size≧76の場合
+ //SSLレコードデータの10バイト目が「0x03」、
+ //且つ11バイト目が「0x00」、「0x01」をチェックする。
+ //チェックが正常の場合、引数の「is_message_form_client」により下記の処理を行う。
+ //・is_message_form_clientがTUREの場合:6バイト目が「1」(client hello)をチェックする。
+ //・is_message_form_clientが FALSEの場合:6バイト目が「2」(server hello)をチェックする。
+ if(record_data[9] == 0x03 &&
+ (record_data[10] == 0x00 || record_data[10] == 0x01) &&
+ ((is_message_form_client && record_data[5] == 0x01) ||
+ (!is_message_form_client && record_data[5] == 0x02)))
+ {//チェック結果 = TRUE
+ //is_hello_messageを TRUEで設定する
+ is_hello_message = true;
+ //SSLレコードデータの4バイト目と5バイト目がSSL recordのmessagesのサイズで、
+ //sSSL recordの全サイズを messagesのサイズ + 5で設定する
+ unsigned short high_length = 0;
+ unsigned short low_length = 0;
+ high_length = static_cast<unsigned short>(static_cast<unsigned char>(record_data[3]));
+ high_length = high_length << 8;
+ low_length = static_cast<unsigned short>(static_cast<unsigned char>(record_data[4]));
+ all_length = (high_length | low_length) + 5;
+ //SSL recordチェック結果を「送信可能」
+ return 0;
+ }
+ else
+ {//チェック結果 = FALSE
+ //SSL recordチェック結果が「異常」を返す
+ return -1;
+ }
+ }
+ else
+ {//data_size<76の場合
+ //SSL recordチェック結果を「送信不可」
+ return 1;
+ }
+ }
+ else
+ {//その他場合
+ //SSLレコードデータの4バイト目と5バイト目がSSL recordのmessagesのサイズで、
+ //sSSL recordの全サイズを messagesのサイズ + 5で設定する
+ unsigned short high_length = 0;
+ unsigned short low_length = 0;
+ high_length = static_cast<unsigned short>(static_cast<unsigned char>(record_data[3]));
+ high_length = high_length << 8;
+ low_length = static_cast<unsigned short>(static_cast<unsigned char>(record_data[4]));
+ all_length = (high_length | low_length) + 5;
+ //SSL recordチェック結果を「送信可能」
+ return 0;
+ }
+ }
+ else
+ {//チェック結果 = NG
+ //SSL recordチェック結果が「異常」を返す
+ return -1;
+ }
+ }
+ else
+ {//data_size<6(SSL record のminimalサイズ)
+ //SSL recordチェック結果を「送信不可」
+ return 1;
+ }
+ }
+
+}
--- /dev/null
+#ifndef SSL_PROTOCOL_MODULE_BASE_H
+#define SSL_PROTOCOL_MODULE_BASE_H
+
+#include "protocol_module_base.h"
+#include <string>
+
+namespace l7vs
+{
+
+class ssl_protocol_module_base : public protocol_module_base
+{
+ public:
+ ssl_protocol_module_base(std::string in_modulename);
+ ~ssl_protocol_module_base();
+//ZLQ modify for test: protected:
+ int get_ssl_session_id(const char* record_data, int recv_length, std::string& session_id);
+
+ int check_ssl_record_sendable( bool is_message_form_client,
+ const char* record_data,
+ int recv_length,
+ int& all_length,
+ bool& is_hello_message);
+};
+
+} // namespace l7vsd
+
+#endif // SSL_PROTOCOL_MODULE_BASE_H
--- /dev/null
+#include "sslid_replication_data_processor.h"
+#include "boost/format.hpp"
+
+#define SSLID_SERVICE_NUMBER (128)
+
+namespace l7vs
+{
+
+sslid_replication_data_processor::sslid_replication_data_processor(
+ int maxlist,
+ char* sslid_replication_area_begain,
+ int sslid_replication_area_size,
+ const boost::asio::ip::tcp::endpoint& virtual_service_endpoint,
+ getloglevel_func_type ingetloglevel,
+ logger_func_type inputLogFatal,
+ logger_func_type inputLogError,
+ logger_func_type inputLogWarn,
+ logger_func_type inputLogInfo,
+ logger_func_type inputLogDebug ) :
+ maxlist( maxlist ),
+ max_temp_list( 2 * maxlist ),
+ replication_area( NULL ),
+ virtual_service_endpoint( virtual_service_endpoint ),
+ getloglevel( ingetloglevel ),
+ putLogFatal( inputLogFatal ),
+ putLogError( inputLogError ),
+ putLogWarn( inputLogWarn ),
+ putLogInfo( inputLogInfo ),
+ putLogDebug( inputLogDebug )
+{
+
+}
+
+sslid_replication_data_processor::~sslid_replication_data_processor()
+{
+ //dtor
+}
+
+void sslid_replication_data_processor::put_into_temp_list(
+ const sslid_replication_temp_data& data )
+{
+
+}
+
+void sslid_replication_data_processor::write_replicaion_area()
+{
+
+}
+
+sslid_replication_data* sslid_replication_data_processor::get_replication_area()
+{
+ return NULL;
+}
+
+void sslid_replication_data_processor::register_replication_area_lock(
+ boost::function<void(void)> intable_lock )
+{
+
+}
+
+void sslid_replication_data_processor::register_replication_area_unlock(
+ boost::function<void(void)> intable_unlock )
+{
+
+}
+
+void sslid_replication_data_processor::get_from_temp_list(
+ sslid_replication_temp_data& data )
+{
+
+}
+
+}
--- /dev/null
+#ifndef SSLID_REPLICATION_DATA_PROCESSOR_H
+#define SSLID_REPLICATION_DATA_PROCESSOR_H
+
+#include <boost/asio.hpp>
+#include <boost/thread/condition.hpp>
+#include "logger_enum.h"
+
+#define SSLID_LENGTH (32)
+#define SSLID_IP_MAXLENGTH (40)
+
+namespace l7vs
+{
+
+struct sslid_replication_data_header
+{
+ char virtualserver_ip[SSLID_IP_MAXLENGTH];
+ unsigned short virtualserver_port;
+ unsigned int offset;
+ unsigned int size;
+};
+
+struct sslid_replication_data
+{
+ char session_id[SSLID_LENGTH];
+ char realserver_ip[SSLID_IP_MAXLENGTH];
+ unsigned short realserver_port;
+ time_t last_time;
+ int valid;
+};
+
+struct sslid_replication_temp_data
+{
+ char op_code;
+ std::string session_id;
+ time_t last_time;
+ boost::asio::ip::tcp::endpoint realserver_addr;
+};
+
+class sslid_replication_data_processor
+{
+ public:
+ //! loglevel get function object type
+ typedef boost::function< LOG_LEVEL_TAG(void) >
+ getloglevel_func_type;
+ //! log output function object type
+ typedef boost::function< void ( const unsigned int, const std::string&, const char*, int ) >
+ logger_func_type;
+
+ public:
+ sslid_replication_data_processor( int maxlist,
+ char* sslid_replication_area_begain,
+ int sslid_replication_area_size,
+ const boost::asio::ip::tcp::endpoint& virtual_service_endpoint,
+ getloglevel_func_type ingetloglevel,
+ logger_func_type inputLogFatal,
+ logger_func_type inputLogError,
+ logger_func_type inputLogWarn,
+ logger_func_type inputLogInfo,
+ logger_func_type inputLogDebug );
+
+ virtual ~sslid_replication_data_processor();
+
+ void put_into_temp_list( const sslid_replication_temp_data& data );
+
+ void write_replicaion_area();
+
+ sslid_replication_data* get_replication_area();
+
+ void register_replication_area_lock( boost::function<void(void)> intable_lock );
+
+ void register_replication_area_unlock( boost::function<void(void)> intable_unlock );
+
+ protected:
+ void get_from_temp_list( sslid_replication_temp_data& data );
+
+ protected:
+ int maxlist;
+ int max_temp_list;// : int = 2*maxlist
+ std::deque<sslid_replication_temp_data> temp_list;
+ boost::mutex temp_list_mutex;
+ boost::condition temp_list_condition;
+ sslid_replication_data* replication_area;
+ boost::function<void(void)> replication_area_lock;
+ boost::function<void(void)> replication_area_unlock;
+ boost::asio::ip::tcp::endpoint virtual_service_endpoint;
+ getloglevel_func_type getloglevel; //!< get loglevel function object
+ logger_func_type putLogFatal; //!< fatal log output function object
+ logger_func_type putLogError; //!< error log output function object
+ logger_func_type putLogWarn; //!< warn log output function object
+ logger_func_type putLogInfo; //!< info log output function object
+ logger_func_type putLogDebug; //!< debug log output function object
+};
+
+}
+
+#endif // SSLID_REPLICATION_DATA_PROCESSOR_H
--- /dev/null
+#include "sslid_session_data_processor.h"
+#include "boost/format.hpp"
+
+namespace l7vs
+{
+
+sslid_session_data_processor::sslid_session_data_processor(
+ int maxlist,
+ int timeout,
+ sslid_replication_data_processor* replication_data_processor,
+ getloglevel_func_type ingetloglevel,
+ logger_func_type inputLogFatal,
+ logger_func_type inputLogError,
+ logger_func_type inputLogWarn,
+ logger_func_type inputLogInfo,
+ logger_func_type inputLogDebug )
+ :maxlist( maxlist ),
+ timeout( timeout ),
+ replication_data_processor( replication_data_processor ),
+ getloglevel( ingetloglevel ),
+ putLogFatal( inputLogFatal ),
+ putLogError( inputLogError ),
+ putLogWarn( inputLogWarn ),
+ putLogInfo( inputLogInfo ),
+ putLogDebug( inputLogDebug )
+{
+ //ctor
+}
+
+sslid_session_data_processor::~sslid_session_data_processor()
+{
+ //dtor
+}
+
+//! get endpoint from session data function
+//! @param const std::string& session_id
+//! @param boost::asio::ip::tcp::endpoint& endpoint
+//! @return 0 : success 1: failed -1:exception
+int sslid_session_data_processor::get_endpoint_from_session_data(
+ const std::string& session_id,
+ boost::asio::ip::tcp::endpoint& endpoint )
+{
+ return 0;
+}
+
+int sslid_session_data_processor::write_session_data(
+ const std::string& session_id,
+ const boost::asio::ip::tcp::endpoint& endpoint,
+ time_t now_time )
+{
+ return 0;
+}
+
+int sslid_session_data_processor::read_session_data_from_replication_area(
+ sslid_replication_data* replication_area )
+{
+ return 0;
+}
+
+int sslid_session_data_processor::clear_expired_session_data()
+{
+ return 0;
+}
+
+}
--- /dev/null
+#ifndef SSLID_SESSION_DATA_PROCESSOR_H
+#define SSLID_SESSION_DATA_PROCESSOR_H
+
+#include "sslid_replication_data_processor.h"
+#include "logger_enum.h"
+#include <boost/asio.hpp>
+#include <string>
+
+namespace l7vs
+{
+
+class sslid_session_data_processor
+{
+ public:
+ //! loglevel get function object type
+ typedef boost::function< LOG_LEVEL_TAG(void) >
+ getloglevel_func_type;
+ //! log output function object type
+ typedef boost::function< void ( const unsigned int, const std::string&, const char*, int ) >
+ logger_func_type;
+
+ public:
+ sslid_session_data_processor(
+ int maxlist,
+ int timeout,
+ sslid_replication_data_processor* replication_data_processor,
+ getloglevel_func_type ingetloglevel,
+ logger_func_type inputLogFatal,
+ logger_func_type inputLogError,
+ logger_func_type inputLogWarn,
+ logger_func_type inputLogInfo,
+ logger_func_type inputLogDebug );
+
+ virtual ~sslid_session_data_processor();
+
+ int get_endpoint_from_session_data(
+ const std::string& session_id,
+ boost::asio::ip::tcp::endpoint& endpoint );
+
+ int write_session_data(
+ const std::string& session_id,
+ const boost::asio::ip::tcp::endpoint& endpoint,
+ time_t now_time );
+
+ int read_session_data_from_replication_area( sslid_replication_data* replication_area );
+
+ protected:
+ int clear_expired_session_data();
+
+ protected:
+ int maxlist;
+ int timeout;
+ std::map<std::string, boost::asio::ip::tcp::endpoint> session_endpoint_map;
+ std::map<std::string, time_t> session_lasttime_map;
+ std::multimap<time_t, std::string> lasttime_session_map;
+ boost::mutex session_map_mutex;
+ sslid_replication_data_processor* replication_data_processor;
+ getloglevel_func_type getloglevel; //!< get loglevel function object
+ logger_func_type putLogFatal; //!< fatal log output function object
+ logger_func_type putLogError; //!< error log output function object
+ logger_func_type putLogWarn; //!< warn log output function object
+ logger_func_type putLogInfo; //!< info log output function object
+ logger_func_type putLogDebug; //!< debug log output function object
+ private:
+};
+
+}
+#endif // SSLID_SESSION_DATA_PROCESSOR_H
# Makefile for sslid unit test frameworks.
#
#
-TARGET = sslid_ut
+TARGET = protocol_module_sslid_ut
CPP = g++
CPPFLAGS = -g -Wall -Werror -pthread -O0 -DDATA_SIZE=480 -DMAX_BUFFER_SIZE=65535
INCLUDES = -I../../include \
-I../../logger \
- -I../../module/protocol
+ -I../../module/protocol \
+ -I../../src
LIBS = -lboost_system-gcc41-mt \
-lboost_thread-gcc41-mt \
LDFLAGS = -lrt -ldl
-SRCS = sslid_ut.cpp
+SRCS = protocol_module_sslid_test.cpp
OBJS = $(SRCS:.cpp=.o)
--- /dev/null
+/*\r
+ * sslid_to_be_test_file.h\r
+ *\r
+ * Created on: Jan 20, 2009\r
+ * Author: root\r
+ */\r
+\r
+#ifndef SSLID_TO_BE_TEST_FILE_H_\r
+#define SSLID_TO_BE_TEST_FILE_H_\r
+\r
+#include <boost/test/included/unit_test.hpp>\r
+\r
+#include "ssl_protocol_module_base.cpp"\r
+#include "sslid_replication_data_processor.cpp"\r
+#include "sslid_session_data_processor.cpp"\r
+#include "protocol_module_sslid.cpp"\r
+\r
+#endif /* SSLID_TO_BE_TEST_FILE_H_ */\r