Changeset 1000

Show
Ignore:
Timestamp:
02/02/08 18:21:40 (10 months ago)
Author:
mbr
Message:

- Applied modified version of the client-defined access timeout patches
submitted by the PICT SPA Group. There are two new message types to
facilitate client timeouts; one for normal access mode, and the other
for the FORWARD access mode. In the access.conf file, there is also a
new variable "PERMIT_CLIENT_TIMEOUT" to allow each SOURCE stanza to
allow client-defined timeouts or not.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • fwknop/trunk/ChangeLog

    r996 r1000  
    33    - (Grant Ferley) Submitted patch to handle Linux "cooked" interfaces for 
    44      packet capture (e.g. rp-pppoe interfaces). 
     5    - Applied modified version of the client-defined access timeout patches 
     6      submitted by the PICT SPA Group.  There are two new message types to 
     7      facilitate client timeouts; one for normal access mode, and the other 
     8      for the FORWARD access mode.  In the access.conf file, there is also a 
     9      new variable "PERMIT_CLIENT_TIMEOUT" to allow each SOURCE stanza to 
     10      allow client-defined timeouts or not. 
    511    - Added full packet hex dumps (including packet headers) to fwknopd in 
    612      --debug --verbose mode.  This is to help diagnose packet sniffing issues 
  • fwknop/trunk/TODO

    r916 r1000  
    7373 
    7474 
    75 Client derived access timeouts: 
    76  
    77     The current fwknopd implementation maintains access timeouts via the 
    78     FW_ACCESS_TIMEOUT variable in the /etc/fwknop/access.conf file.  This 
    79     strategy works well enough, but it would be useful to allow the SPA client 
    80     to set the timeout (subject to a setting in the access.conf file to permit 
    81     this for an applicable SOURCE stanza).  To support this, a new command 
    82     line argument would need to be added to the fwknop client. 
    83  
    84  
    8575Destination IP address restrictions in /etc/fwknop/access.conf: 
    8676 
  • fwknop/trunk/fwknop

    r996 r1000  
    102102$ext_resolve_user_agent =~ s|-pre\d+||; 
    103103 
    104 ### SPA message types from fwknop clients 
     104### ACCESS message: 
     105###     random data :user : client_timestamp : client_version : \ 
     106###     type (1) : access_request : MD5 
     107my $SPA_ACCESS_MODE  = 1;  ### default 
     108 
     109### COMMAND message: 
     110###     random data :user : client_timestamp : client_version : \ 
     111###     type (0) : command : MD5 
    105112my $SPA_COMMAND_MODE = 0; 
    106 my $SPA_ACCESS_MODE  = 1;  ### default 
     113 
     114### FORWARD ACCESS message: 
     115###     random data :user : client_timestamp : client_version : \ 
     116###     type (2) : access_request : NAT_info : MD5 
    107117my $SPA_FORWARD_ACCESS_MODE = 2; 
    108118 
     119### ACCESS message with client-defined firewall timeout: 
     120###     random data :user : client_timestamp : client_version : \ 
     121###     type (3) : access_request : timeout : MD5 
     122my $SPA_CLIENT_TIMEOUT_ACCESS_MODE = 3; 
     123 
     124### FORWARD ACCESS message with client-defined firewall timeout: 
     125###     random data :user : client_timestamp : client_version : \ 
     126###     type (4) : access_request : NAT_info : timeout : MD5 
     127my $SPA_CLIENT_TIMEOUT_FORWARD_ACCESS_MODE = 4; 
     128 
    109129### default time values 
    110 my $knock_interval    = 60; 
    111 my $fw_access_timeout = 300; 
     130my $knock_interval  = 60; 
     131my $cmdl_fw_timeout = 0; 
    112132 
    113133### default to root (client must run as root in this mode) 
     
    215235die "[*] Must specify a destination server with -D <IP|Host>" 
    216236    unless $knock_dst; 
     237 
     238if ($cmdl_fw_timeout ne '0') { 
     239    die "[*] Must specify a firewall timeout > 0" 
     240        unless $cmdl_fw_timeout > 0; 
     241} 
    217242 
    218243my $print_mode = ''; 
     
    395420    $msg .= &SPA_message(); 
    396421 
     422    ### append FORWARD access requirement (optional) 
     423    $msg .= &SPA_forward_access(); 
     424 
    397425    ### append server authentication method (optional) 
    398426    $msg .= &SPA_server_auth(); 
    399427 
    400     ### append FORWARD access requirement (optional) 
    401     $msg .= &SPA_forward_access(); 
     428    ### append any client defined fw timeout (optional) 
     429    $msg .= &SPA_client_timeout(); 
    402430 
    403431    ### append MD5 sum 
     
    461489        return ':' . $SPA_COMMAND_MODE; 
    462490    } elsif ($forward_access_str) { 
    463         print "        Type:           $SPA_FORWARD_ACCESS_MODE ", 
    464             "(FORWARD access mode)\n" unless $quiet; 
    465         return ':' . $SPA_FORWARD_ACCESS_MODE; 
    466     } 
    467     print "        Type:           $SPA_ACCESS_MODE (access mode)\n" 
    468         unless $quiet; 
    469     return ':' . $SPA_ACCESS_MODE; 
     491        if ($cmdl_fw_timeout > 0) { 
     492            print "        Type:           " . 
     493                "$SPA_CLIENT_TIMEOUT_FORWARD_ACCESS_MODE ", 
     494                "(FORWARD client-timeout access mode)\n" unless $quiet; 
     495            return ':' . $SPA_CLIENT_TIMEOUT_FORWARD_ACCESS_MODE; 
     496        } else { 
     497            print "        Type:           $SPA_FORWARD_ACCESS_MODE ", 
     498                "(FORWARD access mode)\n" unless $quiet; 
     499            return ':' . $SPA_FORWARD_ACCESS_MODE; 
     500        } 
     501    } 
     502    if ($cmdl_fw_timeout > 0) { 
     503        print "        Type:           " . 
     504            "$SPA_CLIENT_TIMEOUT_ACCESS_MODE (access ", 
     505            "client-timeout mode)\n" unless $quiet; 
     506        return ':' . $SPA_CLIENT_TIMEOUT_ACCESS_MODE; 
     507    } else { 
     508        print "        Type:           $SPA_ACCESS_MODE (access mode)\n" 
     509            unless $quiet; 
     510        return ':' . $SPA_ACCESS_MODE; 
     511    } 
    470512} 
    471513 
     
    487529        unless $quiet; 
    488530    return ':' . encode_base64("$enc_allow_ip,$access_str"); 
     531} 
     532 
     533sub SPA_client_timeout() { 
     534    return unless $cmdl_fw_timeout; 
     535    return ':' . $cmdl_fw_timeout; 
    489536} 
    490537 
     
    12791326        'TCP-sock'       => \$spa_established_tcp, 
    12801327        'Access=s'       => \$access_str, 
     1328        'fw-timeout=i'   => \$cmdl_fw_timeout, 
    12811329        'allow-IP=s'     => \$enc_allow_ip, 
    12821330        'source-IP'      => \$enc_source_ip, 
     
    14661514                                 (must use the -R option). The default user 
    14671515                                 agent is: $ext_resolve_user_agent 
     1516    -f, --fw-timeout <seconds> - Specify the time the port will remain open 
     1517                                 on the server (requires 
     1518                                 PERMIT_CLIENT_TIMEOUT in access.conf on the 
     1519                                 fwknopd server side). 
    14681520    --Save-dst                 - Save the command line args for this 
    14691521                                 invocation against the destination to the 
  • fwknop/trunk/fwknopd

    r998 r1000  
    114114 
    115115### SPA message types from fwknop clients 
     116 
     117### ACCESS message: 
     118###     random data :user : client_timestamp : client_version : \ 
     119###     type (1) : access_request : MD5 
     120my $SPA_ACCESS_MODE  = 1;  ### default 
     121 
     122### COMMAND message: 
     123###     random data :user : client_timestamp : client_version : \ 
     124###     type (0) : command : MD5 
    116125my $SPA_COMMAND_MODE = 0; 
    117 my $SPA_ACCESS_MODE  = 1;  ### default 
     126 
     127### FORWARD ACCESS message: 
     128###     random data :user : client_timestamp : client_version : \ 
     129###     type (2) : access_request : NAT_info : MD5 
    118130my $SPA_FORWARD_ACCESS_MODE = 2; 
     131 
     132### ACCESS message with client-defined firewall timeout: 
     133###     random data :user : client_timestamp : client_version : \ 
     134###     type (3) : access_request : timeout : MD5 
     135my $SPA_CLIENT_TIMEOUT_ACCESS_MODE = 3; 
     136 
     137### FORWARD ACCESS message with client-defined firewall timeout: 
     138###     random data :user : client_timestamp : client_version : \ 
     139###     type (4) : access_request : NAT_info : timeout : MD5 
     140my $SPA_CLIENT_TIMEOUT_FORWARD_ACCESS_MODE = 4; 
    119141 
    120142### minimum nummber of fields within a decrypted SPA packet 
     
    122144 
    123145### default time values 
    124 my $knock_interval    = 60; 
    125 my $fw_access_timeout = 300; 
     146my $knock_interval = 60; 
     147my $default_access_timeout = 300; 
    126148 
    127149my $enc_port_offset   = 61000;  ### default offset 
     
    192214    'KNOCK_LIMIT'    => '', 
    193215    'PERMIT_CLIENT_PORTS' => '', 
     216    'PERMIT_CLIENT_TIMEOUT' => '', 
    194217    'ENABLE_FORWARD_ACCESS' => 0, 
    195218    'ENABLE_CMD_EXEC'     => '', 
     
    492515                $access_hr, $src_ip, $msg_hr); 
    493516 
    494             if ($msg_hr->{'action_type'} == $SPA_ACCESS_MODE) { 
    495                 if (&SPA_access($msg_hr, $src_ip, $decrypt_algo, 
    496                         $gpg_sign_id, $md5sum, $access_hr)) { 
    497                     last SOURCE; 
    498                 } else { 
    499                     next SOURCE; 
    500                 } 
    501             } elsif ($msg_hr->{'action_type'} == $SPA_FORWARD_ACCESS_MODE) { 
     517            if ($msg_hr->{'action_type'} == $SPA_ACCESS_MODE 
     518                    or $msg_hr->{'action_type'} == $SPA_FORWARD_ACCESS_MODE 
     519                    or $msg_hr->{'action_type'} == $SPA_FORWARD_ACCESS_MODE 
     520                    or $msg_hr->{'action_type'} 
     521                        == $SPA_CLIENT_TIMEOUT_ACCESS_MODE 
     522                    or $msg_hr->{'action_type'} 
     523                        == $SPA_CLIENT_TIMEOUT_FORWARD_ACCESS_MODE) { 
     524 
    502525                if (&SPA_access($msg_hr, $src_ip, $decrypt_algo, 
    503526                        $gpg_sign_id, $md5sum, $access_hr)) { 
     
    602625 
    603626    print STDERR localtime() . " [+] Packet fields:\n"; 
    604     printf STDERR "    %-14s %s\n    %-14s %s\n    %-14s %s\n" . 
    605                   "    %-14s %s\n    %-14s %s", 
     627    printf STDERR "    %-16s %s\n    %-16s %s\n    %-16s %s\n" . 
     628                  "    %-16s %s\n    %-16s %s", 
    606629            'Random data:', $msg_hr->{'random_number'}, 
    607630            'Username:',    $msg_hr->{'username'}, 
     
    616639    } elsif ($msg_hr->{'action_type'} == $SPA_FORWARD_ACCESS_MODE) { 
    617640        print STDERR " (SPA_FORWARD_ACCESS_MODE)\n"; 
    618     } 
    619     printf STDERR "    %-14s %s\n", 
     641    } elsif ($msg_hr->{'action_type'} == $SPA_CLIENT_TIMEOUT_ACCESS_MODE) { 
     642        print STDERR " (SPA_CLIENT_TIMEOUT_ACCESS_MODE)\n"; 
     643    } elsif ($msg_hr->{'action_type'} == $SPA_CLIENT_TIMEOUT_FORWARD_ACCESS_MODE) { 
     644        print STDERR " (SPA_CLIENT_TIMEOUT_FORWARD_ACCESS_MODE)\n"; 
     645    } 
     646    printf STDERR "    %-16s %s\n", 
    620647            'Action:', $msg_hr->{'action'}; 
     648 
     649    if ($msg_hr->{'action_type'} == $SPA_CLIENT_TIMEOUT_ACCESS_MODE 
     650            or $msg_hr->{'action_type'} 
     651                == $SPA_CLIENT_TIMEOUT_FORWARD_ACCESS_MODE) { 
     652        printf STDERR "    %-16s %s\n", 
     653                'Client timeout:', $msg_hr->{'client_timeout'}; 
     654    } 
    621655 
    622656    if ($msg_hr->{'server_auth'}) { 
     
    625659            my $server_auth_crypt_pw = $2; 
    626660            if ($debug) { 
    627                 printf STDERR "    %-14s %s", 'Server auth:', $server_auth_type; 
     661                printf STDERR "    %-16s %s", 'Server auth:', $server_auth_type; 
    628662                for (my $i=0; $i<length($server_auth_crypt_pw); $i++) { 
    629663                    print STDERR '*'; 
     
    634668    } 
    635669    if ($msg_hr->{'forward_info'}) { 
    636         printf STDERR "    %-14s %s\n", 'Forward info:', $msg_hr->{'forward_info'}; 
    637     } 
    638     printf STDERR "    %-14s %s\n", 'MD5 sum:', $msg_hr->{'md5sum'}; 
     670        printf STDERR "    %-16s %s\n", 'Forward info:', 
     671            $msg_hr->{'forward_info'}; 
     672    } 
     673    printf STDERR "    %-16s %s\n", 'MD5 sum:', $msg_hr->{'md5sum'}; 
    639674    return; 
    640675} 
     
    714749    } 
    715750 
     751    if ($msg_hr->{'action_type'} == $SPA_CLIENT_TIMEOUT_ACCESS_MODE 
     752            or $msg_hr->{'action_type'} 
     753                == $SPA_CLIENT_TIMEOUT_FORWARD_ACCESS_MODE) { 
     754 
     755        if ($access_hr->{'PERMIT_CLIENT_TIMEOUT'}) { 
     756            $access_hr->{'FW_ACCESS_TIMEOUT'} = $msg_hr->{'client_timeout'}; 
     757        } else { 
     758            &logr('[-]', "received fw access request from $src_ip, " . 
     759                "with client-defined timeout, but PERMIT_CLIENT_TIMEOUT is not " . 
     760                "set (SOURCE line num: $access_hr->{'src_line_num'})", $NO_MAIL); 
     761            return 0; 
     762        } 
     763    } 
     764 
    716765    $allow_src = $1 if $msg_hr->{'action'} =~ /($ip_re)/; 
    717766 
     
    10631112        'server_auth'     => '',  ### optional 
    10641113        'forward_info'    => '',  ### optional 
     1114        'client_timeout'  => -1,  ### optional 
    10651115        'md5sum'          => '', 
    10661116    ); 
     
    11241174    if (&is_digit($fields[4])) { 
    11251175        return 0, {} unless $fields[4] == $SPA_COMMAND_MODE 
    1126                          or $fields[4] == $SPA_ACCESS_MODE 
    1127                          or $fields[4] == $SPA_FORWARD_ACCESS_MODE; 
     1176                or $fields[4] == $SPA_ACCESS_MODE 
     1177                or $fields[4] == $SPA_FORWARD_ACCESS_MODE 
     1178                or $fields[4] == $SPA_CLIENT_TIMEOUT_ACCESS_MODE 
     1179                or $fields[4] == $SPA_CLIENT_TIMEOUT_FORWARD_ACCESS_MODE; 
    11281180        $msg_hsh{'action_type'} = $fields[4]; 
    11291181    } else { 
     
    11411193        ### iptables FORWARD/DNAT access was introduced in 1.9.0 
    11421194        if ($msg_hsh{'numeric_version'} >= 190) { 
     1195            my $found = 0; 
    11431196            if ($msg_hsh{'action_type'} == $SPA_FORWARD_ACCESS_MODE) { 
    11441197                if ($#fields == $SPA_MIN_PACKET_FIELDS+1) { 
    11451198                    $msg_hsh{'forward_info'} = decode_base64($fields[6]); 
     1199                    $found = 1; 
    11461200                } 
    1147             } else { 
     1201            } elsif ($msg_hsh{'numeric_version'} >= 192) { 
     1202                ### client timeouts were introduced in 1.9.2 
     1203                if ($msg_hsh{'action_type'} == $SPA_CLIENT_TIMEOUT_ACCESS_MODE) { 
     1204                    $msg_hsh{'client_timeout'} = $fields[6]; 
     1205                    $found = 1; 
     1206                } elsif ($msg_hsh{'action_type'} 
     1207                            == $SPA_CLIENT_TIMEOUT_FORWARD_ACCESS_MODE) { 
     1208                    $msg_hsh{'client_timeout'} = $fields[7]; 
     1209                    $found = 1; 
     1210                } 
     1211            } 
     1212            unless ($found) { 
    11481213                if ($#fields > $SPA_MIN_PACKET_FIELDS) { 
    11491214                    $msg_hsh{'server_auth'} = decode_base64($fields[6]); 
     
    11721237            "$msg_hsh{'username'}:$msg_hsh{'remote_time'}:", 
    11731238            "$msg_hsh{'remote_version'}:$msg_hsh{'action_type'}:", 
    1174             "$msg_hsh{'action'}:$msg_hsh{'md5sum'}"; 
     1239            "$msg_hsh{'action'}"; 
     1240 
     1241        if ($msg_hsh{'forward_info'}) { 
     1242            print STDERR ":$msg_hsh{'forward_info'}"; 
     1243        } 
     1244 
     1245        if ($msg_hsh{'client_timeout'}) { 
     1246            print STDERR ":$msg_hsh{'client_timeout'}"; 
     1247        } 
    11751248 
    11761249        ### careful not to display password information 
     
    11821255                print STDERR "*"; 
    11831256            } 
    1184         } elsif ($msg_hsh{'forward_info'}) { 
    1185             print STDERR ":$msg_hsh{'forward_info'}"; 
    1186         } 
    1187         print STDERR "\n"; 
     1257        } 
     1258 
     1259        print STDERR ":$msg_hsh{'md5sum'}\n"; 
    11881260    } 
    11891261    return 1, \%msg_hsh; 
     
    30483120                        $access_hsh{'PERMIT_CLIENT_PORTS'} = 0; 
    30493121                    } 
     3122                } elsif ($line =~ /^\s*PERMIT_CLIENT_TIMEOUT\s*;/) { 
     3123                    $access_hsh{'PERMIT_CLIENT_TIMEOUT'} = 1; 
     3124                } elsif ($line =~ /^\s*PERMIT_CLIENT_TIMEOUT:\s*(\S+);/) { 
     3125                    my $val = $1; 
     3126                    if ($val =~ /y/i) { 
     3127                        $access_hsh{'PERMIT_CLIENT_TIMEOUT'} = 1; 
     3128                    } else { 
     3129                        $access_hsh{'PERMIT_CLIENT_TIMEOUT'} = 0; 
     3130                    } 
    30503131                } elsif ($line =~ /^\s*ENABLE_CMD_EXEC\s*;/) { 
    30513132                    $access_hsh{'ENABLE_CMD_EXEC'} = 1; 
     
    30773158                } elsif ($line =~ /^\s*FW_ACCESS_TIMEOUT:\s*(\d+)\s*;/) { 
    30783159                    $access_hsh{'FW_ACCESS_TIMEOUT'} = $1; 
     3160                } elsif ($line =~ /^\s*MAX_ACCESS_TIMEOUT:\s*(\d+)\s*;/) { 
     3161                    $access_hsh{'FW_ACCESS_TIMEOUT'} = $1; 
    30793162                } elsif ($line =~ /^\s*REQUIRE_OS:\s*(.*)\s*;/) { 
    30803163                    $access_hsh{'REQUIRE_OS'} = $1; 
     
    30953178        unless (defined $access_hsh{'PERMIT_CLIENT_PORTS'}) { 
    30963179            $access_hsh{'PERMIT_CLIENT_PORTS'} = 0; 
     3180        } 
     3181        unless (defined $access_hsh{'PERMIT_CLIENT_TIMEOUT'}) { 
     3182            $access_hsh{'PERMIT_CLIENT_TIMEOUT'} = 0; 
    30973183        } 
    30983184        if (&validate_src_access_hsh(\%access_hsh)) { 
     
    32993385        } 
    33003386    } else { 
    3301         &logr('[-]', "$config{'ACCESS_CONF'}: SOURCE: $src (line: $src_line) " . 
    3302             "missing FW_ACCESS_TIMEOUT, defaulting to $fw_access_timeout", 
    3303             $NO_MAIL); 
    3304         $src_href->{'FW_ACCESS_TIMEOUT'} = $fw_access_timeout; 
     3387        if (defined $src_href->{'PERMIT_CLIENT_TIMEOUT'}) { 
     3388            ### in this case we will derive the timeout from the SPA 
     3389            ### packet. 
     3390            $src_href->{'FW_ACCESS_TIMEOUT'} = 0; 
     3391        } else { 
     3392            &logr('[-]', "$config{'ACCESS_CONF'}: SOURCE: $src (line: $src_line) " . 
     3393                "missing FW_ACCESS_TIMEOUT, defaulting to $default_access_timeout", 
     3394                $NO_MAIL); 
     3395            $src_href->{'FW_ACCESS_TIMEOUT'} = $default_access_timeout; 
     3396        } 
    33053397    } 
    33063398    if (defined $src_href->{'KNOCK_LIMIT'}) { 
  • fwknop/trunk/test/fwknop_test.pl

    r999 r1000  
    5959my $multi_source_access_conf = "$conf_dir/multi_source_access.conf"; 
    6060my $no_loopback_ip_match_access_conf = "$conf_dir/no_loopback_ip_match_access.conf"; 
     61my $client_timeout_access_conf = "$conf_dir/client_timeout_access.conf"; 
    6162 
    6263my $local_key_file = 'local_spa.key'; 
     
    99100my $ip_re   = qr|(?:[0-2]?\d{1,2}\.){3}[0-2]?\d{1,2}|; 
    100101 
    101 ### SPA message types from fwknop clients 
     102### ACCESS message: 
     103###     random data :user : client_timestamp : client_version : \ 
     104###     type (1) : access_request : MD5 
     105my $SPA_ACCESS_MODE  = 1;  ### default 
     106 
     107### COMMAND message: 
     108###     random data :user : client_timestamp : client_version : \ 
     109###     type (0) : command : MD5 
    102110my $SPA_COMMAND_MODE = 0; 
    103 my $SPA_ACCESS_MODE  = 1;  ### default 
     111 
     112### FORWARD ACCESS message: 
     113###     random data :user : client_timestamp : client_version : \ 
     114###     type (2) : access_request : NAT_info : MD5 
    104115my $SPA_FORWARD_ACCESS_MODE = 2; 
     116 
     117### ACCESS message with client-defined firewall timeout: 
     118###     random data :user : client_timestamp : client_version : \ 
     119###     type (3) : access_request : timeout : MD5 
     120my $SPA_CLIENT_TIMEOUT_ACCESS_MODE = 3; 
     121 
     122### FORWARD ACCESS message with client-defined firewall timeout: 
     123###     random data :user : client_timestamp : client_version : \ 
     124###     type (4) : access_request : NAT_info : timeout : MD5 
     125my $SPA_CLIENT_TIMEOUT_FORWARD_ACCESS_MODE = 4; 
    105126 
    106127### make Getopts case sensitive 
     
    191212&stop_fwknopd_quiet(); 
    192213 
     214### client timeout with --fw-timeout on fwknop command line 
     215&test_driver('(Client timeout) Generating SPA access packet', 
     216    \&SPA_client_timeout_access_packet); 
     217&test_driver('(Client timeout) Sniffing SPA access packet', 
     218    \&client_timeout_sniff_decrypt); 
     219&test_driver('(Client timeout) Verifying SPA access packet format', 
     220    \&spa_client_timeout_access_format); 
     221&test_driver('(Client timeout) Firewall access rules exist', 
     222    \&fw_rules_exist); 
     223&fw_sleep_10();  ### give knoptm a chance to remove the rules 
     224&test_driver('(Client timeout) Firewall access rules removed', 
     225    \&fw_rules_removed); 
     226&test_driver('(Client timeout) Stopping all running fwknopd processes', 
     227    \&stop_fwknopd); 
     228 
    193229### It is ok to append data in the current code since the Rijndael decrypt 
    194230### only returns the actual SPA payload (may need to revist this) 
     
    571607 
    572608sub non_matching_source_generation() { 
    573     return &get_access_packet(); 
     609    return &get_access_packet(0); 
    574610} 
    575611 
     
    690726        "rule timeout)\n    "); 
    691727    for (my $i=$fw_access_timeout+3; $i > 0; $i--) { 
     728        &logr("$i "); 
     729        sleep 1; 
     730    } 
     731    &logr("0\n"); 
     732    return; 
     733} 
     734 
     735sub fw_sleep_10() { 
     736    &logr("    (Sleeping for 10 seconds for firewall " . 
     737        "rule timeout)\n    "); 
     738    for (my $i=10; $i > 0; $i--) { 
    692739        &logr("$i "); 
    693740        sleep 1; 
     
    881928} 
    882929 
     930sub spa_client_timeout_access_format() { 
     931    ### Random data:    1946117908964953 
     932    ### Username:       root 
     933    ### Remote time:    1197922462 
     934    ### Remote ver:     1.9.0 
     935    ### Action type:    1 (SPA_ACCESS_MODE) 
     936    ### Action:         127.0.0.2,none,0 
     937    ### Client timeout: 5 
     938    ### MD5 sum:        DLnVQDc5XTkazUbeJX14Og 
     939    my $valid_lines = 0; 
     940    open F, "< $fwknopd_output_file" or die "[*] Could not open ", 
     941        "$fwknopd_output_file: $!"; 
     942    while (<F>) { 
     943        if (/^\s+Random\s+data:\s+\d+/i) { 
     944            $valid_lines++; 
     945        } elsif (/^\s+Username:\s+\w+$/i) { 
     946            $valid_lines++; 
     947        } elsif (/^\s+Remote\s+time:\s+\d+$/i) { 
     948            $valid_lines++; 
     949        } elsif (/^\s+Remote\s+ver:\s+(\S+)$/i) { 
     950            $valid_lines++; 
     951        } elsif (/^\s+Action\s+type:\s+$SPA_CLIENT_TIMEOUT_ACCESS_MODE\s+/i) { 
     952            $valid_lines++; 
     953        } elsif (/^\s+Action:\s+$ip_re/i) { 
     954            $valid_lines++; 
     955        } elsif (/^\s+Client\s+timeout:\s+\d+/i) { 
     956            $valid_lines++; 
     957        } elsif (/^\s+MD5\s+sum:\s+\S+$/i) { 
     958            $valid_lines++; 
     959        } 
     960    } 
     961    close F; 
     962    unless ($valid_lines == 8) { 
     963        return &print_errors("fail ($test_num)\n[*] Dubious " . 
     964            "sniffed packet format"); 
     965    } 
     966    return 1; 
     967} 
     968 
    883969sub spa_access_format() { 
    884970    ### Random data:   1946117908964953 
     
    12391325} 
    12401326 
     1327sub SPA_client_timeout_access_packet() { 
     1328    return &get_access_packet(5); 
     1329} 
     1330 
    12411331sub SPA_access_packet() { 
    1242     return &get_access_packet(); 
     1332    return &get_access_packet(0); 
    12431333} 
    12441334 
     
    12711361    } 
    12721362    die "[*] Could not assign valid unauthorized port" unless $unauth_port; 
    1273     my $rv = &get_access_packet(); 
     1363    my $rv = &get_access_packet(0); 
    12741364    $open_ports = $port_copy; 
    12751365    return $rv; 
     
    13051395    my $require_user_copy = $require_user; 
    13061396    $require_user = 'mbr' . $require_user; 
    1307     my $rv = &get_access_packet(); 
     1397    my $rv = &get_access_packet(0); 
    13081398    $require_user = $require_user_copy; 
    13091399    return $rv; 
     
    13381428 
    13391429sub truncated_SPA_packet() { 
    1340     my $rv = &get_access_packet(); 
     1430    my $rv = &get_access_packet(0); 
    13411431    ### chop off the last 10 chars 
    13421432    $cache_encrypted_Rijndael_spa_packet =~ s|.{10}$||; 
     
    13451435 
    13461436sub append_SPA_packet() { 
    1347     my $rv = &get_access_packet(); 
     1437    my $rv = &get_access_packet(0); 
    13481438    ### append 10 garbage chars 
    13491439    $cache_encrypted_Rijndael_spa_packet .= '1234567890'; 
     
    13901480} 
    13911481 
     1482sub client_timeout_sniff_decrypt() { 
     1483 
     1484    $fwknopd_output_file = "${cmd_stderr}.$test_num"; 
     1485 
     1486    if (&run_fwknopd($cache_encrypted_Rijndael_spa_packet, 
     1487            $default_fwknop_conf, $client_timeout_access_conf)) { 
     1488 
     1489        ### now that fwknopd has exited, see if the SPA packet was valid 
     1490        open SE, "< $fwknopd_output_file" 
     1491            or die "[*] Could not open $fwknopd_output_file: $!"; 
     1492        while (<SE>) { 
     1493            if (/\[\-\]\s+Key\s+mis\-?match/i) { 
     1494                ### [-] Key mis-match or broken message checksum for SOURCE \ 
     1495                ### ANY (# 1 in access.conf) 
     1496                return &print_errors("fail ($test_num)\n[*] " . 
     1497                    "Key mis-match"); 
     1498            } elsif (/\[\-\]\s+Decrypted.*not\s+conform/i) { 
     1499                ### [-] Decrypted message does not conform to a valid SPA packet 
     1500                return &print_errors("fail ($test_num)\n[*] " . 
     1501                        "Invalid SPA packet"); 
     1502            } 
     1503        } 
     1504        close SE; 
     1505        return 1; 
     1506    } 
     1507    return &print_errors("fail ($test_num)\n[*] Sniff alarm " . 
     1508            "($sniff_alarm seconds) expired"); 
     1509} 
     1510 
    13921511sub append_SPA_sniff_decrypt() { 
    13931512 
     
    14611580    my $spa_src_copy = $spa_src; 
    14621581    $spa_src = '0.0.0.0'; 
    1463     my $rv = &get_access_packet(); 
     1582    my $rv = &get_access_packet(0); 
    14641583    $spa_src = $spa_src_copy; 
    14651584    return $rv; 
     
    15021621    for (my $i=0; $i < $NUM_RAND; $i++) { 
    15031622 
    1504         &get_access_packet(); 
     1623        &get_access_packet(0); 
    15051624 
    15061625        if (defined $packet_cache{$cache_encrypted_Rijndael_spa_packet}) { 
     
    16261745 
    16271746sub get_access_packet() { 
     1747    my $client_timeout = shift; 
    16281748 
    16291749    ### --Test so that SPA packet is not sent 
     
    16371757    close K; 
    16381758 
    1639     unless (&run_cmd("$fwknopCmd -A $open_ports --no-save --get-key " . 
     1759    my $cmd = "$fwknopCmd -A $open_ports --no-save --get-key " . 
    16401760            "$local_key_file -D $spa_dst -a $spa_src --Test -v " . 
    1641             "--debug --Spoof-user $require_user")) { 
    1642         return &print_errors("fail ($test_num)\n[*] Could not " . 
    1643                 "generate encrypted SPA packet"); 
     1761            "--debug --Spoof-user $require_user"; 
     1762 
     1763    if ($client_timeout) { 
     1764        $cmd .= " --fw-timeout $client_timeout"; 
     1765    } 
     1766 
     1767    unless (&run_cmd($cmd)) { 
     1768        if ($client_timeout) { 
     1769            return &print_errors("fail ($test_num)\n[*] Could not " . 
     1770                    "generate client timeout encrypted SPA packet"); 
     1771        } else { 
     1772            return &print_errors("fail ($test_num)\n[*] Could not " . 
     1773                    "generate encrypted SPA packet"); 
     1774        } 
    16441775    } 
    16451776    open F, "< ${cmd_stdout}.$test_num"