From: "its_Giaan (Code Review)" Date: Mon, 29 Sep 2025 09:36:34 +0000 In-Reply-To: References: Reply-To: gianmarco@...2726..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641..., gert@...1296... Message-ID: <203849d8bf51e135ba9fe6f08646c4c83face8a2-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="PrwbHxwTXiA="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: multipeer: introduce asymmetric peer-id List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos , flichtenheld Cc: openvpn-devel --PrwbHxwTXiA= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: flichtenheld, its_Giaan. Hello cron2, flichtenheld, plaisthos, I'd like you to reexamine a change. Please visit http://gerrit.openvpn.net/c/openvpn/+/1089?usp=3Demail to look at the new patch set (#3). Change subject: multipeer: introduce asymmetric peer-id ...................................................................... multipeer: introduce asymmetric peer-id In order to achieve a multipeer functionality, peers now use separate IDs for sending (tx_peer_id) and receiving (rx_peer_id). Each peer announces its own ID through pushing peer-info using 'ID=3D7f1' hex format so identification can still happen even if IP/port changes. In P2P mode, peer switch to using the announced IDs after mutual exchange. In P2MP mode, clients always announce their ID, and servers can optionally respond with their own to enable the same behavior. Change-Id: I0a13ee90b6706acf20eabcee3bab3f2dff639bf9 Signed-off-by: Gianmarco De Gregori --- M src/openvpn/dco.c M src/openvpn/init.c M src/openvpn/misc.c M src/openvpn/multi.c M src/openvpn/push.c M src/openvpn/push_util.c M src/openvpn/ssl.c M src/openvpn/ssl_common.h M src/openvpn/ssl_ncp.c M src/openvpn/ssl_util.c M src/openvpn/ssl_util.h 11 files changed, 104 insertions(+), 41 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/89/1089/3 diff --git a/src/openvpn/dco.c b/src/openvpn/dco.c index 6afc680..eb600f0 100644 --- a/src/openvpn/dco.c +++ b/src/openvpn/dco.c @@ -514,14 +514,15 @@ c->c2.tls_multi->dco_peer_id =3D -1; } #endif - int ret =3D dco_new_peer(&c->c1.tuntap->dco, multi->peer_id, sock->sd,= NULL, - proto_is_dgram(sock->info.proto) ? remoteaddr := NULL, NULL, NULL); + int ret =3D dco_new_peer(&c->c1.tuntap->dco, multi->rx_peer_id, sock->= sd, NULL, + proto_is_dgram(sock->info.proto) ? remoteaddr := NULL, + NULL, NULL); if (ret < 0) { return ret; } - c->c2.tls_multi->dco_peer_id =3D multi->peer_id; + c->c2.tls_multi->dco_peer_id =3D multi->rx_peer_id; return 0; } @@ -596,7 +597,7 @@ { struct context *c =3D &mi->context; - int peer_id =3D c->c2.tls_multi->peer_id; + int peer_id =3D c->c2.tls_multi->rx_peer_id; struct sockaddr *remoteaddr, *localaddr =3D NULL; struct sockaddr_storage local =3D { 0 }; const socket_descriptor_t sd =3D c->c2.link_sockets[0]->sd; @@ -667,8 +668,7 @@ if (addrtype =3D=3D MR_ADDR_IPV6) { #if defined(_WIN32) - dco_win_add_iroute_ipv6(&c->c1.tuntap->dco, addr->v6.addr, addr->n= etbits, - c->c2.tls_multi->peer_id); + dco_win_add_iroute_ipv6(&c->c1.tuntap->dco, addr->v6.addr, addr->n= etbits, c->c2.tls_multi->rx_peer_id); #else net_route_v6_add(&m->top.net_ctx, &addr->v6.addr, addr->netbits, &mi->context.c2.push_ifconfig_ipv6_local, c->c1.t= untap->actual_name, 0, @@ -678,8 +678,7 @@ else if (addrtype =3D=3D MR_ADDR_IPV4) { #if defined(_WIN32) - dco_win_add_iroute_ipv4(&c->c1.tuntap->dco, addr->v4.addr, addr->n= etbits, - c->c2.tls_multi->peer_id); + dco_win_add_iroute_ipv4(&c->c1.tuntap->dco, addr->v4.addr, addr->n= etbits, c->c2.tls_multi->rx_peer_id); #else in_addr_t dest =3D htonl(addr->v4.addr); net_route_v4_add(&m->top.net_ctx, &dest, addr->netbits, &mi->conte= xt.c2.push_ifconfig_local, diff --git a/src/openvpn/init.c b/src/openvpn/init.c index f8a0fee..fa841b9 100644 --- a/src/openvpn/init.c +++ b/src/openvpn/init.c @@ -2223,7 +2223,7 @@ if (o->use_peer_id) { - buf_printf(&out, ", peer-id: %d", o->peer_id); + buf_printf(&out, ", rx_peer-id: %u, tx_peer-id: %u", c->c2.tls_mul= ti->rx_peer_id, c->c2.tls_multi->tx_peer_id); } #ifdef USE_COMP @@ -2702,7 +2702,7 @@ { msg(D_PUSH_DEBUG, "OPTIONS IMPORT: peer-id set"); c->c2.tls_multi->use_peer_id =3D true; - c->c2.tls_multi->peer_id =3D c->options.peer_id; + c->c2.tls_multi->tx_peer_id =3D c->options.peer_id; } /* process (potentially) pushed options */ diff --git a/src/openvpn/misc.c b/src/openvpn/misc.c index caf4725..91ab391 100644 --- a/src/openvpn/misc.c +++ b/src/openvpn/misc.c @@ -765,7 +765,8 @@ { chomp(line); if (validate_peer_info_line(line) - && (strncmp(line, "IV_", 3) =3D=3D 0 || strncmp(line, "UV_", 3= ) =3D=3D 0)) + && (strncmp(line, "IV_", 3) =3D=3D 0 || strncmp(line, "UV_", 3= ) =3D=3D 0 + || strncmp(line, "ID", 2) =3D=3D 0)) { msg(M_INFO, "peer info: %s", line); env_set_add(es, line); diff --git a/src/openvpn/multi.c b/src/openvpn/multi.c index 2863ff1..bc8cc7b 100644 --- a/src/openvpn/multi.c +++ b/src/openvpn/multi.c @@ -453,7 +453,7 @@ if (mi->context.c2.tls_multi && check_debug_level(D_DCO_DEBUG) && dco_enabled(&mi->context.options)) { - buf_printf(&out, " peer-id=3D%d", mi->context.c2.tls_multi->pe= er_id); + buf_printf(&out, " rx_peer-id=3D%d", mi->context.c2.tls_multi-= >rx_peer_id); } return BSTR(&out); } @@ -628,9 +628,9 @@ } #endif - if (mi->context.c2.tls_multi->peer_id !=3D MAX_PEER_ID) + if (mi->context.c2.tls_multi->rx_peer_id !=3D MAX_PEER_ID) { - m->instances[mi->context.c2.tls_multi->peer_id] =3D NULL; + m->instances[mi->context.c2.tls_multi->rx_peer_id] =3D NULL; } schedule_remove_entry(m->schedule, (struct schedule_entry *)mi); @@ -949,8 +949,7 @@ #else sep, #endif - sep, - mi->context.c2.tls_multi ? mi->context.c2.tls_mult= i->peer_id : UINT32_MAX, + sep, mi->context.c2.tls_multi ? mi->context.c2.tls= _multi->rx_peer_id : UINT32_MAX, sep, translate_cipher_name_to_openvpn(mi->context.= options.ciphername)); } gc_free(&gc); @@ -1756,6 +1755,17 @@ { tls_multi->use_peer_id =3D true; o->use_peer_id =3D true; + uint32_t peer_id =3D extract_asymmetric_peer_id(peer_info); + if (peer_id) + { + tls_multi->tx_peer_id =3D peer_id; + tls_multi->use_asymmetric_peer_id =3D true; + } + else + { + /*Client has no asymmetric peer-id capability */ + tls_multi->tx_peer_id =3D tls_multi->rx_peer_id; + } } else if (dco_enabled(o)) { @@ -3153,12 +3163,12 @@ * has, so we disallow it. This can happen if a DCO netlink notifi= cation * gets lost and we miss a floating step. */ - if (m1->peer_id =3D=3D m2->peer_id) + if (m1->rx_peer_id =3D=3D m2->rx_peer_id) { msg(M_WARN, "disallowing peer %" PRIu32 " (%s) from floating to " "its own address (%s)", - m1->peer_id, tls_common_name(mi->context.c2.tls_multi, fal= se), + m1->rx_peer_id, tls_common_name(mi->context.c2.tls_multi, = false), mroute_addr_print(&mi->real, &gc)); goto done; } @@ -3171,9 +3181,10 @@ } msg(D_MULTI_MEDIUM, "peer %" PRIu32 " (%s) floated from %s to %s", - mi->context.c2.tls_multi->peer_id, tls_common_name(mi->context.c2.= tls_multi, false), - mroute_addr_print_ex(&mi->real, MAPF_SHOW_FAMILY, &gc), - mroute_addr_print_ex(&real, MAPF_SHOW_FAMILY, &gc)); + mi->context.c2.tls_multi->rx_peer_id, + tls_common_name(mi->context.c2.tls_multi, false), + mroute_addr_print(&mi->real, &gc), + print_link_socket_actual(&m->top.c2.from, &gc)); /* remove old address from hash table before changing address */ ASSERT(hash_remove(m->hash, &mi->real)); @@ -4159,7 +4170,7 @@ { if (!m->instances[i]) { - mi->context.c2.tls_multi->peer_id =3D i; + mi->context.c2.tls_multi->rx_peer_id =3D i; m->instances[i] =3D mi; break; } @@ -4167,7 +4178,7 @@ /* should not really end up here, since multi_create_instance returns = null * if amount of clients exceeds max_clients */ - ASSERT(mi->context.c2.tls_multi->peer_id < m->max_clients); + ASSERT(mi->context.c2.tls_multi->rx_peer_id < m->max_clients); } /*************************************************************************= */ diff --git a/src/openvpn/push.c b/src/openvpn/push.c index e7fc50c..d9e5803 100644 --- a/src/openvpn/push.c +++ b/src/openvpn/push.c @@ -659,9 +659,10 @@ print_in_addr_t(c->c2.push_ifconfig_remote_netmask= , 0, gc)); } - if (tls_multi->use_peer_id) + if (tls_multi->use_peer_id && !tls_multi->use_asymmetric_peer_id) { - push_option_fmt(gc, push_list, M_USAGE, "peer-id %d", tls_multi->p= eer_id); + push_option_fmt(gc, push_list, M_USAGE, "peer-id %d", + tls_multi->rx_peer_id); } /* * If server uses --auth-gen-token and we have an auth token diff --git a/src/openvpn/push_util.c b/src/openvpn/push_util.c index 9138bdb..b5d8a57 100644 --- a/src/openvpn/push_util.c +++ b/src/openvpn/push_util.c @@ -175,14 +175,14 @@ if (process_incoming_push_update(c, pull_permission_mask(c), optio= n_types_found, &msgs[i], true) =3D=3D PUSH_MSG_ERROR) { msg(M_WARN, "Failed to process push update message sent to cli= ent ID: %u", - c->c2.tls_multi ? c->c2.tls_multi->peer_id : UINT32_MAX); + c->c2.tls_multi ? c->c2.tls_multi->rx_peer_id : UINT32_MAX= ); continue; } c->options.push_option_types_found |=3D *option_types_found; if (!options_postprocess_pull(&c->options, c->c2.es)) { msg(M_WARN, "Failed to post-process push update message sent t= o client ID: %u", - c->c2.tls_multi ? c->c2.tls_multi->peer_id : UINT32_MAX); + c->c2.tls_multi ? c->c2.tls_multi->rx_peer_id : UINT32_MAX= ); } } return true; @@ -264,7 +264,7 @@ if (!send_single_push_update(&curr_mi->context, msgs, &option_type= s_found)) { msg(M_CLIENT, "ERROR: Peer ID: %u has not been updated", - curr_mi->context.c2.tls_multi ? curr_mi->context.c2.tls_mu= lti->peer_id : UINT32_MAX); + curr_mi->context.c2.tls_multi ? curr_mi->context.c2.tls_mu= lti->rx_peer_id : UINT32_MAX); continue; } if (option_types_found & OPT_P_UP) diff --git a/src/openvpn/ssl.c b/src/openvpn/ssl.c index 34036f2..fc22287 100644 --- a/src/openvpn/ssl.c +++ b/src/openvpn/ssl.c @@ -1175,7 +1175,9 @@ /* get command line derived options */ ret->opt =3D *tls_options; ret->dco_peer_id =3D -1; - ret->peer_id =3D MAX_PEER_ID; + ret->use_asymmetric_peer_id =3D false; + ret->rx_peer_id =3D MAX_PEER_ID; + ret->tx_peer_id =3D MAX_PEER_ID; return ret; } @@ -1880,7 +1882,7 @@ * @return true if no error was encountered */ static bool -push_peer_info(struct buffer *buf, struct tls_session *session) +push_peer_info(struct buffer *buf, struct tls_session *session, uint32_t p= eer_id) { struct gc_arena gc =3D gc_new(); bool ret =3D false; @@ -1974,6 +1976,11 @@ buf_printf(&out, "IV_PROTO=3D%d\n", iv_proto); + if (peer_id !=3D MAX_PEER_ID) + { + buf_printf(&out, "ID=3D%x\n", peer_id); + } + if (session->opt->push_peer_info_detail > 1) { /* push compression status */ @@ -2154,7 +2161,20 @@ } } - if (!push_peer_info(buf, session)) + /* Calculate the asymmetric peer-id */ + if (multi->rx_peer_id =3D=3D MAX_PEER_ID && session->opt->mode !=3D MO= DE_SERVER) + { + uint8_t peerid[3]; + srand((unsigned)time(NULL)); + for (int i =3D 0; i < 3; i++) + { + peerid[i] =3D rand(); + } + + multi->rx_peer_id =3D (peerid[0] << 16) + (peerid[1] << 8) + peeri= d[2]; + multi->use_asymmetric_peer_id =3D true; + } + if (!push_peer_info(buf, session, multi->rx_peer_id)) { goto error; } @@ -4006,8 +4026,8 @@ msg(D_TLS_DEBUG, __func__); ASSERT(ks); - - peer =3D htonl(((P_DATA_V2 << P_OPCODE_SHIFT) | ks->key_id) << 24 | (m= ulti->peer_id & 0xFFFFFF)); + peer =3D htonl(((P_DATA_V2 << P_OPCODE_SHIFT) | ks->key_id) << 24 + | (multi->tx_peer_id & 0xFFFFFF)); ASSERT(buf_write_prepend(buf, &peer, 4)); } diff --git a/src/openvpn/ssl_common.h b/src/openvpn/ssl_common.h index de89d30..c9818d4 100644 --- a/src/openvpn/ssl_common.h +++ b/src/openvpn/ssl_common.h @@ -697,8 +697,10 @@ #define AUTH_TOKEN_VALID_EMPTYUSER (1 << 2) /* For P_DATA_V2 */ - uint32_t peer_id; + uint32_t rx_peer_id; + uint32_t tx_peer_id; bool use_peer_id; + bool use_asymmetric_peer_id; char *remote_ciphername; /**< cipher specified in peer's config file */ bool remote_usescomp; /**< remote announced comp-lzo in OCC string = */ diff --git a/src/openvpn/ssl_ncp.c b/src/openvpn/ssl_ncp.c index 790e50f..0f0d6bb 100644 --- a/src/openvpn/ssl_ncp.c +++ b/src/openvpn/ssl_ncp.c @@ -406,6 +406,7 @@ { /* will return 0 if peer_info is null */ const unsigned int iv_proto_peer =3D extract_iv_proto(multi->peer_info= ); + const unsigned int tx_peer_id =3D extract_asymmetric_peer_id(multi->pe= er_info); /* The other peer does not support P2P NCP */ if (!(iv_proto_peer & IV_PROTO_NCP_P2P)) @@ -416,9 +417,15 @@ if (iv_proto_peer & IV_PROTO_DATA_V2) { multi->use_peer_id =3D true; - multi->peer_id =3D 0x76706e; /* 'v' 'p' 'n' */ + multi->use_asymmetric_peer_id =3D true; + multi->rx_peer_id =3D 0x76706e; /* 'v' 'p' 'n' */ + multi->tx_peer_id =3D 0x76706e; /* 'v' 'p' 'n' */ } + if (tx_peer_id) + { + multi->tx_peer_id =3D tx_peer_id; + } if (iv_proto_peer & IV_PROTO_CC_EXIT_NOTIFY) { session->opt->crypto_flags |=3D CO_USE_CC_EXIT_NOTIFY; @@ -458,7 +465,7 @@ } else { - multi->peer_id =3D (peerid[0] << 16) + (peerid[1] << 8) + = peerid[2]; + multi->rx_peer_id =3D (peerid[0] << 16) + (peerid[1] << 8)= + peerid[2]; } } } @@ -500,11 +507,13 @@ common_cipher =3D BSTR(&out); } - msg(D_TLS_DEBUG_LOW, - "P2P mode NCP negotiation result: " - "TLS_export=3D%d, DATA_v2=3D%d, peer-id %d, epoch=3D%d, cipher=3D%= s", - (bool)(session->opt->crypto_flags & CO_USE_TLS_KEY_MATERIAL_EXPORT= ), multi->use_peer_id, - multi->peer_id, (bool)(session->opt->crypto_flags & CO_EPOCH_DATA_= KEY_FORMAT), + msg(D_TLS_DEBUG_LOW, "P2P mode NCP negotiation result: " + "TLS_export=3D%d, DATA_v2=3D%d, rx-peer-id %d, tx= -peer-id %d, epoch=3D%d, cipher=3D%s", + (bool)(session->opt->crypto_flags & CO_USE_TLS_KEY_MATERIAL_EXPORT= ), + multi->use_peer_id, + multi->rx_peer_id, + multi->tx_peer_id, + (bool)(session->opt->crypto_flags & CO_EPOCH_DATA_KEY_FORMAT), common_cipher); gc_free(&gc); diff --git a/src/openvpn/ssl_util.c b/src/openvpn/ssl_util.c index 50e8c03..655497e 100644 --- a/src/openvpn/ssl_util.c +++ b/src/openvpn/ssl_util.c @@ -72,6 +72,24 @@ return 0; } +uint32_t +extract_asymmetric_peer_id(const char *peer_info) +{ + const char *optstr =3D peer_info ? strstr(peer_info, "ID=3D") : NULL; + if (optstr) + { + uint32_t peer_id =3D 0; + int r =3D sscanf(optstr, "ID=3D%x", &peer_id); + { + if (r =3D=3D 1 && peer_id >=3D 0) + { + return peer_id; + } + } + } + return 0; +} + const char * options_string_compat_lzo(const char *options, struct gc_arena *gc) { diff --git a/src/openvpn/ssl_util.h b/src/openvpn/ssl_util.h index 007ed69..56e4d26 100644 --- a/src/openvpn/ssl_util.h +++ b/src/openvpn/ssl_util.h @@ -53,6 +53,8 @@ */ unsigned int extract_iv_proto(const char *peer_info); +uint32_t extract_asymmetric_peer_id(const char *peer_info); + /** * Takes a locally produced OCC string for TLS server mode and modifies as * if the option comp-lzo was enabled. This is to send a client in -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1089?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I0a13ee90b6706acf20eabcee3bab3f2dff639bf9 Gerrit-Change-Number: 1089 Gerrit-PatchSet: 3 Gerrit-Owner: its_Giaan Gerrit-Reviewer: cron2 Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: its_Giaan Gerrit-Attention: flichtenheld Gerrit-MessageType: newpatchset --PrwbHxwTXiA= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: flichtenheld, its_Giaan.

its_Giaan uploaded patch set #3 to this change.

<= a href=3D"http://gerrit.openvpn.net/c/openvpn/+/1089?usp=3Demail">View Chan= ge

multipeer: introduce asymmetric peer-id

In order to achieve a= multipeer functionality, peers now
use separate IDs for sending (tx_pee= r_id) and receiving
(rx_peer_id).

Each peer announces its own ID = through pushing peer-info
using 'ID=3D7f1' hex format so identif= ication can still
happen even if IP/port changes.

In P2P mode, pe= er switch to using the announced IDs after
mutual exchange.
In P2MP m= ode, clients always announce their ID, and servers
can optionally respon= d with their own to enable the same
behavior.

Change-Id: I0a13ee9= 0b6706acf20eabcee3bab3f2dff639bf9
Signed-off-by: Gianmarco De Gregori &l= t;gianmarco@...2726...>
---
M src/openvpn/dco.c
M src/openvpn/i= nit.c
M src/openvpn/misc.c
M src/openvpn/multi.c
M src/openvpn/pus= h.c
M src/openvpn/push_util.c
M src/openvpn/ssl.c
M src/openvpn/ss= l_common.h
M src/openvpn/ssl_ncp.c
M src/openvpn/ssl_util.c
M src/= openvpn/ssl_util.h
11 files changed, 104 insertions(+), 41 deletions(-)<= br>
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/89/1=
089/3
diff --git a/src/openvpn/dco.c b/src/openvpn/dco.c
= index 6afc680..eb600f0 100644
--- a/src/openvpn/dco.c=
+++ b/src/openvpn/dco.c
@@ -514,14 +514,15= @@
c->c2.tls_multi->dco_peer_id =3D -1;
}
#endif
- int ret =3D dco_new_peer(&c->c1.tuntap->= ;dco, multi->peer_id, sock->sd, NULL,
- proto_is_dgram(sock->in= fo.proto) ? remoteaddr : NULL, NULL, NULL);
+ int ret =3D dco_new_peer(&c->c1.tuntap-&= gt;dco, multi->rx_peer_id, sock->sd, NULL,
+ proto_is_dgram(sock= ->info.proto) ? remoteaddr : NULL,
+ NULL, NULL);
= if (ret < 0)
{
return = ret;
}

- c->c2.tls_multi->dco_peer_id =3D multi-&g= t;peer_id;
+ c->= ;c2.tls_multi->dco_peer_id =3D multi->rx_peer_id;

return 0;
}
@@ -596,7 = +597,7 @@
{
struct context *c =3D &am= p;mi->context;

- int peer_id =3D c->c2.tls_multi->peer_id;+ int peer_id =3D c->c2.= tls_multi->rx_peer_id;
struct sockaddr *remoteaddr,= *localaddr =3D NULL;
struct sockaddr_storage local = =3D { 0 };
const socket_descriptor_t sd =3D c->c2.l= ink_sockets[0]->sd;
@@ -667,8 +668,7 @@
= if (addrtype =3D=3D MR_ADDR_IPV6)
{
#if defined(_WIN32)

- dco_win_add_iroute_ipv6(&c->c1.tuntap->dco, addr->v6= .addr, addr->netbits,
+ dco_win_add_iroute_= ipv6(&c->c1.tuntap->dco, addr->v6.addr, addr->netbits, c-&g= t;c2.tls_multi->rx_peer_id);
#else
= net_route_v6_add(&m->top.net_ctx, &addr->v6.addr, addr-&= gt;netbits,
&mi->context.c= 2.push_ifconfig_ipv6_local, c->c1.tuntap->actual_name, 0,
<= span>@@ -678,8 +678,7 @@

else if (addrtype =3D=3D MR_A= DDR_IPV4)
{
#if defined(_WIN32)
- dco_win_add_iroute_= ipv4(&c->c1.tuntap->dco, addr->v4.addr, addr->netbits,
- = c->c2.tls_multi->peer_id);
+ dco_win_add_iroute_ipv4(&c->c1.tuntap->= ;dco, addr->v4.addr, addr->netbits, c->c2.tls_multi->rx_peer_id= );
#else
in_addr_t dest =3D htonl= (addr->v4.addr);
net_route_v4_add(&m->to= p.net_ctx, &dest, addr->netbits, &mi->context.c2.push_ifconfi= g_local,
diff --git a/src/openvpn/init.c b/src/openvpn/init= .c
index f8a0fee..fa841b9 100644
--- a/src/= openvpn/init.c
+++ b/src/openvpn/init.c
@@ = -2223,7 +2223,7 @@

if (o->use_pee= r_id)
{
- buf_printf(&out, ", peer-id: %d", o->peer_i= d);
+ buf_prin= tf(&out, ", rx_peer-id: %u, tx_peer-id: %u", c->c2.tls_mul= ti->rx_peer_id, c->c2.tls_multi->tx_peer_id);
= }

#ifdef USE_COMP
@@ -2= 702,7 +2702,7 @@
{
msg(D_PUSH= _DEBUG, "OPTIONS IMPORT: peer-id set");
= c->c2.tls_multi->use_peer_id =3D true;
- c->c2.tls_multi->peer_id =3D c->opt= ions.peer_id;
+ = c->c2.tls_multi->tx_peer_id =3D c->options.peer_id;
}


/* process (potentially) = pushed options */
diff --git a/src/openvpn/misc.c b/src/ope= nvpn/misc.c
index caf4725..91ab391 100644
-= -- a/src/openvpn/misc.c
+++ b/src/openvpn/misc.c
= @@ -765,7 +765,8 @@
{
c= homp(line);
if (validate_peer_info_line(line)
- && (st= rncmp(line, "IV_", 3) =3D=3D 0 || strncmp(line, "UV_", = 3) =3D=3D 0))
+ = && (strncmp(line, "IV_", 3) =3D=3D 0 || strncmp(lin= e, "UV_", 3) =3D=3D 0
+ || strncmp(line, "ID", 2) =3D=3D 0))<= /span>
{
msg(M_INFO, "p= eer info: %s", line);
env_set_add(es, lin= e);
diff --git a/src/openvpn/multi.c b/src/openvpn/multi.c<= /span>
index 2863ff1..bc8cc7b 100644
--- a/src/ope= nvpn/multi.c
+++ b/src/openvpn/multi.c
@@ -= 453,7 +453,7 @@
if (mi->context.c2.tls_multi &a= mp;& check_debug_level(D_DCO_DEBUG)
&&= amp; dco_enabled(&mi->context.options))
{
- buf_printf(= &out, " peer-id=3D%d", mi->context.c2.tls_multi->peer_i= d);
+ buf_= printf(&out, " rx_peer-id=3D%d", mi->context.c2.tls_multi-= >rx_peer_id);
}
return= BSTR(&out);
}
@@ -628,9 +628,9 @@=
}
#endif

- if (mi->context.= c2.tls_multi->peer_id !=3D MAX_PEER_ID)
+ if (mi->context.c2.tls_multi->rx_peer_= id !=3D MAX_PEER_ID)
{
- m->instances[mi->context.c2.tls= _multi->peer_id] =3D NULL;
+ m->instances[mi->context.c2.tls_multi->rx_pe= er_id] =3D NULL;
}

schedule_remove_entry(m->schedule, (struct schedule_entry *)= mi);

@@ -949,8 +949,7 @@
#else
<= span> sep,

#endif
- sep,- mi->= context.c2.tls_multi ? mi->context.c2.tls_multi->peer_id : UINT32_MAX= ,
+ = sep, mi->context.c2.tls_multi ? mi->context.c2.tls_multi->rx= _peer_id : UINT32_MAX,
sep, transl= ate_cipher_name_to_openvpn(mi->context.options.ciphername));
<= span> }

gc_free(&gc);<= /span>
@@ -1756,6 +1755,17 @@
{
tls_multi->use_peer_id =3D true;

o-= >use_peer_id =3D true;
+ uint32_t peer_id =3D extract_asymmetric_peer_id(peer_info);
+ if (peer_id)<= /span>
+ {
= + tls_multi->tx_p= eer_id =3D peer_id;
+= tls_multi->use_asymmetric_peer_id =3D true;
+ }
+ else
+ {
+ /*Client has no asymmetric peer-id capability */
+ tls_multi-= >tx_peer_id =3D tls_multi->rx_peer_id;
+ }
}
= else if (dco_enabled(o))
{
@@ -315= 3,12 +3163,12 @@
* has, so we disallow it. This c= an happen if a DCO netlink notification
* gets lo= st and we miss a floating step.
*/
- if (m1->peer_id =3D=3D m2= ->peer_id)

+ = if (m1->rx_peer_id =3D=3D m2->rx_peer_id)
= {
msg(M_WARN,
= "disallowing peer %" PRIu32 " (%s) from floating to "<= /span>
"its own address (%s)",- m1->peer_id= , tls_common_name(mi->context.c2.tls_multi, false),
+ m1->rx_peer_id, tls_c= ommon_name(mi->context.c2.tls_multi, false),
= mroute_addr_print(&mi->real, &gc));
= goto done;
}
@@ -3171,9 +31= 81,10 @@
}

msg(= D_MULTI_MEDIUM, "peer %" PRIu32 " (%s) floated from %s to %s= ",
- mi->= ;context.c2.tls_multi->peer_id, tls_common_name(mi->context.c2.tls_mu= lti, false),
- m= route_addr_print_ex(&mi->real, MAPF_SHOW_FAMILY, &gc),- mroute_addr_print_ex(&a= mp;real, MAPF_SHOW_FAMILY, &gc));
+ mi->context.c2.tls_multi->rx_peer_id,
+ tls_common_name(m= i->context.c2.tls_multi, false),
+ mroute_addr_print(&mi->real, &gc),
+ print_link_socket= _actual(&m->top.c2.from, &gc));

/* remove old address from hash table before changing address */
ASSERT(hash_remove(m->hash, &mi->real));=
@@ -4159,7 +4170,7 @@
{
= if (!m->instances[i])
{
- mi->context.c2.tls_multi-= >peer_id =3D i;
+ = mi->context.c2.tls_multi->rx_peer_id =3D i;
m->instances[i] =3D mi;

brea= k;
}
@@ -4167,7 +4178,7 @@<= br>
/* should not really end up here, since mul= ti_create_instance returns null
* if amount of client= s exceeds max_clients */
+ ASSERT(mi-&g= t;context.c2.tls_multi->rx_peer_id < m->max_clients);
}


/********************************= ******************************************/
diff --git a/sr= c/openvpn/push.c b/src/openvpn/push.c
index e7fc50c..d9e580= 3 100644
--- a/src/openvpn/push.c
+++ b/src= /openvpn/push.c
@@ -659,9 +659,10 @@
= print_in_addr_t(c->c2.push_ifconfig_remote_netmask, 0= , gc));
}

- if (tls_multi->use_peer_id)
+ if (tls_multi->use_peer_id= && !tls_multi->use_asymmetric_peer_id)

{
- push_option_fmt= (gc, push_list, M_USAGE, "peer-id %d", tls_multi->peer_id);
+ push_option_fm= t(gc, push_list, M_USAGE, "peer-id %d",
+ tls_multi->rx_peer= _id);
}
/*
= * If server uses --auth-gen-token and we have an auth token
diff --git a/src/openvpn/push_util.c b/src/openvpn/push_util.c

<= span>index 9138bdb..b5d8a57 100644

--- a/src/openvpn/push_u= til.c
+++ b/src/openvpn/push_util.c
@@ -175= ,14 +175,14 @@
if (process_incoming_push_update(c,= pull_permission_mask(c), option_types_found, &msgs[i], true) =3D=3D PU= SH_MSG_ERROR)
{
msg(M= _WARN, "Failed to process push update message sent to client ID: %u&qu= ot;,
- c= ->c2.tls_multi ? c->c2.tls_multi->peer_id : UINT32_MAX);+ c->c2.tls_= multi ? c->c2.tls_multi->rx_peer_id : UINT32_MAX);
= continue;
}
c-= >options.push_option_types_found |=3D *option_types_found;
if (!options_postprocess_pull(&c->options, c->c2.es))=

{
msg(M_WARN, "= Failed to post-process push update message sent to client ID: %u",
- c->c2.= tls_multi ? c->c2.tls_multi->peer_id : UINT32_MAX);
+ c->c2.tls_multi ? = c->c2.tls_multi->rx_peer_id : UINT32_MAX);
}=
}
return true;
@= @ -264,7 +264,7 @@
if (!send_single_push_update(&a= mp;curr_mi->context, msgs, &option_types_found))
= {
msg(M_CLIENT, "ERROR: Peer ID: %u= has not been updated",
- curr_mi->context.c2.tls_multi ? curr_mi->conte= xt.c2.tls_multi->peer_id : UINT32_MAX);
+ curr_mi->context.c2.tls_multi ? c= urr_mi->context.c2.tls_multi->rx_peer_id : UINT32_MAX);
continue;

}
= if (option_types_found & OPT_P_UP)
diff --git a/src/= openvpn/ssl.c b/src/openvpn/ssl.c
index 34036f2..fc22287 10= 0644
--- a/src/openvpn/ssl.c
+++ b/src/open= vpn/ssl.c
@@ -1175,7 +1175,9 @@
/* get= command line derived options */
ret->opt =3D *tls_= options;
ret->dco_peer_id =3D -1;
- ret->peer_id =3D MAX_PEER_ID;
+ ret->use_asymme= tric_peer_id =3D false;
+ ret->rx_peer_id =3D MAX_PEER_ID;
+ ret->tx_peer_id =3D MAX_PEER_ID;
<= span>

return ret;
}
= @@ -1880,7 +1882,7 @@
* @return true if no error= was encountered
*/
static bool-push_peer_info(struct buffer *= buf, struct tls_session *session)
+push_peer_info(struct buffer *buf, struct tls_session *sessio= n, uint32_t peer_id)
{
struct gc_aren= a gc =3D gc_new();
bool ret =3D false;
@@ -1974,6 +1976,11 @@


buf_prin= tf(&out, "IV_PROTO=3D%d\n", iv_proto);

+ if (peer_id !=3D= MAX_PEER_ID)
+ = {
+ buf_= printf(&out, "ID=3D%x\n", peer_id);
+ }
+
if (session->opt->push_= peer_info_detail > 1)
{
= /* push compression status */
@@ -2154,7 +2161,20 @@<= /span>
}
}
<= br>- if (!push_peer_info(buf, = session))
+ /* Cal= culate the asymmetric peer-id */
+ if (multi->rx_peer_id =3D=3D MAX_PEER_ID && ses= sion->opt->mode !=3D MODE_SERVER)
+ {
+ uint8_t peerid[3];
+ srand((unsigned)time(NULL));
+ for (int i =3D 0; i < 3; i++)
+ {
+ peerid[i] =3D rand();<= /span>
+ }
= +
+ multi->rx_peer_id =3D (peerid[0] <&= lt; 16) + (peerid[1] << 8) + peerid[2];
+ multi->use_asymmetric_peer_id =3D true= ;
+ }
+ if (!push_peer_info(buf, ses= sion, multi->rx_peer_id))

{
= goto error;
}
@@ -4006,8 +4026,8 @@<= /span>
msg(D_TLS_DEBUG, __func__);
ASSERT(ks);
- peer =3D htonl= (((P_DATA_V2 << P_OPCODE_SHIFT) | ks->key_id) << 24 | (multi= ->peer_id & 0xFFFFFF));
+ peer =3D htonl(((P_DATA_V2 << P_OPCODE_SHIFT) | ks->= ;key_id) << 24
= + | (multi->tx_peer_id & 0xFFFFFF));
ASSERT(buf_write_prepend(buf, &peer, 4));

}

diff --git a/src/openvpn/ssl_common.h b/src/o= penvpn/ssl_common.h
index de89d30..c9818d4 100644--- a/src/openvpn/ssl_common.h
+++ b/src/openvpn/ssl= _common.h
@@ -697,8 +697,10 @@
#define AUT= H_TOKEN_VALID_EMPTYUSER (1 << 2)

= /* For P_DATA_V2 */
= - uint32_t peer_id;
+ uint32_t tx_peer_id;
bool use_peer_id;
+ bool use_asymmetric= _peer_id;

char *remote_ciphername; /= **< cipher specified in peer's config file */
b= ool remote_usescomp; /**< remote announced comp-lzo in OCC string */<= /span>
diff --git a/src/openvpn/ssl_ncp.c b/src/openvpn/ssl_ncp.c<= /span>
index 790e50f..0f0d6bb 100644
--- a/src/ope= nvpn/ssl_ncp.c
+++ b/src/openvpn/ssl_ncp.c
= @@ -406,6 +406,7 @@
{
/* will return = 0 if peer_info is null */
const unsigned int iv_proto_= peer =3D extract_iv_proto(multi->peer_info);
+ const unsigned int tx_peer_id =3D extract_a= symmetric_peer_id(multi->peer_info);

= /* The other peer does not support P2P NCP */
if (= !(iv_proto_peer & IV_PROTO_NCP_P2P))
@@ -416,9 +417,15 = @@
if (iv_proto_peer & IV_PROTO_DATA_V2) {
multi->use_peer_id =3D true;
- multi->peer_id = =3D 0x76706e; /* 'v' 'p' 'n' */
+ multi->use_asymmetric_peer_i= d =3D true;
+ = multi->rx_peer_id =3D 0x76706e; /* 'v' 'p' 'n' *= /
+ multi->= tx_peer_id =3D 0x76706e; /* 'v' 'p' 'n' */ }

+ if (tx_peer_id)
+ {
+ = multi->tx_peer_id =3D tx_peer_id;
+ }
if (iv_proto_peer & = IV_PROTO_CC_EXIT_NOTIFY)
{
se= ssion->opt->crypto_flags |=3D CO_USE_CC_EXIT_NOTIFY;
= @@ -458,7 +465,7 @@
}
= else
{
- multi->peer_id =3D (peerid[0] <<= ; 16) + (peerid[1] << 8) + peerid[2];
+ multi->rx_peer_id =3D (peerid[0]= << 16) + (peerid[1] << 8) + peerid[2];
= }
}
}
@= @ -500,11 +507,13 @@
common_cipher =3D BSTR(&o= ut);
}

- msg(D_TLS_DEBUG_LOW,
- "P2P mode NCP negotiation result: &= quot;
- "TL= S_export=3D%d, DATA_v2=3D%d, peer-id %d, epoch=3D%d, cipher=3D%s",
- (bool)(session-&g= t;opt->crypto_flags & CO_USE_TLS_KEY_MATERIAL_EXPORT), multi->use= _peer_id,
- mult= i->peer_id, (bool)(session->opt->crypto_flags & CO_EPOCH_DATA_= KEY_FORMAT),
+ msg= (D_TLS_DEBUG_LOW, "P2P mode NCP negotiation result: "
<= span style=3D"color: hsl(120, 100%, 40%);">+ "= TLS_export=3D%d, DATA_v2=3D%d, rx-peer-id %d, tx-peer-id %d, epoch=3D%d, ci= pher=3D%s",

+ = (bool)(session->opt->crypto_flags & CO_USE_TLS_KEY_MATERIAL_= EXPORT),
+ mul= ti->use_peer_id,
+= multi->rx_peer_id,
+ multi->tx_peer_id,
+ (bool)(session->opt->crypto_flags & C= O_EPOCH_DATA_KEY_FORMAT),
common_cipher);
gc_free(&gc);
diff --git= a/src/openvpn/ssl_util.c b/src/openvpn/ssl_util.c
index 50= e8c03..655497e 100644
--- a/src/openvpn/ssl_util.c+++ b/src/openvpn/ssl_util.c
@@ -72,6 +72,24 @@
return 0;
}

= +uint32_t
+extract_asymmetric_peer_id(const char *pe= er_info)
+{+ const char *optstr =3D pe= er_info ? strstr(peer_info, "ID=3D") : NULL;
+ if (optstr)
+ {
+ uint32_t peer_id =3D 0;
+ int r =3D sscanf(optstr, "ID=3D%x= ", &peer_id);
+ = if (r =3D=3D 1 && peer_id >=3D 0)
+ {
+ return peer_id;
+ }
+ }
+ }
+ return 0;
+= }
+
= const char *
options_string_compat_lzo(const char *options= , struct gc_arena *gc)
{
diff --git a/src/= openvpn/ssl_util.h b/src/openvpn/ssl_util.h
index 007ed69..= 56e4d26 100644
--- a/src/openvpn/ssl_util.h
+++ b/src/openvpn/ssl_util.h

@@ -53,6 +53,8 @@
<= span> */

unsigned int extract_iv_proto(const char *peer_i= nfo);

+uint32_t extract_asymmetric_peer_id(const char *peer_info);
<= span style=3D"color: hsl(120, 100%, 40%);">+

/** * Takes a locally produced OCC string for TLS server mode and modi= fies as
* if the option comp-lzo was enabled. This is to = send a client in

To view, visit change 1089= . To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I0a13ee90b6706acf20eabcee3ba= b3f2dff639bf9
Gerrit-Change-Number: 1089
Gerrit-PatchSet: 3
Gerrit-Owner: its_Giaan <gianmarco@...2786...= ..>
Gerrit-Reviewer: cron2 <gert@...1296...>=
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: its_Giaan <gianmarco@...1665...= 726...>
Gerrit-Attention: flichtenheld <frank@...2375...= 41...>
Gerrit-MessageType: newpatchset
--PrwbHxwTXiA=--