Asterisk - The Open Source Telephony Project  GIT-master-a24979a
tcptls.c
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 2007 - 2008, Digium, Inc.
5  *
6  * Luigi Rizzo (TCP and TLS server code)
7  * Brett Bryant <brettbryant@gmail.com> (updated for client support)
8  *
9  * See http://www.asterisk.org for more information about
10  * the Asterisk project. Please do not directly contact
11  * any of the maintainers of this project for assistance;
12  * the project provides a web site, mailing lists and IRC
13  * channels for your use.
14  *
15  * This program is free software, distributed under the terms of
16  * the GNU General Public License Version 2. See the LICENSE file
17  * at the top of the source tree.
18  */
19 
20 /*!
21  * \file
22  * \brief Code to support TCP and TLS server/client
23  *
24  * \author Luigi Rizzo
25  * \author Brett Bryant <brettbryant@gmail.com>
26  */
27 
28 #include "asterisk.h"
29 
30 #include "asterisk/tcptls.h" /* for ast_tls_config, ast_tcptls_se... */
31 #include "asterisk/iostream.h" /* for DO_SSL, ast_iostream_close, a... */
32 
33 #ifdef HAVE_FCNTL_H
34 #include <fcntl.h> /* for O_NONBLOCK */
35 #endif /* HAVE_FCNTL_H */
36 #include <netinet/in.h> /* for IPPROTO_TCP */
37 #ifdef DO_SSL
38 #include <openssl/asn1.h> /* for ASN1_STRING_to_UTF8 */
39 #include <openssl/crypto.h> /* for OPENSSL_free */
40 #include <openssl/err.h> /* for ERR_print_errors_fp */
41 #include <openssl/opensslconf.h> /* for OPENSSL_NO_SSL3_METHOD, OPENS... */
42 #include <openssl/opensslv.h> /* for OPENSSL_VERSION_NUMBER */
43 #include <openssl/safestack.h> /* for STACK_OF */
44 #include <openssl/ssl.h> /* for SSL_CTX_free, SSL_get_error, ... */
45 #include <openssl/x509.h> /* for X509_free, X509_NAME_ENTRY_ge... */
46 #include <openssl/x509v3.h> /* for GENERAL_NAME, sk_GENERAL_NAME... */
47 #ifndef OPENSSL_NO_DH
48 #include <openssl/bio.h> /* for BIO_free, BIO_new_file */
49 #include <openssl/dh.h> /* for DH_free */
50 #include <openssl/pem.h> /* for PEM_read_bio_DHparams */
51 #endif /* OPENSSL_NO_DH */
52 #ifndef OPENSSL_NO_EC
53 #include <openssl/ec.h> /* for EC_KEY_free, EC_KEY_new_by_cu... */
54 #endif /* OPENSSL_NO_EC */
55 #endif /* DO_SSL */
56 #include <pthread.h> /* for pthread_cancel, pthread_join */
57 #include <signal.h> /* for pthread_kill, SIGURG */
58 #include <sys/socket.h> /* for setsockopt, shutdown, socket */
59 #include <sys/stat.h> /* for stat */
60 
61 #include "asterisk/app.h" /* for ast_read_textfile */
62 #include "asterisk/astobj2.h" /* for ao2_ref, ao2_t_ref, ao2_alloc */
63 #include "asterisk/compat.h" /* for strcasecmp */
64 #include "asterisk/config.h" /* for ast_parse_arg, ast_parse_flag... */
65 #include "asterisk/io.h" /* for ast_sd_get_fd */
66 #include "asterisk/lock.h" /* for AST_PTHREADT_NULL */
67 #include "asterisk/logger.h" /* for ast_log, LOG_ERROR, ast_debug */
68 #include "asterisk/netsock2.h" /* for ast_sockaddr_copy, ast_sockad... */
69 #include "asterisk/pbx.h" /* for ast_thread_inhibit_escalations */
70 #include "asterisk/utils.h" /* for ast_true, ast_free, ast_wait_... */
71 
72 static void session_instance_destructor(void *obj)
73 {
74  struct ast_tcptls_session_instance *i = obj;
75 
76  if (i->stream) {
78  i->stream = NULL;
79  }
82 }
83 
84 #ifdef DO_SSL
85 static int check_tcptls_cert_name(ASN1_STRING *cert_str, const char *hostname, const char *desc)
86 {
87  unsigned char *str;
88  int ret;
89 
90  ret = ASN1_STRING_to_UTF8(&str, cert_str);
91  if (ret < 0 || !str) {
92  return -1;
93  }
94 
95  if (strlen((char *) str) != ret) {
96  ast_log(LOG_WARNING, "Invalid certificate %s length (contains NULL bytes?)\n", desc);
97 
98  ret = -1;
99  } else if (!strcasecmp(hostname, (char *) str)) {
100  ret = 0;
101  } else {
102  ret = -1;
103  }
104 
105  ast_debug(3, "SSL %s compare s1='%s' s2='%s'\n", desc, hostname, str);
106  OPENSSL_free(str);
107 
108  return ret;
109 }
110 
111 static void write_openssl_error_to_log(void)
112 {
113  FILE *fp;
114  char *buffer;
115  size_t length;
116 
117  fp = open_memstream(&buffer, &length);
118  if (!fp) {
119  return;
120  }
121 
122  ERR_print_errors_fp(fp);
123  fclose(fp);
124 
125  if (length) {
126  ast_log(LOG_ERROR, "%.*s\n", (int) length, buffer);
127  }
128 
129  ast_free(buffer);
130 }
131 #endif
132 
133 /*! \brief
134 * creates a FILE * from the fd passed by the accept thread.
135 * This operation is potentially expensive (certificate verification),
136 * so we do it in the child thread context.
137 *
138 * \note must decrement ref count before returning NULL on error
139 */
140 static void *handle_tcptls_connection(void *data)
141 {
142  struct ast_tcptls_session_instance *tcptls_session = data;
143 #ifdef DO_SSL
144  SSL *ssl;
145 #endif
146 
147  /* TCP/TLS connections are associated with external protocols, and
148  * should not be allowed to execute 'dangerous' functions. This may
149  * need to be pushed down into the individual protocol handlers, but
150  * this seems like a good general policy.
151  */
153  ast_log(LOG_ERROR, "Failed to inhibit privilege escalations; killing connection from peer '%s'\n",
154  ast_sockaddr_stringify(&tcptls_session->remote_address));
155  ast_tcptls_close_session_file(tcptls_session);
156  ao2_ref(tcptls_session, -1);
157  return NULL;
158  }
159 
160  /*
161  * TCP/TLS connections are associated with external protocols which can
162  * be considered to be user interfaces (even for SIP messages), and
163  * will not handle channel media. This may need to be pushed down into
164  * the individual protocol handlers, but this seems like a good start.
165  */
167  ast_log(LOG_ERROR, "Failed to set user interface status; killing connection from peer '%s'\n",
168  ast_sockaddr_stringify(&tcptls_session->remote_address));
169  ast_tcptls_close_session_file(tcptls_session);
170  ao2_ref(tcptls_session, -1);
171  return NULL;
172  }
173 
174  if (tcptls_session->parent->tls_cfg) {
175 #ifdef DO_SSL
176  if (ast_iostream_start_tls(&tcptls_session->stream, tcptls_session->parent->tls_cfg->ssl_ctx, tcptls_session->client) < 0) {
177  SSL *ssl = ast_iostream_get_ssl(tcptls_session->stream);
178  if (ssl) {
179  ast_log(LOG_ERROR, "Unable to set up ssl connection with peer '%s'\n",
180  ast_sockaddr_stringify(&tcptls_session->remote_address));
181  }
182  ast_tcptls_close_session_file(tcptls_session);
183  ao2_ref(tcptls_session, -1);
184  return NULL;
185  }
186 
187  ssl = ast_iostream_get_ssl(tcptls_session->stream);
188  if ((tcptls_session->client && !ast_test_flag(&tcptls_session->parent->tls_cfg->flags, AST_SSL_DONT_VERIFY_SERVER))
189  || (!tcptls_session->client && ast_test_flag(&tcptls_session->parent->tls_cfg->flags, AST_SSL_VERIFY_CLIENT))) {
190  X509 *peer;
191  long res;
192  peer = SSL_get_peer_certificate(ssl);
193  if (!peer) {
194  ast_log(LOG_ERROR, "No SSL certificate to verify from peer '%s'\n",
195  ast_sockaddr_stringify(&tcptls_session->remote_address));
196  ast_tcptls_close_session_file(tcptls_session);
197  ao2_ref(tcptls_session, -1);
198  return NULL;
199  }
200 
201  res = SSL_get_verify_result(ssl);
202  if (res != X509_V_OK) {
203  ast_log(LOG_ERROR, "Certificate from peer '%s' did not verify: %s\n",
204  ast_sockaddr_stringify(&tcptls_session->remote_address),
205  X509_verify_cert_error_string(res));
206  X509_free(peer);
207  ast_tcptls_close_session_file(tcptls_session);
208  ao2_ref(tcptls_session, -1);
209  return NULL;
210  }
211  if (!ast_test_flag(&tcptls_session->parent->tls_cfg->flags, AST_SSL_IGNORE_COMMON_NAME)) {
212  ASN1_STRING *str;
213  X509_NAME *name = X509_get_subject_name(peer);
214  STACK_OF(GENERAL_NAME) *alt_names;
215  int pos = -1;
216  int found = 0;
217 
218  for (;;) {
219  /* Walk the certificate to check all available "Common Name" */
220  /* XXX Probably should do a gethostbyname on the hostname and compare that as well */
221  pos = X509_NAME_get_index_by_NID(name, NID_commonName, pos);
222  if (pos < 0) {
223  break;
224  }
225  str = X509_NAME_ENTRY_get_data(X509_NAME_get_entry(name, pos));
226  if (!check_tcptls_cert_name(str, tcptls_session->parent->hostname, "common name")) {
227  found = 1;
228  break;
229  }
230  }
231 
232  if (!found) {
233  alt_names = X509_get_ext_d2i(peer, NID_subject_alt_name, NULL, NULL);
234  if (alt_names != NULL) {
235  int alt_names_count = sk_GENERAL_NAME_num(alt_names);
236 
237  for (pos = 0; pos < alt_names_count; pos++) {
238  const GENERAL_NAME *alt_name = sk_GENERAL_NAME_value(alt_names, pos);
239 
240  if (alt_name->type != GEN_DNS) {
241  continue;
242  }
243 
244  if (!check_tcptls_cert_name(alt_name->d.dNSName, tcptls_session->parent->hostname, "alt name")) {
245  found = 1;
246  break;
247  }
248  }
249 
250  sk_GENERAL_NAME_pop_free(alt_names, GENERAL_NAME_free);
251  }
252  }
253 
254  if (!found) {
255  ast_log(LOG_ERROR, "Certificate common name from peer '%s' did not match (%s)\n",
256  ast_sockaddr_stringify(&tcptls_session->remote_address), tcptls_session->parent->hostname);
257  X509_free(peer);
258  ast_tcptls_close_session_file(tcptls_session);
259  ao2_ref(tcptls_session, -1);
260  return NULL;
261  }
262  }
263  X509_free(peer);
264  }
265 #else
266  ast_log(LOG_ERROR, "TLS client failed: Asterisk is compiled without OpenSSL support. Install OpenSSL development headers and rebuild Asterisk after running ./configure\n");
267  ast_tcptls_close_session_file(tcptls_session);
268  ao2_ref(tcptls_session, -1);
269  return NULL;
270 #endif /* DO_SSL */
271  }
272 
273  if (tcptls_session->parent->worker_fn) {
274  return tcptls_session->parent->worker_fn(tcptls_session);
275  } else {
276  return tcptls_session;
277  }
278 }
279 
280 void *ast_tcptls_server_root(void *data)
281 {
282  struct ast_tcptls_session_args *desc = data;
283  int fd;
284  struct ast_sockaddr addr;
285  struct ast_tcptls_session_instance *tcptls_session;
286  pthread_t launched;
287 
288  for (;;) {
289  int i;
290 
291  if (desc->periodic_fn) {
292  desc->periodic_fn(desc);
293  }
294  i = ast_wait_for_input(desc->accept_fd, desc->poll_timeout);
295  if (i <= 0) {
296  /* Prevent tight loop from hogging CPU */
297  usleep(1);
298  continue;
299  }
300  fd = ast_accept(desc->accept_fd, &addr);
301  if (fd < 0) {
302  if (errno != EAGAIN
303  && errno != EWOULDBLOCK
304  && errno != EINTR
305  && errno != ECONNABORTED) {
306  ast_log(LOG_ERROR, "TCP/TLS accept failed: %s\n", strerror(errno));
307  if (errno != EMFILE) {
308  break;
309  }
310  }
311  /* Prevent tight loop from hogging CPU */
312  usleep(1);
313  continue;
314  }
315  tcptls_session = ao2_alloc(sizeof(*tcptls_session), session_instance_destructor);
316  if (!tcptls_session) {
317  close(fd);
318  continue;
319  }
320 
321  tcptls_session->overflow_buf = ast_str_create(128);
322  if (!tcptls_session->overflow_buf) {
323  ao2_ref(tcptls_session, -1);
324  close(fd);
325  continue;
326  }
327  ast_fd_clear_flags(fd, O_NONBLOCK);
328 
329  tcptls_session->stream = ast_iostream_from_fd(&fd);
330  if (!tcptls_session->stream) {
331  ao2_ref(tcptls_session, -1);
332  close(fd);
333  continue;
334  }
335 
336  tcptls_session->parent = desc;
337  ast_sockaddr_copy(&tcptls_session->remote_address, &addr);
338 
339  tcptls_session->client = 0;
340 
341  /* This thread is now the only place that controls the single ref to tcptls_session */
342  if (ast_pthread_create_detached_background(&launched, NULL, handle_tcptls_connection, tcptls_session)) {
343  ast_log(LOG_ERROR, "TCP/TLS unable to launch helper thread for peer '%s': %s\n",
344  ast_sockaddr_stringify(&tcptls_session->remote_address),
345  strerror(errno));
346  ao2_ref(tcptls_session, -1);
347  }
348  }
349 
350  ast_log(LOG_ERROR, "TCP/TLS listener thread ended abnormally\n");
351 
352  /* Close the listener socket so Asterisk doesn't appear dead. */
353  fd = desc->accept_fd;
354  desc->accept_fd = -1;
355  if (0 <= fd) {
356  close(fd);
357  }
358  return NULL;
359 }
360 
361 #ifdef DO_SSL
362 static void __ssl_setup_certs(struct ast_tls_config *cfg, const size_t cert_file_len, const char *key_type_extension, const char *key_type)
363 {
364  char *cert_file = ast_strdupa(cfg->certfile);
365 
366  memcpy(cert_file + cert_file_len - 8, key_type_extension, 5);
367  if (access(cert_file, F_OK) == 0) {
368  if (SSL_CTX_use_certificate_chain_file(cfg->ssl_ctx, cert_file) == 0) {
369  ast_log(LOG_WARNING, "TLS/SSL error loading public %s key (certificate) from <%s>.\n", key_type, cert_file);
370  write_openssl_error_to_log();
371  } else if (SSL_CTX_use_PrivateKey_file(cfg->ssl_ctx, cert_file, SSL_FILETYPE_PEM) == 0) {
372  ast_log(LOG_WARNING, "TLS/SSL error loading private %s key from <%s>.\n", key_type, cert_file);
373  write_openssl_error_to_log();
374  } else if (SSL_CTX_check_private_key(cfg->ssl_ctx) == 0) {
375  ast_log(LOG_WARNING, "TLS/SSL error matching private %s key and certificate in <%s>.\n", key_type, cert_file);
376  write_openssl_error_to_log();
377  }
378  }
379 }
380 #endif
381 
382 static int __ssl_setup(struct ast_tls_config *cfg, int client)
383 {
384 #ifndef DO_SSL
385  if (cfg->enabled) {
386  ast_log(LOG_ERROR, "TLS server failed: Asterisk is compiled without OpenSSL support. Install OpenSSL development headers and rebuild Asterisk after running ./configure\n");
387  cfg->enabled = 0;
388  }
389  return 0;
390 #else
391  int disable_ssl = 0;
392  long ssl_opts = 0;
393 
394  if (!cfg->enabled) {
395  return 0;
396  }
397 
398  /* Get rid of an old SSL_CTX since we're about to
399  * allocate a new one
400  */
401  if (cfg->ssl_ctx) {
402  SSL_CTX_free(cfg->ssl_ctx);
403  cfg->ssl_ctx = NULL;
404  }
405 
406  if (client) {
407 #if !defined(OPENSSL_NO_SSL2) && (OPENSSL_VERSION_NUMBER < 0x10100000L)
409  ast_log(LOG_WARNING, "Usage of SSLv2 is discouraged due to known vulnerabilities. Please use 'tlsv1' or leave the TLS method unspecified!\n");
410  cfg->ssl_ctx = SSL_CTX_new(SSLv2_client_method());
411  } else
412 #endif
413 #if !defined(OPENSSL_NO_SSL3_METHOD) && !(defined(OPENSSL_API_COMPAT) && (OPENSSL_API_COMPAT >= 0x10100000L))
415  ast_log(LOG_WARNING, "Usage of SSLv3 is discouraged due to known vulnerabilities. Please use 'tlsv1' or leave the TLS method unspecified!\n");
416  cfg->ssl_ctx = SSL_CTX_new(SSLv3_client_method());
417  } else
418 #endif
419 #if OPENSSL_VERSION_NUMBER >= 0x10100000L
420  cfg->ssl_ctx = SSL_CTX_new(TLS_client_method());
421 #else
423  cfg->ssl_ctx = SSL_CTX_new(TLSv1_client_method());
424  } else {
425  disable_ssl = 1;
426  cfg->ssl_ctx = SSL_CTX_new(SSLv23_client_method());
427  }
428 #endif
429  } else {
430  disable_ssl = 1;
431  cfg->ssl_ctx = SSL_CTX_new(SSLv23_server_method());
432  }
433 
434  if (!cfg->ssl_ctx) {
435  ast_debug(1, "Sorry, SSL_CTX_new call returned null...\n");
436  cfg->enabled = 0;
437  return 0;
438  }
439 
440  /* Due to the POODLE vulnerability, completely disable
441  * SSLv2 and SSLv3 if we are not explicitly told to use
442  * them. SSLv23_*_method supports TLSv1+.
443  */
444  if (disable_ssl) {
445  ssl_opts |= SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3;
446  }
447 
449  ssl_opts |= SSL_OP_CIPHER_SERVER_PREFERENCE;
450  }
451 
453  ssl_opts |= SSL_OP_NO_TLSv1;
454  }
455 #if defined(SSL_OP_NO_TLSv1_1) && defined(SSL_OP_NO_TLSv1_2)
457  ssl_opts |= SSL_OP_NO_TLSv1_1;
458  }
460  ssl_opts |= SSL_OP_NO_TLSv1_2;
461  }
462 #else
463  ast_log(LOG_WARNING, "Your version of OpenSSL leaves you potentially vulnerable "
464  "to the SSL BEAST attack. Please upgrade to OpenSSL 1.0.1 or later\n");
465 #endif
466 
467  SSL_CTX_set_options(cfg->ssl_ctx, ssl_opts);
468 
469  SSL_CTX_set_verify(cfg->ssl_ctx,
470  ast_test_flag(&cfg->flags, AST_SSL_VERIFY_CLIENT) ? SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT : SSL_VERIFY_NONE,
471  NULL);
472 
473  if (!ast_strlen_zero(cfg->certfile)) {
474  char *tmpprivate = ast_strlen_zero(cfg->pvtfile) ? cfg->certfile : cfg->pvtfile;
475  if (SSL_CTX_use_certificate_chain_file(cfg->ssl_ctx, cfg->certfile) == 0) {
476  if (!client) {
477  /* Clients don't need a certificate, but if its setup we can use it */
478  ast_log(LOG_ERROR, "TLS/SSL error loading cert file. <%s>\n", cfg->certfile);
479  write_openssl_error_to_log();
480  cfg->enabled = 0;
481  SSL_CTX_free(cfg->ssl_ctx);
482  cfg->ssl_ctx = NULL;
483  return 0;
484  }
485  }
486  if ((SSL_CTX_use_PrivateKey_file(cfg->ssl_ctx, tmpprivate, SSL_FILETYPE_PEM) == 0) || (SSL_CTX_check_private_key(cfg->ssl_ctx) == 0 )) {
487  if (!client) {
488  /* Clients don't need a private key, but if its setup we can use it */
489  ast_log(LOG_ERROR, "TLS/SSL error loading private key file. <%s>\n", tmpprivate);
490  write_openssl_error_to_log();
491  cfg->enabled = 0;
492  SSL_CTX_free(cfg->ssl_ctx);
493  cfg->ssl_ctx = NULL;
494  return 0;
495  }
496  }
497  if (!client) {
498  size_t certfile_len = strlen(cfg->certfile);
499 
500  /* expects a file name which contains _rsa. like asterisk_rsa.pem
501  * ignores any 3-character file-extension like .pem, .cer, .crt
502  */
503  if (certfile_len >= 8 && !strncmp(cfg->certfile + certfile_len - 8, "_rsa.", 5)) {
504  __ssl_setup_certs(cfg, certfile_len, "_ecc.", "ECC");
505  __ssl_setup_certs(cfg, certfile_len, "_dsa.", "DSA");
506  }
507  }
508  }
509  if (!ast_strlen_zero(cfg->cipher)) {
510  if (SSL_CTX_set_cipher_list(cfg->ssl_ctx, cfg->cipher) == 0 ) {
511  if (!client) {
512  ast_log(LOG_ERROR, "TLS/SSL cipher error <%s>\n", cfg->cipher);
513  write_openssl_error_to_log();
514  cfg->enabled = 0;
515  SSL_CTX_free(cfg->ssl_ctx);
516  cfg->ssl_ctx = NULL;
517  return 0;
518  }
519  }
520  }
521  if (!ast_strlen_zero(cfg->cafile) || !ast_strlen_zero(cfg->capath)) {
522  if (SSL_CTX_load_verify_locations(cfg->ssl_ctx, S_OR(cfg->cafile, NULL), S_OR(cfg->capath,NULL)) == 0) {
523  ast_log(LOG_ERROR, "TLS/SSL CA file(%s)/path(%s) error\n", cfg->cafile, cfg->capath);
524  write_openssl_error_to_log();
525  }
526  }
527 
528 #ifndef OPENSSL_NO_DH
529  if (!ast_strlen_zero(cfg->pvtfile)) {
530  BIO *bio = BIO_new_file(cfg->pvtfile, "r");
531  if (bio != NULL) {
532  DH *dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL);
533  if (dh != NULL) {
534  if (SSL_CTX_set_tmp_dh(cfg->ssl_ctx, dh)) {
535  long options = SSL_OP_CIPHER_SERVER_PREFERENCE | SSL_OP_SINGLE_DH_USE | SSL_OP_SINGLE_ECDH_USE;
536  options = SSL_CTX_set_options(cfg->ssl_ctx, options);
537  ast_verb(2, "TLS/SSL DH initialized, PFS cipher-suites enabled\n");
538  }
539  DH_free(dh);
540  }
541  BIO_free(bio);
542  }
543  }
544 #endif
545 
546  #ifndef SSL_CTRL_SET_ECDH_AUTO
547  #define SSL_CTRL_SET_ECDH_AUTO 94
548  #endif
549  /* SSL_CTX_set_ecdh_auto(cfg->ssl_ctx, on); requires OpenSSL 1.0.2 which wraps: */
550  if (SSL_CTX_ctrl(cfg->ssl_ctx, SSL_CTRL_SET_ECDH_AUTO, 1, NULL)) {
551  ast_verb(2, "TLS/SSL ECDH initialized (automatic), faster PFS ciphers enabled\n");
552 #if !defined(OPENSSL_NO_ECDH) && (OPENSSL_VERSION_NUMBER >= 0x10000000L) && (OPENSSL_VERSION_NUMBER < 0x10100000L)
553  } else {
554  /* enables AES-128 ciphers, to get AES-256 use NID_secp384r1 */
555  EC_KEY *ecdh = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
556  if (ecdh != NULL) {
557  if (SSL_CTX_set_tmp_ecdh(cfg->ssl_ctx, ecdh)) {
558  ast_verb(2, "TLS/SSL ECDH initialized (secp256r1), faster PFS cipher-suites enabled\n");
559  }
560  EC_KEY_free(ecdh);
561  }
562 #endif
563  }
564 
565  ast_verb(2, "TLS/SSL certificate ok\n"); /* We should log which one that is ok. This message doesn't really make sense in production use */
566  return 1;
567 #endif
568 }
569 
571 {
572  return __ssl_setup(cfg, 0);
573 }
574 
576 {
577 #ifdef DO_SSL
578  if (cfg && cfg->ssl_ctx) {
579  SSL_CTX_free(cfg->ssl_ctx);
580  cfg->ssl_ctx = NULL;
581  }
582 #endif
583 }
584 
585 /*!
586  * \internal
587  * \brief Connect a socket
588  *
589  * Attempt to connect to a given address for up to 'timeout' milliseconds. A negative
590  * timeout value equates to an infinite wait time.
591  *
592  * A -1 is returned on error, and an appropriate errno value is set based on the
593  * type of error.
594  *
595  * \param sockfd The socket file descriptor
596  * \param addr The address to connect to
597  * \param timeout How long, in milliseconds, to attempt to connect
598  *
599  * \return 0 if successfully connected, -1 otherwise
600  */
601 static int socket_connect(int sockfd, const struct ast_sockaddr *addr, int timeout)
602 {
603  int optval = 0;
604  socklen_t optlen = sizeof(int);
605 
606  errno = 0;
607 
608  if (ast_connect(sockfd, addr)) {
609  int res;
610 
611  /*
612  * A connect failure could mean things are still in progress.
613  * If so wait for it to complete.
614  */
615 
616  if (errno != EINPROGRESS) {
617  return -1;
618  }
619 
620  while ((res = ast_wait_for_output(sockfd, timeout)) != 1) {
621  if (res == 0) {
622  errno = ETIMEDOUT;
623  return -1;
624  }
625 
626  if (errno != EINTR) {
627  return -1;
628  }
629  }
630  }
631 
632  /* Check the status to ensure it actually connected successfully */
633  if (getsockopt(sockfd, SOL_SOCKET, SO_ERROR, &optval, &optlen) < 0) {
634  return -1;
635  }
636 
637  if (optval) {
638  errno = optval;
639  return -1;
640  }
641 
642  return 0;
643 }
644 
646  struct ast_tcptls_session_instance *tcptls_session, int timeout)
647 {
649 
650  if (!(desc = tcptls_session->parent)) {
651  ao2_ref(tcptls_session, -1);
652  return NULL;
653  }
654 
655  if (socket_connect(desc->accept_fd, &desc->remote_address, timeout)) {
656  ast_log(LOG_WARNING, "Unable to connect %s to %s: %s\n", desc->name,
657  ast_sockaddr_stringify(&desc->remote_address), strerror(errno));
658 
659  ao2_ref(tcptls_session, -1);
660  return NULL;
661  }
662 
663  ast_fd_clear_flags(desc->accept_fd, O_NONBLOCK);
664 
665  if (desc->tls_cfg) {
666  desc->tls_cfg->enabled = 1;
667  __ssl_setup(desc->tls_cfg, 1);
668  }
669 
670  return handle_tcptls_connection(tcptls_session);
671 }
672 
674 {
675  return ast_tcptls_client_start_timeout(tcptls_session, -1);
676 }
677 
679 {
680  int fd, x = 1;
681  struct ast_tcptls_session_instance *tcptls_session = NULL;
682 
683  /* Do nothing if nothing has changed */
684  if (!ast_sockaddr_cmp(&desc->old_address, &desc->remote_address)) {
685  ast_debug(1, "Nothing changed in %s\n", desc->name);
686  return NULL;
687  }
688 
689  /* If we return early, there is no connection */
690  ast_sockaddr_setnull(&desc->old_address);
691 
692  fd = desc->accept_fd = ast_socket_nonblock(ast_sockaddr_is_ipv6(&desc->remote_address) ?
693  AF_INET6 : AF_INET, SOCK_STREAM, IPPROTO_TCP);
694  if (desc->accept_fd < 0) {
695  ast_log(LOG_ERROR, "Unable to allocate socket for %s: %s\n",
696  desc->name, strerror(errno));
697  return NULL;
698  }
699 
700  /* if a local address was specified, bind to it so the connection will
701  originate from the desired address */
702  if (!ast_sockaddr_isnull(&desc->local_address) &&
703  !ast_sockaddr_is_any(&desc->local_address)) {
704  setsockopt(desc->accept_fd, SOL_SOCKET, SO_REUSEADDR, &x, sizeof(x));
705  if (ast_bind(desc->accept_fd, &desc->local_address)) {
706  ast_log(LOG_ERROR, "Unable to bind %s to %s: %s\n",
707  desc->name,
708  ast_sockaddr_stringify(&desc->local_address),
709  strerror(errno));
710  goto error;
711  }
712  }
713 
714  tcptls_session = ao2_alloc(sizeof(*tcptls_session), session_instance_destructor);
715  if (!tcptls_session) {
716  goto error;
717  }
718 
719  tcptls_session->overflow_buf = ast_str_create(128);
720  if (!tcptls_session->overflow_buf) {
721  goto error;
722  }
723  tcptls_session->client = 1;
724  tcptls_session->stream = ast_iostream_from_fd(&fd);
725  if (!tcptls_session->stream) {
726  goto error;
727  }
728 
729  /* From here on out, the iostream owns the accept_fd and it will take
730  * care of closing it when the iostream is closed */
731 
732  tcptls_session->parent = desc;
733  tcptls_session->parent->worker_fn = NULL;
734  ast_sockaddr_copy(&tcptls_session->remote_address,
735  &desc->remote_address);
736 
737  /* Set current info */
738  ast_sockaddr_copy(&desc->old_address, &desc->remote_address);
739 
740  return tcptls_session;
741 
742 error:
743  close(desc->accept_fd);
744  desc->accept_fd = -1;
745  ao2_cleanup(tcptls_session);
746  return NULL;
747 }
748 
750 {
751  int x = 1;
752  int tls_changed = 0;
753  int sd_socket;
754 
755  if (desc->tls_cfg) {
756  char hash[41];
757  char *str = NULL;
758  struct stat st;
759 
760  /* Store the hashes of the TLS certificate etc. */
761  if (stat(desc->tls_cfg->certfile, &st) || NULL == (str = ast_read_textfile(desc->tls_cfg->certfile))) {
762  memset(hash, 0, 41);
763  } else {
764  ast_sha1_hash(hash, str);
765  }
766  ast_free(str);
767  str = NULL;
768  memcpy(desc->tls_cfg->certhash, hash, 41);
769  if (stat(desc->tls_cfg->pvtfile, &st) || NULL == (str = ast_read_textfile(desc->tls_cfg->pvtfile))) {
770  memset(hash, 0, 41);
771  } else {
772  ast_sha1_hash(hash, str);
773  }
774  ast_free(str);
775  str = NULL;
776  memcpy(desc->tls_cfg->pvthash, hash, 41);
777  if (stat(desc->tls_cfg->cafile, &st) || NULL == (str = ast_read_textfile(desc->tls_cfg->cafile))) {
778  memset(hash, 0, 41);
779  } else {
780  ast_sha1_hash(hash, str);
781  }
782  ast_free(str);
783  str = NULL;
784  memcpy(desc->tls_cfg->cahash, hash, 41);
785 
786  /* Check whether TLS configuration has changed */
787  if (!desc->old_tls_cfg) { /* No previous configuration */
788  tls_changed = 1;
789  desc->old_tls_cfg = ast_calloc(1, sizeof(*desc->old_tls_cfg));
790  } else if (memcmp(desc->tls_cfg->certhash, desc->old_tls_cfg->certhash, 41)) {
791  tls_changed = 1;
792  } else if (memcmp(desc->tls_cfg->pvthash, desc->old_tls_cfg->pvthash, 41)) {
793  tls_changed = 1;
794  } else if (strcmp(desc->tls_cfg->cipher, desc->old_tls_cfg->cipher)) {
795  tls_changed = 1;
796  } else if (memcmp(desc->tls_cfg->cahash, desc->old_tls_cfg->cahash, 41)) {
797  tls_changed = 1;
798  } else if (strcmp(desc->tls_cfg->capath, desc->old_tls_cfg->capath)) {
799  tls_changed = 1;
800  } else if (memcmp(&desc->tls_cfg->flags, &desc->old_tls_cfg->flags, sizeof(desc->tls_cfg->flags))) {
801  tls_changed = 1;
802  }
803 
804  if (tls_changed) {
805  ast_debug(1, "Changed parameters for %s found\n", desc->name);
806  }
807  }
808 
809  /* Do nothing if nothing has changed */
810  if (!tls_changed && !ast_sockaddr_cmp(&desc->old_address, &desc->local_address)) {
811  ast_debug(1, "Nothing changed in %s\n", desc->name);
812  return;
813  }
814 
815  /* If we return early, there is no one listening */
816  ast_sockaddr_setnull(&desc->old_address);
817 
818  /* Shutdown a running server if there is one */
819  if (desc->master != AST_PTHREADT_NULL) {
820  pthread_cancel(desc->master);
821  pthread_kill(desc->master, SIGURG);
822  pthread_join(desc->master, NULL);
823  }
824 
825  sd_socket = ast_sd_get_fd(SOCK_STREAM, &desc->local_address);
826 
827  if (sd_socket != -1) {
828  if (desc->accept_fd != sd_socket) {
829  if (desc->accept_fd != -1) {
830  close(desc->accept_fd);
831  }
832  desc->accept_fd = sd_socket;
833  }
834 
835  goto systemd_socket_activation;
836  }
837 
838  if (desc->accept_fd != -1) {
839  close(desc->accept_fd);
840  }
841 
842  /* If there's no new server, stop here */
843  if (ast_sockaddr_isnull(&desc->local_address)) {
844  ast_debug(2, "Server disabled: %s\n", desc->name);
845  return;
846  }
847 
848  desc->accept_fd = ast_socket_nonblock(ast_sockaddr_is_ipv6(&desc->local_address) ?
849  AF_INET6 : AF_INET, SOCK_STREAM, 0);
850  if (desc->accept_fd < 0) {
851  ast_log(LOG_ERROR, "Unable to allocate socket for %s: %s\n", desc->name, strerror(errno));
852  return;
853  }
854 
855  setsockopt(desc->accept_fd, SOL_SOCKET, SO_REUSEADDR, &x, sizeof(x));
856  if (ast_bind(desc->accept_fd, &desc->local_address)) {
857  ast_log(LOG_ERROR, "Unable to bind %s to %s: %s\n",
858  desc->name,
859  ast_sockaddr_stringify(&desc->local_address),
860  strerror(errno));
861  goto error;
862  }
863  if (listen(desc->accept_fd, 10)) {
864  ast_log(LOG_ERROR, "Unable to listen for %s!\n", desc->name);
865  goto error;
866  }
867 
868 systemd_socket_activation:
869  if (ast_pthread_create_background(&desc->master, NULL, desc->accept_fn, desc)) {
870  ast_log(LOG_ERROR, "Unable to launch thread for %s on %s: %s\n",
871  desc->name,
872  ast_sockaddr_stringify(&desc->local_address),
873  strerror(errno));
874  goto error;
875  }
876 
877  /* Set current info */
878  ast_sockaddr_copy(&desc->old_address, &desc->local_address);
879  if (desc->old_tls_cfg) {
880  ast_free(desc->old_tls_cfg->certfile);
881  ast_free(desc->old_tls_cfg->pvtfile);
882  ast_free(desc->old_tls_cfg->cipher);
883  ast_free(desc->old_tls_cfg->cafile);
884  ast_free(desc->old_tls_cfg->capath);
885  desc->old_tls_cfg->certfile = ast_strdup(desc->tls_cfg->certfile);
886  desc->old_tls_cfg->pvtfile = ast_strdup(desc->tls_cfg->pvtfile);
887  desc->old_tls_cfg->cipher = ast_strdup(desc->tls_cfg->cipher);
888  desc->old_tls_cfg->cafile = ast_strdup(desc->tls_cfg->cafile);
889  desc->old_tls_cfg->capath = ast_strdup(desc->tls_cfg->capath);
890  memcpy(desc->old_tls_cfg->certhash, desc->tls_cfg->certhash, 41);
891  memcpy(desc->old_tls_cfg->pvthash, desc->tls_cfg->pvthash, 41);
892  memcpy(desc->old_tls_cfg->cahash, desc->tls_cfg->cahash, 41);
893  memcpy(&desc->old_tls_cfg->flags, &desc->tls_cfg->flags, sizeof(desc->old_tls_cfg->flags));
894  }
895 
896  return;
897 
898 error:
899  close(desc->accept_fd);
900  desc->accept_fd = -1;
901 }
902 
904 {
905  if (tcptls_session->stream) {
906  ast_iostream_close(tcptls_session->stream);
907  tcptls_session->stream = NULL;
908  } else {
909  ast_debug(1, "ast_tcptls_close_session_file invoked on session instance without file or file descriptor\n");
910  }
911 }
912 
914 {
915  if (desc->master != AST_PTHREADT_NULL) {
916  pthread_cancel(desc->master);
917  pthread_kill(desc->master, SIGURG);
918  pthread_join(desc->master, NULL);
919  desc->master = AST_PTHREADT_NULL;
920  }
921  if (desc->accept_fd != -1) {
922  close(desc->accept_fd);
923  }
924  desc->accept_fd = -1;
925 
926  if (desc->old_tls_cfg) {
927  ast_free(desc->old_tls_cfg->certfile);
928  ast_free(desc->old_tls_cfg->pvtfile);
929  ast_free(desc->old_tls_cfg->cipher);
930  ast_free(desc->old_tls_cfg->cafile);
931  ast_free(desc->old_tls_cfg->capath);
932  ast_free(desc->old_tls_cfg);
933  desc->old_tls_cfg = NULL;
934  }
935 
936  ast_debug(2, "Stopped server :: %s\n", desc->name);
937 }
938 
939 int ast_tls_read_conf(struct ast_tls_config *tls_cfg, struct ast_tcptls_session_args *tls_desc, const char *varname, const char *value)
940 {
941  if (!strcasecmp(varname, "tlsenable") || !strcasecmp(varname, "sslenable")) {
942  tls_cfg->enabled = ast_true(value) ? 1 : 0;
943  } else if (!strcasecmp(varname, "tlscertfile") || !strcasecmp(varname, "sslcert") || !strcasecmp(varname, "tlscert")) {
944  ast_free(tls_cfg->certfile);
945  tls_cfg->certfile = ast_strdup(value);
946  } else if (!strcasecmp(varname, "tlsprivatekey") || !strcasecmp(varname, "sslprivatekey")) {
947  ast_free(tls_cfg->pvtfile);
948  tls_cfg->pvtfile = ast_strdup(value);
949  } else if (!strcasecmp(varname, "tlscipher") || !strcasecmp(varname, "sslcipher")) {
950  ast_free(tls_cfg->cipher);
951  tls_cfg->cipher = ast_strdup(value);
952  } else if (!strcasecmp(varname, "tlscafile")) {
953  ast_free(tls_cfg->cafile);
954  tls_cfg->cafile = ast_strdup(value);
955  } else if (!strcasecmp(varname, "tlscapath") || !strcasecmp(varname, "tlscadir")) {
956  ast_free(tls_cfg->capath);
957  tls_cfg->capath = ast_strdup(value);
958  } else if (!strcasecmp(varname, "tlsverifyclient")) {
960  } else if (!strcasecmp(varname, "tlsdontverifyserver")) {
962  } else if (!strcasecmp(varname, "tlsbindaddr") || !strcasecmp(varname, "sslbindaddr")) {
963  if (ast_parse_arg(value, PARSE_ADDR, &tls_desc->local_address))
964  ast_log(LOG_ERROR, "Invalid %s '%s'\n", varname, value);
965  } else if (!strcasecmp(varname, "tlsclientmethod") || !strcasecmp(varname, "sslclientmethod")) {
966  if (!strcasecmp(value, "tlsv1")) {
970  } else if (!strcasecmp(value, "sslv3")) {
974  } else if (!strcasecmp(value, "sslv2")) {
978  }
979  } else if (!strcasecmp(varname, "tlsservercipherorder")) {
981  } else if (!strcasecmp(varname, "tlsdisablev1")) {
983  } else if (!strcasecmp(varname, "tlsdisablev11")) {
985  } else if (!strcasecmp(varname, "tlsdisablev12")) {
987  } else {
988  return -1;
989  }
990 
991  return 0;
992 }
const char * str
Definition: app_jack.c:147
Asterisk main include file. File version handling, generic pbx functions.
#define ast_free(a)
Definition: astmm.h:180
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:241
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
#define ast_log
Definition: astobj2.c:42
#define ao2_cleanup(obj)
Definition: astobj2.h:1934
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
#define ao2_alloc(data_size, destructor_fn)
Definition: astobj2.h:409
static const char desc[]
Definition: cdr_radius.c:84
static const char name[]
Definition: format_mp3.c:68
Application convenience functions, designed to give consistent look and feel to Asterisk apps.
char * ast_read_textfile(const char *file)
Read a file into asterisk.
Definition: main/app.c:3009
General Definitions for Asterisk top level program Included by asterisk.h to handle platform-specific...
Configuration File Parser.
int ast_parse_arg(const char *arg, enum ast_parse_flags flags, void *p_result,...)
The argument parsing routine.
Definition: main/config.c:3726
Support for logging to various files, console and syslog Configuration in file logger....
#define ast_debug(level,...)
Log a DEBUG message.
#define LOG_ERROR
#define ast_verb(level,...)
#define LOG_WARNING
I/O Management (derived from Cheops-NG)
int ast_sd_get_fd(int type, const struct ast_sockaddr *addr)
Find a listening file descriptor provided by socket activation.
Definition: io.c:438
Generic abstraction for input/output streams.
SSL * ast_iostream_get_ssl(struct ast_iostream *stream)
Get a pointer to an iostream's OpenSSL SSL structure.
Definition: iostream.c:108
int ast_iostream_start_tls(struct ast_iostream **stream, SSL_CTX *ctx, int client)
Begin TLS on an iostream.
Definition: iostream.c:620
struct ast_iostream * ast_iostream_from_fd(int *fd)
Create an iostream from a file descriptor.
Definition: iostream.c:604
struct ssl_st SSL
Definition: iostream.h:37
int ast_iostream_close(struct ast_iostream *stream)
Close an iostream.
Definition: iostream.c:528
Asterisk locking-related definitions:
#define AST_PTHREADT_NULL
Definition: lock.h:66
static char hostname[MAXHOSTNAMELEN]
Definition: logger.c:119
int errno
Network socket handling.
int ast_connect(int sockfd, const struct ast_sockaddr *addr)
Wrapper around connect(2) that uses struct ast_sockaddr.
Definition: netsock2.c:595
static void ast_sockaddr_copy(struct ast_sockaddr *dst, const struct ast_sockaddr *src)
Copies the data from one ast_sockaddr to another.
Definition: netsock2.h:167
int ast_sockaddr_is_ipv6(const struct ast_sockaddr *addr)
Determine if this is an IPv6 address.
Definition: netsock2.c:524
int ast_bind(int sockfd, const struct ast_sockaddr *addr)
Wrapper around bind(2) that uses struct ast_sockaddr.
Definition: netsock2.c:590
int ast_sockaddr_is_any(const struct ast_sockaddr *addr)
Determine if the address type is unspecified, or "any" address.
Definition: netsock2.c:534
int ast_accept(int sockfd, struct ast_sockaddr *addr)
Wrapper around accept(2) that uses struct ast_sockaddr.
Definition: netsock2.c:584
static int ast_sockaddr_isnull(const struct ast_sockaddr *addr)
Checks if the ast_sockaddr is null. "null" in this sense essentially means uninitialized,...
Definition: netsock2.h:127
static char * ast_sockaddr_stringify(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() with default format.
Definition: netsock2.h:256
int ast_sockaddr_cmp(const struct ast_sockaddr *a, const struct ast_sockaddr *b)
Compares two ast_sockaddr structures.
Definition: netsock2.c:388
static void ast_sockaddr_setnull(struct ast_sockaddr *addr)
Sets address addr to null.
Definition: netsock2.h:138
Core PBX routines and definitions.
int ast_thread_inhibit_escalations(void)
Inhibit (in the current thread) the execution of dialplan functions which cause privilege escalations...
#define NULL
Definition: resample.c:96
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one.
Definition: strings.h:80
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true"....
Definition: main/utils.c:2097
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
Definition: strings.h:640
Socket address structure.
Definition: netsock2.h:97
arguments for the accepting thread
Definition: tcptls.h:130
void *(* worker_fn)(void *)
Definition: tcptls.h:142
struct ast_sockaddr local_address
Definition: tcptls.h:131
struct ast_tls_config * tls_cfg
Definition: tcptls.h:135
char hostname[MAXHOSTNAMELEN]
Definition: tcptls.h:134
describes a server instance
Definition: tcptls.h:150
struct ast_iostream * stream
Definition: tcptls.h:161
struct ast_sockaddr remote_address
Definition: tcptls.h:152
struct ast_tcptls_session_args * parent
Definition: tcptls.h:153
struct ast_str * overflow_buf
Definition: tcptls.h:159
int enabled
Definition: tcptls.h:89
char * certfile
Definition: tcptls.h:90
char * cipher
Definition: tcptls.h:92
SSL_CTX * ssl_ctx
Definition: tcptls.h:96
char * pvtfile
Definition: tcptls.h:91
char * capath
Definition: tcptls.h:94
char * cafile
Definition: tcptls.h:93
struct ast_flags flags
Definition: tcptls.h:95
int value
Definition: syslog.c:37
struct ast_tcptls_session_instance * ast_tcptls_client_start_timeout(struct ast_tcptls_session_instance *tcptls_session, int timeout)
Attempt to connect and start a tcptls session within the given timeout.
Definition: tcptls.c:645
static int __ssl_setup(struct ast_tls_config *cfg, int client)
Definition: tcptls.c:382
static int socket_connect(int sockfd, const struct ast_sockaddr *addr, int timeout)
Definition: tcptls.c:601
void ast_tcptls_server_stop(struct ast_tcptls_session_args *desc)
Shutdown a running server if there is one.
Definition: tcptls.c:913
int ast_ssl_setup(struct ast_tls_config *cfg)
Set up an SSL server.
Definition: tcptls.c:570
void ast_tcptls_server_start(struct ast_tcptls_session_args *desc)
This is a generic (re)start routine for a TCP server, which does the socket/bind/listen and starts a ...
Definition: tcptls.c:749
static void session_instance_destructor(void *obj)
Definition: tcptls.c:72
void ast_ssl_teardown(struct ast_tls_config *cfg)
free resources used by an SSL server
Definition: tcptls.c:575
void * ast_tcptls_server_root(void *data)
Definition: tcptls.c:280
int ast_tls_read_conf(struct ast_tls_config *tls_cfg, struct ast_tcptls_session_args *tls_desc, const char *varname, const char *value)
Used to parse conf files containing tls/ssl options.
Definition: tcptls.c:939
struct ast_tcptls_session_instance * ast_tcptls_client_create(struct ast_tcptls_session_args *desc)
Creates a client connection's ast_tcptls_session_instance.
Definition: tcptls.c:678
static void * handle_tcptls_connection(void *data)
creates a FILE * from the fd passed by the accept thread. This operation is potentially expensive (ce...
Definition: tcptls.c:140
void ast_tcptls_close_session_file(struct ast_tcptls_session_instance *tcptls_session)
Closes a tcptls session instance's file and/or file descriptor. The tcptls_session will be set to NUL...
Definition: tcptls.c:903
struct ast_tcptls_session_instance * ast_tcptls_client_start(struct ast_tcptls_session_instance *tcptls_session)
Attempt to connect and start a tcptls session.
Definition: tcptls.c:673
Generic support for tcp/tls servers in Asterisk.
@ AST_SSL_VERIFY_CLIENT
Definition: tcptls.h:67
@ AST_SSL_DONT_VERIFY_SERVER
Definition: tcptls.h:69
@ AST_SSL_SSLV3_CLIENT
Definition: tcptls.h:75
@ AST_SSL_DISABLE_TLSV11
Definition: tcptls.h:83
@ AST_SSL_IGNORE_COMMON_NAME
Definition: tcptls.h:71
@ AST_SSL_TLSV1_CLIENT
Definition: tcptls.h:77
@ AST_SSL_DISABLE_TLSV12
Definition: tcptls.h:85
@ AST_SSL_SERVER_CIPHER_ORDER
Definition: tcptls.h:79
@ AST_SSL_DISABLE_TLSV1
Definition: tcptls.h:81
@ AST_SSL_SSLV2_CLIENT
Definition: tcptls.h:73
static struct test_options options
int error(const char *format,...)
Definition: utils/frame.c:999
Utility functions.
#define ast_test_flag(p, flag)
Definition: utils.h:63
#define ast_socket_nonblock(domain, type, protocol)
Create a non-blocking socket.
Definition: utils.h:1068
int ast_thread_user_interface_set(int is_user_interface)
Set the current thread's user interface status.
Definition: main/utils.c:3129
#define ast_pthread_create_background(a, b, c, d)
Definition: utils.h:587
int ast_wait_for_input(int fd, int ms)
Definition: main/utils.c:1665
#define ast_set2_flag(p, value, flag)
Definition: utils.h:94
#define ast_clear_flag(p, flag)
Definition: utils.h:77
int ast_wait_for_output(int fd, int ms)
Definition: main/utils.c:1675
#define ast_pthread_create_detached_background(a, b, c, d)
Definition: utils.h:592
#define ast_set_flag(p, flag)
Definition: utils.h:70
#define ast_fd_clear_flags(fd, flags)
Clear flags on the given file descriptor.
Definition: utils.h:1050
void ast_sha1_hash(char *output, const char *input)
Produces SHA1 hash based on input string.
Definition: main/utils.c:266