/usr/lib/ipsec/verify is in openswan 1:2.6.37-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 | #!/usr/bin/perl
#
# Copyright (C) 2003 Sam Sgro <sam@freeswan.org>
# Copyright (C) 2005-2008 Michael Richardson <mcr@xelerance.com>
# Copyright (C) 2005-2009 Paul Wouters <paul@xelerance.com>
#
# Based on "verify" from the FreeS/WAN distribution, (C) 2001 Michael
# Richardson <mcr@freeswan.org>
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
$reterr = 0;
$me="ipsec verify";
$ENV{'PATH'}="/sbin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/sbin:$ENV{'PATH'}";
if($ENV{'IPSEC_CONFS'}) { $conf=$ENV{'IPSEC_CONFS'} } else { $conf= `ipsec --confdir`; chomp($conf); }
$print_deprecated = 1;
# Should we print in colour by default?
if ( -e "/sbin/consoletype" )
{
$ctype=`/sbin/consoletype`;
if ( $ctype && !($ctype eq "serial"))
{
$colour="1";
}
}
else
{
if ( -e "/usr/bin/tput" )
{
$ctype=`/usr/bin/tput colors`;
if ( $ctype && ($ctype gt "0"))
{
$colour="1";
}
}
}
sub printfun {
print sprintf("%-60s",@_);
}
# capture STDOUT as @out, STDERR as @err with no temp files.
sub run {
$command=shift;
pipe child_read, parent_write;
pipe parent_read, child_write;
pipe err_read, err_write;
$mypid=fork;
if($mypid)
{
close child_write; close err_write;
@out=<parent_read>;
@err=<err_read>;
}
else
{
close parent_read; close parent_write;
open STDOUT,">&child_write";
open STDERR,">&err_write";
exec $command; $reterr = 1 ; print STDERR "Cannot execute command \"$command\": $!\n";
}
}
# Code to print out [OK], [FAILED].
sub errchk {
if (!shift(@_))
{
print "\t[";
if($colour) { print "\e[1;31m"; }
if(@_)
{
print "@_";
}
else
{
print "FAILED";
$reterr = 1;
}
if($colour) { print "\e[0;39m"; }
print "]\n";
if(@err)
{
print " @err";
$reterr = 1;
}
}
else
{
print "\t[";
if($colour) { print "\e[1;32m"; }
print "OK";
if($colour) { print "\e[0;39m"; }
print "]\n";
}
}
# Code to print out [OK], [FAILED] in warning colours
sub warnchk {
if (!shift(@_))
{
print "\t[";
if($colour) { print "\e[1;33m"; }
if(@_)
{
print "@_";
}
else
{
print "FAILED";
$reterr = 1;
}
if($colour) { print "\e[0;39m"; }
print "]\n";
if(@err)
{
print " @err";
$reterr = 1;
}
}
else
{
print "\t[";
if($colour) { print "\e[1;32m"; }
print "OK";
if($colour) { print "\e[0;39m"; }
print "]\n";
}
}
# Code to print out [DEPRECATED] and key restrict message
sub deprecated {
print "\t[";
if($colour) { print "\e[1;33m"; }
print "DEPRECATED";
if($colour) { print "\e[0;39m"; }
print "]\n";
}
# Verification routines begin here...
#
# Check DNS Configuration based on a hostname
# $1 = Hostname (string)
# eg: checkdnshost oetest.freeswan.org
sub checkdnshost {
run "host -t key $_[0]";
($keypresent)=grep /(0x4200|16896)/, @out;
if($keypresent)
{
printfun " Looking for KEY in forward dns zone: $_[0]";
deprecated;
}
printfun " Looking for TXT in forward dns zone: $_[0]";
run "host -t txt $_[0]";
($txtpresent)=grep /X-IPsec-Server/,@out;
errchk "$txtpresent", "MISSING";
}
# Check DNS Configuration based on IP address
# $1 = IP Address (string)
# eg: checkdnsip 127.0.0.2
sub checkdnsip {
$fortxt=$_[0];
$revtxt=join('.',reverse(split(/\./, $fortxt))).".in-addr.arpa.";
printfun " Looking for TXT in reverse dns zone: $revtxt";
run "host -t txt $revtxt";
($txtpresent)=grep /X-IPsec-Server/,@out;
errchk "$txtpresent", "MISSING";
if($txtpresent) {
$txtpresent=~ s/.*X-IPsec-Server\([0-9].*\)=//; $txtpresent=~ s/[\"\ ].*//;
$gwip=$txtpresent;
chomp($gwip);
$gwrev=join('.',reverse(split(/\./, $gwip))).".in-addr.arpa.";
# Check for a KEY record for the indicated IPSec GW.
run "host -t key $gwrev";
($keypresent)=grep /(0x4200|16896)/, @out;
if($keypresent)
{
printfun " Looking for KEY in reverse dns zone: $gwrev";
deprecated;
$print_deprecated = 1;
}
# If the host is its own gateway, then we know we've got a TXT record.
if($gwip ne $fortxt) {
printfun "Looking for TXT in reverse dns zone: $gwrev";
run "host -t txt $gwrev";
($txtpresent)=grep /X-IPsec-Server/,@out;
errchk "$txtpresent", "MISSING";
}
}
}
sub udp500check {
printfun " Pluto listening for IKE on udp 500";
run "lsof -i UDP:500";
#run "netstat -an";
($listen)=grep /pluto/, @out;
if(!$listen)
{
errchk "", "FAILED";
$reterr = 1;
}
else
{
errchk "1";
}
}
sub udp4500check {
printfun " Pluto listening for NAT-T on udp 4500";
run "lsof -i UDP:4500";
#run "netstat -an";
($listen)=grep /pluto/, @out;
if(!$listen)
{
errchk "", "FAILED";
$reterr = 1;
}
else
{
errchk "1";
}
}
sub checktunnel {
$csource=$_[0]; $cdest=$_[1]; $ctun=$_[2]; $all="0.0.0.0/0";
printfun "Checking $ctun from $csource to $cdest";
run "iptables -t nat -L POSTROUTING -n";
@out=grep !/(Chain POSTROUTING|target)/, @out;
foreach (@out) {
( $target, $prot, $opt, $source, $dest ) = split(' ',$_);
if(((($source eq $csource) || ($source eq $all)) && (($dest eq $cdest) || ($dest = $all))) && $target eq "ACCEPT")
{
errchk "@out";
$reterr = 1;
}
else
{
@err="$target from $source to $dest kills tunnel $source -> $cdest\n";
errchk "","FAILED";
$reterr = 1;
}
}
}
sub installstartcheck {
print "Checking your system to see if IPsec got installed and started correctly:\n";
printfun "Version check and ipsec on-path";
run "ipsec --version";
errchk "@out";
print grep /Linux/, @out;
printfun "Checking for IPsec support in kernel";
if ( -e "/proc/net/ipsec_eroute" || -e "/proc/net/pfkey" ) { $test="1" }
errchk "$test";
# This requires KLIPS NAT-T patch > 2.4.x
if ( -e "/proc/net/ipsec_eroute") {
printfun " KLIPS: checking for NAT Traversal support";
if ( -e "/sys/module/ipsec/parameters/natt_available") {
run "cat /sys/module/ipsec/parameters/natt_available";
if("@out" =="1\n")
{ warnchk "", "OLD STYLE"; }
else {
if("@out" == "2\n")
{ errchk "OK"; }
else
{ warnchk "", "UNKNOWN"; }
}
} else { warnchk "","UNKNOWN"; }
printfun " KLIPS: checking for OCF crypto offload support ";
if ( -e "/sys/module/ipsec/parameters/ocf_available") {
run "cat /sys/module/ipsec/parameters/ocf_available";
if("@out" =="1\n")
{ errchk "OK"; }
else {
{ warnchk "", "N/A"; }
}
} else { warnchk "","UNKNOWN"; }
}
# Check for SAref kernel
if ( -e "/proc/net/ipsec/saref") {
printfun " Kernel: IPsec SAref kernel support";
run "grep 'refinfo patch applied' /proc/net/ipsec/saref";
if("@out" eq "refinfo patch applied\n")
{ errchk "OK"; }
else
{ warnchk "", "N/A"; }
printfun " Kernel: IPsec SAref Bind kernel support";
run "grep 'bindref patch applied' /proc/net/ipsec/saref";
if("@out" eq "bindref patch applied\n")
{ errchk "OK"; }
else
{ warnchk "", "N/A"; }
} else {
printfun " SAref kernel support";
{ warnchk "", "N/A"; }
}
if ( -e "/proc/net/pfkey") {
printfun " NETKEY: Testing XFRM related proc values";
open("cat", "/proc/sys/net/ipv4/conf/default/send_redirects");
if(<cat> == "1")
{
errchk "";
$reterr = 1;
print "\n Please disable /proc/sys/net/ipv4/conf/*/send_redirects\n or NETKEY will cause the sending of bogus ICMP redirects!\n\n";
}
else { errchk "1"; }
open("cat", "/proc/sys/net/ipv4/conf/default/accept_redirects");
if(<cat> == "1")
{
$reterr = 1;
errchk "";
print "\n Please disable /proc/sys/net/ipv4/conf/*/accept_redirects\n or NETKEY will accept bogus ICMP redirects!\n\n";
}
else { errchk "1"; }
open("cat", "/proc/sys/net/core/xfrm_larval_drop");
if(<cat> == "0")
{
$reterr = 1;
errchk "";
print "\n Please enable /proc/sys/net/core/xfrm_larval_drop\n or NETKEY will cause non-POSIX compliant long time-outs\n\n";
}
else { errchk "1"; }
}
if ( -e "/selinux/enforce") {
printfun "Testing against enforced SElinux mode";
open("cat", "/selinux/enforce");
if(<cat> == "1")
{
errchk "";
print "\n SElinux is running in 'enforced' mode.\n If you encounter network related SElinux errors, especially when using KLIPS,\n try disabling SElinux using:\n";
print "\n echo \"0\" > /selinux/enforce (or edit /etc/sysconfig/selinux)\n\n";
$reterr = 1;
}
else { errchk "1"; }
}
if ( -c "/dev/hw_random" || -c "/dev/hwrng" ) {
printfun "Hardware RNG detected, testing if used properly";
run "pidof rngd";
($processid) = @out;
chomp($processid);
if( $processid eq "" ) {
run "pidof clrngd";
($processid2) = @out;
if( $processid2 eq "" ) {
errchk "";
print "\n Hardware RNG is present but 'rngd' or 'clrngd' is not running.\n No harware random used!\n\n";
$reterr = 1;
}
else { errchk "1"; }
}
else { errchk "1"; }
}
# Wouldn't this test fail if your mucked up your interface definition?
printfun "Checking that pluto is running";
run "ipsec whack --status";
errchk "@out";
if (grep /interface/, @out)
{
udp500check;
udp4500check;
}
}
sub tunnelchecks {
open("dev", "/proc/net/dev");
if((grep !/(ipsec|lo:|Inter|packets)/, <dev>) > 1)
{
printfun "Two or more interfaces found, checking IP forwarding";
open("cat", "/proc/sys/net/ipv4/ip_forward");
if(<cat> == "0")
{
$reterr = 1;
errchk "";
}
else
{
errchk "@out";
printfun "Checking NAT and MASQUERADEing";
# This assumes KLIPS eroute information, we should add support
# for NETKEY, but ip xfrm is very annoying to parse
if(( -e "/proc/net/nf_conntrack" || -e "/proc/net/ip_conntrack")
&& -e "/proc/net/ipsec_eroute" )
{
run "iptables -t nat -L -n";
if(grep /(NAT|MASQ)/, @out)
{
printf "\n";
open("cat", "/proc/net/ipsec_eroute");
foreach(grep /tun0x/, <cat>)
{
@eroute=split(' ',$_);
checktunnel $eroute[1], $eroute[3], $eroute[5];
}
}
else
{
errchk "1";
}
}
else
{
errchk "OK";
}
}
}
}
sub cmdchecks {
# check for vital commands
printfun "Checking for 'ip' command";
run "which ip";
errchk "@out";
printfun "Checking /bin/sh is not /bin/dash";
if (-e "/bin/dash") {
run "cmp /bin/sh /bin/dash";
($dash)=grep(/differ/, @out);
if(!$dash) {
warnchk "", "WARNING";
} else {
errchk "OK";
}
} else {
errchk "OK";
}
printfun "Checking for 'iptables' command";
run "which iptables";
errchk "@out";
open("cat","$conf/ipsec.conf");
foreach(grep /crlcheckinterval/,<cat>)
{
if(!$curlcheckdone) {
$curlcheckdone=1;
printfun "Checking for 'curl' command for CRL fetching";
run "which curl";
errchk "@out";
}
}
# perhaps check for ip xfrm support, but forget about setkey.
# if ( -e "/proc/net/pfkey") {
# printfun "Checking for 'setkey' command for NETKEY IPsec stack support";
# run "which setkey";
# errchk "@out";
# }
}
sub dnschecks {
# Check the running hostname.
printf "\nOpportunistic Encryption DNS checks:\n";
run "hostname";
($hostname)=@out; chomp $hostname;
checkdnshost $hostname;
# Check all the public IP addresses...
run "/sbin/ifconfig -a";
foreach (grep /inet addr/,@out)
{
$_=~ s/^\s*//;
@temp=split(/[:\ ]+/, $_);
push(@address,$temp[2]);
}
# Purge all non-routeable IPs...
@address=grep !/^(127.*|10.*|172.1[6789]+.*.*|172.2+.*.*|172.3[01]+.*.*|192.168.*.*|169.254.*.*)/,@address;
printfun " Does the machine have at least one non-private address?";
errchk @address;
foreach(@address=grep !$check{$_}++,@address)
{
checkdnsip $_;
}
}
# Main function begins here!
# Harvest options, ensure they're valid.
use Getopt::Long;
%optctl = ("host" => \$hostname,"ip" => \$ip, "colour" => \$colour);
GetOptions(\%optctl, "host=s" ,"ip=s", "colour!");
# Exit if we get passed an option we don't recognize.
if($Getopt::Long::error) { exit 1; }
# If you've passed --host or --ip, do only those checks.
if($hostname || $ip)
{
# Check this --host for OE.
if($hostname)
{
printf "Checking $hostname for Opportunistic Encryption:\n";
checkdnshost $hostname;
run "host -t A $hostname";
if(($ipaddr) = grep (/address/i, @out))
{
$ipaddr=~ s/.*address\ //;
chomp $ipaddr;
checkdnsip $ipaddr;
}
else
{
printf "$hostname does not resolve to an IP, no reverse lookup tests possible.\n";
}
}
# Check this IP for OE.
if($ip)
{
printf "Checking IP $ip for Opportunistic Encryption:\n";
checkdnsip $ip;
}
}
else
{
# Call the default routines...
# Root check...
if($> != "0")
{
print "To check this machine, you need to run \"$me\" as root.\n"; exit;
}
else
{
installstartcheck;
tunnelchecks;
cmdchecks;
run "ipsec addconn --configsetup";
($oe)=grep(/oe=\'yes\'/, @out);
if( $oe) {
dnschecks;
if($print_deprecated)
{
print "
RFC 3445 restricts the use of the KEY RR to DNSSEC applications. The use of
a KEY record sub-type for Opporunistic Encryption (OE) has been deprecated.
TXT records are used to provide all OE functionality.\n";
}
} else {
printfun "Opportunistic Encryption Support";
warnchk "", "DISABLED";
}
}
# finally, run the config file through the parser checks
run "ipsec auto addconn --checkconfig";
}
exit $reterr
|