Greenbone Vulnerability Management Libraries: util/serverutils.h File Reference

Greenbone Vulnerability Management Libraries 23.1.1

Data Structures | Functions
serverutils.h File Reference

GnuTLS based functions for server communication - header file. More...

`#include <glib.h>`
`#include <gnutls/gnutls.h>`
`#include <stdarg.h>`
`#include <sys/param.h>`
`#include <netinet/ip.h>`

Go to the source code of this file.

## Data Structures
struct | gvm_connection_t
| Connection. More...

## Functions
void | gvm_connection_free (gvm_connection_t *)
| Free connection.
void | gvm_connection_close (gvm_connection_t *)
| Close a server connection and its socket.
int | gvm_server_verify (gnutls_session_t)
| Verify certificate.
int | gvm_server_open (gnutls_session_t *, const char *, int)
| Connect to the server using a given host and port.
int | gvm_server_open_verify (gnutls_session_t *, const char *, int, const char *, const char *, const char *, int)
| Connect to the server using a given host, port and cert.
int | gvm_server_open_with_cert (gnutls_session_t *, const char *, int, const char *, const char *, const char *)
| Connect to the server using a given host, port and cert.
int | gvm_server_close (int, gnutls_session_t)
| Close a server connection and its socket.
int | gvm_server_attach (int, gnutls_session_t *)
| Attach a socket to a session, and shake hands with the peer.
int | gvm_server_sendf (gnutls_session_t *, const char *,...) __attribute__((format(printf
int int | gvm_server_vsendf (gnutls_session_t *, const char *, va_list)
| Send a string to the server.
int | gvm_socket_vsendf (int, const char *, va_list)
| Send a string to the server.
int | gvm_server_sendf_xml (gnutls_session_t *, const char *,...)
| Format and send an XML string to the server.
int | gvm_server_sendf_xml_quiet (gnutls_session_t *, const char *,...)
| Format and send an XML string to the server.
int | gvm_connection_sendf_xml (gvm_connection_t *, const char *,...)
| Format and send an XML string to the server.
int | gvm_connection_sendf_xml_quiet (gvm_connection_t *, const char *,...)
| Format and send an XML string to the server.
int | gvm_connection_sendf (gvm_connection_t *, const char *,...)
| Format and send a string to the server.
int | gvm_server_new (unsigned int, gchar *, gchar *, gchar *, gnutls_session_t *, gnutls_certificate_credentials_t *)
| Make a session for connecting to a server.
int | gvm_server_new_mem (unsigned int, const char *, const char *, const char *, gnutls_session_t *, gnutls_certificate_credentials_t *)
| Make a session for connecting to a server, with certificates stored in memory.
int | gvm_server_free (int, gnutls_session_t, gnutls_certificate_credentials_t)
| Cleanup a server session.
int | gvm_server_session_free (gnutls_session_t, gnutls_certificate_credentials_t)
int | load_gnutls_file (const char *, gnutls_datum_t *)
| Loads a file's data into gnutls_datum_t struct.
void | unload_gnutls_file (gnutls_datum_t *)
| Unloads a gnutls_datum_t struct's data.
int | set_gnutls_dhparams (gnutls_certificate_credentials_t, const char *)
| Set a gnutls session's Diffie-Hellman parameters.

## Detailed Description

GnuTLS based functions for server communication - header file.

This module supplies low-level communication functions for communication with a server over GnuTLS.

## Function Documentation

## ◆ gvm_connection_close()

void gvm_connection_close | ( | gvm_connection_t * | connection | ) |

Close a server connection and its socket.

Parameters

  [in] | connection | Connection.

## ◆ gvm_connection_free()

void gvm_connection_free | ( | gvm_connection_t * | client_connection | ) |

Free connection.

Parameters

  [in] | client_connection | Connection.

## ◆ gvm_connection_sendf()

int gvm_connection_sendf | ( | gvm_connection_t * | connection,
|  | const char * | format,
|  |  | ... )

Format and send a string to the server.

Parameters

  [in] | connection | Connection.
  [in] | format | printf-style format string for message.

Returns
  0 on success, -1 on error.

## ◆ gvm_connection_sendf_xml()

int gvm_connection_sendf_xml | ( | gvm_connection_t * | connection,
|  | const char * | format,
|  |  | ... )

Format and send an XML string to the server.

Escape XML in string and character args.

Parameters

  [in] | connection | Connection.
  [in] | format | printf-style format string for message.

Returns
  0 on success, -1 on error.

## ◆ gvm_connection_sendf_xml_quiet()

int gvm_connection_sendf_xml_quiet | ( | gvm_connection_t * | connection,
|  | const char * | format,
|  |  | ... )

Format and send an XML string to the server.

Escape XML in string and character args.

Quiet version, only logs warnings.

Parameters

  [in] | connection | Connection.
  [in] | format | printf-style format string for message.

Returns
  0 on success, -1 on error.

## ◆ gvm_server_attach()

int gvm_server_attach | ( | int | socket,
|  | gnutls_session_t * | session )

Attach a socket to a session, and shake hands with the peer.

Parameters

  [in] | socket | Socket.
  [in] | session | Pointer to GNUTLS session. FIXME: Why is this a pointer to a session?

Returns
  0 on success, -1 on error.

## ◆ gvm_server_close()

int gvm_server_close | ( | int | socket,
|  | gnutls_session_t | session )

Close a server connection and its socket.

Parameters

  [in] | socket | Socket connected to server.
  [in] | session | GNUTLS session with server.

Returns
  0 on success, -1 on error.

## ◆ gvm_server_free()

int gvm_server_free | ( | int | server_socket,
|  | gnutls_session_t | server_session,
|  | gnutls_certificate_credentials_t | server_credentials )

Cleanup a server session.

This shuts down the TLS session, closes the socket and releases the TLS resources.

Parameters

  [in] | server_socket | The socket connected to the server.
  [in] | server_session | The session with the server.
  [in] | server_credentials | Credentials or NULL.

Returns
  0 success, -1 error.

## ◆ gvm_server_new()

int gvm_server_new | ( | unsigned int | end_type,
|  | gchar * | ca_cert_file,
|  | gchar * | cert_file,
|  | gchar * | key_file,
|  | gnutls_session_t * | server_session,
|  | gnutls_certificate_credentials_t * | server_credentials )

Make a session for connecting to a server.

Parameters

  [in] | end_type | Connection end type (GNUTLS_SERVER or GNUTLS_CLIENT).
  [in] | ca_cert_file | Certificate authority file.
  [in] | cert_file | Certificate file.
  [in] | key_file | Key file.
  [out] | server_session | The session with the server.
  [out] | server_credentials | Server credentials.

Returns
  0 on success, -1 on error.

## ◆ gvm_server_new_mem()

int gvm_server_new_mem | ( | unsigned int | end_type,
|  | const char * | ca_cert,
|  | const char * | pub_key,
|  | const char * | priv_key,
|  | gnutls_session_t * | session,
|  | gnutls_certificate_credentials_t * | credentials )

Make a session for connecting to a server, with certificates stored in memory.

Parameters

  [in] | end_type | Connection end type: GNUTLS_SERVER or GNUTLS_CLIENT.
  [in] | ca_cert | Certificate authority public key.
  [in] | pub_key | Public key.
  [in] | priv_key | Private key.
  [out] | session | The session with the server.
  [out] | credentials | Server credentials.

Returns
  0 on success, -1 on error.

## ◆ gvm_server_open()

int gvm_server_open | ( | gnutls_session_t * | session,
|  | const char * | host,
|  | int | port )

Connect to the server using a given host and port.

Parameters

  [in] | session | Pointer to GNUTLS session.
  [in] | host | Host to connect to.
  [in] | port | Port to connect to.

Returns
  0 on success, -1 on error.

## ◆ gvm_server_open_verify()

int gvm_server_open_verify | ( | gnutls_session_t * | session,
|  | const char * | host,
|  | int | port,
|  | const char * | ca_mem,
|  | const char * | pub_mem,
|  | const char * | priv_mem,
|  | int | verify )

Connect to the server using a given host, port and cert.

Parameters

  [in] | session | Pointer to GNUTLS session.
  [in] | host | Host to connect to.
  [in] | port | Port to connect to.
  [in] | ca_mem | CA cert.
  [in] | pub_mem | Public key.
  [in] | priv_mem | Private key.
  [in] | verify | Whether to verify.

Returns
  0 on success, -1 on error.

Warning
  On success we are leaking the credentials. We can't free them because the session only makes a shallow copy.

## ◆ gvm_server_open_with_cert()

int gvm_server_open_with_cert | ( | gnutls_session_t * | session,
|  | const char * | host,
|  | int | port,
|  | const char * | ca_mem,
|  | const char * | pub_mem,
|  | const char * | priv_mem )

Connect to the server using a given host, port and cert.

Verify if all cert args are given.

Parameters

  [in] | session | Pointer to GNUTLS session.
  [in] | host | Host to connect to.
  [in] | port | Port to connect to.
  [in] | ca_mem | CA cert.
  [in] | pub_mem | Public key.
  [in] | priv_mem | Private key.

Returns
  0 on success, -1 on error.

## ◆ gvm_server_sendf()

int gvm_server_sendf | ( | gnutls_session_t * | ,
|  | const char * | ,
|  |  | ... )

## ◆ gvm_server_sendf_xml()

int gvm_server_sendf_xml | ( | gnutls_session_t * | session,
|  | const char * | format,
|  |  | ... )

Format and send an XML string to the server.

Escape XML in string and character args.

Parameters

  [in] | session | Pointer to GNUTLS session.
  [in] | format | printf-style format string for message.

Returns
  0 on success, -1 on error.

## ◆ gvm_server_sendf_xml_quiet()

int gvm_server_sendf_xml_quiet | ( | gnutls_session_t * | session,
|  | const char * | format,
|  |  | ... )

Format and send an XML string to the server.

Escape XML in string and character args.

Quiet version, only logs warnings.

Parameters

  [in] | session | Pointer to GNUTLS session.
  [in] | format | printf-style format string for message.

Returns
  0 on success, -1 on error.

## ◆ gvm_server_session_free()

int gvm_server_session_free | ( | gnutls_session_t | ,
|  | gnutls_certificate_credentials_t | )

## ◆ gvm_server_verify()

int gvm_server_verify | ( | gnutls_session_t | session | ) |

Verify certificate.

Parameters

  [in] | session | Pointer to GNUTLS session.

Returns
  0 on success, 1 on failure, -1 on error.

## ◆ gvm_server_vsendf()

int int gvm_server_vsendf | ( | gnutls_session_t * | session,
|  | const char * | fmt,
|  | va_list | ap )

Send a string to the server.

Parameters

  [in] | session | Pointer to GNUTLS session.
  [in] | fmt | Format of string to send.
  [in] | ap | Args for fmt.

Returns
  0 on success, 1 if server closed connection, -1 on error.

## ◆ gvm_socket_vsendf()

int gvm_socket_vsendf | ( | int | socket,
|  | const char * | fmt,
|  | va_list | ap )

Send a string to the server.

Parameters

  [in] | socket | Socket to send string through.
  [in] | fmt | Format of string to send.
  [in] | ap | Args for fmt.

Returns
  0 on success, 1 if server closed connection, -1 on error.

## ◆ load_gnutls_file()

int load_gnutls_file | ( | const char * | file,
|  | gnutls_datum_t * | loaded_file )

Loads a file's data into gnutls_datum_t struct.

Parameters

  [in] | file | File to load.
  [out] | loaded_file | Destination to load file into.

Returns
  0 if success, -1 if error.

## ◆ set_gnutls_dhparams()

int set_gnutls_dhparams | ( | gnutls_certificate_credentials_t | creds,
|  | const char * | dhparams_file )

Set a gnutls session's Diffie-Hellman parameters.

Parameters

  [in] | creds | GnuTLS credentials.
  [in] | dhparams_file | Path to PEM file containing the DH parameters.

Returns
  0 on success, -1 on error.

## ◆ unload_gnutls_file()

void unload_gnutls_file | ( | gnutls_datum_t * | data | ) |

Unloads a gnutls_datum_t struct's data.

Parameters

  [in] | data | Pointer to gnutls_datum_t struct to be unloaded.