Main Page | Class List | File List | Class Members

ace-radius/RadiusPacket.h

00001 /* 00002 * This source file is part of the ace-radius library. This code was 00003 * written by Alex Agranov in 2004-2009, and is covered by the BSD open source 00004 * license. Refer to the accompanying documentation for details on usage and 00005 * license. 00006 */ 00007 00008 #ifndef _RADIUSPACKET_H__ 00009 #define _RADIUSPACKET_H__ 00010 00011 #include "RadiusAttribute.h" 00012 00013 00014 // Radius packet code values (from RFC2865) 00015 #define D_PACKET_ACCESS_REQUEST 1 00016 #define D_PACKET_ACCESS_ACCEPT 2 00017 #define D_PACKET_ACCESS_REJECT 3 00018 #define D_PACKET_ACCOUNTING_REQUEST 4 00019 #define D_PACKET_ACCOUNTING_RESPONSE 5 00020 #define D_PACKET_ACCESS_CHALLENGE 11 00021 #define D_PACKET_STATUS_SERVER 12 00022 #define D_PACKET_STATUS_CLIENT 13 00023 00024 #define D_PACKET_MAX_KNOWN_CODE 13 00025 00026 00027 00028 // Some global constants (following RFC definitions) 00029 #define D_RADIUS_PACKET_HEADER_LENGTH 20 00030 #define D_RADIUS_PACKET_MAX_LENGTH 4096 00031 #define D_AUTHENTICATOR_LENGTH 16 00032 00033 // Raw data buffer is used for storing the whole RADIUS packet _AND_ secret key 00034 // (hence it should be D_RADIUS_PACKET_MAX_LENGTH + D_SECRET_MAX_LENGTH) 00035 #define D_RAW_DATA_LENGTH 4352 00036 00037 00038 class RadiusSecret; 00039 class RadiusClientStack; 00040 00051 class RadiusPacket 00052 { 00053 public: 00054 00056 00065 RadiusPacket(unsigned char p_code, RadiusClientStack & p_stack); 00066 00068 00076 RadiusPacket(unsigned char p_code, RadiusPacket & p_request); 00077 00079 00091 RadiusPacket(unsigned char p_code); 00092 00093 00095 RadiusPacket(const RadiusPacket & p_packet); 00096 00098 ~RadiusPacket(); 00099 00100 00102 00105 unsigned char getCode(void); 00106 00108 const char * getCodeDescription(void); 00109 00110 00112 00115 uint16_t getLength(void); 00116 00117 00118 00120 00123 unsigned char getID(void); 00124 00126 00129 void setID(unsigned char p_id); 00130 00132 void randomID(); 00133 00134 00136 00139 RadiusSecret * getSecret(void); 00140 00142 00145 void setSecret(RadiusSecret * p_secret); 00146 00147 00149 const unsigned char * getAuthenticator(void); 00150 00152 void setAuthenticator(const unsigned char * p_auth); 00153 00154 00155 00157 void dump(); 00158 00159 00161 00182 int getFirstAttribute(RadiusAttribute & p_attr); 00183 00184 00186 00197 int getNextAttribute(RadiusAttribute & p_attr); 00198 00199 00201 00213 int findAttribute(unsigned char p_attrType, RadiusAttribute & p_attr); 00214 00215 00217 00234 int addAttribute(unsigned char p_attrType, RadiusAttribute & p_attr); 00235 00236 00238 unsigned char * getRawData(void); 00239 00240 00242 00249 int adjustLength(uint16_t p_length); 00250 00251 00253 00261 void responseAuthenticator(RadiusSecret * p_secret = NULL); 00262 00263 00264 // Encode User-Password attribute 00265 /* 00266 * When packet is retransmitted through new connection, there may be a need to reencode 00267 * User-Password attribute, since secret key of the new connection may be different. 00268 * That's exacly what this method does - reencodes User-Password attribute, if the 00269 * latter exists in this packet. 00270 * 00271 * RadiusClientConnection class uses this method. 00272 * There seems to be no reason why user application would use this API. 00273 */ 00274 void encodeUserPassword(void); 00275 00276 00278 00286 void accountingRequestAuthenticator(RadiusSecret * p_secret = NULL); 00287 00288 00290 bool verifyResponse(RadiusPacket & p_packet); 00291 00292 private: 00293 00294 friend class RadiusAttribute; 00295 00297 void init(unsigned char p_code); 00298 00300 void randomAuthenticator(void); 00301 00302 00304 00311 void setCode(unsigned char p_code); 00312 00313 00315 00320 void setLength(uint16_t p_length); 00321 00322 00323 00325 unsigned char m_data[D_RAW_DATA_LENGTH]; 00326 00327 00329 RadiusSecret * m_secret; 00330 00331 00332 // User-Password attribute in unencrypted format 00333 /* 00334 * We need this data in order to re-encode User-Password attribute prior to retransmitting it 00335 * through another connection (when more than one RadiusClientConnection is defined); 00336 */ 00337 unsigned char m_password[D_USER_PASSWORD_MAX_LENGTH]; 00338 uint16_t m_passwordLength; 00339 uint16_t m_passwordOffset; 00340 00341 // Old-Password attribute in unencrypted format 00342 /* 00343 * We need this data in order to re-encode Old-Password attribute prior to retransmitting it 00344 * through another connection (when more than one RadiusClientConnection is defined); 00345 */ 00346 unsigned char m_oldPassword[D_USER_PASSWORD_MAX_LENGTH]; 00347 uint16_t m_oldPasswordLength; 00348 uint16_t m_oldPasswordOffset; 00349 }; 00350 00351 #endif // _RADIUSPACKET_H__ 00352

Generated on Tue Aug 11 18:35:06 2009 for ace-radius by doxygen 1.3.7-20040704