def domain?(pem, domain)
      if cert = OpenSSL::X509::Certificate.new(pem) rescue nil
        OpenSSL::SSL.verify_certificate_identity(cert, domain) rescue false
      end
    end
def domain?(pem, domain)
      if cert = OpenSSL::X509::Certificate.new(pem) rescue nil
        OpenSSL::SSL.verify_certificate_identity(cert, domain) rescue false
      end
    end
Return true if the domain name matches one of the names in the
 certificate. In other words, is the certificate provided to us really
 for the domain to which we think we're connected?

 pem    - The PEM encoded certificate String.
 domain - The domain name String.

 Returns true if the certificate was issued for the domain.