NSIS-ka
A free C++ implementation of NSIS protocols

Changeset 4098


Ignore:
Timestamp:
Jul 15, 2009, 5:32:51 PM (8 years ago)
Author:
bless
Message:
  • added additional consistency check for stack configuration data and

stack profile

  • added at() operators in stackconf and stackprop for more robust access
Location:
ntlp/branches/20080820-configpar/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • ntlp/branches/20080820-configpar/src/capability.cpp

    r4087 r4098  
    3131#include "gist_conf.h" // required to to access to config parameters
    3232
    33 namespace ntlp {
     33  using namespace ntlp;
    3434  using namespace protlib;
    3535  using namespace protlib::log;
     
    419419}
    420420
     421// create responder stack configuration data
     422// @param sc existing stack configuration data which is used to put the result in
     423//           may be NULL (then a new one is allocated)
    421424stack_conf_data*
    422425capability::resp_stackconf(stack_conf_data* sc, bool secure) const
     
    513516}
    514517
    515 
    516 } // end namespace
     518// compares a stack profile and stack configuration data
     519// and checks for consistency
     520bool
     521capability::is_consistent(const stackprop* sp, const stack_conf_data* sc) const
     522{
     523    if ( sp == NULL || sc == NULL )
     524                return true;
     525
     526    const ma_protocol_option* ma_prot_opt= NULL;
     527    const stackprofile* stackprof= NULL;
     528    uint8 profile_index= 0;
     529    // the following checks whether protocols at the
     530    // stack conf and stack profile are the same at the same index
     531    for (unsigned int i = 0; i<sc->length(); i++)
     532    {
     533            ma_prot_opt= sc->get_protoption(i);
     534            if ( ma_prot_opt )
     535            {
     536                    profile_index= ma_prot_opt->get_profile();
     537                    if (profile_index > 0)
     538                    {
     539                            stackprof= sp->get_profile(profile_index-1);
     540                            bool found_protid= false;
     541                            for (unsigned int j= 0; j<stackprof->prof_vec.size(); j++)
     542                                    if ( stackprof && ma_prot_opt->get_protocol() == stackprof->prof_vec.at(j) )
     543                                    {
     544                                            found_protid= true;
     545                                    }
     546                            if (!found_protid) // protocol mismatch at the profile index
     547                                    return false;
     548                    }
     549            }
     550    } // end for
     551    return true;
     552}
     553
  • ntlp/branches/20080820-configpar/src/capability.h

    r2949 r4098  
    7474  bool accept_proposal(const stackprop* sp, bool secure = false) const;
    7575 
     76  bool is_consistent(const stackprop* sp, const stack_conf_data* sc) const;
     77 
    7678private:
    7779 
  • ntlp/branches/20080820-configpar/src/ntlp_statemodule_querier.cpp

    r4093 r4098  
    249249    sc= cap.query_stackconf(secure);
    250250    sc->set_ma_hold_time(gconf.getpar<uint32>(gistconf_ma_hold_time));
    251  
    252     DLog(param.name, "Constructed Stack Proposal/Stack Configuration data for C-Mode handshake");
     251
     252    if (cap.is_consistent(sp,sc))
     253    {
     254        DLog(param.name, "Successfully constructed Stack Proposal/Stack Configuration data for C-Mode handshake");
     255    }
     256    else
     257    {
     258      ERRCLog(param.name, "Constructed inconsistent Stack Proposal/Stack Configuration data for C-Mode handshake, not sending any query. Programming error, please fix the code.");
     259      delete mysid;
     260      delete mymri;
     261      delete data;
     262      delete mynli;
     263      delete sp;
     264      delete sc;
     265      return;
     266    }
    253267  }
    254268
  • ntlp/branches/20080820-configpar/src/ntlp_statemodule_responder.cpp

    r4010 r4098  
    10461046      own_sc->set_ma_hold_time(gconf.getpar<uint32>(gistconf_ma_hold_time));
    10471047     
     1048      if (cap.is_consistent(own_sp,own_sc))
     1049      {
     1050              DLog(param.name, "Successfully constructed Stack Proposal/Stack Configuration data for C-Mode handshake");
     1051      }
     1052      else
     1053      {
     1054              ERRCLog(param.name, "Constructed inconsistent Stack Proposal/Stack Configuration data for C-Mode handshake, not sending any query. Programming error, please fix the code.");
     1055      }
     1056
    10481057      // save them for retries
    10491058      delete (r_entry->sp);
  • ntlp/branches/20080820-configpar/src/pdu/stackconf.h

    r4097 r4098  
    3131#include "protlib_types.h"
    3232
     33#include <stdexcept> // for std::out_of_range
    3334
    3435
     
    9495  void set_protocol(protocol_t prot) { protocol=prot; }
    9596
     97  /// returns number of profile
    9698  uint8 get_profile() const { return profile; }
    9799
     100  /// sets number of profile
    98101  void set_profile(uint8 prop) { profile=prop; }
    99102
     
    159162
    160163  /// get a protocol option
    161   const ma_protocol_option* get_protoption(uint32 index) const { return &ma_prot_options[index]; }
     164  const ma_protocol_option* get_protoption(uint32 index) const { try { return &ma_prot_options.at(index); } catch (std::out_of_range& e) { return NULL; } }
    162165
    163166  /// get length
  • ntlp/branches/20080820-configpar/src/pdu/stackprop.cpp

    r2926 r4098  
    3434#include "logfile.h"
    3535#include <iomanip>
     36#include <stdexcept>
    3637
    3738namespace ntlp {
     
    327328
    328329
     330const stackprofile*
     331stackprop::get_profile(uint32 index) const
     332{
     333        try
     334        {
     335                return &(profiles.at(index));
     336        }
     337        catch(std::out_of_range& orexception)
     338        {
     339                return NULL;
     340        } 
     341}
     342
    329343//@}
    330344
  • ntlp/branches/20080820-configpar/src/pdu/stackprop.h

    r2748 r4098  
    110110
    111111  // get a profile
    112   const stackprofile* get_profile(uint32 index) const {return &(profiles[index]); }
     112  const stackprofile* get_profile(uint32 index) const;
    113113
    114114  // return profile count
Note: See TracChangeset for help on using the changeset viewer.