Maaz2212 commented on issue #13985:
URL: 
https://github.com/apache/trafficserver/issues/13985#issuecomment-6988917912

   Thank you for the detailed feedback and architectural direction, @maskit. 
Moving the verification state into an event-attached opaque handle makes 
complete sense—it eliminates the temporal state in `TLSBasicSupport` and 
prevents legacy plugins from crashing on `NULL` store contexts.
   
   I've worked through the implementation details across both OpenSSL and 
BoringSSL paths in `SSLNetVConnection` and `TLSBasicSupport`. Here is the 
refined design: I am proposing two PR's structure if you want i can combine and 
make only single but it will lead not clear understanding.
   
   ### PR 1: Restrict Legacy Verify Hooks to X.509 (Pre-11.0 Fix)
   - In `SSLUtils.cc` and `SSLClientUtils.cc`, guard the invocation of 
`TS_SSL_VERIFY_CLIENT_HOOK` and `TS_SSL_VERIFY_SERVER_HOOK` so they only fire 
when the peer presented an X.509 certificate.
   - When the peer authenticates with an RFC 7250 raw public key, skip invoking 
these legacy hooks entirely. This guarantees pre-existing plugins never receive 
a `NULL` context.
   
   ---
   
   ### PR 2: Modern Unified Peer Verification Hooks
   
   #### 1. New Hooks & Events
   - **Hooks:** `TS_SSL_PEER_VERIFY_CLIENT_HOOK`, 
`TS_SSL_PEER_VERIFY_SERVER_HOOK`
   - **Events:** `TS_EVENT_SSL_PEER_VERIFY_CLIENT`, 
`TS_EVENT_SSL_PEER_VERIFY_SERVER`
   - Invoked for both X.509 and RPK handshakes. (If a legacy hook is also 
registered on an X.509 connection, the legacy hook runs first, followed by the 
new hook, matching existing hook cascading).
   
   #### 2. Opaque Handle & C API (`ts.h`)
   The `edata` passed to the continuation will be an opaque handle 
`TSSslPeerVerifyCTX`. Since TLS library verification callbacks are synchronous, 
`TSSslPeerVerifyCTX` is stack-allocated by ATS for the lifetime of the hook 
invocation:
   
   ```c
   typedef struct tsapi_ssl_peer_verify_ctx *TSSslPeerVerifyCTX;
   
   typedef enum {
     TS_SSL_PEER_CRED_NONE = 0,
     TS_SSL_PEER_CRED_X509,
     TS_SSL_PEER_CRED_RPK,
   } TSSslPeerCredType;
   
   TSVConn           TSSslPeerVerifyCTXVConnGet(TSSslPeerVerifyCTX ctx);
   TSSslPeerCredType TSSslPeerVerifyCTXCredTypeGet(TSSslPeerVerifyCTX ctx);
   TSSslVerifyCTX    TSSslPeerVerifyCTXStoreCTXGet(TSSslPeerVerifyCTX ctx);   
/* NULL for RPK */
   EVP_PKEY         *TSSslPeerVerifyCTXPeerRPKGet(TSSslPeerVerifyCTX ctx);    
/* Borrowed pointer; NULL for X.509 */
   int               TSSslPeerVerifyCTXPreverifyGet(TSSslPeerVerifyCTX ctx);  
/* Pre-verification status before hook */
   ```
   
   #### 3. Core Implementation Details
   - **RPK Extraction (Unified):**
     - **OpenSSL:** Extracted from `X509_STORE_CTX_get0_rpk(store_ctx)` inside 
`ssl_verify_client_callback()` / `verify_callback()` (since 
`SSL_get0_peer_rpk()` is not yet populated on the session at this point for 
inbound clients).
     - **BoringSSL:** Extracted from `SSL_get0_peer_rpk(ssl)` inside the custom 
verify callback.
   - **Pointer Ownership:** `TSSslPeerVerifyCTXPeerRPKGet()` returns a borrowed 
`EVP_PKEY *` valid for the duration of the callback. Plugins should call 
`EVP_PKEY_up_ref()` if they retain it.
   - **Preverify Status:** Captures the TLS library's pre-verification result 
(`preverify_ok` / error state in OpenSSL, or pin match result in BoringSSL/RPK) 
before plugin execution.
   - **Handshake Control:** The plugin continues via `TSVConnReenable(vc)` or 
rejects the handshake synchronously via `TSVConnReenableEx(vc, TS_EVENT_ERROR)`.
   - **Internal Cleanup:** With `TSSslPeerVerifyCTX` passed via `edata`, 
`TLSBasicSupport::_cert_to_verify` can be completely bypassed on the new path.
   
   #### 4. Deprecations
   - Mark `TS_SSL_VERIFY_CLIENT_HOOK`, `TS_SSL_VERIFY_SERVER_HOOK`, and 
`TSVConnSslVerifyCTXGet()` as deprecated in ATS 11.
   
   ---
   
   If this design looks good to you, I will start by opening **PR 1** to guard 
the legacy hooks, and then proceed with **PR 2**.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to