Bug #9644

Updated by nobu (Nobuyoshi Nakada) over 5 years ago

I'm not a ruby developer but the maintainer of the IO::Socket::SSL module in Perl. While comparing the state of the SSL implementations in various languages I've noticed, that your validation of the hostname inside the certificate is wrong regarding wildcards.

According to the RFC2818 (http) or RFC6125 (includes http and others) only the leftmost part of the name specification might contain a wildcard, e.g `*` is allowed, but not `www.*` or even `www.*.*.*`. Unfortunatly the implementation of `verify_certificate_identity` in openssl/ssl.rb (or openssl/ssl-internal.rb in older versions) does a global substitution of `*` with `[^.]+` and thus allows wildcards anywhere and also multiple wildcards. I've verified my assumption with a certificate for `www.*.foo.*`, which got successfully verified against `` or `` on ruby 1.9.1. And, from looking at the code the current ruby version has the same problem.

Also, from reading the code I understand that you use the same hostname verification for SMTP, IMAP and POP too. But the verification schemes for these protocols differ from http (see RFC2595 for SMTP, RFC4642 for IMAP and POP):

* while http allows something like www* the other protocols only allow *, e.g. the the wildcard must fully replace the leftmost part of the hostname.
* while with http one should not check the common name if subject alternative names exist (and you've implemented it this way), with the other protocols one check common name too.