Skip to content

Commit ed66e7d

Browse files
authored
Adds new API: TSVConnSslSniGet (#8313)
1 parent 978bf0f commit ed66e7d

5 files changed

Lines changed: 59 additions & 1 deletion

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
.. Licensed to the Apache Software Foundation (ASF) under one or more
2+
contributor license agreements. See the NOTICE file distributed
3+
with this work for additional information regarding copyright
4+
ownership. The ASF licenses this file to you under the Apache
5+
License, Version 2.0 (the "License"); you may not use this file
6+
except in compliance with the License. You may obtain a copy of
7+
the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14+
implied. See the License for the specific language governing
15+
permissions and limitations under the License.
16+
17+
18+
TSVConnSslSniGet
19+
================
20+
21+
Synopsis
22+
--------
23+
24+
.. code-block:: cpp
25+
26+
#include <ts/ts.h>
27+
28+
.. c:function:: const char TSVConnSslSniGet(TSVConn sslp, int *length)
29+
30+
31+
Description
32+
-----------
33+
Get the SNI (Server Name Indication) that corresponds to SSL connection :arg:`sslp`.

include/ts/ts.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,6 +1325,7 @@ tsapi int TSVConnIsSsl(TSVConn sslp);
13251325
/* Returns 1 if a certificate was provided in the TLS handshake, 0 otherwise.
13261326
*/
13271327
tsapi int TSVConnProvidedSslCert(TSVConn sslp);
1328+
tsapi const char *TSVConnSslSniGet(TSVConn sslp, int *length);
13281329

13291330
tsapi TSSslSession TSSslSessionGet(const TSSslSessionID *session_id);
13301331
tsapi int TSSslSessionGetBuffer(const TSSslSessionID *session_id, char *buffer, int *len_ptr);

src/traffic_server/InkAPI.cc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9474,6 +9474,25 @@ TSVConnSslConnectionGet(TSVConn sslp)
94749474
return ssl;
94759475
}
94769476

9477+
const char *
9478+
TSVConnSslSniGet(TSVConn sslp, int *length)
9479+
{
9480+
char const *server_name = nullptr;
9481+
NetVConnection *vc = reinterpret_cast<NetVConnection *>(sslp);
9482+
9483+
if (vc == nullptr) {
9484+
return nullptr;
9485+
}
9486+
9487+
server_name = vc->get_server_name();
9488+
9489+
if (length) {
9490+
*length = server_name ? strlen(server_name) : 0;
9491+
}
9492+
9493+
return server_name;
9494+
}
9495+
94779496
tsapi TSSslVerifyCTX
94789497
TSVConnSslVerifyCTXGet(TSVConn sslp)
94799498
{

tests/gold_tests/tls/tls_hooks_verify.test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
tr3.Processes.Default.ReturnCode = 0
9393
tr3.Processes.Default.Streams.stdout = Testers.ExcludesExpression("Could Not Connect", "Curl attempt should have failed")
9494

95-
# Over riding the built in ERROR check since we expect tr2 to fail
95+
# Overriding the built in ERROR check since we expect tr2 to fail
9696
ts.Disk.diags_log.Content = Testers.ContainsExpression(
9797
"WARNING: TS_EVENT_SSL_VERIFY_SERVER plugin failed the origin certificate check for 127.0.0.1. Action=Terminate SNI=random.com",
9898
"random.com should fail")
@@ -113,3 +113,4 @@
113113
"Server verify callback 0 [\da-fx]+? - event is good SNI=bar.com error HS", "verify callback happens 2 times")
114114
ts.Streams.All += Testers.ContainsExpression(
115115
"Server verify callback 1 [\da-fx]+? - event is good SNI=bar.com error HS", "verify callback happens 2 times")
116+
ts.Streams.All += Testers.ContainsExpression("Server verify callback SNI APIs match=true", "verify SNI names match")

tests/tools/plugins/ssl_verify_test.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ CB_server_verify(TSCont cont, TSEvent event, void *edata)
6161
event == TS_EVENT_SSL_VERIFY_SERVER ? "good" : "bad", sni_name,
6262
reenable_event == TS_EVENT_ERROR ? "error HS" : "good HS");
6363

64+
int len;
65+
const char *method2_name = TSVConnSslSniGet(ssl_vc, &len);
66+
TSDebug(PN, "Server verify callback SNI APIs match=%s", 0 == strncmp(method2_name, sni_name, len) ? "true" : "false");
67+
6468
// All done, reactivate things
6569
TSVConnReenableEx(ssl_vc, reenable_event);
6670
return TS_SUCCESS;

0 commit comments

Comments
 (0)