What is a self-signed certificate, and why can a client still trust one?
A certificate signed with its own private key instead of by a certificate authority (CA), so issuer and subject are the same. Its signature proves nothing on its own; a client trusts it only because the exact certificate was installed on the client beforehand through a channel it already trusts.
A certificate binds a public key to a name (here the server's address). Normally a CA signs that binding, and a client trusts it because the CA's own certificate is in its trust store. A self-signed certificate skips the CA: the server's key signs its own certificate. Anyone can make one for any name, so receiving one over the network proves nothing.
What makes it trustworthy here is how the client got it. The certificate was copied by hand from the server and compiled into the ESP32's firmware (and given to curl with --cacert). During the handshake the server sends its certificate again, and the client accepts the connection only if it is that exact certificate, signed correctly, and the server proves it holds the matching private key. An attacker can make a certificate with the same name, but not with the same key, so it does not match.
| CA-signed | Self-signed and pinned | |
|---|---|---|
| Trust comes from | The CA's certificate in the client's trust store | The certificate itself, installed on the client in advance |
| Needs | A domain name and a CA | Nothing; works for a private IP address |
| Renewal | New certificate from the CA; clients unchanged | Every client must get the new certificate |
| Fits | Public servers, browsers | Closed systems where one party controls server and clients |
The certificate is public information. Copying it to clients, putting it in firmware or showing it in Wireshark leaks nothing; only the private key is secret.
Go deeper:
Wikipedia — Self-signed certificate — security issues and where self-signed certificates are appropriate.
OWASP — Certificate and public key pinning — what pinning is, when it makes sense and its rotation risks.