Skip to content

Commit

Permalink
Merge branch 'master' of vault.libreswan.fi:/srv/src/libreswan
Browse files Browse the repository at this point in the history
  • Loading branch information
letoams committed Jun 1, 2015
2 parents 3eca211 + d1aa9d6 commit dbf8e1a
Show file tree
Hide file tree
Showing 20 changed files with 134 additions and 33 deletions.
11 changes: 7 additions & 4 deletions include/pluto_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ typedef enum {
#define MAX_IKE_FRAGMENTS 16

#define KERNEL_PROCESS_Q_PERIOD 1 /* seconds */
#define DEFAULT_MAXIMIM_HALFOPEN_IKE_SA 50000 /* fairly arbitrary */
#define DEFAULT_MAXIMUM_HALFOPEN_IKE_SA 50000 /* fairly arbitrary */
#define DEFAULT_IKE_SA_DDOS_TRESHOLD 25000 /* fairly arbitrary */

/* debugging settings: a set of selections for reporting
Expand Down Expand Up @@ -494,7 +494,9 @@ enum original_role {

#define IS_V2_ESTABLISHED(s) ((s) == STATE_PARENT_R2 || (s) == STATE_PARENT_I3)

#define IS_IKE_SA_ESTABLISHED(st) (IS_ISAKMP_SA_ESTABLISHED(st->st_state) || IS_PARENT_SA_ESTABLISHED(st))
#define IS_IKE_SA_ESTABLISHED(st) \
( IS_ISAKMP_SA_ESTABLISHED(st->st_state) || \
(IS_PARENT_SA_ESTABLISHED(st) && st->st_clonedfrom) )

/*
* ??? Issue here is that our child SA appears as a
Expand All @@ -513,8 +515,9 @@ enum original_role {

#define IS_PARENT_SA(st) (!IS_CHILD_SA(st))

#define IS_IKE_SA(st) (IS_PHASE1(st->st_state) || IS_PHASE15(st->st_state) ||\
IS_PARENT_SA(st))
#define IS_IKE_SA(st) ( (st->st_clonedfrom == SOS_NOBODY) && (IS_PHASE1(st->st_state) || IS_PHASE15(st->st_state) || \
IS_PARENT_SA(st)) )

#define IS_PARENT_STATE(s) ((s) >= STATE_PARENT_I1 && (s) <= STATE_IKESA_DEL)
#define IS_IKE_STATE(s) (IS_PHASE1(s) || IS_PHASE15(s) || IS_PARENT_STATE(s))

Expand Down
2 changes: 1 addition & 1 deletion lib/libipsecconf/confread.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void ipsecconf_default_values(struct starter_config *cfg)
cfg->setup.options[KBF_KEEPALIVE] = 0; /* config setup */
cfg->setup.options[KBF_NATIKEPORT] = NAT_IKE_UDP_PORT;
cfg->setup.options[KBF_DDOS_IKE_TRESHOLD] = DEFAULT_IKE_SA_DDOS_TRESHOLD;
cfg->setup.options[KBF_MAX_HALFOPEN_IKE] = DEFAULT_MAXIMIM_HALFOPEN_IKE_SA;
cfg->setup.options[KBF_MAX_HALFOPEN_IKE] = DEFAULT_MAXIMUM_HALFOPEN_IKE_SA;
/* Don't inflict BSI requirements on everyone */
cfg->setup.options[KBF_SEEDBITS] = 0;

Expand Down
2 changes: 1 addition & 1 deletion lib/libipsecconf/keywords.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ const struct keyword_def ipsec_conf_keywords_v2[] = {
{ "ocsp-enable", kv_config, kt_bool, KBF_OCSPENABLE, NOT_ENUM },
{ "ocsp-uri", kv_config, kt_string, KSF_OCSPURI, NOT_ENUM },
{ "ocsp-timeout", kv_config, kt_number, KBF_OCSPTIMEOUT, NOT_ENUM },
{ "ocsp-trust_name", kv_config, kt_string, KSF_OCSPTRUSTNAME, NOT_ENUM },
{ "ocsp-trustname", kv_config, kt_string, KSF_OCSPTRUSTNAME, NOT_ENUM },
{ "crlcheckinterval", kv_config, kt_time, KBF_CRLCHECKINTERVAL, NOT_ENUM },
{ "crl_strict", kv_config | kv_alias, kt_bool, KBF_STRICTCRLPOLICY, NOT_ENUM }, /* obsolete _ */
{ "ocsp_strict", kv_config | kv_alias, kt_bool, KBF_STRICTOCSPPOLICY, NOT_ENUM }, /* obsolete _ */
Expand Down
65 changes: 65 additions & 0 deletions programs/configs/d.ipsec.conf/ocsp-global.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<varlistentry>
<term><emphasis remap='B'>ocsp-enable</emphasis></term>
<listitem>
<para>
Whether to perform Online Certificate Store Protocol ("OCSP") checks on
those certificates that have an OCSP URI defined. Acceptable values are
<emphasis remap='B'>yes</emphasis> or <emphasis remap='B'>no</emphasis>
(the default).
</para>
</listitem>
</varlistentry>

<varlistentry>
<term><emphasis remap='B'>ocsp-strict</emphasis></term>
<listitem>
<para>if set to no, pluto is tolerant about failing to obtain an OCSP
responses and a certificate is not rejected when the OCSP request
fails, only when the OCSP request succeeds and lists the certificate as
revoked. If set to yes, any failure on obtaining an OCSP status for a
certificate will be fatal and the certificate will be rejected.
Acceptable values are <emphasis remap='B'>yes</emphasis> or
<emphasis remap='B'>no</emphasis> (the default).
</para>
<para>
The strict mode refers to the NSS ocspMode_FailureIsVerificationFailure
mode, while non-strict mode refers to the NSS
ocspMode_FailureIsNotAVerificationFailure mode.
</para>
</listitem>
</varlistentry>

<varlistentry>
<term><emphasis remap='B'>ocsp-timeout</emphasis></term>
<listitem>
<para>
The time until an OCSP request is aborted and considered failed. The
default value is 2 seconds.
</para>
</listitem>
</varlistentry>

<varlistentry>
<term><emphasis remap='B'>ocsp-uri</emphasis></term>
<listitem>
<para>
The URI to use for OCSP requests instead of the default OCSP URI listed
in the CA certificate. This requires the ocsp-trustname option to be set
to the nick (friendly name) of the OCSP server certificate, which needs
to be present in the NSS database. These option combined with the next
option sets the OCSP <emphasis remap='I'>default responder</emphasis>.
</para>
</listitem>
</varlistentry>

<varlistentry>
<term><emphasis remap='B'>ocsp-trustname</emphasis></term>
<listitem>
<para>
The nickname of the certificate that has been imported into the NSS
database of the server handling the OCSP requests. This requires the
ocsp-uri option to be set as well. This option and the previous options
sets the OCSP <emphasis remap='I'>default responder</emphasis>.
</para>
</listitem>
</varlistentry>
1 change: 1 addition & 0 deletions programs/configs/d.ipsec.conf/order.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ d.ipsec.conf/secctx-attr-type.xml
d.ipsec.conf/plutofork.xml
d.ipsec.conf/crlcheckinterval.xml
d.ipsec.conf/strictcrlpolicy.xml
d.ipsec.conf/ocsp-global.xml
d.ipsec.conf/forwardcontrol.xml
d.ipsec.conf/rp_filter.xml
d.ipsec.conf/syslog.xml
Expand Down
16 changes: 13 additions & 3 deletions programs/pluto/ikev2.c
Original file line number Diff line number Diff line change
Expand Up @@ -1243,7 +1243,9 @@ time_t ikev2_replace_delay(struct state *st, enum event_type *pkind,
time_t delay; /* unwrapped deltatime_t */
struct connection *c = st->st_connection;

if (IS_PARENT_SA(st)) {
if (IS_PARENT_SA(st) &&
(st)->st_clonedfrom == SOS_NOBODY ) /* workaround for child appearing as parent */
{
/* Note: we will defer to the "negotiated" (dictated)
* lifetime if we are POLICY_DONT_REKEY.
* This allows the other side to dictate
Expand All @@ -1256,12 +1258,15 @@ time_t ikev2_replace_delay(struct state *st, enum event_type *pkind,
*/
if (IS_IKE_SA_ESTABLISHED(st)) {
delay = deltasecs(c->sa_ike_life_seconds);
DBG(DBG_LIFECYCLE, DBG_log("ikev2_replace_delay() picked up estalibhsed ikelifetime=%lu", delay));
} else {
delay = PLUTO_HALFOPEN_SA_LIFE;
DBG(DBG_LIFECYCLE, DBG_log("ikev2_replace_delay() picked up half-open SA ikelifetime=%lu", delay));
}
} else {
/* Delay is what the user said, no negotiation. */
delay = deltasecs(c->sa_ipsec_life_seconds);
DBG(DBG_LIFECYCLE, DBG_log("ikev2_replace_delay() picked up salifetime=%lu", delay));
}

/* By default, we plan to rekey.
Expand Down Expand Up @@ -1439,16 +1444,21 @@ static void success_v2_state_transition(struct msg_digest *md)
EVENT_RELEASE_WHACK_DELAY, st);
kind = EVENT_SA_REPLACE;
delay = ikev2_replace_delay(st, &kind, md->original_role);
DBG(DBG_LIFECYCLE, DBG_log("ikev2 case EVENT_v2_RETRANSMIT: for %lu seconds", delay));
event_schedule(kind, delay, st);

} else {
DBG(DBG_LIFECYCLE,DBG_log(
"success_v2_state_transition scheduling EVENT_v2_RETRANSMIT of c->r_interval=%lu",
c->r_interval));
event_schedule_ms(EVENT_v2_RETRANSMIT,
c->r_interval, st);
}
break;
case EVENT_SA_REPLACE: /* SA replacement event */

case EVENT_SA_REPLACE: /* IKE or IPsec SA replacement event */
delay = ikev2_replace_delay(st, &kind, md->original_role);
DBG(DBG_LIFECYCLE, DBG_log("ikev2 case EVENT_SA_REPLACE for %s state for %lu seconds",
IS_IKE_SA(st) ? "parent" : "child", delay));
delete_event(st);
event_schedule(kind, delay, st);
break;
Expand Down
6 changes: 5 additions & 1 deletion programs/pluto/ikev2_parent.c
Original file line number Diff line number Diff line change
Expand Up @@ -2914,14 +2914,18 @@ stf_status ikev2parent_inR2(struct msg_digest *md)
return STF_FAIL;
}

/* authentication good */

/*
* update the parent state to make sure that it knows we have
* authenticated properly.
*/
change_state(pst, STATE_PARENT_I3);
c->newest_isakmp_sa = pst->st_serialno;

/* authentication good */
/* replace HALFOPEN IKE expire time with ikelifetime= */
delete_event(pst);
event_schedule(EVENT_SA_REPLACE, deltasecs(c->sa_ike_life_seconds), pst);

#ifdef USE_LINUX_AUDIT
linux_audit_conn(st, LAK_PARENT_START);
Expand Down
4 changes: 2 additions & 2 deletions programs/pluto/plutomain.c
Original file line number Diff line number Diff line change
Expand Up @@ -472,8 +472,8 @@ static const struct option long_opts[] = {
{ "ocsp_uri\0", required_argument, NULL, 'Y' }, /* _ */
{ "ocsp-timeout\0", required_argument, NULL, 'T' },
{ "ocsp_timeout\0", required_argument, NULL, 'T' }, /* _ */
{ "ocsp-trust_name\0", required_argument, NULL, 'J' },
{ "ocsp_trust_name\0", required_argument, NULL, 'J' }, /* _ */
{ "ocsp-trustname\0", required_argument, NULL, 'J' },
{ "ocsp_trustname\0", required_argument, NULL, 'J' }, /* _ */
{ "crlcheckinterval\0", required_argument, NULL, 'x' },
{ "uniqueids\0", no_argument, NULL, 'u' },
{ "noklips\0>use-nostack", no_argument, NULL, 'n' }, /* redundant spelling */
Expand Down
2 changes: 1 addition & 1 deletion programs/pluto/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ void delete_ctl_socket(void)
bool listening = FALSE; /* should we pay attention to IKE messages? */

enum ddos_mode pluto_ddos_mode = DDOS_AUTO; /* default to auto-detect */
unsigned int pluto_max_halfopen = DEFAULT_MAXIMIM_HALFOPEN_IKE_SA;
unsigned int pluto_max_halfopen = DEFAULT_MAXIMUM_HALFOPEN_IKE_SA;
unsigned int pluto_ddos_treshold = DEFAULT_IKE_SA_DDOS_TRESHOLD;

struct iface_port *interfaces = NULL; /* public interfaces */
Expand Down
54 changes: 35 additions & 19 deletions programs/pluto/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -565,13 +565,19 @@ static void timer_event_cb(evutil_socket_t fd UNUSED, const short event UNUSED,
case EVENT_SA_REPLACE_IF_USED:
{
struct connection *c = st->st_connection;
so_serial_t newest = IS_IKE_SA(st) ?
c->newest_isakmp_sa : c->newest_ipsec_sa;
so_serial_t newest;

if (IS_IKE_SA(st)) {
newest = c->newest_isakmp_sa;
DBG(DBG_LIFECYCLE, DBG_log("EVENT_SA_REPLACE{IF_USED} picked newest_isakmp_sa"));
} else {
newest = c->newest_ipsec_sa;
DBG(DBG_LIFECYCLE, DBG_log("EVENT_SA_REPLACE{IF_USED} picked newest_ipsec_sa"));
}

if (newest != SOS_NOBODY && newest > st->st_serialno) {
/* not very interesting: no need to replace */
DBG(DBG_LIFECYCLE,
libreswan_log(
DBG(DBG_LIFECYCLE, DBG_log(
"not replacing stale %s SA: #%lu will do",
IS_IKE_SA(st) ?
"ISAKMP" : "IPsec", newest));
Expand All @@ -592,21 +598,14 @@ static void timer_event_cb(evutil_socket_t fd UNUSED, const short event UNUSED,
* This is just an optimization: correctness is not
* at stake.
*/
/* ??? we are abusing the DBG mechanism to control
* normal log output.
*/
DBG(DBG_LIFECYCLE,
libreswan_log(
DBG(DBG_LIFECYCLE, DBG_log(
"not replacing stale %s SA: inactive for %lds",
IS_IKE_SA(st) ? "ISAKMP" : "IPsec",
(long)deltasecs(monotimediff(mononow(),
st->st_outbound_time))));
} else {
/* ??? we are abusing the DBG mechanism to control
* normal log output.
*/
DBG(DBG_LIFECYCLE,
libreswan_log("replacing stale %s SA",
DBG(DBG_LIFECYCLE, DBG_log(
"replacing stale %s SA",
IS_IKE_SA(st) ? "ISAKMP" : "IPsec"));
ipsecdoi_replace(st, LEMPTY, LEMPTY, 1);
}
Expand All @@ -629,15 +628,17 @@ static void timer_event_cb(evutil_socket_t fd UNUSED, const short event UNUSED,
if (IS_IKE_SA(st)) {
satype = "ISAKMP";
latest = c->newest_isakmp_sa;
DBG(DBG_LIFECYCLE, DBG_log("EVENT_SA_EXPIRE picked newest_isakmp_sa"));
} else {
satype = "IPsec";
latest = c->newest_ipsec_sa;
DBG(DBG_LIFECYCLE, DBG_log("EVENT_SA_EXPIRE picked newest_ipsec_sa"));
}

if (st->st_serialno < latest) {
/* not very interesting: already superseded */
DBG(DBG_LIFECYCLE,
libreswan_log("%s SA expired (superseded by #%lu)",
DBG(DBG_LIFECYCLE, DBG_log(
"%s SA expired (superseded by #%lu)",
satype, latest));
} else {
libreswan_log("%s %s (%s)", satype,
Expand Down Expand Up @@ -674,7 +675,7 @@ static void timer_event_cb(evutil_socket_t fd UNUSED, const short event UNUSED,
break;

case EVENT_CRYPTO_FAILED:
DBG(DBG_CONTROL,
DBG(DBG_LIFECYCLE,
DBG_log("event crypto_failed on state #%lu, aborting",
st->st_serialno));
delete_state(st);
Expand Down Expand Up @@ -724,7 +725,7 @@ void delete_event(struct state *st)
enum_show(&timer_event_names,
st->st_event->ev_type)));

if (st->st_event->ev_type == EVENT_v1_RETRANSMIT)
if (st->st_event->ev_type == EVENT_v1_RETRANSMIT || st->st_event->ev_type == EVENT_v2_RETRANSMIT)
st->st_retransmit = 0;
delete_pluto_event(&st->st_event);
}
Expand Down Expand Up @@ -841,6 +842,16 @@ static void event_schedule_tv(enum event_type type, const struct timeval delay,
struct pluto_event *ev = alloc_thing(struct pluto_event,
"struct pluto_event in event_schedule()");

DBG(DBG_LIFECYCLE, DBG_log("event_schedule_tv called for about %lu seconds and change",
delay.tv_sec));

/*
* Scheduling a month into the future is most likely a bug.
* pexpect() causes us to flag this in our test cases
* But do allow (unwise) people to set insame > 1m lifetimes
*/
pexpect(delay.tv_sec < 3600 * 24 * 31);

ev->ev_type = type;

/* ??? ev_time lacks required precision */
Expand Down Expand Up @@ -910,6 +921,8 @@ void event_schedule_ms(enum event_type type, unsigned long delay_ms, struct stat
{
struct timeval delay;

DBG(DBG_LIFECYCLE, DBG_log("event_schedule_ms called for about %lu ms", delay_ms));

delay.tv_sec = delay_ms / 1000;
delay.tv_usec = (delay_ms % 1000) * 1000;
event_schedule_tv(type, delay, st);
Expand All @@ -919,7 +932,10 @@ void event_schedule(enum event_type type, time_t delay_sec, struct state *st)
{
struct timeval delay;

passert(delay_sec >= 0);
DBG(DBG_LIFECYCLE, DBG_log("event_schedule called for %lu seconds", delay_sec));

/* unexpectedly far away, pexpect will flag in test cases */
pexpect(delay_sec < 3600 * 24 * 31);
delay.tv_sec = delay_sec;
delay.tv_usec = 0;
event_schedule_tv(type, delay, st);
Expand Down
2 changes: 1 addition & 1 deletion testing/pluto/TESTLIST
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ kvmplutotest ikev2-12-transport-psk good
kvmplutotest ikev2-13-ah good
kvmplutotest ikev2-14-missing-ke good
kvmplutotest ikev2-15-fuzzer good
kvmplutotest ikev2-17-rekey good
kvmplutotest ikev2-17-rekey-ipsec good
kvmplutotest ikev2-18-x509-alias good
kvmplutotest ikev2-19-x509-auto-start good

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ config setup
conn westnet-eastnet-ikev2
also=westnet-eastnet-ipv4
ikev2=insist
rekey=no

include /testing/baseconfigs/all/etc/ipsec.d/ipsec.conf.common
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ conn westnet-eastnet-ikev2
ikev2=insist
# rekey test
salifetime=1m
rekey=yes

include /testing/baseconfigs/all/etc/ipsec.d/ipsec.conf.common
File renamed without changes.
File renamed without changes.

0 comments on commit dbf8e1a

Please sign in to comment.