20#include <gnutls/gnutls.h>
21#include <gnutls/x509.h>
22#include <gvm/base/logging.h>
23#include <gvm/base/networking.h>
24#include <gvm/base/prefs.h>
25#include <gvm/util/kb.h>
26#include <gvm/util/serverutils.h>
37#include <netinet/in.h>
38#define s6_addr32 __u6_addr.__u6_addr32
48#define INADDR_NONE 0xffffffff
55#define G_LOG_DOMAIN "lib misc"
91#define OPENVAS_FD_MAX 1024
92#define OPENVAS_FD_OFF 1000000
113#define OPENVAS_STREAM(x) \
114 (((x - OPENVAS_FD_OFF) < OPENVAS_FD_MAX) && ((x - OPENVAS_FD_OFF) >= 0))
119#define OVAS_CONNECTION_FROM_FD(fd) (connections + ((fd) - OPENVAS_FD_OFF))
127 g_debug (
"[%d] %s : %s", getpid (), error, strerror (errno));
166 g_message (
"[%d] %s:%d : Out of OpenVAS file descriptors", getpid (),
196 g_debug (
"[%d] release_connection_fd: fd > 0 fd=%d", getpid (), p->
fd);
197 if (shutdown (p->
fd, 2) < 0)
204 pid_perror (
"release_connection_fd: shutdown()");
207 pid_perror (
"release_connection_fd: close()");
213 gnutls_certificate_free_credentials (p->
tls_cred);
218 bzero (p,
sizeof (*p));
235 gnutls_certificate_credentials_t certcred,
274 bzero (p,
sizeof (*p));
288 int flags = fcntl (soc, F_GETFL, 0);
294 if (fcntl (soc, F_SETFL, O_NONBLOCK | flags) < 0)
305 int flags = fcntl (soc, F_GETFL, 0);
311 if (fcntl (soc, F_SETFL, (~O_NONBLOCK) & flags) < 0)
328 g_message (
"[%d] %s: %s", getpid (), txt, gnutls_strerror (err));
334 g_debug (
"LEVEL %d: %s", level, msg);
343 gnutls_global_set_log_level (2);
346 int ret = gnutls_global_init ();
349 tlserror (
"gnutls_global_init", ret);
363 g_message (
"[%d] openvas_get_socket_from_connection: bad fd <%d>",
370 g_message (
"openvas_get_socket_from_connection: fd <%d> is closed", fd);
395 const char *priority,
unsigned int flags)
397 const char *priorities;
404 priorities =
"NORMAL:-VERS-TLS-ALL:+VERS-SSL3.0:+ARCFOUR-128:%COMPAT";
407 priorities =
"NORMAL:-VERS-TLS-ALL:+VERS-TLS1.0:+ARCFOUR-128:%COMPAT";
410 priorities =
"NORMAL:-VERS-TLS-ALL:+VERS-TLS1.1:+ARCFOUR-128:%COMPAT";
413 priorities =
"NORMAL:-VERS-TLS-ALL:+VERS-TLS1.2:+ARCFOUR-128:%COMPAT";
416 priorities =
"NORMAL:-VERS-TLS-ALL:+VERS-TLS1.3:%COMPAT";
420 "NORMAL:-VERS-TLS-ALL:+VERS-TLS1.0:+VERS-SSL3.0:+ARCFOUR-128:%COMPAT";
423 g_debug (
"*Bug* at %s:%d. Unknown transport %d", __FILE__, __LINE__,
427 priorities = priority;
431 g_debug (
"%s: setting %s as priority_string based on %d", __func__,
433 if ((err = gnutls_priority_set_direct (session, priorities, &errloc)))
435 g_message (
"[%d] setting session priorities '%.20s': %s", getpid (),
436 errloc, gnutls_strerror (err));
443 gnutls_dh_set_prime_bits (session, 128);
458 const char *key,
const char *passwd)
460 gnutls_x509_crt_t x509_crt = NULL;
461 gnutls_x509_privkey_t x509_key = NULL;
466 if (load_gnutls_file (cert, &data))
468 g_message (
"[%d] load_cert_and_key: Error loading cert file %s",
473 ret = gnutls_x509_crt_init (&x509_crt);
476 tlserror (
"gnutls_x509_crt_init", ret);
482 ret = gnutls_x509_crt_import (x509_crt, &data, GNUTLS_X509_FMT_PEM);
485 tlserror (
"gnutls_x509_crt_import", ret);
489 unload_gnutls_file (&data);
491 if (load_gnutls_file (key, &data))
493 g_message (
"[%d] load_cert_and_key: Error loading key file %s", getpid (),
498 ret = gnutls_x509_privkey_init (&x509_key);
501 tlserror (
"gnutls_x509_privkey_init", ret);
509 ret = gnutls_x509_privkey_import_pkcs8 (x509_key, &data,
510 GNUTLS_X509_FMT_PEM, passwd, 0);
513 tlserror (
"gnutls_x509_privkey_import_pkcs8", ret);
520 ret = gnutls_x509_privkey_import (x509_key, &data, GNUTLS_X509_FMT_PEM);
523 tlserror (
"gnutls_x509_privkey_import", ret);
528 unload_gnutls_file (&data);
530 ret = gnutls_certificate_set_x509_key (xcred, &x509_crt, 1, x509_key);
533 tlserror (
"gnutls_certificate_set_x509_key", ret);
541 gnutls_x509_crt_deinit (x509_crt);
543 gnutls_x509_privkey_deinit (x509_key);
551 struct sockaddr_in sa;
552 struct sockaddr_in6 sa6;
554 if (inet_pton (AF_INET, str, &(sa.sin_addr)) == 1)
557 return inet_pton (AF_INET6, str, &(sa6.sin6_addr)) == 1;
581 const char *passwd,
const char *cafile,
582 const char *
hostname,
unsigned int flags)
589 ret = gnutls_init (&(fp->
tls_session), GNUTLS_CLIENT);
611 ret = gnutls_certificate_allocate_credentials (&(fp->
tls_cred));
614 tlserror (
"gnutls_certificate_allocate_credentials", ret);
617 ret = gnutls_credentials_set (fp->
tls_session, GNUTLS_CRD_CERTIFICATE,
621 tlserror (
"gnutls_credentials_set", ret);
625 if (cert != NULL && key != NULL)
633 ret = gnutls_certificate_set_x509_trust_file (fp->
tls_cred, cafile,
634 GNUTLS_X509_FMT_PEM);
637 tlserror (
"gnutls_certificate_set_x509_trust_file", ret);
645 (gnutls_transport_ptr_t) GSIZE_TO_POINTER (fp->
fd));
647 tictac = time (NULL);
658 if (err == GNUTLS_E_DH_PRIME_UNACCEPTABLE
661 g_message (
"[%d] gnutls_handshake: %s", getpid (),
662 gnutls_strerror (err));
665 else if (err == GNUTLS_E_FATAL_ALERT_RECEIVED)
667 g_debug (
"[%d] gnutls_handshake: %s", getpid (),
668 gnutls_strerror (err));
671 else if (err != GNUTLS_E_INTERRUPTED && err != GNUTLS_E_AGAIN
672 && err != GNUTLS_E_WARNING_ALERT_RECEIVED)
674 g_debug (
"[%d] gnutls_handshake: %s, %d", getpid (),
675 gnutls_strerror (err), err);
680 FD_SET (fp->
fd, &fdr);
682 FD_SET (fp->
fd, &fdw);
686 d = tictac + fp->
timeout - time (NULL);
695 if ((ret = select (fp->
fd + 1, &fdr, &fdw, NULL, &to)) <= 0)
698 while (ret < 0 && errno == EINTR);
722 g_message (
"%s: Socket %d is not stream", __func__, fd);
727 return gnutls_safe_renegotiation_status (fp->
tls_session);
747 g_message (
"%s: Socket %d is not stream", __func__, fd);
752 tictac = time (NULL);
760 g_debug (
"no error during handshake");
763 if (err != GNUTLS_E_INTERRUPTED && err != GNUTLS_E_AGAIN
764 && err != GNUTLS_E_WARNING_ALERT_RECEIVED)
766 g_debug (
"[%d] %s: %s", getpid (), __func__, gnutls_strerror (err));
769 else if (err == GNUTLS_E_WARNING_ALERT_RECEIVED)
774 g_debug (
"[%d] %s: %s", getpid (), __func__, gnutls_strerror (err));
776 g_debug (
"* Received alert '%d': %s.\n", last_alert,
777 gnutls_alert_get_name (last_alert));
781 FD_SET (fp->
fd, &fdr);
783 FD_SET (fp->
fd, &fdw);
787 d = tictac + fp->
timeout - time (NULL);
791 g_debug (
"%s: time out", __func__);
797 if ((ret = select (fp->
fd + 1, &fdr, &fdw, NULL, &to)) <= 0)
800 while (ret < 0 && errno == EINTR);
805 g_debug (
"%s: time out", __func__);
823 char *cert = NULL, *key = NULL, *passwd = NULL, *cafile = NULL;
828 static gboolean connection_failed_msg_sent = FALSE;
832 g_message (
"Socket %d is not stream", fd);
837 cert = kb_item_get_str (kb,
"SSL/cert");
838 key = kb_item_get_str (kb,
"SSL/key");
839 passwd = kb_item_get_str (kb,
"SSL/password");
840 cafile = kb_item_get_str (kb,
"SSL/CA");
841 snprintf (buf,
sizeof (buf),
"Host/SNI/%d/force_disable", fp->
port);
842 if (kb_item_get_int (kb, buf) <= 0)
855 if (!connection_failed_msg_sent)
857 g_message (
"Function socket_negotiate_ssl called from %s: "
858 "SSL/TLS connection (host: %s, ip: %s) failed.",
864 connection_failed_msg_sent = TRUE;
889 gnutls_session_t session;
890 const gnutls_datum_t *cert_list;
891 unsigned int cert_list_len = 0;
893 if (!cert || !certlen)
897 g_message (
"Socket %d is not stream", fd);
903 g_message (
"Socket %d is not SSL/TLS encapsulated", fd);
906 if (gnutls_certificate_type_get (session) != GNUTLS_CRT_X509)
908 cert_list = gnutls_certificate_get_peers (session, &cert_list_len);
909 if (cert_list_len == 0)
911 *certlen = cert_list[0].size;
912 *cert = g_memdup2 (cert_list[0].data, *certlen);
925 gnutls_session_t session;
926 gnutls_protocol_t version;
930 g_message (
"Socket %d is not stream", fd);
936 g_message (
"Socket %d is not SSL/TLS encapsulated", fd);
940 version = gnutls_protocol_get_version (session);
968 gnutls_session_t session;
970 *ssize = GNUTLS_MAX_SESSION_ID;
977 g_message (
"Socket %d is not stream", fd);
983 g_message (
"Socket %d is not SSL/TLS encapsulated", fd);
986 tmp = g_malloc0 (*ssize);
987 ret = gnutls_session_get_id (session, tmp, ssize);
988 if (ret == GNUTLS_E_SUCCESS)
994 tlserror (
"gnutls_session_id", ret);
1008 gnutls_session_t session;
1009 gnutls_kx_algorithm_t kx, kx2;
1010 gnutls_cipher_algorithm_t cipher, cipher2;
1011 gnutls_mac_algorithm_t
mac, mac2;
1013 unsigned char cs_id[2];
1017 g_message (
"Socket %d is not stream", fd);
1023 g_message (
"Socket %d is not SSL/TLS encapsulated", fd);
1027 kx = gnutls_kx_get (session);
1028 cipher = gnutls_cipher_get (session);
1029 mac = gnutls_mac_get (session);
1031 gnutls_cipher_suite_info (idx, (
void *) cs_id, &kx2, &cipher2, &mac2, NULL))
1033 if (kx == kx2 && cipher == cipher2 &&
mac == mac2)
1034 return cs_id[0] + cs_id[1];
1047 int transport,
int timeout,
const char *priority,
1054 char *passwd = NULL;
1055 char *cafile = NULL;
1057 char *hostname_aux = NULL;
1066 g_debug (
"[%d] open_stream_connection: TCP:%d transport:%d timeout:%d "
1068 getpid (), port, transport, timeout, priority);
1089 g_message (
"open_stream_connection_ext(): unsupported transport"
1090 " layer %d passed by %s",
1091 transport, args->
name);
1094 g_free (hostname_aux);
1100 g_free (hostname_aux);
1108 fp->
priority = g_strdup (priority);
1133 cert = kb_item_get_str (kb,
"SSL/cert");
1134 key = kb_item_get_str (kb,
"SSL/key");
1135 passwd = kb_item_get_str (kb,
"SSL/password");
1137 cafile = kb_item_get_str (kb,
"SSL/CA");
1143 snprintf (buf,
sizeof (buf),
"Host/SNI/%d/force_disable", fp->
port);
1144 if (kb_item_get_int (kb, buf) <= 0)
1158 g_free (hostname_aux);
1176 int transport,
int timeout)
1186 int timeout,
int force)
1234 int ret, realfd, trp, t, select_status;
1235 int total = 0, flag = 0, timeout =
TIMEOUT, waitall = 0;
1236 unsigned char *buf = (
unsigned char *) buf0;
1254 if (fd < 0 || fd > 1024)
1263#define INCR_TIMEOUT 1
1266 if (min_len == max_len || timeout <= 0)
1267 waitall = MSG_WAITALL;
1270 for (t = 0; total < max_len && (timeout <= 0 || t < timeout);)
1275 FD_SET (realfd, &fdr);
1276 if (select (realfd + 1, &fdr, NULL, NULL, timeout > 0 ? &tv : NULL)
1281 if (total > 0 && flag)
1283 else if (total >= min_len)
1289 ret = recv (realfd, buf + total, max_len - total, waitall);
1303 if (min_len > 0 && total >= min_len)
1322 if (getpid () != fp->
pid)
1324 g_debug (
"PID %d tries to use a SSL/TLS connection established "
1326 getpid (), fp->
pid);
1332 for (t = 0; timeout <= 0 || t < timeout; t = now - then)
1339 FD_SET (realfd, &fdr);
1340 FD_SET (realfd, &fdw);
1342 select_status = select (realfd + 1, &fdr, &fdw, NULL, &tv);
1344 if (select_status > 0)
1347 ret = gnutls_record_recv (fp->
tls_session, buf + total,
1352 if (total >= max_len)
1355 else if (ret != GNUTLS_E_INTERRUPTED && ret != GNUTLS_E_AGAIN)
1366 g_debug (
"gnutls_record_recv[%d]: EOF\n", getpid ());
1372 if (min_len > 0 && total >= min_len)
1381 g_message (
"Function %s (calling internal function %s) called from %s: "
1382 "Severe bug! Unhandled transport layer %d (fd=%d).",
1384 :
"script_main_function",
1387 g_message (
"read_stream_connection_unbuffered: "
1404 if (fp->
buf != NULL)
1413 memcpy (buf0, fp->
buf + fp->
bufptr, l2);
1422 if (l2 >= min_len || l2 >= max_len)
1427 if (min_len > fp->
bufsz)
1444 memcpy ((
char *) buf0 + l2, fp->
buf + fp->
bufptr, l1);
1466 unsigned char *buf = (
unsigned char *) buf0;
1474 g_debug (
"write_stream_connection: fd <%d> invalid\n", fd);
1485 for (count = 0; count < n;)
1487 ret = send (fp->
fd, buf + count, n - count, i_opt);
1512 for (count = 0; count < n;)
1514 ret = gnutls_record_send (fp->
tls_session, buf + count, n - count);
1520 else if (ret != GNUTLS_E_INTERRUPTED && ret != GNUTLS_E_AGAIN)
1530 g_debug (
"gnutls_record_send[%d]: EOF\n", getpid ());
1546 FD_SET (fp->
fd, &fdr);
1547 FD_SET (fp->
fd, &fdw);
1548 e = select (fp->
fd + 1, &fdr, &fdw, NULL, &tv);
1550 while (e < 0 && errno == EINTR);
1563 g_message (
"Function %s (calling internal function %s) called from %s: "
1564 "Severe bug! Unhandled transport layer %d (fd=%d).",
1566 :
"script_main_function",
1569 g_message (
"read_stream_connection_unbuffered: fd=%d is "
1576 if (count == 0 && n > 0)
1596 g_message (
"OpenVAS file descriptor %d closed ?!", fd);
1612 e = select (fd + 1, NULL, &wr, NULL, &tv);
1615 else if (e < 0 && errno == EINTR)
1620 while (n <= 0 && errno == EINTR);
1622 g_message (
"[%d] nsend():send %s", getpid (), strerror (errno));
1634 g_message (
"OpenVAS file descriptor %d closed ?!", fd);
1646 e = recv (fd, data,
length, i_opt);
1648 while (e < 0 && errno == EINTR);
1674 hook = g_malloc0 (
sizeof *hook);
1699 if (hook->
fnc && !hook->
fnc (fd))
1714 g_debug (
"close_stream_connection TCP:%d (fd=%d)", fp->
port, fd);
1718 if (fd < 0 || fd > 1024)
1735 static char str[100];
1759 snprintf (str,
sizeof (str),
"[unknown transport layer - code %d (0x%x)]",
1768 static char str[100];
1781 return " through SSL/TLS";
1783 snprintf (str,
sizeof (str),
1784 " through unknown transport layer - code %d (0x%x)",
code,
1798 unsigned int opt_sz;
1803 if (paddr->sa_family == AF_INET)
1806 if ((soc = socket (AF_INET, type,
protocol)) < 0)
1815 if ((soc = socket (AF_INET6, type,
protocol)) < 0)
1832 gvm_source_set_socket (soc, 0, family);
1834 if (connect (soc, paddr,
len) < 0)
1843 FD_SET (soc, &fd_w);
1844 to.tv_sec = timeout;
1846 x = select (soc + 1, NULL, &fd_w, NULL, &to);
1867 opt_sz =
sizeof (opt);
1868 if (getsockopt (soc, SOL_SOCKET, SO_ERROR, &opt, &opt_sz) < 0)
1893 struct sockaddr_in addr;
1894 struct sockaddr_in6 addr6;
1895 struct in6_addr in6addr;
1897 gvm_resolve_as_addr6 (
hostname, &in6addr);
1898 if (IN6_IS_ADDR_V4MAPPED (&in6addr))
1900 bzero ((
void *) &addr,
sizeof (addr));
1901 addr.sin_family = AF_INET;
1902 addr.sin_port = htons ((
unsigned short) port);
1903 addr.sin_addr.s_addr = in6addr.s6_addr32[3];
1905 sizeof (
struct sockaddr_in));
1909 bzero ((
void *) &addr6,
sizeof (addr6));
1910 addr6.sin6_family = AF_INET6;
1911 addr6.sin6_port = htons ((
unsigned short) port);
1912 memcpy (&addr6.sin6_addr, &in6addr, sizeof (
struct in6_addr));
1914 sizeof (
struct sockaddr_in6));
1922 const char *timeout_retry;
1924 timeout_retry = prefs_get (
"timeout_retry");
1926 retry = atoi (timeout_retry);
1934 if (ret >= 0 || errno != ETIMEDOUT)
1938 if (ret < 0 && errno == ETIMEDOUT)
1940 int log_count, attempts = 0;
1943 const char *max_attempts;
1945 max_attempts = prefs_get (
"open_sock_max_attempts");
1947 attempts = atoi (max_attempts);
1951 g_snprintf (buffer,
sizeof (buffer),
"ConnectTimeout/%s/%d", ip_str,
1953 log_count = kb_item_get_int (kb, buffer);
1954 if (log_count == -1)
1958 g_message (
"open_sock_tcp: %s:%d time-out.", ip_str, port);
1962 if ((log_count >= attempts) && (attempts != 0))
1969 char host_port_ip_str[INET6_ADDRSTRLEN];
1971 addr6_to_str (args->
ip, host_port_ip_str);
1972 g_snprintf (buffer,
sizeof (buffer),
"Ports/tcp/%d", port);
1973 g_message (
"open_sock_tcp: %s:%d too many timeouts. "
1974 "This port will be set to closed.",
1975 host_port_ip_str, port);
1979 buffer,
sizeof (buffer),
1980 "ERRMSG|||%s|||%s|||%d/tcp||| |||Too many timeouts. The port"
1981 " was set to closed.",
1986 "internal/results", buffer);
1999 struct sockaddr_in addr;
2000 struct sockaddr_in6 addr6;
2006 g_message (
"ERROR ! NO ADDRESS ASSOCIATED WITH NAME");
2009 if (IN6_ARE_ADDR_EQUAL (t, &in6addr_any))
2011 if (IN6_IS_ADDR_V4MAPPED (t))
2013 bzero ((
void *) &addr,
sizeof (addr));
2014 addr.sin_family = AF_INET;
2015 addr.sin_port = htons ((
unsigned short) port);
2016 addr.sin_addr.s_addr = t->s6_addr32[3];
2018 sizeof (
struct sockaddr_in));
2022 bzero ((
void *) &addr6,
sizeof (addr6));
2023 addr6.sin6_family = AF_INET6;
2024 addr6.sin6_port = htons ((
unsigned short) port);
2025 memcpy (&addr6.sin6_addr, t, sizeof (
struct in6_addr));
2027 sizeof (
struct sockaddr_in6));
2043 unsigned int ret = 0;
2070 while (buf[ret - 1] !=
'\0' && buf[ret - 1] !=
'\n' && ret < bufsiz);
2074 if (buf[ret - 1] !=
'\0')
2079 buf[bufsiz - 1] =
'\0';
2096 e = select (soc + 1, &rd, NULL, NULL, NULL);
2097 if (e == 0 && !FD_ISSET (soc, &rd))
2099 if (e < 0 && errno == EINTR)
2103 n = recv (soc, buf + ret, 1, 0);
2124 while (buf[ret - 1] !=
'\0' && buf[ret - 1] !=
'\n' && ret < bufsiz);
2128 if (buf[ret - 1] !=
'\0')
2133 buf[bufsiz - 1] =
'\0';
2187 else if (p->
buf == 0)
2189 p->
buf = g_malloc0 (sz);
2204 b = g_realloc (p->
buf, sz);
2218 char *buf0 = (
char *) buf;
2220 for (n = 0; n <
len;)
2223 e = send (soc, buf0 + n,
len - n, opt);
2224 if (e < 0 && errno == EINTR)
2237 char *buf0 = (
char *) buf;
2239 for (n = 0; n <
len;)
2242 e = recv (soc, buf0 + n,
len - n, opt);
2243 if (e < 0 && errno == EINTR)
2276 u_short *aa = (u_short *) a;
2277 u_short *bb = (u_short *) b;
2300 unsigned short *tmp, *ports;
2301 int i = 0, j = 0, start, end;
2304 char *s_start, *s_end;
2305 static unsigned short *last_ret = NULL;
2306 static char *last_expr = NULL;
2307 static int last_num;
2309 expr = g_strdup (origexpr);
2310 exlen = strlen (origexpr);
2313 if (last_expr != NULL)
2315 if (strcmp (last_expr, expr) == 0)
2331 ports = g_malloc0 (65536 *
sizeof (
short));
2332 for (; j < exlen; j++)
2334 expr[i++] = expr[j];
2337 if ((s_start = strstr (expr,
"T:")) != NULL)
2338 expr = &(s_start[2]);
2340 if ((s_end = strstr (expr,
"U:")) != NULL)
2342 if (s_end[-1] ==
',')
2348 while ((p = strchr (expr,
',')))
2354 end = atoi (expr + 1);
2358 start = end = atoi (expr);
2359 if ((q = strchr (expr,
'-')) && *(q + 1))
2361 else if (q && !*(q + 1))
2372 for (j = start; j <= end; j++)
2379 end = atoi (expr + 1);
2383 start = end = atoi (expr);
2384 if ((q = strchr (expr,
'-')) && *(q + 1))
2386 else if (q && !*(q + 1))
2397 for (j = start; j <= end; j++)
2402 tmp = g_realloc (ports, i *
sizeof (
short));
2408 last_expr = g_strdup (origexpr);
kb_t get_main_kb(void)
gets the main_kb. @description returns the previously set main_kb; when asserts are enabled it will a...
Header file to cache main_kb.
static struct timeval timeval(unsigned long val)
gpg_err_code_t mac(const char *key, const size_t key_len, const char *data, const size_t data_len, const char *iv, const size_t iv_len, int algo, int flags, char **out, size_t *out_len)
const char * nasl_get_plugin_filename()
Get the current launched plugin filename.
const char * nasl_get_function_name()
static int pid_perror(const char *error)
static int open_socket(struct sockaddr *paddr, int type, int protocol, int timeout, int len)
static int write_stream_connection4(int fd, void *buf0, int n, int i_opt)
int open_sock_opt_hn(const char *hostname, unsigned int port, int type, int protocol, int timeout)
const char * get_encaps_through(openvas_encaps_t code)
int stream_get_err(int fd)
int openvas_get_socket_from_connection(int fd)
int stream_set_buffer(int fd, int sz)
void socket_get_ssl_session_id(int fd, void **sid, size_t *ssize)
int nsend(int fd, void *data, int length, int i_opt)
static int is_ip_address(const char *str)
int socket_negotiate_ssl(int fd, openvas_encaps_t transport, struct script_infos *args)
Upgrade an ENCAPS_IP socket to an SSL/TLS encapsulated one.
int read_stream_connection_min(int fd, void *buf0, int min_len, int max_len)
unsigned short * getpts(char *origexpr, int *len)
Converts a string like "-100,200-1024,3000-4000,60000-" into an array.
int socket_ssl_do_handshake(int fd)
Do a re-handshake of the TLS/SSL protocol.
int open_stream_connection_ext(struct script_infos *args, unsigned int port, int transport, int timeout, const char *priority, int flags)
int openvas_register_connection(int soc, void *ssl, gnutls_certificate_credentials_t certcred, openvas_encaps_t encaps)
static int load_cert_and_key(gnutls_certificate_credentials_t xcred, const char *cert, const char *key, const char *passwd)
Loads a certificate and the corresponding private key from PEM files.
#define OPENVAS_STREAM(x)
static int qsort_compar(const void *a, const void *b)
gnutls_session_t ovas_get_tlssession_from_connection(int fd)
static int get_connection_fd(void)
Returns a free file descriptor.
int socket_get_ssl_version(int fd)
int socket_close(int soc)
static int run_csc_hooks(int fd)
Run the hooks for close_stream_connection.
static int read_stream_connection_unbuffered(int fd, void *buf0, int min_len, int max_len)
static int release_connection_fd(int fd, int already_closed)
int read_stream_connection(int fd, void *buf0, int len)
int nrecv(int fd, void *data, int length, int i_opt)
void open_stream_tls_default_priorities(const char *p, const int pflag)
int get_sock_infos(int sock, int *r_transport, void **r_tls_session)
int open_sock_tcp(struct script_infos *args, unsigned int port, int timeout)
int os_send(int soc, void *buf, int len, int opt)
static int unblock_socket(int soc)
static void tlserror(char *txt, int err)
static void log_message_gnutls(int level, const char *msg)
int write_stream_connection(int fd, void *buf0, int n)
int socket_get_ssl_ciphersuite(int fd)
static int block_socket(int soc)
static struct csc_hook_s * csc_hooks
Linked list of hooks to be run by close_stream_connection.
static int open_SSL_connection(openvas_connection *fp, const char *cert, const char *key, const char *passwd, const char *cafile, const char *hostname, unsigned int flags)
Open an TLS/SSL connection.
int os_recv(int soc, void *buf, int len, int opt)
int open_sock_option(struct script_infos *args, unsigned int port, int type, int protocol, int timeout)
int openvas_SSL_init()
Initializes SSL support.
int open_stream_connection(struct script_infos *args, unsigned int port, int transport, int timeout)
#define OVAS_CONNECTION_FROM_FD(fd)
void socket_get_cert(int fd, void **cert, int *certlen)
const char * tls_priorities
void add_close_stream_connection_hook(int(*fnc)(int fd))
Register a hook function for close_stream_connection.
int openvas_deregister_connection(int fd)
int socket_ssl_safe_renegotiation_status(int fd)
Check if Secure Renegotiation is supported in the server side.
const char * get_encaps_name(openvas_encaps_t code)
int recv_line(int soc, char *buf, size_t bufsiz)
Reads a text from the socket stream into the argument buffer, always.
int stream_set_timeout(int fd, int timeout)
int open_stream_auto_encaps_ext(struct script_infos *args, unsigned int port, int timeout, int force)
static openvas_connection connections[OPENVAS_FD_MAX]
int stream_get_buffer_sz(int fd)
static int set_gnutls_protocol(gnutls_session_t session, openvas_encaps_t encaps, const char *priority, unsigned int flags)
int close_stream_connection(int fd)
Header file for module network.
@ OPENVAS_ENCAPS_TLScustom
enum openvas_encaps openvas_encaps_t
#define INSECURE_DH_PRIME_BITS
#define NO_PRIORITY_FLAGS
int host_get_port_state(struct script_infos *plugdata, int portnum)
int plug_get_port_transport(struct script_infos *args, int port)
const char * plug_current_vhost(void)
void plug_set_port_transport(struct script_infos *args, int port, int tr)
char * plug_get_host_fqdn(struct script_infos *args)
int kb_item_push_str_with_main_kb_check(kb_t kb, const char *name, const char *value)
Check if the current kb corresponds to the original scanid, if it matches it kb_item_push_str....
char * plug_get_host_ip_str(struct script_infos *desc)
struct in6_addr * plug_get_host_ip(struct script_infos *args)
int kb_item_set_int_with_main_kb_check(kb_t kb, const char *name, int value)
Check if the current kb corresponds to the original scanid, if it matches it call kb_item_set_int....
kb_t plug_get_kb(struct script_infos *args)
Header file for module plugutils.
Object to store a list of hooks for close_stream_connection.
gnutls_session_t tls_session
openvas_encaps_t transport
gnutls_certificate_credentials_t tls_cred
Support macros for special platforms.