ext-mysqlnd: can't set SSL server hostname verification independent of general certificate validation
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 40.4k
- Forks
- 8.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 96
Description
Description
The mysql command line client and related tools verify SSL certificates, but by default do not verify that the server name used to connect matches the Subject CN, or one of the SAN extension entries, of the server certificate.
This additional verification needs to be requested using the --ssl-verify-server-cert option (which was not the best name for this, -ssl-verify-server-cert-hostname would have been a better choice, bu that is a different story); or when using encrypted replication: the MASTER_SSL_VERIFY_SERVER_CERT=1 option to CHANGE MASTER.
With mysqlnd though both verification aspects are tightly coupled, and can only be both on, or both off, controlled by the single MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT flag.
See also: ext/mysqlnd/mysqlnd_vio.c:
555 ZVAL_BOOL(&verify_peer_zval, verify);
556 php_stream_context_set_option(context, "ssl", "verify_peer", &verify_peer_zval);
557 php_stream_context_set_option(context, "ssl", "verify_peer_name", &verify_peer_zval);
https://github.com/php/php-src/blob/master/ext/mysqlnd/mysqlnd_vio.c#L555
There needs to be an extra option like MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_HOSTNAME to control hostname verification independent of general certificate verification.
PHP Version
PHP 8.1.2
Operating System
Ubuntu 22.04
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Read ext/mysqlnd/mysqlnd_vio.c around lines 555-557, where verify_peer and verify_peer_name are set together, and review the MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT flag. The change is complete when hostname verification can be controlled independently through an additional option while general certificate validation remains separately controllable.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, mysql
- Domain
- databases, security
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100