{
hpconn->conn.haproxy.ssl = (ssl_kv->client & (PP2_CLIENT_SSL)) != 0;
+ /* The client byte indicates whether a client certificate was
+ presented on this connection or session. Only trust the
+ sub-TLVs (e.g. the common name) when HAProxy reports the
+ certificate was successfully verified (verify == 0). */
+ bool client_cert_present =
+ (ssl_kv->client &
+ (PP2_CLIENT_CERT_CONN | PP2_CLIENT_CERT_SESS)) != 0;
+ bool client_cert_verified =
+ client_cert_present && ssl_kv->verify == 0;
+
/* try parse some more */
for(size_t i = 0; i < ssl_kv->len;) {
struct haproxy_pp2_tlv kv;
case PP2_SUBTYPE_SSL_KEY_ALG:
break;
case PP2_SUBTYPE_SSL_CN:
+ if (!client_cert_verified)
+ break;
hpconn->conn.haproxy.cert_common_name =
p_strndup(hpconn->pool, kv.data, kv.len);
break;