1 /* @(#) $Id: ./src/os_auth/ssl.c, 2011/09/08 dcid Exp $
4 /* Copyright (C) 2010 Trend Micro Inc.
7 * This program is a free software; you can redistribute it
8 * and/or modify it under the terms of the GNU General Public
9 * License (version 2) as published by the FSF - Free Software
12 * In addition, as a special exception, the copyright holders give
13 * permission to link the code of portions of this program with the
14 * OpenSSL library under certain conditions as described in each
15 * individual source file, and distribute linked combinations
18 * You must obey the GNU General Public License in all respects
19 * for all of the code used other than OpenSSL. If you modify
20 * file(s) with this exception, you may extend this exception to your
21 * version of the file(s), but you are not obligated to do so. If you
22 * do not wish to do so, delete this exception statement from your
23 * version. If you delete this exception statement from all source
24 * files in the program, then also delete it here.
35 void *os_ssl_keys(int isclient, char *dir)
43 SSL_load_error_strings();
44 OpenSSL_add_all_algorithms();
45 bio_err = BIO_new_fp(stderr,BIO_NOCLOSE);
48 /* Create our context */
49 sslmeth = (SSL_METHOD *)SSLv23_method();
50 ctx = SSL_CTX_new(sslmeth);
54 debug1("%s: DEBUG: Returning CTX for client.", ARGV0);
64 /* Setting final cert/key files */
67 snprintf(certf, 1023, "%s%s", dir, CERTFILE);
68 snprintf(keyf, 1023, "%s%s", dir, KEYFILE);
71 if(File_DateofChange(certf) <= 0)
73 merror("%s: ERROR: Unable to read certificate file (not found): %s", ARGV0, certf);
77 /* Load our keys and certificates*/
78 if(!(SSL_CTX_use_certificate_chain_file(ctx, certf)))
80 merror("%s: ERROR: Unable to read certificate file: %s", ARGV0, certf);
81 ERR_print_errors_fp(stderr);
85 if(!(SSL_CTX_use_PrivateKey_file(ctx, keyf, SSL_FILETYPE_PEM)))
87 merror("%s: ERROR: Unable to read private key file: %s", ARGV0, keyf);
91 if (!SSL_CTX_check_private_key(ctx))
93 merror("%s: ERROR: Unable to verify private key file", ARGV0);
98 #if(OPENSSL_VERSION_NUMBER < 0x00905100L)
99 SSL_CTX_set_verify_depth(ctx,1);