Better wildcard matching for CN

This is a fix for https://bugs.php.net/bug.php?id=65729

It also allows for better wildcard matching, such as `foo*.bar.com` and `*baz.foo.com`, as per [rfc 2818](http://tools.ietf.org/html/rfc2818#section-3.1).