OK, because I hate it when I find these questions on the internet with no answers, I will now answer my own question.
So a little more research and this is what I came up with. First of all, it turns out racoon is required. You can set up IPSec using just setkey, but then the keys never change. I hadn't realized that the "pre-shared key" is not the same as the "key" in the setkey commands.
Anyway, so the first part of this turned out to be creating the ipsec.conf file and filling it with the correct policy. Setkey was confusing because it has the SAD and SPD items. The add commands enters SADs and the spdadd command enters the SPDs. Turns out I don't need any SADs because racoon is going to generate those on the fly using my pre-shared key.
So, my ipsec.conf file looks like this:
Code:
#!/usr/sbin/setkey -f
flush;
spdflush;
spdadd 192.168.1.89 192.168.50.0/24 any
-P out ipsec esp/tunnel/192.168.1.89-a.b.c.d/require;
spdadd 192.168.50.0/24 192.168.1.89 any
-P in ipsec esp/tunnel/a.b.c.d-192.168.1.89/require;
spdadd 192.168.1.89 172.20.75.0/24 any
-P out ipsec esp/tunnel/192.168.1.89-a.b.c.d/require;
spdadd 172.20.75.0/24 192.168.1.89 any
-P in ipsec esp/tunnel/a.b.c.d-192.168.1.89/require;
This basically just tells the IPSec that it should encode/decode and tunnel anything going to or coming from 192.168.50.* or 172.20.75.*
You might notice the hardcoded ip address (192.168.1.89) from my local network. I haven't quite found a way around that, but since I can use the hardcoded IP address of my computer on my local network, not having to worry about my router's dynamic IP, it became less of a problem. If I find a solution for it, I'll put it here. I tried using 0.0.0.0, which would connect and create the key, but would not decrypt any data returned.
I then ran that file with:
Code:
setkey -f ipsec.conf
Now for the racoon.conf:
Code:
# search this file for pre_shared_key with various ID key.
path pre_shared_key "/etc/racoon/psk.txt";
# if no listen directive is specified, racoon will listen to all
# available interface addresses.
remote anonymous
{
exchange_mode aggressive,main;
doi ipsec_doi;
situation identity_only;
generate_policy on;
proposal_check obey;
my_identifier user_fqdn "myemail@mycompany.com";
proposal {
encryption_algorithm 3des;
hash_algorithm sha1;
authentication_method pre_shared_key;
dh_group 2;
}
}
sainfo anonymous
{
encryption_algorithm 3des;
authentication_algorithm hmac_sha1;
compression_algorithm deflate;
}
The exchange mode must be agressive, and I think proposal_check has to be obey. generate_policy is set to on so that racoon will generate the SADs required when you attempt to connect to the networks.
My psk.txt file is simply one line:
Code:
a.b.c.d My_Pre_Shared_Key
So now I'll set up the setkey script and racoon daemon to run at startup and all should be well.
One point to mention is that the first time I attempt to do something that requires a connection, it fails. So for example if I try:
I'll get an error saying the connection is temporarily unavailable. racoon is actually generating the keys and SADs the first connection attempt. After that it seems to work fine.
Hope this helps somebody.

miscreant