OPNsense Forum

Archive => 17.1 Legacy Series => Topic started by: tofflock on April 26, 2017, 03:58:42 pm

Title: 17.1.5 - Problem with IPsec after a REBOOT
Post by: tofflock on April 26, 2017, 03:58:42 pm
Hi

I have identified a problem with IPsec after a REBOOT

I have two FWs (UK-FW & FR-FW) both running OPNsense 17.1 series:

My tests and investigations described below have been carried out on UK-FW which is up-to-date and has the following overall build:

OPNsense 17.1.5-amd64
FreeBSD 11.0-RELEASE-p8
OpenSSL 1.0.2k 26 Jan 2017
 
Both firewalls use a domestic ADSL line for their WAN connection. 
I have configured a VPN between the two firewalls. 
Both firewalls use a dynamic dns service to facilitate flexible configuration using FQDN, and not hard-coded IP addresses. 
This VPN uses a PSK, and it works well.

However, when either firewall is rebooted, IPsec reports that

Code: [Select]
charon: 12[IKE] no shared key found for 'aa.bbb.ccc.248' –
and the VPN does not connect.

Now looking in detail at UK-FW since this is running the latest OPNsense build.

The report that there is no shared key turns out to be correct, since although the IPsec configuration is safely stored in /conf/config.xml, the file /usr/local/etc/ipsec.secrets (SECRETS) is empty (it exists, but has zero length).

I can also report that the file /usr/local/etc/ipsec.conf (CONF) is incomplete.  In my case (on UK-FW), the line

Code: [Select]
  rightid = aa.bbb.ccc.ddd
is missing.

The SECRETS and CONF files are produced by function ipsec_configure() in file /usr/local/etc/inc/ipsec.inc.  Correct production of these two files requires a working WAN (public DNS is required).

At boot-up, a start-up script (/usr/local/etc/rc.bootup) is invoked and this calls function ipsec_configure()

However, in my two firewalls, the execution of this script (rc.bootup) happens too soon, and before the WAN has come up and is usable.

Using the script /usr/local/etc/rc.bootup as a basis, I carried out some severe pruning to generate a new script which I called rc.ipsec.  This script is shown here:

Code: [Select]
#!/usr/local/bin/php
<?php

/*
    Copyright (C) 2014-2016 Franco Fichtner <franco@opnsense.org>
    Copyright (C) 2004-2009 Scott Ullrich <sullrich@pfsense.org>.
    Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
    Copyright (C) 2009 Erik Kristensen
    All rights reserved.

    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions are met:

    1. Redistributions of source code must retain the above copyright notice,
       this list of conditions and the following disclaimer.

    2. Redistributions in binary form must reproduce the above copyright
       notice, this list of conditions and the following disclaimer in the
       documentation and/or other materials provided with the distribution.

    THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
    INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
    AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
    AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
    OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    POSSIBILITY OF SUCH DAMAGE.
*/

/* looks weird, but means we started PHP successfully */
echo "done.\n";

echo 
"Initializing...";
flush();

$inc_files = array(
    
'config.inc',
    
'util.inc',
    
'interfaces.inc',
    
'services.inc',
);

foreach (
$inc_files as $inc_file) {
    require_once 
$inc_file;
    echo 
'.';
    
flush();
}

echo 
"done.\n";

/* start IPsec tunnels */
$ipsec_dynamic_hosts ipsec_configure(true);

/* If there are ipsec dynamic hosts try again to reload the tunnels as rc.newipsecdns does */
if ($ipsec_dynamic_hosts) {
    
ipsec_configure(true);
}

exit(
0);

Running this script (manually) after the system has been rebooted, and when the WAN is up, configures IPsec correctly, and the VPN then comes up very quickly.

The configuration of IPsec definitely needs to take place later in the start-up sequence, but I don’t have enough knowledge of the overall architecture of the start-up process to make a recommendation as to how it should be amended.

Any suggestions please?

Thanks,

Peter
Title: Re: 17.1.5 - Problem with IPsec after a REBOOT
Post by: tofflock on May 08, 2017, 11:59:18 pm
Hi

I haven't had any suggestions on the way forward with this one.
Should I open an issue on github?

Thanks,

Peter

Title: Re: 17.1.5 - Problem with IPsec after a REBOOT
Post by: franco on May 09, 2017, 06:49:51 am
Hi tofflock,

Are you using XMLRPC between the two? Are you maybe also using IPv6 as DHCPv6 on WAN?


Cheers,
Franco
Title: Re: 17.1.5 - Problem with IPsec after a REBOOT
Post by: tofflock on May 09, 2017, 09:28:26 am
Hi franco

I had to go and lookup XMLRPC, so that's probably a "NO" then  :)
I have no need for IPv6 yet; my ISPs are stuck firmly in V4 land, and my private networks fit easily into V4 as well.
So that's  a "NO" as well then.

Thanks,
Peter