NCBI C++ ToolKit
Classes | Macros | Functions | Variables
ncbi_mbedtls.c File Reference
#include "ncbi_ansi_ext.h"
#include "ncbi_connssl.h"
#include "ncbi_priv.h"
#include "ncbi_servicep.h"
#include <connect/ncbi_mbedtls.h>
#include <connect/ncbi_tls.h>
#include <stdlib.h>
#include <mbedtls/ctr_drbg.h>
#include <mbedtls/debug.h>
#include <mbedtls/entropy.h>
#include <mbedtls/error.h>
#include <mbedtls/pk.h>
#include <mbedtls/net_sockets.h>
#include <mbedtls/ssl.h>
#include <mbedtls/threading.h>
#include <mbedtls/version.h>
#include <psa/crypto.h>
+ Include dependency graph for ncbi_mbedtls.c:

Go to the source code of this file.

Go to the SVN repository for this file.

Classes

struct  SNcbiMbedTlsCred
 

Macros

#define NCBI_USE_ERRCODE_X   Connect_TLS
 
#define NCBI_NOTSUPPORTED   EINVAL
 
#define ALIGN2(s, a)   ((((s) + ((a) - 1)) / (a)) * (a))
 
#define ALIGN(s)   ALIGN2(s, sizeof(double))
 

Functions

static EIO_Status s_MbedTlsInit (FSSLPull pull, FSSLPush push)
 
static void * s_MbedTlsCreate (ESOCK_Side side, SNcbiSSLctx *ctx, int *error)
 
static EIO_Status s_MbedTlsOpen (void *session, int *error, char **desc)
 
static EIO_Status s_MbedTlsRead (void *session, void *buf, size_t size, size_t *done, int *error)
 
static EIO_Status s_MbedTlsWrite (void *session, const void *data, size_t size, size_t *done, int *error)
 
static EIO_Status s_MbedTlsClose (void *session, int how, int *error)
 
static void s_MbedTlsDelete (void *session)
 
static void s_MbedTlsExit (void)
 
static const char * s_MbedTlsError (void *session, int error, char *buf, size_t size)
 
static void x_MbedTlsLogger (void *data, int level, const char *file, int line, const char *message)
 
static int x_MbedTlsPull (void *, unsigned char *, size_t)
 
static int x_MbedTlsPush (void *, const unsigned char *, size_t)
 
static EIO_Status x_RetryStatus (SOCK sock, EIO_Event direction)
 
static EIO_Status x_ErrorToStatus (int error, mbedtls_ssl_context *session, EIO_Event direction)
 
static int x_StatusToError (EIO_Status status, SOCK sock, EIO_Event direction)
 
static int x_IfToLog (void)
 
static EIO_Status x_MbedTlsWrite (void *session, const void *data, size_t n_todo, size_t *n_done, int *error)
 
static EIO_Status x_InitLocking (void)
 
static void x_MbedTlsExit (void)
 
SOCKSSL NcbiSetupMbedTls (void)
 Explicitly setup mbedTLS library to support SSL in ncbi_socket.h[pp]. More...
 
NCBI_CRED NcbiCredMbedTls (void *xcert, void *xpkey)
 Convert native mbedTLS certificate credentials' handles into an abstract toolkit handle. More...
 
void NcbiDeleteMbedTlsCertCredentials (NCBI_CRED cred)
 
NCBI_CRED NcbiCreateMbedTlsCertCredentials (const void *cert, size_t certsz, const void *pkey, size_t pkeysz)
 

Variables

static volatile int s_MbedTlsLogLevel
 
static mbedtls_entropy_context s_MbedTlsEntropy
 
static mbedtls_ctr_drbg_context s_MbedTlsCtrDrbg
 
static mbedtls_ssl_config s_MbedTlsConf
 
static volatile FSSLPull s_Pull
 
static volatile FSSLPush s_Push
 

Macro Definition Documentation

◆ ALIGN

#define ALIGN (   s)    ALIGN2(s, sizeof(double))

Definition at line 879 of file ncbi_mbedtls.c.

◆ ALIGN2

#define ALIGN2 (   s,
  a 
)    ((((s) + ((a) - 1)) / (a)) * (a))

Definition at line 878 of file ncbi_mbedtls.c.

◆ NCBI_NOTSUPPORTED

#define NCBI_NOTSUPPORTED   EINVAL

Definition at line 62 of file ncbi_mbedtls.c.

◆ NCBI_USE_ERRCODE_X

#define NCBI_USE_ERRCODE_X   Connect_TLS

Definition at line 41 of file ncbi_mbedtls.c.

Function Documentation

◆ NcbiCreateMbedTlsCertCredentials()

NCBI_CRED NcbiCreateMbedTlsCertCredentials ( const void *  cert,
size_t  certsz,
const void *  pkey,
size_t  pkeysz 
)

◆ NcbiDeleteMbedTlsCertCredentials()

void NcbiDeleteMbedTlsCertCredentials ( NCBI_CRED  cred)

◆ s_MbedTlsClose()

static EIO_Status s_MbedTlsClose ( void *  session,
int  how,
int error 
)
static

◆ s_MbedTlsCreate()

static void * s_MbedTlsCreate ( ESOCK_Side  side,
SNcbiSSLctx ctx,
int error 
)
static

◆ s_MbedTlsDelete()

static void s_MbedTlsDelete ( void *  session)
static

Definition at line 648 of file ncbi_mbedtls.c.

References assert, CORE_DEBUG_ARG, CORE_TRACEF, free(), mbedtls_ssl_free(), and s_MbedTlsLogLevel.

Referenced by NcbiSetupMbedTls().

◆ s_MbedTlsError()

static const char * s_MbedTlsError ( void *  session,
int  error,
char *  buf,
size_t  size 
)
static

Definition at line 836 of file ncbi_mbedtls.c.

References buf, mbedtls_strerror(), and ncbi::grid::netcache::search::fields::size.

Referenced by NcbiSetupMbedTls().

◆ s_MbedTlsExit()

static void s_MbedTlsExit ( void  )
static

Definition at line 825 of file ncbi_mbedtls.c.

References CORE_DEBUG_ARG, CORE_TRACE, s_MbedTlsLogLevel, and x_MbedTlsExit().

Referenced by NcbiSetupMbedTls().

◆ s_MbedTlsInit()

static EIO_Status s_MbedTlsInit ( FSSLPull  pull,
FSSLPush  push 
)
static

◆ s_MbedTlsOpen()

static EIO_Status s_MbedTlsOpen ( void *  session,
int error,
char **  desc 
)
static

◆ s_MbedTlsRead()

static EIO_Status s_MbedTlsRead ( void *  session,
void *  buf,
size_t  size,
size_t *  done,
int error 
)
static

Definition at line 546 of file ncbi_mbedtls.c.

References assert, buf, eIO_Read, eIO_Success, mbedtls_ssl_read(), and x_ErrorToStatus().

Referenced by NcbiSetupMbedTls().

◆ s_MbedTlsWrite()

static EIO_Status s_MbedTlsWrite ( void *  session,
const void *  data,
size_t  size,
size_t *  done,
int error 
)
static

◆ x_ErrorToStatus()

static EIO_Status x_ErrorToStatus ( int  error,
mbedtls_ssl_context session,
EIO_Event  direction 
)
static

◆ x_IfToLog()

static int x_IfToLog ( void  )
static

Definition at line 487 of file ncbi_mbedtls.c.

References s_MbedTlsLogLevel.

Referenced by x_MbedTlsPull(), and x_MbedTlsPush().

◆ x_InitLocking()

static EIO_Status x_InitLocking ( void  )
static

◆ x_MbedTlsExit()

static void x_MbedTlsExit ( void  )
static

◆ x_MbedTlsLogger()

static void x_MbedTlsLogger ( void *  data,
int  level,
const char *  file,
int  line,
const char *  message 
)
static

Definition at line 180 of file ncbi_mbedtls.c.

References CORE_LOGF_X, eLOG_Note, and len.

Referenced by s_MbedTlsInit().

◆ x_MbedTlsPull()

static int x_MbedTlsPull ( void *  ctx,
unsigned char *  buf,
size_t  size 
)
static

◆ x_MbedTlsPush()

static int x_MbedTlsPush ( void *  ctx,
const unsigned char *  data,
size_t  size 
)
static

◆ x_MbedTlsWrite()

static EIO_Status x_MbedTlsWrite ( void *  session,
const void *  data,
size_t  n_todo,
size_t *  n_done,
int error 
)
static

Definition at line 571 of file ncbi_mbedtls.c.

References assert, data, eIO_Success, eIO_Write, mbedtls_ssl_write(), and x_ErrorToStatus().

Referenced by s_MbedTlsWrite().

◆ x_RetryStatus()

static EIO_Status x_RetryStatus ( SOCK  sock,
EIO_Event  direction 
)
static

Definition at line 198 of file ncbi_mbedtls.c.

References eIO_Open, eIO_Read, eIO_Success, eIO_Timeout, eIO_Write, and SOCK_Status().

Referenced by x_ErrorToStatus().

◆ x_StatusToError()

static int x_StatusToError ( EIO_Status  status,
SOCK  sock,
EIO_Event  direction 
)
static

Variable Documentation

◆ s_MbedTlsConf

mbedtls_ssl_config s_MbedTlsConf
static

Definition at line 174 of file ncbi_mbedtls.c.

Referenced by s_MbedTlsCreate(), s_MbedTlsInit(), and x_MbedTlsExit().

◆ s_MbedTlsCtrDrbg

mbedtls_ctr_drbg_context s_MbedTlsCtrDrbg
static

Definition at line 173 of file ncbi_mbedtls.c.

Referenced by NcbiCreateMbedTlsCertCredentials(), s_MbedTlsInit(), and x_MbedTlsExit().

◆ s_MbedTlsEntropy

mbedtls_entropy_context s_MbedTlsEntropy
static

Definition at line 172 of file ncbi_mbedtls.c.

Referenced by s_MbedTlsInit(), and x_MbedTlsExit().

◆ s_MbedTlsLogLevel

volatile int s_MbedTlsLogLevel
static

◆ s_Pull

volatile FSSLPull s_Pull
static

Definition at line 175 of file ncbi_mbedtls.c.

Referenced by s_MbedTlsInit(), x_MbedTlsExit(), and x_MbedTlsPull().

◆ s_Push

volatile FSSLPush s_Push
static

Definition at line 176 of file ncbi_mbedtls.c.

Referenced by s_MbedTlsInit(), x_MbedTlsExit(), and x_MbedTlsPush().

Modified on Thu May 30 12:23:56 2024 by modify_doxy.py rev. 669887