Main Page | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages

eap_tls_parser.hxx

00001 /* BEGIN_COPYRIGHT                                                        */
00002 /*                                                                        */
00003 /* Open Diameter: Open-source software for the Diameter and               */
00004 /*                Diameter related protocols                              */
00005 /*                                                                        */
00006 /* Copyright (C) 2002-2004 Open Diameter Project                          */
00007 /*                                                                        */
00008 /* This program is free software; you can redistribute it and/or modify   */
00009 /* it under the terms of the GNU General Public License as published by   */
00010 /* the Free Software Foundation; either version 2 of the License, or      */
00011 /* (at your option) any later version.                                    */
00012 /*                                                                        */          
00013 /* This program is distributed in the hope that it will be useful,        */
00014 /* but WITHOUT ANY WARRANTY; without even the implied warranty of         */
00015 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          */
00016 /* GNU General Public License for more details.                           */
00017 /*                                                                        */
00018 /* You should have received a copy of the GNU General Public License      */
00019 /* along with this program; if not, write to the Free Software            */
00020 /* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307    */
00021 /* USA.                                                                   */
00022 /*                                                                        */
00023 /* In addition, when you copy and redistribute some or the entire part of */
00024 /* the source code of this software with or without modification, you     */
00025 /* MUST include this copyright notice in each copy.                       */
00026 /*                                                                        */
00027 /* If you make any changes that are appeared to be useful, please send    */
00028 /* sources that include the changed part to                               */
00029 /* diameter-developers@lists.sourceforge.net so that we can reflect your  */
00030 /* changes to one unified version of this software.                       */
00031 /*                                                                        */
00032 /* END_COPYRIGHT                                                          */
00033 /***************************************************************************
00034                           eap_tls_parser.cxx  -  description
00035                              -------------------
00036     begin                : vie mar 12 2004
00037     copyright            : (C) 2004 by 
00038     email                : 
00039  ***************************************************************************/
00040 
00041 /***************************************************************************
00042  *                                                                         *
00043  *   This program is free software; you can redistribute it and/or modify  *
00044  *   it under the terms of the GNU General Public License as published by  *
00045  *   the Free Software Foundation; either version 2 of the License, or     *
00046  *   (at your option) any later version.                                   *
00047  *                                                                         *
00048  ***************************************************************************/
00049 
00050 
00051 #ifndef  __EAP_TLS_PARSER_HXX__
00052 #define  __EAP_TLS_PARSER_HXX__
00053 
00054 #include "eap_tls.hxx"
00055 #include "eap_parser.hxx"
00056 
00057 //EAP-TLS Request parser
00058 
00059 
00060 typedef AAAParser<AAAMessageBlock *, EapRequestTls *> EapRequestTlsParser;
00061 
00062 inline void EapRequestTlsParser::parseRawToApp()
00063 {
00064 
00065   AAAMessageBlock* msg = getRawData();
00066   EapRequestTls *request = getAppData();
00067 
00068   ACE_INT16 length_packet = ntohs(*(short *)(msg->base()+2)); //Get Packet Length
00069   ACE_UINT32 length_data = length_packet-5-1;
00070                                                                   
00071   EAP_LOG(LM_DEBUG,"EapRequestTlsParser::parseRawToApp LENGTH PACKET %d \n ",length_packet);
00072 
00073   ACE_Byte flags= *(msg->rd_ptr());
00074   //Packet is bad-formatted
00075   if (!TLS_START(flags))
00076   {
00077       if (length_packet < 6) throw -1;
00078   }
00079   else EAP_LOG(LM_DEBUG,"EapRequestTlsParser::parseRawToApp: START flag\n");
00080   //Read flags byte.
00081   request->set_flags(flags);
00082   msg->rd_ptr(1);
00083   //Flags must be examined to know if TLS Message Length is present 
00084   if (TLS_LENGTH_INCLUDED(flags))
00085   {    EAP_LOG(LM_DEBUG,"EapRequestTlsParser::parseRawToApp: LENGTH INCLUDED flag\n");
00086        if (length_packet < 10)  throw -1; //TLS message length doesn't exit
00087        //Read TLS Message Length
00088        request->set_tls_message_length(ntohl(*(ACE_UINT32*)msg->rd_ptr()));
00089        msg->rd_ptr(4);
00090        length_data -= 4; //Packet includes a LENGTH field.
00091   } else request->set_tls_message_length(0); //EAP PACKET has not TLS message length field.
00092   //Copy data field.
00093 
00094   if (length_data)
00095   {
00096      AAAMessageBlock *data = AAAMessageBlock::Acquire(length_data);
00097      data->copy(msg->rd_ptr(),length_data);
00098      //Assign TLS data.
00099      request->set_data(data);
00100      request->set_is_ack(false);
00101    }
00102    else
00103    {
00104       request->set_data(NULL);
00105       if (flags == (ACE_Byte)0x00) request->set_is_ack(true); //it is an ack.
00106    }
00107    
00108 }
00109 
00110 inline void EapRequestTlsParser::parseAppToRaw()
00111 {
00112   AAAMessageBlock *msg = getRawData();
00113   EapRequestTls* request = getAppData();
00114 
00115   // Write type field
00116   EapRequestParser requestParser;
00117   requestParser.setRawData(msg);
00118   requestParser.setAppData(request);
00119   requestParser.parseAppToRaw();            //Here msg->wr_ptr() is placed on after Type field.
00120   //Write flags
00121   ACE_Byte  flags = request->get_flags();
00122   *(ACE_Byte*)msg->wr_ptr() = flags;
00123   msg->wr_ptr(1);
00124   if (TLS_LENGTH_INCLUDED(flags))
00125   {
00126     EAP_LOG(LM_DEBUG,"EapRequestTlsParser::parseAppToRaw LENGTH INCLUDED %d\n",request->get_data()->length());
00127     //Write length
00128     *(ACE_UINT32*)msg->wr_ptr() = htonl(request->get_data()->length());
00129     msg->wr_ptr(4);
00130   }
00131   //TLS data
00132   ACE_UINT32 length_to_copy = msg->end()-msg->wr_ptr();
00133   EAP_LOG(LM_DEBUG,"EapRequestTlsParser::parseAppToRaw LENGTH PACKET %d \n ",length_to_copy);
00134   if (!TLS_START(flags) && (request->get_data() != NULL))
00135     msg->copy(request->get_data()->rd_ptr(),length_to_copy);
00136 }
00137 
00138 //EAP-TLS Request parser
00139 typedef EapRequestTlsParser EapResponseTlsParser;  
00140 
00141 #endif

Generated on Fri Jun 25 19:16:16 2004 for EAP State Machine by doxygen 1.3.5