21.03.2013 Views

Problem - Kevin Tafuro

Problem - Kevin Tafuro

Problem - Kevin Tafuro

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

if (mysql_real_connect(mysql, host, user, pw, db, port, socket, flags))<br />

result = 1;<br />

if (host_copy) free(host_copy);<br />

return result;<br />

}<br />

If the server is configured to require a peer certificate, the certificate and key to use<br />

can be specified in my.cnf, and you should use mysql_options( ) with the MYSQL_READ_<br />

DEFAULT_GROUP option to read the appropriate configuration group for your application.<br />

The options for the certificate and key to use are ssl-cert and ssl-key, respectively.<br />

In addition, use ssl-ca and ssl-capath to set a file or directory containing<br />

trusted certificates that are to be used when verifying the peer’s certificate. The final<br />

option is ssl-cipher, which can be used to specify a specific cipher or cipher set to be<br />

used. All of these keys also apply for server configuration.<br />

Alternately, you can use the undocumented mysql_ssl_set( ) function to set the key,<br />

certificate, trusted certificate file, trusted certificate directory, and cipher. Because<br />

this function is undocumented, it is possible that it will go away or change at any<br />

point without warning. * The prototype for this function is in mysql.h and is as follows:<br />

int STDCALL mysql_ssl_set(MYSQL *mysql, const char *key, const char *cert,<br />

const char *ca, const char *capath, const char *cipher);<br />

Finally, note that examination of the MySQL-4.0.10-gamma source code (the latest<br />

available at the time of this writing) reveals that if you set a certificate using either<br />

configuration file options or the undocumented mysql_ssl_set( ) API, the client will<br />

attempt to connect to the server using SSLregardless of whether you specify CLIENT_<br />

SSL in the flag passed to mysql_real_connect( ).<br />

PostgreSQL<br />

By default, SSLsupport is disabled when you are building PostgreSQL. To build<br />

PostgreSQLwith OpenSSLsupport enabled, you must specify the --with-openssl<br />

option on the command line to the configuration script. Even with a PostgreSQL<br />

server build that has OpenSSLsupport compiled in, the default is still to have SSL<br />

support disabled. To enable it, you’ll need to set the ssl parameter to on in your<br />

postgresql.conf configuration file. When SSLsupport is enabled, make sure that the<br />

files server.key and server.crt contain the server’s private key and certificate,<br />

respectively. PostgreSQLwill look for the two files in the data directory, and they<br />

must be present for the server to start.<br />

* Versions of MySQLprior to 4.00 seem to have included at least partial support for SSLconnections, but no<br />

configuration options exist to enable it. The function mysql_ssl_set( ) exists in the 3.23 series, and possibly<br />

earlier versions as well, but its signature is different from what exists in 4.00.<br />

Securing Database Connections | 489<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!