| 1832 | #if defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY) |
| 1833 | |
| 1834 | static int ssl_verify_server_cert(Vio *vio, const char* server_hostname, const char **errptr) |
| 1835 | { |
| 1836 | SSL *ssl; |
| 1837 | X509 *server_cert; |
| 1838 | char *cp1, *cp2; |
| 1839 | char buf[256]; |
| 1840 | DBUG_ENTER("ssl_verify_server_cert"); |
| 1841 | DBUG_PRINT("enter", ("server_hostname: %s", server_hostname)); |
| 1842 | |
| 1843 | if (!(ssl= (SSL*)vio->ssl_arg)) |
| 1844 | { |
| 1845 | *errptr= "No SSL pointer found"; |
| 1846 | DBUG_RETURN(1); |
| 1847 | } |
| 1848 | |
| 1849 | if (!server_hostname) |
| 1850 | { |
| 1851 | *errptr= "No server hostname supplied"; |
| 1852 | DBUG_RETURN(1); |
| 1853 | } |
| 1854 | |
| 1855 | if (!(server_cert= SSL_get_peer_certificate(ssl))) |
| 1856 | { |
| 1857 | *errptr= "Could not get server certificate"; |
| 1858 | DBUG_RETURN(1); |
| 1859 | } |
| 1860 | |
| 1861 | if (X509_V_OK != SSL_get_verify_result(ssl)) |
| 1862 | { |
| 1863 | *errptr= "Failed to verify the server certificate"; |
| 1864 | X509_free(server_cert); |
| 1865 | DBUG_RETURN(1); |
| 1866 | } |
| 1867 | /* |
| 1868 | We already know that the certificate exchanged was valid; the SSL library |
| 1869 | handled that. Now we need to verify that the contents of the certificate |
| 1870 | are what we expect. |
| 1871 | */ |
| 1872 | |
| 1873 | X509_NAME_oneline(X509_get_subject_name(server_cert), buf, sizeof(buf)); |
| 1874 | X509_free (server_cert); |
| 1875 | |
| 1876 | DBUG_PRINT("info", ("hostname in cert: %s", buf)); |
| 1877 | cp1= strstr(buf, "/CN="); |
| 1878 | if (cp1) |
| 1879 | { |
| 1880 | cp1+= 4; /* Skip the "/CN=" that we found */ |
| 1881 | /* Search for next / which might be the delimiter for email */ |
| 1882 | cp2= strchr(cp1, '/'); |
| 1883 | if (cp2) |
| 1884 | *cp2= '\0'; |
| 1885 | DBUG_PRINT("info", ("Server hostname in cert: %s", cp1)); |
| 1886 | if (!strcmp(cp1, server_hostname)) |
| 1887 | { |
| 1888 | /* Success */ |
| 1889 | DBUG_RETURN(0); |
| 1890 | } |
| 1891 | } |
no test coverage detected