6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 * Copyright 2001 hereUare Communications, Inc. <raghud@hereuare.com>
21 * Copyright 2003 Alan DeKok <aland@freeradius.org>
22 * Copyright 2006 The FreeRADIUS server project
25 #include <freeradius-devel/ident.h>
28 #include <freeradius-devel/autoconf.h>
29 #include <freeradius-devel/radiusd.h>
30 #include <freeradius-devel/tls.h>
31 #include <freeradius-devel/rad_assert.h>
33 #ifdef HAVE_SYS_STAT_H
38 #ifdef HAVE_OPENSSL_RAND_H
39 #include <openssl/rand.h>
42 #ifdef HAVE_OPENSSL_OCSP_H
43 #include <openssl/ocsp.h>
47 #define PTHREAD_MUTEX_LOCK pthread_mutex_lock
48 #define PTHREAD_MUTEX_UNLOCK pthread_mutex_unlock
50 #define PTHREAD_MUTEX_LOCK(_x)
51 #define PTHREAD_MUTEX_UNLOCK(_x)
56 static void record_init(record_t *buf);
57 static void record_close(record_t *buf);
58 static unsigned int record_plus(record_t *buf, const void *ptr,
60 static unsigned int record_minus(record_t *buf, void *ptr,
63 tls_session_t *tls_new_session(SSL_CTX *ssl_ctx, int client_cert)
65 tls_session_t *state = NULL;
68 client_cert = client_cert; /* -Wunused. See bug #350 */
70 if ((new_tls = SSL_new(ssl_ctx)) == NULL) {
71 radlog(L_ERR, "SSL: Error creating new SSL: %s",
72 ERR_error_string(ERR_get_error(), NULL));
76 /* We use the SSL's "app_data" to indicate a call-back */
77 SSL_set_app_data(new_tls, NULL);
79 state = (tls_session_t *)malloc(sizeof(*state));
80 memset(state, 0, sizeof(*state));
87 * Initialize callbacks
89 state->record_init = record_init;
90 state->record_close = record_close;
91 state->record_plus = record_plus;
92 state->record_minus = record_minus;
95 * Create & hook the BIOs to handle the dirty side of the
96 * SSL. This is *very important* as we want to handle
97 * the transmission part. Now the only IO interface
98 * that SSL is aware of, is our defined BIO buffers.
100 * This means that all SSL IO is done to/from memory,
101 * and we can update those BIOs from the packets we've
104 state->into_ssl = BIO_new(BIO_s_mem());
105 state->from_ssl = BIO_new(BIO_s_mem());
106 SSL_set_bio(state->ssl, state->into_ssl, state->from_ssl);
109 * Add the message callback to identify what type of
110 * message/handshake is passed
112 SSL_set_msg_callback(new_tls, cbtls_msg);
113 SSL_set_msg_callback_arg(new_tls, state);
114 SSL_set_info_callback(new_tls, cbtls_info);
117 * In Server mode we only accept.
119 SSL_set_accept_state(state->ssl);
125 * Print out some text describing the error.
127 static int int_ssl_check(REQUEST *request, SSL *s, int ret, const char *text)
132 if ((l = ERR_get_error()) != 0) {
133 const char *p = ERR_error_string(l, NULL);
136 radlog(L_ERR, "SSL error %s", p);
139 vp = pairmake("Module-Failure-Message", p, T_OP_ADD);
140 if (vp) pairadd(&request->packet->vps, vp);
143 e = SSL_get_error(s, ret);
147 * These seem to be harmless and already "dealt
148 * with" by our non-blocking environment. NB:
149 * "ZERO_RETURN" is the clean "error"
150 * indicating a successfully closed SSL
151 * tunnel. We let this happen because our IO
152 * loop should not appear to have broken on
153 * this condition - and outside the IO loop, the
154 * "shutdown" state is checked.
156 * Don't print anything if we ignore the error.
159 case SSL_ERROR_WANT_READ:
160 case SSL_ERROR_WANT_WRITE:
161 case SSL_ERROR_WANT_X509_LOOKUP:
162 case SSL_ERROR_ZERO_RETURN:
166 * These seem to be indications of a genuine
167 * error that should result in the SSL tunnel
168 * being regarded as "dead".
170 case SSL_ERROR_SYSCALL:
171 radlog(L_ERR, "SSL: %s failed in a system call (%d), TLS session fails.",
176 radlog(L_ERR, "SSL: %s failed inside of TLS (%d), TLS session fails.",
182 * For any other errors that (a) exist, and (b)
183 * crop up - we need to interpret what to do with
184 * them - so "politely inform" the caller that
185 * the code needs updating here.
187 radlog(L_ERR, "SSL: FATAL SSL error ..... %d\n", e);
195 * We are the server, we always get the dirty data
196 * (Handshake data is also considered as dirty data)
197 * During handshake, since SSL API handles itself,
198 * After clean-up, dirty_out will be filled with
199 * the data required for handshaking. So we check
200 * if dirty_out is empty then we simply send it back.
201 * As of now, if handshake is successful, then we keep going,
204 * Fill the Bio with the dirty data to clean it
205 * Get the cleaned data from SSL, if it is not Handshake data
207 int tls_handshake_recv(REQUEST *request, tls_session_t *ssn)
211 BIO_write(ssn->into_ssl, ssn->dirty_in.data, ssn->dirty_in.used);
213 err = SSL_read(ssn->ssl, ssn->clean_out.data + ssn->clean_out.used,
214 sizeof(ssn->clean_out.data) - ssn->clean_out.used);
216 ssn->clean_out.used += err;
217 record_init(&ssn->dirty_in);
221 if (!int_ssl_check(request, ssn->ssl, err, "SSL_read")) {
225 /* Some Extra STATE information for easy debugging */
226 if (SSL_is_init_finished(ssn->ssl)) {
227 DEBUG2("SSL Connection Established\n");
229 if (SSL_in_init(ssn->ssl)) {
230 DEBUG2("In SSL Handshake Phase\n");
232 if (SSL_in_before(ssn->ssl)) {
233 DEBUG2("Before SSL Handshake Phase\n");
235 if (SSL_in_accept_init(ssn->ssl)) {
236 DEBUG2("In SSL Accept mode \n");
238 if (SSL_in_connect_init(ssn->ssl)) {
239 DEBUG2("In SSL Connect mode \n");
242 err = BIO_ctrl_pending(ssn->from_ssl);
244 err = BIO_read(ssn->from_ssl, ssn->dirty_out.data,
245 sizeof(ssn->dirty_out.data));
247 ssn->dirty_out.used = err;
249 } else if (BIO_should_retry(ssn->from_ssl)) {
250 record_init(&ssn->dirty_in);
251 DEBUG2(" tls: Asking for more data in tunnel");
255 int_ssl_check(request, ssn->ssl, err, "BIO_read");
256 record_init(&ssn->dirty_in);
260 DEBUG2("SSL Application Data");
261 /* Its clean application data, do whatever we want */
262 record_init(&ssn->clean_out);
265 /* We are done with dirty_in, reinitialize it */
266 record_init(&ssn->dirty_in);
271 * Take clear-text user data, and encrypt it into the output buffer,
272 * to send to the client at the other end of the SSL connection.
274 int tls_handshake_send(REQUEST *request, tls_session_t *ssn)
279 * If there's un-encrypted data in 'clean_in', then write
280 * that data to the SSL session, and then call the BIO function
281 * to get that encrypted data from the SSL session, into
282 * a buffer which we can then package into an EAP packet.
284 * Based on Server's logic this clean_in is expected to
285 * contain the data to send to the client.
287 if (ssn->clean_in.used > 0) {
290 written = SSL_write(ssn->ssl, ssn->clean_in.data, ssn->clean_in.used);
291 record_minus(&ssn->clean_in, NULL, written);
293 /* Get the dirty data from Bio to send it */
294 err = BIO_read(ssn->from_ssl, ssn->dirty_out.data,
295 sizeof(ssn->dirty_out.data));
297 ssn->dirty_out.used = err;
299 int_ssl_check(request, ssn->ssl, err, "handshake_send");
306 void session_init(tls_session_t *ssn)
309 ssn->into_ssl = ssn->from_ssl = NULL;
310 record_init(&ssn->clean_in);
311 record_init(&ssn->clean_out);
312 record_init(&ssn->dirty_in);
313 record_init(&ssn->dirty_out);
315 memset(&ssn->info, 0, sizeof(ssn->info));
319 ssn->tls_msg_len = 0;
320 ssn->length_flag = 0;
322 ssn->free_opaque = NULL;
325 void session_close(tls_session_t *ssn)
327 if (ssn->ssl->session) {
330 vp = SSL_SESSION_get_ex_data(ssn->ssl->session,
331 FR_TLS_EX_INDEX_VPS);
332 if (vp) pairfree(&vp);
335 SSL_set_quiet_shutdown(ssn->ssl, 1);
336 SSL_shutdown(ssn->ssl);
342 * WARNING: SSL_free seems to decrement the reference counts already,
343 * so doing this might crash the application.
346 BIO_free(ssn->into_ssl);
348 BIO_free(ssn->from_ssl);
350 record_close(&ssn->clean_in);
351 record_close(&ssn->clean_out);
352 record_close(&ssn->dirty_in);
353 record_close(&ssn->dirty_out);
357 void session_free(void *ssn)
359 tls_session_t *sess = (tls_session_t *)ssn;
364 * Free any opaque TTLS or PEAP data.
366 if ((sess->opaque) && (sess->free_opaque)) {
367 sess->free_opaque(sess->opaque);
376 static void record_init(record_t *rec)
381 static void record_close(record_t *rec)
388 * Copy data to the intermediate buffer, before we send
391 static unsigned int record_plus(record_t *rec, const void *ptr,
394 unsigned int added = MAX_RECORD_SIZE - rec->used;
400 memcpy(rec->data + rec->used, ptr, added);
406 * Take data from the buffer, and give it to the caller.
408 static unsigned int record_minus(record_t *rec, void *ptr,
411 unsigned int taken = rec->used;
418 memcpy(ptr, rec->data, taken);
422 * This is pretty bad...
425 memmove(rec->data, rec->data + taken, rec->used);
429 void tls_session_information(tls_session_t *tls_session)
431 const char *str_write_p, *str_version, *str_content_type = "";
432 const char *str_details1 = "", *str_details2= "";
436 * Don't print this out in the normal course of
439 if (debug_flag == 0) {
443 str_write_p = tls_session->info.origin ? ">>>" : "<<<";
445 switch (tls_session->info.version)
448 str_version = "SSL 2.0";
451 str_version = "SSL 3.0 ";
454 str_version = "TLS 1.0 ";
457 str_version = "Unknown TLS version";
461 if (tls_session->info.version == SSL3_VERSION ||
462 tls_session->info.version == TLS1_VERSION) {
463 switch (tls_session->info.content_type) {
464 case SSL3_RT_CHANGE_CIPHER_SPEC:
465 str_content_type = "ChangeCipherSpec";
468 str_content_type = "Alert";
470 case SSL3_RT_HANDSHAKE:
471 str_content_type = "Handshake";
473 case SSL3_RT_APPLICATION_DATA:
474 str_content_type = "ApplicationData";
477 str_content_type = "UnknownContentType";
481 if (tls_session->info.content_type == SSL3_RT_ALERT) {
482 str_details1 = ", ???";
484 if (tls_session->info.record_len == 2) {
486 switch (tls_session->info.alert_level) {
487 case SSL3_AL_WARNING:
488 str_details1 = ", warning";
491 str_details1 = ", fatal";
495 str_details2 = " ???";
496 switch (tls_session->info.alert_description) {
497 case SSL3_AD_CLOSE_NOTIFY:
498 str_details2 = " close_notify";
500 case SSL3_AD_UNEXPECTED_MESSAGE:
501 str_details2 = " unexpected_message";
503 case SSL3_AD_BAD_RECORD_MAC:
504 str_details2 = " bad_record_mac";
506 case TLS1_AD_DECRYPTION_FAILED:
507 str_details2 = " decryption_failed";
509 case TLS1_AD_RECORD_OVERFLOW:
510 str_details2 = " record_overflow";
512 case SSL3_AD_DECOMPRESSION_FAILURE:
513 str_details2 = " decompression_failure";
515 case SSL3_AD_HANDSHAKE_FAILURE:
516 str_details2 = " handshake_failure";
518 case SSL3_AD_BAD_CERTIFICATE:
519 str_details2 = " bad_certificate";
521 case SSL3_AD_UNSUPPORTED_CERTIFICATE:
522 str_details2 = " unsupported_certificate";
524 case SSL3_AD_CERTIFICATE_REVOKED:
525 str_details2 = " certificate_revoked";
527 case SSL3_AD_CERTIFICATE_EXPIRED:
528 str_details2 = " certificate_expired";
530 case SSL3_AD_CERTIFICATE_UNKNOWN:
531 str_details2 = " certificate_unknown";
533 case SSL3_AD_ILLEGAL_PARAMETER:
534 str_details2 = " illegal_parameter";
536 case TLS1_AD_UNKNOWN_CA:
537 str_details2 = " unknown_ca";
539 case TLS1_AD_ACCESS_DENIED:
540 str_details2 = " access_denied";
542 case TLS1_AD_DECODE_ERROR:
543 str_details2 = " decode_error";
545 case TLS1_AD_DECRYPT_ERROR:
546 str_details2 = " decrypt_error";
548 case TLS1_AD_EXPORT_RESTRICTION:
549 str_details2 = " export_restriction";
551 case TLS1_AD_PROTOCOL_VERSION:
552 str_details2 = " protocol_version";
554 case TLS1_AD_INSUFFICIENT_SECURITY:
555 str_details2 = " insufficient_security";
557 case TLS1_AD_INTERNAL_ERROR:
558 str_details2 = " internal_error";
560 case TLS1_AD_USER_CANCELLED:
561 str_details2 = " user_canceled";
563 case TLS1_AD_NO_RENEGOTIATION:
564 str_details2 = " no_renegotiation";
570 if (tls_session->info.content_type == SSL3_RT_HANDSHAKE) {
571 str_details1 = "???";
573 if (tls_session->info.record_len > 0)
574 switch (tls_session->info.handshake_type)
576 case SSL3_MT_HELLO_REQUEST:
577 str_details1 = ", HelloRequest";
579 case SSL3_MT_CLIENT_HELLO:
580 str_details1 = ", ClientHello";
582 case SSL3_MT_SERVER_HELLO:
583 str_details1 = ", ServerHello";
585 case SSL3_MT_CERTIFICATE:
586 str_details1 = ", Certificate";
588 case SSL3_MT_SERVER_KEY_EXCHANGE:
589 str_details1 = ", ServerKeyExchange";
591 case SSL3_MT_CERTIFICATE_REQUEST:
592 str_details1 = ", CertificateRequest";
594 case SSL3_MT_SERVER_DONE:
595 str_details1 = ", ServerHelloDone";
597 case SSL3_MT_CERTIFICATE_VERIFY:
598 str_details1 = ", CertificateVerify";
600 case SSL3_MT_CLIENT_KEY_EXCHANGE:
601 str_details1 = ", ClientKeyExchange";
603 case SSL3_MT_FINISHED:
604 str_details1 = ", Finished";
610 snprintf(tls_session->info.info_description,
611 sizeof(tls_session->info.info_description),
612 "%s %s%s [length %04lx]%s%s\n",
613 str_write_p, str_version, str_content_type,
614 (unsigned long)tls_session->info.record_len,
615 str_details1, str_details2);
617 request = SSL_get_ex_data(tls_session->ssl, FR_TLS_EX_INDEX_REQUEST);
619 RDEBUG2("%s\n", tls_session->info.info_description);
622 static CONF_PARSER cache_config[] = {
623 { "enable", PW_TYPE_BOOLEAN,
624 offsetof(fr_tls_server_conf_t, session_cache_enable), NULL, "no" },
625 { "lifetime", PW_TYPE_INTEGER,
626 offsetof(fr_tls_server_conf_t, session_timeout), NULL, "24" },
627 { "max_entries", PW_TYPE_INTEGER,
628 offsetof(fr_tls_server_conf_t, session_cache_size), NULL, "255" },
629 { "name", PW_TYPE_STRING_PTR,
630 offsetof(fr_tls_server_conf_t, session_id_name), NULL, NULL},
631 { NULL, -1, 0, NULL, NULL } /* end the list */
634 static CONF_PARSER verify_config[] = {
635 { "tmpdir", PW_TYPE_STRING_PTR,
636 offsetof(fr_tls_server_conf_t, verify_tmp_dir), NULL, NULL},
637 { "client", PW_TYPE_STRING_PTR,
638 offsetof(fr_tls_server_conf_t, verify_client_cert_cmd), NULL, NULL},
639 { NULL, -1, 0, NULL, NULL } /* end the list */
642 #ifdef HAVE_OPENSSL_OCSP_H
643 static CONF_PARSER ocsp_config[] = {
644 { "enable", PW_TYPE_BOOLEAN,
645 offsetof(fr_tls_server_conf_t, ocsp_enable), NULL, "no"},
646 { "override_cert_url", PW_TYPE_BOOLEAN,
647 offsetof(fr_tls_server_conf_t, ocsp_override_url), NULL, "no"},
648 { "url", PW_TYPE_STRING_PTR,
649 offsetof(fr_tls_server_conf_t, ocsp_url), NULL, NULL },
650 { NULL, -1, 0, NULL, NULL } /* end the list */
654 static CONF_PARSER tls_server_config[] = {
655 { "rsa_key_exchange", PW_TYPE_BOOLEAN,
656 offsetof(fr_tls_server_conf_t, rsa_key), NULL, "no" },
657 { "dh_key_exchange", PW_TYPE_BOOLEAN,
658 offsetof(fr_tls_server_conf_t, dh_key), NULL, "yes" },
659 { "rsa_key_length", PW_TYPE_INTEGER,
660 offsetof(fr_tls_server_conf_t, rsa_key_length), NULL, "512" },
661 { "dh_key_length", PW_TYPE_INTEGER,
662 offsetof(fr_tls_server_conf_t, dh_key_length), NULL, "512" },
663 { "verify_depth", PW_TYPE_INTEGER,
664 offsetof(fr_tls_server_conf_t, verify_depth), NULL, "0" },
665 { "CA_path", PW_TYPE_FILENAME,
666 offsetof(fr_tls_server_conf_t, ca_path), NULL, NULL },
667 { "pem_file_type", PW_TYPE_BOOLEAN,
668 offsetof(fr_tls_server_conf_t, file_type), NULL, "yes" },
669 { "private_key_file", PW_TYPE_FILENAME,
670 offsetof(fr_tls_server_conf_t, private_key_file), NULL, NULL },
671 { "certificate_file", PW_TYPE_FILENAME,
672 offsetof(fr_tls_server_conf_t, certificate_file), NULL, NULL },
673 { "CA_file", PW_TYPE_FILENAME,
674 offsetof(fr_tls_server_conf_t, ca_file), NULL, NULL },
675 { "private_key_password", PW_TYPE_STRING_PTR,
676 offsetof(fr_tls_server_conf_t, private_key_password), NULL, NULL },
677 { "dh_file", PW_TYPE_STRING_PTR,
678 offsetof(fr_tls_server_conf_t, dh_file), NULL, NULL },
679 { "random_file", PW_TYPE_STRING_PTR,
680 offsetof(fr_tls_server_conf_t, random_file), NULL, NULL },
681 { "fragment_size", PW_TYPE_INTEGER,
682 offsetof(fr_tls_server_conf_t, fragment_size), NULL, "1024" },
683 { "include_length", PW_TYPE_BOOLEAN,
684 offsetof(fr_tls_server_conf_t, include_length), NULL, "yes" },
685 { "check_crl", PW_TYPE_BOOLEAN,
686 offsetof(fr_tls_server_conf_t, check_crl), NULL, "no"},
687 { "allow_expired_crl", PW_TYPE_BOOLEAN,
688 offsetof(fr_tls_server_conf_t, allow_expired_crl), NULL, NULL},
689 { "check_cert_cn", PW_TYPE_STRING_PTR,
690 offsetof(fr_tls_server_conf_t, check_cert_cn), NULL, NULL},
691 { "cipher_list", PW_TYPE_STRING_PTR,
692 offsetof(fr_tls_server_conf_t, cipher_list), NULL, NULL},
693 { "check_cert_issuer", PW_TYPE_STRING_PTR,
694 offsetof(fr_tls_server_conf_t, check_cert_issuer), NULL, NULL},
695 { "make_cert_command", PW_TYPE_STRING_PTR,
696 offsetof(fr_tls_server_conf_t, make_cert_command), NULL, NULL},
698 { "cache", PW_TYPE_SUBSECTION, 0, NULL, (const void *) cache_config },
700 { "verify", PW_TYPE_SUBSECTION, 0, NULL, (const void *) verify_config },
702 #ifdef HAVE_OPENSSL_OCSP_H
703 { "ocsp", PW_TYPE_SUBSECTION, 0, NULL, (const void *) ocsp_config },
706 { NULL, -1, 0, NULL, NULL } /* end the list */
710 * TODO: Check for the type of key exchange * like conf->dh_key
712 static int load_dh_params(SSL_CTX *ctx, char *file)
717 if ((bio = BIO_new_file(file, "r")) == NULL) {
718 radlog(L_ERR, "rlm_eap_tls: Unable to open DH file - %s", file);
722 dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL);
725 DEBUG2("WARNING: rlm_eap_tls: Unable to set DH parameters. DH cipher suites may not work!");
726 DEBUG2("WARNING: Fix this by running the OpenSSL command listed in eap.conf");
730 if (SSL_CTX_set_tmp_dh(ctx, dh) < 0) {
731 radlog(L_ERR, "rlm_eap_tls: Unable to set DH parameters");
742 * Generate ephemeral RSA keys.
744 static int generate_eph_rsa_key(SSL_CTX *ctx)
748 rsa = RSA_generate_key(512, RSA_F4, NULL, NULL);
750 if (!SSL_CTX_set_tmp_rsa(ctx, rsa)) {
751 radlog(L_ERR, "rlm_eap_tls: Couldn't set ephemeral RSA key");
761 * These functions don't do anything other than print debugging
764 * FIXME: Write sessions to some long-term storage, so that
765 * session resumption can still occur after the server
768 #define MAX_SESSION_SIZE (256)
770 static void cbtls_remove_session(UNUSED SSL_CTX *ctx, SSL_SESSION *sess)
773 char buffer[2 * MAX_SESSION_SIZE + 1];
775 size = sess->session_id_length;
776 if (size > MAX_SESSION_SIZE) size = MAX_SESSION_SIZE;
778 fr_bin2hex(sess->session_id, buffer, size);
780 DEBUG2(" SSL: Removing session %s from the cache", buffer);
781 SSL_SESSION_free(sess);
786 static int cbtls_new_session(UNUSED SSL *s, SSL_SESSION *sess)
789 char buffer[2 * MAX_SESSION_SIZE + 1];
791 size = sess->session_id_length;
792 if (size > MAX_SESSION_SIZE) size = MAX_SESSION_SIZE;
794 fr_bin2hex(sess->session_id, buffer, size);
796 DEBUG2(" SSL: adding session %s to cache", buffer);
801 static SSL_SESSION *cbtls_get_session(UNUSED SSL *s,
802 unsigned char *data, int len,
806 char buffer[2 * MAX_SESSION_SIZE + 1];
809 if (size > MAX_SESSION_SIZE) size = MAX_SESSION_SIZE;
811 fr_bin2hex(data, buffer, size);
813 DEBUG2(" SSL: Client requested nonexistent cached session %s",
819 #ifdef HAVE_OPENSSL_OCSP_H
821 * This function extracts the OCSP Responder URL
822 * from an existing x509 certificate.
824 static int ocsp_parse_cert_url(X509 *cert, char **phost, char **pport,
825 char **ppath, int *pssl)
829 AUTHORITY_INFO_ACCESS *aia;
830 ACCESS_DESCRIPTION *ad;
832 aia = X509_get_ext_d2i(cert, NID_info_access, NULL, NULL);
834 for (i = 0; i < sk_ACCESS_DESCRIPTION_num(aia); i++) {
835 ad = sk_ACCESS_DESCRIPTION_value(aia, 0);
836 if (OBJ_obj2nid(ad->method) == NID_ad_OCSP) {
837 if (ad->location->type == GEN_URI) {
838 if(OCSP_parse_url(ad->location->d.ia5->data,
839 phost, pport, ppath, pssl))
848 * This function sends a OCSP request to a defined OCSP responder
849 * and checks the OCSP response for correctness.
851 static int ocsp_check(X509_STORE *store, X509 *issuer_cert, X509 *client_cert,
852 fr_tls_server_conf_t *conf)
857 OCSP_BASICRESP *bresp = NULL;
867 * Create OCSP Request
869 certid = OCSP_cert_to_id(NULL, client_cert, issuer_cert);
870 req = OCSP_REQUEST_new();
871 OCSP_request_add0_id(req, certid);
872 OCSP_request_add1_nonce(req, NULL, 8);
875 * Send OCSP Request and get OCSP Response
878 /* Get OCSP responder URL */
879 if(conf->ocsp_override_url) {
880 OCSP_parse_url(conf->ocsp_url, &host, &port, &path, &use_ssl);
883 ocsp_parse_cert_url(client_cert, &host, &port, &path, &use_ssl);
886 DEBUG2("[ocsp] --> Responder URL = http://%s:%s%s", host, port, path);
888 /* Setup BIO socket to OCSP responder */
889 cbio = BIO_new_connect(host);
890 BIO_set_conn_port(cbio, port);
891 BIO_do_connect(cbio);
893 /* Send OCSP request and wait for response */
894 resp = OCSP_sendreq_bio(cbio, path, req);
896 radlog(L_ERR, "Error: Couldn't get OCSP response");
901 /* Verify OCSP response */
902 status = OCSP_response_status(resp);
903 if(status != OCSP_RESPONSE_STATUS_SUCCESSFUL) {
904 radlog(L_ERR, "Error: OCSP response status: %s", OCSP_response_status_str(status));
908 bresp = OCSP_response_get1_basic(resp);
909 if(OCSP_check_nonce(req, bresp)!=1) {
910 radlog(L_ERR, "Error: OCSP response has wrong nonce value");
914 if(OCSP_basic_verify(bresp, NULL, store, 0)!=1){
915 radlog(L_ERR, "Error: Couldn't verify OCSP basic response");
923 /* Free OCSP Stuff */
924 OCSP_REQUEST_free(req);
925 OCSP_RESPONSE_free(resp);
930 OCSP_BASICRESP_free(bresp);
933 DEBUG2("[ocsp] --> Certificate is valid!");
935 DEBUG2("[ocsp] --> Certificate has been expired/revoked!");
940 #endif /* HAVE_OPENSSL_OCSP_H */
943 * For creating certificate attributes.
945 static const char *cert_attr_names[5][2] = {
946 { "TLS-Client-Cert-Serial", "TLS-Cert-Serial" },
947 { "TLS-Client-Cert-Expiration", "TLS-Cert-Expiration" },
948 { "TLS-Client-Cert-Subject", "TLS-Cert-Subject" },
949 { "TLS-Client-Cert-Issuer", "TLS-Cert-Issuer" },
950 { "TLS-Client-Cert-Common-Name", "TLS-Cert-Common-Name" }
953 #define EAPTLS_SERIAL (0)
954 #define EAPTLS_EXPIRATION (1)
955 #define EAPTLS_SUBJECT (2)
956 #define EAPTLS_ISSUER (3)
957 #define EAPTLS_CN (4)
960 * Before trusting a certificate, you must make sure that the
961 * certificate is 'valid'. There are several steps that your
962 * application can take in determining if a certificate is
963 * valid. Commonly used steps are:
965 * 1.Verifying the certificate's signature, and verifying that
966 * the certificate has been issued by a trusted Certificate
969 * 2.Verifying that the certificate is valid for the present date
970 * (i.e. it is being presented within its validity dates).
972 * 3.Verifying that the certificate has not been revoked by its
973 * issuing Certificate Authority, by checking with respect to a
974 * Certificate Revocation List (CRL).
976 * 4.Verifying that the credentials presented by the certificate
977 * fulfill additional requirements specific to the application,
978 * such as with respect to access control lists or with respect
979 * to OCSP (Online Certificate Status Processing).
981 * NOTE: This callback will be called multiple times based on the
982 * depth of the root certificate chain
984 int cbtls_verify(int ok, X509_STORE_CTX *ctx)
986 char subject[1024]; /* Used for the subject name */
987 char issuer[1024]; /* Used for the issuer name */
988 char common_name[1024];
994 int err, depth, lookup;
995 fr_tls_server_conf_t *conf;
998 ASN1_INTEGER *sn = NULL;
999 ASN1_TIME *asn_time = NULL;
1002 #ifdef HAVE_OPENSSL_OCSP_H
1003 X509_STORE *ocsp_store = NULL;
1006 client_cert = X509_STORE_CTX_get_current_cert(ctx);
1007 err = X509_STORE_CTX_get_error(ctx);
1008 depth = X509_STORE_CTX_get_error_depth(ctx);
1013 * Log client/issuing cert. If there's an error, log
1016 if ((lookup > 1) && !my_ok) lookup = 1;
1019 * Retrieve the pointer to the SSL of the connection currently treated
1020 * and the application specific data stored into the SSL object.
1022 ssl = X509_STORE_CTX_get_ex_data(ctx, SSL_get_ex_data_X509_STORE_CTX_idx());
1023 conf = (fr_tls_server_conf_t *)SSL_get_ex_data(ssl, FR_TLS_EX_INDEX_CONF);
1024 if (!conf) return 1;
1026 request = (REQUEST *)SSL_get_ex_data(ssl, FR_TLS_EX_INDEX_REQUEST);
1028 if (!request) return 1; /* FIXME: outbound TLS */
1030 rad_assert(request != NULL);
1031 certs = (VALUE_PAIR **)SSL_get_ex_data(ssl, FR_TLS_EX_INDEX_CERTS);
1032 rad_assert(certs != NULL);
1033 identity = (char **)SSL_get_ex_data(ssl, FR_TLS_EX_INDEX_IDENTITY);
1034 #ifdef HAVE_OPENSSL_OCSP_H
1035 ocsp_store = (X509_STORE *)SSL_get_ex_data(ssl, FR_TLS_EX_INDEX_STORE);
1040 * Get the Serial Number
1043 sn = X509_get_serialNumber(client_cert);
1046 * For this next bit, we create the attributes *only* if
1047 * we're at the client or issuing certificate.
1049 if ((lookup <= 1) && sn && (sn->length < (sizeof(buf) / 2))) {
1053 for (i = 0; i < sn->length; i++) {
1054 sprintf(p, "%02x", (unsigned int)sn->data[i]);
1058 pairmake(cert_attr_names[EAPTLS_SERIAL][lookup], buf, T_OP_SET));
1063 * Get the Expiration Date
1066 asn_time = X509_get_notAfter(client_cert);
1067 if ((lookup <= 1) && asn_time && (asn_time->length < MAX_STRING_LEN)) {
1068 memcpy(buf, (char*) asn_time->data, asn_time->length);
1069 buf[asn_time->length] = '\0';
1071 pairmake(cert_attr_names[EAPTLS_EXPIRATION][lookup], buf, T_OP_SET));
1075 * Get the Subject & Issuer
1077 subject[0] = issuer[0] = '\0';
1078 X509_NAME_oneline(X509_get_subject_name(client_cert), subject,
1080 subject[sizeof(subject) - 1] = '\0';
1081 if ((lookup <= 1) && subject[0] && (strlen(subject) < MAX_STRING_LEN)) {
1083 pairmake(cert_attr_names[EAPTLS_SUBJECT][lookup], subject, T_OP_SET));
1086 X509_NAME_oneline(X509_get_issuer_name(ctx->current_cert), issuer,
1088 issuer[sizeof(issuer) - 1] = '\0';
1089 if ((lookup <= 1) && issuer[0] && (strlen(issuer) < MAX_STRING_LEN)) {
1091 pairmake(cert_attr_names[EAPTLS_ISSUER][lookup], issuer, T_OP_SET));
1095 * Get the Common Name
1097 X509_NAME_get_text_by_NID(X509_get_subject_name(client_cert),
1098 NID_commonName, common_name, sizeof(common_name));
1099 common_name[sizeof(common_name) - 1] = '\0';
1100 if ((lookup <= 1) && common_name[0] && (strlen(common_name) < MAX_STRING_LEN)) {
1102 pairmake(cert_attr_names[EAPTLS_CN][lookup], common_name, T_OP_SET));
1106 * If the CRL has expired, that might still be OK.
1109 (conf->allow_expired_crl) &&
1110 (err == X509_V_ERR_CRL_HAS_EXPIRED)) {
1112 X509_STORE_CTX_set_error( ctx, 0 );
1116 const char *p = X509_verify_cert_error_string(err);
1117 radlog(L_ERR,"--> verify error:num=%d:%s\n",err, p);
1118 radius_pairmake(request, &request->packet->vps,
1119 "Module-Failure-Message", p, T_OP_SET);
1123 switch (ctx->error) {
1125 case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT:
1126 radlog(L_ERR, "issuer= %s\n", issuer);
1128 case X509_V_ERR_CERT_NOT_YET_VALID:
1129 case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD:
1130 radlog(L_ERR, "notBefore=");
1132 ASN1_TIME_print(bio_err, X509_get_notBefore(ctx->current_cert));
1135 case X509_V_ERR_CERT_HAS_EXPIRED:
1136 case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD:
1137 radlog(L_ERR, "notAfter=");
1139 ASN1_TIME_print(bio_err, X509_get_notAfter(ctx->current_cert));
1145 * If we're at the actual client cert, apply additional
1150 * If the conf tells us to, check cert issuer
1151 * against the specified value and fail
1152 * verification if they don't match.
1154 if (conf->check_cert_issuer &&
1155 (strcmp(issuer, conf->check_cert_issuer) != 0)) {
1156 radlog(L_AUTH, "rlm_eap_tls: Certificate issuer (%s) does not match specified value (%s)!", issuer, conf->check_cert_issuer);
1161 * If the conf tells us to, check the CN in the
1162 * cert against xlat'ed value, but only if the
1163 * previous checks passed.
1165 if (my_ok && conf->check_cert_cn) {
1166 if (!radius_xlat(cn_str, sizeof(cn_str), conf->check_cert_cn, request, NULL)) {
1167 radlog(L_ERR, "rlm_eap_tls (%s): xlat failed.",
1168 conf->check_cert_cn);
1169 /* if this fails, fail the verification */
1172 RDEBUG2("checking certificate CN (%s) with xlat'ed value (%s)", common_name, cn_str);
1173 if (strcmp(cn_str, common_name) != 0) {
1174 radlog(L_AUTH, "rlm_eap_tls: Certificate CN (%s) does not match specified value (%s)!", common_name, cn_str);
1178 } /* check_cert_cn */
1180 #ifdef HAVE_OPENSSL_OCSP_H
1181 if (my_ok && conf->ocsp_enable){
1182 RDEBUG2("--> Starting OCSP Request");
1183 if(X509_STORE_CTX_get1_issuer(&issuer_cert, ctx, client_cert)!=1) {
1184 radlog(L_ERR, "Error: Couldn't get issuer_cert for %s", common_name);
1186 my_ok = ocsp_check(ocsp_store, issuer_cert, client_cert, conf);
1190 while (conf->verify_client_cert_cmd) {
1195 snprintf(filename, sizeof(filename), "%s/%s.client.XXXXXXXX",
1196 conf->verify_tmp_dir, progname);
1197 fd = mkstemp(filename);
1199 RDEBUG("Failed creating file in %s: %s",
1200 conf->verify_tmp_dir, strerror(errno));
1204 fp = fdopen(fd, "w");
1206 RDEBUG("Failed opening file %s: %s",
1207 filename, strerror(errno));
1211 if (!PEM_write_X509(fp, client_cert)) {
1213 RDEBUG("Failed writing certificate to file");
1218 if (!radius_pairmake(request, &request->packet->vps,
1219 "TLS-Client-Cert-Filename",
1220 filename, T_OP_SET)) {
1221 RDEBUG("Failed creating TLS-Client-Cert-Filename");
1226 RDEBUG("Verifying client certificate: %s",
1227 conf->verify_client_cert_cmd);
1228 if (radius_exec_program(conf->verify_client_cert_cmd,
1229 request, 1, NULL, 0,
1230 request->packet->vps,
1232 radlog(L_AUTH, "rlm_eap_tls: Certificate CN (%s) fails external verification!", common_name);
1235 RDEBUG("Client certificate CN %s passed external validation", common_name);
1246 if (debug_flag > 0) {
1247 RDEBUG2("chain-depth=%d, ", depth);
1248 RDEBUG2("error=%d", err);
1250 RDEBUG2("--> User-Name = %s", *identity);
1251 RDEBUG2("--> BUF-Name = %s", common_name);
1252 RDEBUG2("--> subject = %s", subject);
1253 RDEBUG2("--> issuer = %s", issuer);
1254 RDEBUG2("--> verify return:%d", my_ok);
1260 #ifdef HAVE_OPENSSL_OCSP_H
1262 * Create Global X509 revocation store and use it to verify
1265 * - Load the trusted CAs
1266 * - Load the trusted issuer certificates
1268 static X509_STORE *init_revocation_store(fr_tls_server_conf_t *conf)
1270 X509_STORE *store = NULL;
1272 store = X509_STORE_new();
1274 /* Load the CAs we trust */
1275 if (conf->ca_file || conf->ca_path)
1276 if(!X509_STORE_load_locations(store, conf->ca_file, conf->ca_path)) {
1277 radlog(L_ERR, "rlm_eap: X509_STORE error %s", ERR_error_string(ERR_get_error(), NULL));
1278 radlog(L_ERR, "rlm_eap_tls: Error reading Trusted root CA list %s",conf->ca_file );
1282 #ifdef X509_V_FLAG_CRL_CHECK
1283 if (conf->check_crl)
1284 X509_STORE_set_flags(store, X509_V_FLAG_CRL_CHECK);
1288 #endif /* HAVE_OPENSSL_OCSP_H */
1291 * Create Global context SSL and use it in every new session
1293 * - Load the trusted CAs
1294 * - Load the Private key & the certificate
1295 * - Set the Context options & Verify options
1297 static SSL_CTX *init_tls_ctx(fr_tls_server_conf_t *conf)
1301 X509_STORE *certstore;
1302 int verify_mode = SSL_VERIFY_NONE;
1303 int ctx_options = 0;
1307 * Add all the default ciphers and message digests
1308 * Create our context.
1311 SSL_load_error_strings();
1314 * SHA256 is in all versions of OpenSSL, but isn't
1315 * initialized by default. It's needed for WiMAX
1318 #ifdef HAVE_OPENSSL_EVP_SHA256
1319 EVP_add_digest(EVP_sha256());
1322 meth = TLSv1_method();
1323 ctx = SSL_CTX_new(meth);
1326 * Identify the type of certificates that needs to be loaded
1328 if (conf->file_type) {
1329 type = SSL_FILETYPE_PEM;
1331 type = SSL_FILETYPE_ASN1;
1335 * Set the password to load private key
1337 if (conf->private_key_password) {
1340 * We don't want to put the private key password in eap.conf, so check
1341 * for our special string which indicates we should get the password
1344 const char* special_string = "Apple:UseCertAdmin";
1345 if (strncmp(conf->private_key_password,
1347 strlen(special_string)) == 0)
1350 const long max_password_len = 128;
1351 snprintf(cmd, sizeof(cmd) - 1,
1352 "/usr/sbin/certadmin --get-private-key-passphrase \"%s\"",
1353 conf->private_key_file);
1355 DEBUG2("rlm_eap: Getting private key passphrase using command \"%s\"", cmd);
1357 FILE* cmd_pipe = popen(cmd, "r");
1359 radlog(L_ERR, "rlm_eap: %s command failed. Unable to get private_key_password", cmd);
1360 radlog(L_ERR, "rlm_eap: Error reading private_key_file %s", conf->private_key_file);
1364 free(conf->private_key_password);
1365 conf->private_key_password = malloc(max_password_len * sizeof(char));
1366 if (!conf->private_key_password) {
1367 radlog(L_ERR, "rlm_eap: Can't malloc space for private_key_password");
1368 radlog(L_ERR, "rlm_eap: Error reading private_key_file %s", conf->private_key_file);
1373 fgets(conf->private_key_password, max_password_len, cmd_pipe);
1376 /* Get rid of newline at end of password. */
1377 conf->private_key_password[strlen(conf->private_key_password) - 1] = '\0';
1378 DEBUG2("rlm_eap: Password from command = \"%s\"", conf->private_key_password);
1381 SSL_CTX_set_default_passwd_cb_userdata(ctx, conf->private_key_password);
1382 SSL_CTX_set_default_passwd_cb(ctx, cbtls_password);
1386 * Load our keys and certificates
1388 * If certificates are of type PEM then we can make use
1389 * of cert chain authentication using openssl api call
1390 * SSL_CTX_use_certificate_chain_file. Please see how
1391 * the cert chain needs to be given in PEM from
1394 if (type == SSL_FILETYPE_PEM) {
1395 if (!(SSL_CTX_use_certificate_chain_file(ctx, conf->certificate_file))) {
1396 radlog(L_ERR, "rlm_eap: SSL error %s", ERR_error_string(ERR_get_error(), NULL));
1397 radlog(L_ERR, "rlm_eap_tls: Error reading certificate file %s", conf->certificate_file);
1401 } else if (!(SSL_CTX_use_certificate_file(ctx, conf->certificate_file, type))) {
1402 radlog(L_ERR, "rlm_eap: SSL error %s", ERR_error_string(ERR_get_error(), NULL));
1403 radlog(L_ERR, "rlm_eap_tls: Error reading certificate file %s", conf->certificate_file);
1407 /* Load the CAs we trust */
1408 if (conf->ca_file || conf->ca_path) {
1409 if (!SSL_CTX_load_verify_locations(ctx, conf->ca_file, conf->ca_path)) {
1410 radlog(L_ERR, "rlm_eap: SSL error %s", ERR_error_string(ERR_get_error(), NULL));
1411 radlog(L_ERR, "rlm_eap_tls: Error reading Trusted root CA list %s",conf->ca_file );
1415 if (conf->ca_file && *conf->ca_file) SSL_CTX_set_client_CA_list(ctx, SSL_load_client_CA_file(conf->ca_file));
1416 if (!(SSL_CTX_use_PrivateKey_file(ctx, conf->private_key_file, type))) {
1417 radlog(L_ERR, "rlm_eap: SSL error %s", ERR_error_string(ERR_get_error(), NULL));
1418 radlog(L_ERR, "rlm_eap_tls: Error reading private key file %s", conf->private_key_file);
1423 * Check if the loaded private key is the right one
1425 if (!SSL_CTX_check_private_key(ctx)) {
1426 radlog(L_ERR, "rlm_eap_tls: Private key does not match the certificate public key");
1433 ctx_options |= SSL_OP_NO_SSLv2;
1434 ctx_options |= SSL_OP_NO_SSLv3;
1435 #ifdef SSL_OP_NO_TICKET
1436 ctx_options |= SSL_OP_NO_TICKET ;
1440 * SSL_OP_SINGLE_DH_USE must be used in order to prevent
1441 * small subgroup attacks and forward secrecy. Always
1444 * SSL_OP_SINGLE_DH_USE has an impact on the computer
1445 * time needed during negotiation, but it is not very
1448 ctx_options |= SSL_OP_SINGLE_DH_USE;
1451 * SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS to work around issues
1452 * in Windows Vista client.
1453 * http://www.openssl.org/~bodo/tls-cbc.txt
1454 * http://www.nabble.com/(RADIATOR)-Radiator-Version-3.16-released-t2600070.html
1456 ctx_options |= SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS;
1458 SSL_CTX_set_options(ctx, ctx_options);
1461 * TODO: Set the RSA & DH
1462 * SSL_CTX_set_tmp_rsa_callback(ctx, cbtls_rsa);
1463 * SSL_CTX_set_tmp_dh_callback(ctx, cbtls_dh);
1467 * set the message callback to identify the type of
1468 * message. For every new session, there can be a
1469 * different callback argument.
1471 * SSL_CTX_set_msg_callback(ctx, cbtls_msg);
1474 /* Set Info callback */
1475 SSL_CTX_set_info_callback(ctx, cbtls_info);
1478 * Callbacks, etc. for session resumption.
1480 if (conf->session_cache_enable) {
1481 SSL_CTX_sess_set_new_cb(ctx, cbtls_new_session);
1482 SSL_CTX_sess_set_get_cb(ctx, cbtls_get_session);
1483 SSL_CTX_sess_set_remove_cb(ctx, cbtls_remove_session);
1485 SSL_CTX_set_quiet_shutdown(ctx, 1);
1489 * Check the certificates for revocation.
1491 #ifdef X509_V_FLAG_CRL_CHECK
1492 if (conf->check_crl) {
1493 certstore = SSL_CTX_get_cert_store(ctx);
1494 if (certstore == NULL) {
1495 radlog(L_ERR, "rlm_eap: SSL error %s", ERR_error_string(ERR_get_error(), NULL));
1496 radlog(L_ERR, "rlm_eap_tls: Error reading Certificate Store");
1499 X509_STORE_set_flags(certstore, X509_V_FLAG_CRL_CHECK);
1505 * Always verify the peer certificate
1507 verify_mode |= SSL_VERIFY_PEER;
1508 verify_mode |= SSL_VERIFY_FAIL_IF_NO_PEER_CERT;
1509 verify_mode |= SSL_VERIFY_CLIENT_ONCE;
1510 SSL_CTX_set_verify(ctx, verify_mode, cbtls_verify);
1512 if (conf->verify_depth) {
1513 SSL_CTX_set_verify_depth(ctx, conf->verify_depth);
1516 /* Load randomness */
1517 if (!(RAND_load_file(conf->random_file, 1024*1024))) {
1518 radlog(L_ERR, "rlm_eap: SSL error %s", ERR_error_string(ERR_get_error(), NULL));
1519 radlog(L_ERR, "rlm_eap_tls: Error loading randomness");
1524 * Set the cipher list if we were told to
1526 if (conf->cipher_list) {
1527 if (!SSL_CTX_set_cipher_list(ctx, conf->cipher_list)) {
1528 radlog(L_ERR, "rlm_eap_tls: Error setting cipher list");
1534 * Setup session caching
1536 if (conf->session_cache_enable) {
1538 * Create a unique context Id per EAP-TLS configuration.
1540 if (conf->session_id_name) {
1541 snprintf(conf->session_context_id,
1542 sizeof(conf->session_context_id),
1543 "FreeRADIUS EAP-TLS %s",
1544 conf->session_id_name);
1546 snprintf(conf->session_context_id,
1547 sizeof(conf->session_context_id),
1548 "FreeRADIUS EAP-TLS %p", conf);
1552 * Cache it, and DON'T auto-clear it.
1554 SSL_CTX_set_session_cache_mode(ctx, SSL_SESS_CACHE_SERVER | SSL_SESS_CACHE_NO_AUTO_CLEAR);
1556 SSL_CTX_set_session_id_context(ctx,
1557 (unsigned char *) conf->session_context_id,
1558 (unsigned int) strlen(conf->session_context_id));
1561 * Our timeout is in hours, this is in seconds.
1563 SSL_CTX_set_timeout(ctx, conf->session_timeout * 3600);
1566 * Set the maximum number of entries in the
1569 SSL_CTX_sess_set_cache_size(ctx, conf->session_cache_size);
1572 SSL_CTX_set_session_cache_mode(ctx, SSL_SESS_CACHE_OFF);
1579 void tls_server_conf_free(fr_tls_server_conf_t *conf)
1583 if (conf->cs) cf_section_parse_free(conf->cs, conf);
1585 if (conf->ctx) SSL_CTX_free(conf->ctx);
1587 #ifdef HAVE_OPENSSL_OCSP_H
1588 if (conf->ocsp_store) X509_STORE_free(conf->ocsp_store);
1589 conf->ocsp_store = NULL;
1592 memset(conf, 0, sizeof(*conf));
1597 fr_tls_server_conf_t *tls_server_conf_parse(CONF_SECTION *cs)
1599 fr_tls_server_conf_t *conf;
1601 conf = malloc(sizeof(*conf));
1603 radlog(L_ERR, "Out of memory");
1606 memset(conf, 0, sizeof(*conf));
1608 if (cf_section_parse(cs, conf, tls_server_config) < 0) {
1610 tls_server_conf_free(conf);
1615 * Save people from their own stupidity.
1617 if (conf->fragment_size < 100) conf->fragment_size = 100;
1620 * This magic makes the administrators life HUGELY easier
1621 * on initial deployments.
1623 * If the server starts up in debugging mode, AND the
1624 * bootstrap command is configured, AND it exists, AND
1625 * there is no server certificate
1627 if (conf->make_cert_command && (debug_flag >= 2)) {
1630 if ((stat(conf->make_cert_command, &buf) == 0) &&
1631 (stat(conf->certificate_file, &buf) < 0) &&
1632 (errno == ENOENT) &&
1633 (radius_exec_program(conf->make_cert_command, NULL, 1,
1634 NULL, 0, NULL, NULL, 0) != 0)) {
1639 if (!conf->private_key_file) {
1640 radlog(L_ERR, "TLS Server requires a private key file");
1644 if (!conf->private_key_password) {
1645 radlog(L_ERR, "TLS Server requires a private key password");
1649 if (!conf->certificate_file) {
1650 radlog(L_ERR, "TLS Server requires a certificate file");
1657 conf->ctx = init_tls_ctx(conf);
1658 if (conf->ctx == NULL) {
1662 #ifdef HAVE_OPENSSL_OCSP_H
1664 * Initialize OCSP Revocation Store
1666 if (conf->ocsp_enable) {
1667 conf->ocsp_store = init_revocation_store(conf);
1668 if (conf->ocsp_store == NULL) goto error;
1670 #endif HAVE_OPENSSL_OCSP_H
1672 if (load_dh_params(conf->ctx, conf->dh_file) < 0) {
1676 if (generate_eph_rsa_key(conf->ctx) < 0) {
1680 if (conf->verify_tmp_dir) {
1681 if (chmod(conf->verify_tmp_dir, S_IRWXU) < 0) {
1682 radlog(L_ERR, "Failed changing permissions on %s: %s", conf->verify_tmp_dir, strerror(errno));
1687 if (conf->verify_client_cert_cmd && !conf->verify_tmp_dir) {
1688 radlog(L_ERR, "You MUST set the verify directory in order to use verify_client_cmd");
1694 #endif /* WITH_TLS */