I have seen at least two commercial firewalls operating SSL TLS filtering based on server certificate (or client SNI request). My answer will be from the protocol point of view: no code supplied.
Basically the proxy will not try to intercept the TLS conversation itself, but rather judge from the handshake conversation that mandatorily occurs in plaintext.
Image credits
When a client wants to establish an encrypted session with a server, the two must start a conversation in plaintext and then switch to encrypted. It is my personal technological opinion that the process could be improved in order not to leak certain information in this phase.
The goal of a TLS handshake is to authenticate the server versus the client, i.e. there is no MiTM proxy sniffing traffic. Rewording: once the client is negotiating (I won't go into details) an encryption key with the server, they must be sure that the agreed secret key is known only by themselves and the legitimate example.org
.
As you can see in the diagram, that phase is "Cryptographic parameters & key exchange", which I won't describe further.
In order to perform such exchange correctly, the cryptographic parameters must be linked to the server certificate, which, in turn, contains details about the visited site. The certificate is not just publicly available (so that the proxy could try to connect independently and test the server), but is transmitted in plaintext in this phase.
Without SNI, the server transmits in plaintext the certificate(s) it operates. They are in plaintext, so example.org
is clearly visible in the CN (Common Name) attribute.
In TLS 1.3 (disclaimer: information comes from experimenting and the linked article, please highlight incorrect information) and particularly when SNI is enabled, the client requests for the target server example.org
in plaintext.
The idea behind a TLS content filtering based on URL filtering, with the only constraint that the filtering is done up to the domain level and not single-url level, is the following:
- Allow the client to initiate a TCP/TLS connection, monitor it
- If during the handshake the firewall detects a blocked DNS, kill the connection
- Otherwise let the conversation continue, without sniffing
I have experimented using Wireshark and found that, apparently, the remote host was killing the connection to my workstation.
In reality, the firewall was simply injecting TCP packets with RST
flag on and dropping packets related to that TCP stream. That results in an abnormal TLS termination, but serves for the purpose.