Skip to contentSkip to conversation

Floating: Add support for floating in TLS mode (upd.)

PATCH Superseded André Valentin 3 participants 4 messages Oct 30, 2013 – Nov 16, 2013

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Floating: Add support for floating in TLS mode (upd.)

Add support for floating in tls mode using the HMAC of a packet. It costs a roundtrip through the clients. Its security comes from a secret key, both peers have. This key and the data form the signature used, which is then checked againts existing peer connections. Therefore a good auth algo is recommended.

URL: https://community.openvpn.net/openvpn/ticket/49

---
 src/openvpn/crypto.c  |   55 ++++++++++++++++++++++++
 src/openvpn/crypto.h  |    4 ++
 src/openvpn/mudp.c    |  112 +++++++++++++++++++++++++++++++++++++++++++++++++
 src/openvpn/mudp.h    |   18 ++++++++
 src/openvpn/options.c |    3 ++
 src/openvpn/perf.h    |    2 +
 src/openvpn/ssl.c     |   28 +++++++++++++
 src/openvpn/ssl.h     |    6 +++
 8 files changed, 228 insertions(+)
src/openvpn/crypto.c +55 -0
index c4c356d..891488d 100644
@@ -389,6 +389,61 @@ openvpn_decrypt (struct buffer *buf, struct buffer work,
 }
 
 /*
+ * This verifies if a packet and its HMAC fit to a crypto context.
+ *
+ * On success true is returned.
+ */
+bool
+crypto_test_hmac (struct buffer *buf,
+          const struct crypto_options *opt)
+{
+  struct gc_arena gc;
+  gc_init (&gc);
+  int offset = 1;
+
+  if (buf->len > 0 && opt->key_ctx_bi)
+    {
+      struct key_ctx *ctx = &opt->key_ctx_bi->decrypt;
+
+      /* Verify the HMAC */
+      if (ctx->hmac)
+        {
+          int hmac_len;
+          uint8_t local_hmac[MAX_HMAC_KEY_LENGTH]; /* HMAC of ciphertext computed locally */
+
+          hmac_ctx_reset(ctx->hmac);
+
+          /* Assume the length of the input HMAC */
+          hmac_len = hmac_ctx_size (ctx->hmac);
+
+          /* Authentication fails if insufficient data in packet for HMAC */
+          if ((buf->len - offset) < hmac_len) 
+            {
+              gc_free (&gc);
+              return false;
+            }
+
+          hmac_ctx_update (ctx->hmac, BPTR (buf) + offset + hmac_len, BLEN (buf) - offset - hmac_len);
+          hmac_ctx_final (ctx->hmac, local_hmac);
+
+          /* Compare locally computed HMAC with packet HMAC */
+          if (memcmp_constant_time (local_hmac, BPTR (buf) + offset, hmac_len))
+            {
+              gc_free (&gc);
+              return false;
+            }
+            
+          gc_free (&gc);
+          return true;
+        }
+    }
+
+  gc_free (&gc);
+  return false;
+}
+
+
+/*
  * How many bytes will we add to frame buffer for a given
  * set of crypto options?
  */
src/openvpn/crypto.h +4 -0
index 3b4b88e..296519a 100644
@@ -279,6 +279,10 @@ bool openvpn_decrypt (struct buffer *buf, struct buffer work,
 		      const struct crypto_options *opt,
 		      const struct frame* frame);
 
+
+bool crypto_test_hmac (struct buffer *buf,
+           const struct crypto_options *opt);
+           
 /** @} name Functions for performing security operations on data channel packets */
 
 void crypto_adjust_frame_parameters(struct frame *frame,
src/openvpn/mudp.c +112 -0

124 lines not on this page · raw message

src/openvpn/mudp.h +18 -0
index 97f961b..759ea6d 100644
@@ -67,5 +67,23 @@ void tunnel_server_udp (struct context *top);
  */
 struct multi_instance *multi_get_create_instance_udp (struct multi_context *m);
 
+
+/**************************************************************************/
+/**
+ * Find a client instance based on the HMAC, if auth is used.
+ * @ingroup external_multiplexer
+ *
+ * Find a client instance based on the HMAC, if auth is used. The function 
+ * iterates over all peers to find a fitting instance. The found instance is
+ * updated with the current peer address.
+ *  
+ * @param m            - The single multi_context structure.
+ * @param mi           - The multi_instance structure.
+ * @param real         - The mroute_addr structure.
+ *
+ * @return Boolen, true if peer found, false if not.
+ */
+bool multi_find_instance_udp (struct multi_context *m,  struct multi_instance *mi, struct mroute_addr real);
+
 #endif
 #endif
src/openvpn/options.c +3 -0
index 4d0271f..e14a1b7 100644
@@ -166,6 +166,9 @@ static const char usage_message[] =
   "                  Set n=\"infinite\" to retry indefinitely.\n"
   "--float         : Allow remote to change its IP address/port, such as through\n"
   "                  DHCP (this is the default if --remote is not used).\n"
+#ifdef ENABLE_CRYPTO
+  "                  In server mode a valid/default auth algo is needed.\n"
+#endif
   "--ipchange cmd  : Run command cmd on remote ip address initial\n"
   "                  setting or change -- execute as: cmd ip-address port#\n"
   "--port port     : TCP/UDP port # for both local and remote.\n"
src/openvpn/perf.h +2 -0
index c531d9c..e1121d2 100644
@@ -57,6 +57,8 @@
 #define PERF_PROC_OUT_TUN           18
 #define PERF_PROC_OUT_TUN_MTCP      19
 #define PERF_N                      20
+#define PERF_MULTI_FIND_INSTANCE    21
+
 
 #ifdef ENABLE_PERFORMANCE_METRICS
 
src/openvpn/ssl.c +28 -0
index 69f77f3..709edf7 100644
@@ -3454,6 +3454,34 @@ tls_rec_payload (struct tls_multi *multi,
   return ret;
 }
 
+/* Update the remote_addr, needed if a client floats. */
+void
+tls_update_remote_addr (struct tls_multi *multi,
+               const struct link_socket_actual *from)
+{
+  struct gc_arena gc = gc_new ();
+  int i;
+  
+  for (i = 0; i < KEY_SCAN_SIZE; ++i)
+    {
+      struct key_state *ks = multi->key_scan[i];
+      if (DECRYPT_KEY_ENABLED (multi, ks)
+         && ks->authenticated
+         && link_socket_actual_defined(&ks->remote_addr)
+      )
+       {
+         if (link_socket_actual_match (from, &ks->remote_addr))
+           continue;
+          dmsg (D_TLS_KEYSELECT,
+              "TLS: tls_update_remote_addr from IP=%s to IP=%s",
+              print_link_socket_actual (&ks->remote_addr, &gc),
+              print_link_socket_actual (from, &gc));
+          ks->remote_addr = *from;
+       }
+    }
+  gc_free (&gc);
+}
+
 /*
  * Dump a human-readable rendition of an openvpn packet
  * into a garbage collectable string which is returned.
src/openvpn/ssl.h +6 -0
index cd7cae2..c501b64 100644
@@ -431,6 +431,12 @@ bool tls_send_payload (struct tls_multi *multi,
 bool tls_rec_payload (struct tls_multi *multi,
 		      struct buffer *buf);
 
+/*
+ * Update remote address of a tls_multi structure
+ */
+void tls_update_remote_addr (struct tls_multi *multi,
+                 const struct link_socket_actual *from);
+                 
 #ifdef MANAGEMENT_DEF_AUTH
 static inline char *
 tls_get_peer_info(const struct tls_multi *multi)
Signature · 1 line
1.7.10.4
#1 lore raw

Hi,

Quoted 5 lines · André Valentin

Add support for floating in tls mode using the HMAC of a packet. It costs a roundtrip through the clients. Its security comes from a secret key, both peers have. This key and the data form the signature used, which is then checked againts existing peer connections. Therefore a good auth algo is recommended.

Uh. Could you remark on what changed between this and the previous patch, and possibly add a "version X" identifier to Subject: or the commit text?

Should people actually start reviewing the code (ahem...) it is enormously helpful to see which version a review is for - and when I commit it, it also eases attribution to which version of the patch went in.

(Arne, David and I are famous for sending patches with versions on versions...)

gert

Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
                                                           //www.muc.de/~gert/
Gert Doering - Munich, Germany                             [email protected]...
fax: +49-89-35655025                        [email protected]...
#2 lore raw
In reply to André Valentin
Quoted 7 lines · André Valentin

Add support for floating in tls mode using the HMAC of a packet. It costs a roundtrip through the clients. Its security comes from a secret key, both peers have. This key and the data form the signature used, which is then checked againts existing peer connections. Therefore a good auth algo is recommended.

URL: https://community.openvpn.net/openvpn/ticket/49

I took a look at this patch, since I am frustrated by the same problem, so +1 for the conceptual issue. It seems to work:

Nov 15 15:18:01 gw ovpn-udp[9964]: hessu/85.188.36.24.36:58639 MULTI:
Detected floating by hmac test, new client address:
[AF_INET]85.188.36.24.36:58640
Nov 15 15:18:01 gw ovpn-udp[9964]: hessu/85.188.36.24.36:58640 MULTI:

Floated with HMAC authentication to a new client address:
[AF_INET]85.188.36.24.36:58640

In this case the client's source port changed, because the client is behind a NAT device, and the client didn't have traffic within 60 seconds (the NAT device's UDP session timeout). Without this patch --float does not have any effect on the multi-client tls-server setup, and after a 60-second break in traffic the session is dead (until keepalive ping timeout and reconnection). I'd like to use a large keepalive timer, since on mobile devices a 29-second keepalive tends to drain the battery.

I think, however, there might be a problem with the patch: When a packet is received from a srcip-srcport which does not belong to any current client, it goes and scans through the whole client list, calculating a HMAC for the packet contents using the HMAC key of each and every client, effectively looking for a match in HMAC keys. An attacker could transmit large packets with random source IP addresses to a server which has a large number of clients (think 2000 or something? how large client loads are people having, anyway?), and cause extra CPU load, maybe enough to DOS the server with a smallish packet rate.

On the other hand, it is commonly quite easy to DOS servers by sheer packet/data volume... but we shouldn't make it any easier with new developments.

The more elegant way would be to have a session ID in each data packet, which would used to look up the client, and then a single HMAC calculation would tell if the packet is from that client. No need for scanning. That session ID could be used even for every packet instead of looking at the client IP address+port at all initially (well, for sending any following packets you'd use the peer's latest source address).

Putting a session ID in the data packet would require changing the on-the-wire data packet format, and make the packets a bit larger. The ID doesn't have to be very large, though, since it's not secret or used for keying, just an integer large enough to index the maximum number of VPN clients on a single server. This would require a new protocol version, backward compatibility and all that work.

- Hessu

#3 lore raw

Hi!

Quoted 4 lines · Heikki Hannikainen
Nov 15 15:18:01 gw ovpn-udp[9964]: hessu/85.188.36.24.36:58640 MULTI:

Floated with HMAC authentication to a new client address:
[AF_INET]85.188.36.24.36:58640

Quoted 8 lines

In this case the client's source port changed, because the client is behind a NAT device, and the client didn't have traffic within 60 seconds (the NAT device's UDP session timeout). Without this patch --float does not have any effect on the multi-client tls-server setup, and after a 60-second break in traffic the session is dead (until keepalive ping timeout and reconnection). I'd like to use a large keepalive timer, since on mobile devices a 29-second keepalive tends to drain the battery.

That's why I'm using 60s ping from device, and 30s from gateway. This seems to work with most gateways. But I have a big ping-restart to prevent openvpn to go into expensive "reconnect mode".

Quoted 11 lines

I think, however, there might be a problem with the patch: When a packet is received from a srcip-srcport which does not belong to any current client, it goes and scans through the whole client list, calculating a HMAC for the packet contents using the HMAC key of each and every client, effectively looking for a match in HMAC keys. An attacker could transmit large packets with random source IP addresses to a server which has a large number of clients (think 2000 or something? how large client loads are people having, anyway?), and cause extra CPU load, maybe enough to DOS the server with a smallish packet rate.

In April/May another developer also created a patch and made some performance tests. He got about 700k packets/sec. This seems fast good and would make an attack quite expensive.

Quoted 4 lines

On the other hand, it is commonly quite easy to DOS servers by sheer packet/data volume... but we shouldn't make it any easier with new developments.

If a normal connection would be pretended by a DOS attack, this is going to be more a problem because it eats more CPU, I think. [DH i.e.]

Quoted 9 lines

The more elegant way would be to have a session ID in each data packet, which would used to look up the client, and then a single HMAC calculation would tell if the packet is from that client. No need for scanning. That session ID could be used even for every packet instead of looking at the client IP address+port at all initially (well, for sending any following packets you'd use the peer's latest source address).

Quoted 6 lines

Putting a session ID in the data packet would require changing the on-the-wire data packet format, and make the packets a bit larger. The ID doesn't have to be very large, though, since it's not secret or used for keying, just an integer large enough to index the maximum number of VPN clients on a single server. This would require a new protocol version, backward compatibility and all that work.

I also thought about this. But if it is not backwards compatible, it won't be used. Perhaps as a second, more secure implementation would be a good idea when openvpn is multithreaded and can handle thousands of connections.

BTW, the patch is not final. I'm just testing a enhanced version. It seems in this version is a seg fault problem.

André