message.h

00001 /***************************************************************************
00002 *   Copyright (C) 2005 by                                                 *
00003 *   Pedro J. Fernandez Ruiz    pedroj.fernandez@dif.um.es                 *
00004 *   Alejandro Perez Mendez     alejandro_perez@dif.um.es                  *
00005 *                                                                         *
00006 *   This library is free software; you can redistribute it and/or         *
00007 *   modify it under the terms of the GNU Lesser General Public            *
00008 *   License as published by the Free Software Foundation; either          *
00009 *   version 2.1 of the License, or (at your option) any later version.    *
00010 *                                                                         *
00011 *   This library is distributed in the hope that it will be useful,       *
00012 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00014 *   Lesser General Public License for more details.                       *
00015 *                                                                         *
00016 *   You should have received a copy of the GNU Lesser General Public      *
00017 *   License along with this library; if not, write to the Free Software   *
00018 *   Foundation, Inc., 51 Franklin St, Fifth Floor,                        *
00019 *   Boston, MA  02110-1301  USA                                           *
00020 ***************************************************************************/
00021 #ifndef MESSAGE_H
00022 #define MESSAGE_H
00023 
00024 #ifdef HAVE_CONFIG_H
00025 #include "config.h"
00026 #endif
00027 
00028 #include "payload.h"
00029 #include "payload_sk.h"
00030 #include "cipher.h"
00031 #include "payload_notify.h"
00032 #include "ipaddress.h"
00033 #include "autovector.h"
00034 
00035 using namespace std;
00036 
00037 namespace openikev2 {
00038 
00043     class Message : public Printable {
00044 
00045             /****************************** ENUMS ******************************/
00046         public:
00048             enum EXCHANGE_TYPE {
00049                 IKE_SA_INIT = 34,   
00050                 IKE_AUTH,           
00051                 CREATE_CHILD_SA,    
00052                 INFORMATIONAL       
00053         };
00054 
00056             enum MESSAGE_TYPE {
00057                 REQUEST = 0,        
00058                 RESPONSE            
00059         };
00060 
00061             /****************************** ATTRIBUTES ******************************/
00062         protected:
00063             AutoVector<Payload> unencrypted_payloads;   
00064             AutoVector<Payload> encrypted_payloads;     
00065             Payload::PAYLOAD_TYPE first_payload_type;   
00066             Payload::PAYLOAD_TYPE first_payload_type_sk; 
00067             auto_ptr<IpAddress> src_addr;               
00068             auto_ptr<IpAddress> dst_addr;               
00069             auto_ptr<ByteArray> binary_representation;  
00070             auto_ptr<Payload_SK> payload_sk;            
00072         public:
00073             bool can_use_higher_major_version;          
00074             uint8_t major_version;                      
00075             uint8_t minor_version;                      
00076             EXCHANGE_TYPE exchange_type;                
00077             MESSAGE_TYPE message_type;                  
00078             bool is_initiator;                          
00079             uint64_t spi_i;                             
00080             uint64_t spi_r;                             
00081             uint32_t message_id;                        
00084             /****************************** METHODS ******************************/
00085         protected:
00093             static Payload::PAYLOAD_TYPE generatePayloads( Payload::PAYLOAD_TYPE first_payload_type, ByteBuffer& byte_buffer, vector<Payload*> &payloads );
00094 
00101             static auto_ptr<ByteArray> generateBinaryRepresentation( Payload::PAYLOAD_TYPE last_payload_type, const vector<Payload*> payloads );
00102 
00103         public:
00118             Message( auto_ptr<IpAddress> src_addr, auto_ptr<IpAddress> dst_addr, uint64_t spi_i, uint64_t spi_r, uint8_t major_version, uint8_t minor_version, EXCHANGE_TYPE exchange_type, MESSAGE_TYPE message_type, bool is_initiator, bool can_use_higher_major_version, uint32_t message_id );
00119 
00126             Message( auto_ptr<IpAddress> src_addr, auto_ptr<IpAddress> dst_addr, ByteBuffer& byte_buffer );
00127 
00132             Message( const Message& other );
00133 
00139             vector<Payload*> getPayloadsByType( Payload::PAYLOAD_TYPE type ) const;
00140 
00146             Payload* getFirstPayloadByType( Payload::PAYLOAD_TYPE type ) const;
00147 
00154             Payload& getUniquePayloadByType( Payload::PAYLOAD_TYPE type ) const;
00155 
00161             vector<Payload_NOTIFY*> getNotifiesByType( Payload_NOTIFY::NOTIFY_TYPE notification_type ) const ;
00162 
00168             Payload_NOTIFY* getFirstNotifyByType( Payload_NOTIFY::NOTIFY_TYPE notification_type ) const;
00169 
00176             Payload_NOTIFY& getUniqueNotifyByType( Payload_NOTIFY::NOTIFY_TYPE notification_type ) const;
00177 
00183             void addPayload( auto_ptr<Payload> payload, bool is_encrypted );
00184 
00190             void replaceFirstPayloadByType( Payload::PAYLOAD_TYPE type, auto_ptr<Payload> new_payload );
00191 
00197             void replaceFirstNotifyByType( Payload_NOTIFY::NOTIFY_TYPE notify_type, auto_ptr< Payload_NOTIFY > new_payload );
00198 
00204             void addPayloadNotify( auto_ptr<Payload_NOTIFY> notify_payload, bool is_encrypted );
00205 
00211             void addPayloadsNotify( AutoVector<Payload_NOTIFY> notifies, bool is_encrypted );
00212             
00218             ByteArray& getBinaryRepresentation( Cipher *cipher );
00219 
00225             void decryptPayloadSK( Cipher *cipher );
00226 
00232             bool checkIntegrity( Cipher * cipher ) const;
00233 
00238             auto_ptr<Message> clone() const;
00239 
00244             IpAddress& getSrcAddress() const;
00245 
00250             IpAddress& getDstAddress() const;
00251 
00252 
00258             static string EXCHANGE_TYPE_STR( EXCHANGE_TYPE exchange_type );
00259             
00265             static string MESSAGE_TYPE_STR( MESSAGE_TYPE message_type );
00266 
00267             virtual string toStringTab( uint8_t tabs ) const ;
00268 
00269             virtual ~Message();
00270 
00271     };
00272 };
00273 #endif

Generated on Fri Jul 27 11:04:45 2007 for libopenikev2 by  doxygen 1.5.1