Blame SOURCES/libreswan-3.27-1671793-delete.patch

89d32f
diff -Naur libreswan-3.27-orig/include/pluto_constants.h libreswan-3.27/include/pluto_constants.h
89d32f
--- libreswan-3.27-orig/include/pluto_constants.h	2018-10-07 22:52:09.000000000 -0400
89d32f
+++ libreswan-3.27/include/pluto_constants.h	2019-02-05 16:53:07.442895489 -0500
89d32f
@@ -421,6 +421,8 @@
89d32f
 
89d32f
 	IMPAIR_SEND_PKCS7_THINGIE_IX,
89d32f
 
89d32f
+	IMPAIR_IKEv1_DEL_WITH_NOTIFY_IX,
89d32f
+
89d32f
 	IMPAIR_roof_IX	/* first unassigned IMPAIR */
89d32f
 };
89d32f
 
89d32f
@@ -463,6 +465,7 @@
89d32f
 #define IMPAIR_REPLAY_DUPLICATES 	LELEM(IMPAIR_REPLAY_DUPLICATES_IX)
89d32f
 #define IMPAIR_REPLAY_FORWARD	 	LELEM(IMPAIR_REPLAY_FORWARD_IX)
89d32f
 #define IMPAIR_REPLAY_BACKWARD 		LELEM(IMPAIR_REPLAY_BACKWARD_IX)
89d32f
+#define IMPAIR_IKEv1_DEL_WITH_NOTIFY 	LELEM(IMPAIR_IKEv1_DEL_WITH_NOTIFY_IX)
89d32f
 
89d32f
 #define IMPAIR_REPLAY_ENCRYPTED			LELEM(IMPAIR_REPLAY_ENCRYPTED_IX)
89d32f
 #define IMPAIR_CORRUPT_ENCRYPTED		LELEM(IMPAIR_CORRUPT_ENCRYPTED_IX)
89d32f
@@ -478,6 +481,8 @@
89d32f
 
89d32f
 #define IMPAIR_SEND_PKCS7_THINGIE		LELEM(IMPAIR_SEND_PKCS7_THINGIE_IX)
89d32f
 
89d32f
+#define IMPAIR_IKEv1_DEL_WITH_NOTIFY           LELEM(IMPAIR_IKEv1_DEL_WITH_NOTIFY_IX)
89d32f
+
89d32f
 /* State of exchanges
89d32f
  *
89d32f
  * The name of the state describes the last message sent, not the
89d32f
diff -Naur libreswan-3.27-orig/lib/libswan/impair.c libreswan-3.27/lib/libswan/impair.c
89d32f
--- libreswan-3.27-orig/lib/libswan/impair.c	2018-10-07 22:52:09.000000000 -0400
89d32f
+++ libreswan-3.27/lib/libswan/impair.c	2019-02-05 16:51:07.522924972 -0500
89d32f
@@ -87,6 +87,7 @@
89d32f
        S(IMPAIR_SUPPRESS_RETRANSMITS, "impair-suppress-retransmits", "causes pluto to never send retransmits (wait the full timeout)"),
89d32f
        S(IMPAIR_TIMEOUT_ON_RETRANSMIT, "impair-timeout-on-retransmit", "causes pluto to 'retry' (switch protocol) on the first retransmit"),
89d32f
        S(IMPAIR_UNKNOWN_PAYLOAD_CRITICAL, "impair-unknown-payload-critical", "mark the unknown payload as critical"),
89d32f
+       S(IMPAIR_IKEv1_DEL_WITH_NOTIFY, "impair-ikev1-del-with-notify", "causes pluto to send IKE Delete with additional bogus Notify payload"),
89d32f
 
89d32f
 #undef S
89d32f
 };
89d32f
diff -Naur libreswan-3.27-orig/programs/pluto/ikev1_main.c libreswan-3.27/programs/pluto/ikev1_main.c
89d32f
--- libreswan-3.27-orig/programs/pluto/ikev1_main.c	2018-10-07 22:52:09.000000000 -0400
89d32f
+++ libreswan-3.27/programs/pluto/ikev1_main.c	2019-02-05 16:48:16.241538787 -0500
89d32f
@@ -2347,12 +2347,36 @@
89d32f
 				.isad_protoid = ns->proto,
89d32f
 				.isad_nospi = 1,
89d32f
 			};
89d32f
+
89d32f
+			if (DBGP(IMPAIR_IKEv1_DEL_WITH_NOTIFY))
89d32f
+				isad.isad_np = ISAKMP_NEXT_N; /* Notify */
89d32f
+
89d32f
 			passert(out_struct(&isad, &isakmp_delete_desc, &r_hdr_pbs,
89d32f
 					   &del_pbs));
89d32f
 			passert(out_raw(&ns->spi, sizeof(ipsec_spi_t),
89d32f
 					&del_pbs,
89d32f
 					"delete payload"));
89d32f
 			close_output_pbs(&del_pbs);
89d32f
+
89d32f
+			if (DBGP(IMPAIR_IKEv1_DEL_WITH_NOTIFY)) {
89d32f
+				pb_stream cruft_pbs;
89d32f
+
89d32f
+				libreswan_log("IMPAIR: adding bogus Notify payload after IKE Delete payload");
89d32f
+				struct isakmp_notification isan = {
89d32f
+					.isan_np = ISAKMP_NEXT_NONE,
89d32f
+					.isan_doi = ISAKMP_DOI_IPSEC,
89d32f
+					.isan_protoid = PROTO_ISAKMP,
89d32f
+					.isan_spisize = COOKIE_SIZE * 2,
89d32f
+					.isan_type = INVALID_PAYLOAD_TYPE,
89d32f
+				};
89d32f
+
89d32f
+				passert(out_struct(&isan, &isakmp_notification_desc, &r_hdr_pbs,
89d32f
+					&cruft_pbs));
89d32f
+				passert(out_raw(&ns->spi, sizeof(ipsec_spi_t), &cruft_pbs,
89d32f
+					"notify payload"));
89d32f
+				close_output_pbs(&cruft_pbs);
89d32f
+			}
89d32f
+
89d32f
 		}
89d32f
 	}
89d32f
 
89d32f
@@ -2599,7 +2623,9 @@
89d32f
 					rc->policy &= ~POLICY_UP;
89d32f
 					if (!shared_phase1_connection(rc)) {
89d32f
 						flush_pending_by_connection(rc);
89d32f
+						/* This also deletes the IKE SA, clear pointer  */
89d32f
 						delete_states_by_connection(rc, FALSE);
89d32f
+						md->st = NULL;
89d32f
 					}
89d32f
 					reset_cur_connection();
89d32f
 				}