NCBI C++ ToolKit
ncbi_mbedtls.c
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: ncbi_mbedtls.c 103129 2024-09-11 23:45:43Z lavr $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Author: Anton Lavrentiev
27  *
28  * File Description:
29  * MBEDTLS support for SSL in connection library
30  *
31  */
32 
33 #include "ncbi_ansi_ext.h"
34 #include "ncbi_connssl.h"
35 #include "ncbi_priv.h"
36 #include "ncbi_servicep.h"
37 #include <connect/ncbi_mbedtls.h>
38 #include <connect/ncbi_tls.h>
39 #include <stdlib.h>
40 
41 #define NCBI_USE_ERRCODE_X Connect_TLS
42 
43 
44 #if defined(HAVE_LIBMBEDTLS) || defined(NCBI_CXX_TOOLKIT)
45 
46 # include <mbedtls/ctr_drbg.h>
47 # include <mbedtls/debug.h>
48 # include <mbedtls/entropy.h>
49 # include <mbedtls/error.h>
50 # include <mbedtls/pk.h>
51 # include <mbedtls/net_sockets.h>
52 # include <mbedtls/ssl.h>
53 # include <mbedtls/threading.h>
54 # include <mbedtls/version.h>
55 # ifdef MBEDTLS_PSA_CRYPTO_C
56 # include <psa/crypto.h>
57 # endif /*MBEDTLS_PSA_CRYPTO_C*/
58 
59 # if defined(ENOTSUP)
60 # define NCBI_NOTSUPPORTED ENOTSUP
61 # elif defined(ENOSYS)
62 # define NCBI_NOTSUPPORTED ENOSYS
63 # else
64 # define NCBI_NOTSUPPORTED EINVAL
65 # endif
66 
67 #else
68 
69 # define mbedtls_x509_crt void
70 # define mbedtls_pk_context void
71 
72 #endif /*HAVE_LIBMBEDTLS || NCBI_CXX_TOOLKIT*/
73 
74 
78 };
79 
80 
81 #if defined(HAVE_LIBMBEDTLS) || defined(NCBI_CXX_TOOLKIT)
82 
83 # if defined(MBEDTLS_THREADING_ALT) && defined(NCBI_THREADS)
84 # ifdef MBEDTLS_THREADING_PTHREAD
85 # error "MBEDTLS_THREADING_ALT and MBEDTLS_THREADING_PTHREAD conflict"
86 # endif /*MBEDTLS_THREADING_PTHREAD*/
87 static void mbtls_user_mutex_init(MT_LOCK* lock)
88 {
90 }
91 static void mbtls_user_mutex_deinit(MT_LOCK* lock)
92 {
93  if (*lock) {
94  if (!(*lock = MT_LOCK_Delete(*lock))) {
95  /* NB: Do not use CORE_SetLOCK() here! */
96  g_CORE_MT_Lock = 0;
97  } else
98  *lock = 0;
99  } else
100  CORE_LOG_X(20, eLOG_Warning, "NULL MT_LOCK deinit in MBEDTLS");
101 }
102 static int mbtls_user_mutex_lock(MT_LOCK* lock)
103 {
104  if (lock) {
105  switch (MT_LOCK_Do(*lock, eMT_Lock)) {
106  case -1:
107 #ifdef MBEDTLS_ERR_THREADING_FEATURE_UNAVAILABLE
108  return MBEDTLS_ERR_THREADING_FEATURE_UNAVAILABLE;
109 #else
111 #endif
112  case 0:
114  case 1:
115  return 0;
116  default:
117  break;
118  }
119  }
121 }
122 static int mbtls_user_mutex_unlock(MT_LOCK* lock)
123 {
124  if (lock) {
125  switch (MT_LOCK_Do(*lock, eMT_Unlock)) {
126  case -1:
127 #ifdef MBEDTLS_ERR_THREADING_FEATURE_UNAVAILABLE
128  return MBEDTLS_ERR_THREADING_FEATURE_UNAVAILABLE;
129 #else
131 #endif
132  case 0:
134  case 1:
135  return 0;
136  default:
137  break;
138  }
139  }
141 }
142 # endif /*MBEDTLS_THREADING_ALT && NCBI_THREADS*/
143 
144 # ifdef __cplusplus
145 extern "C" {
146 # endif /*__cplusplus*/
147 
149 static void* s_MbedTlsCreate(ESOCK_Side side, SNcbiSSLctx* ctx,
150  int* error);
151 static EIO_Status s_MbedTlsOpen (void* session, int* error, char** desc);
152 static EIO_Status s_MbedTlsRead (void* session, void* buf,
153  size_t size, size_t* done, int* error);
154 static EIO_Status s_MbedTlsWrite (void* session, const void* data,
155  size_t size, size_t* done, int* error);
156 static EIO_Status s_MbedTlsClose (void* session, int how, int* error);
157 static void s_MbedTlsDelete(void* session);
158 static void s_MbedTlsExit (void);
159 static const char* s_MbedTlsError (void* session, int error,
160  char* buf, size_t size);
161 
162 static void x_MbedTlsLogger(void* data, int level,
163  const char* file, int line,
164  const char* message);
165 static int x_MbedTlsPull (void*, unsigned char*, size_t);
166 static int x_MbedTlsPush (void*, const unsigned char*, size_t);
167 
168 # ifdef __cplusplus
169 }
170 # endif /*__cplusplus*/
171 
172 
173 static volatile int s_MbedTlsLogLevel;
177 static volatile FSSLPull s_Pull;
178 static volatile FSSLPush s_Push;
179 
180 
181 /*ARGSUSED*/
182 static void x_MbedTlsLogger(void* unused, int level,
183  const char* file, int line,
184  const char* message)
185 {
186  /* do some basic filtering and EOL cut-offs */
187  size_t len = message ? strlen(message) : 0;
188  if (!len || *message == '\n')
189  return;
190  if (message[len - 1] == '\n')
191  --len;
193  ("MBEDTLS%d: %.*s", level, (int) len, message));
194 }
195 
196 
197 # ifdef __GNUC__
198 inline
199 # endif /*__GNUC__*/
200 static EIO_Status x_RetryStatus(SOCK sock, EIO_Event direction)
201 {
202  EIO_Status status;
203  if (direction == eIO_Open) {
204  EIO_Status r_status = SOCK_Status(sock, eIO_Read);
205  EIO_Status w_status = SOCK_Status(sock, eIO_Write);
206  status = r_status != eIO_Closed && w_status != eIO_Closed
207  ? r_status > w_status ? r_status : w_status
208  : eIO_Closed;
209  } else
210  status = SOCK_Status(sock, direction);
211  return status;
212 }
213 
214 
215 # ifdef __GNUC__
216 inline
217 # endif /*__GNUC__*/
219  EIO_Event direction)
220 {
221  SOCK sock;
222  EIO_Status status;
223 
224  assert(error <= 0);
225 
226  if (!error)
227  return eIO_Success;
228 #if MBEDTLS_VERSION_MAJOR >= 3
229  sock = ((SNcbiSSLctx*)(session->MBEDTLS_PRIVATE(p_bio)))->sock;
230 #else
231  sock = ((SNcbiSSLctx*)(session->p_bio))->sock;
232 #endif
233  switch (error) {
235  status = x_RetryStatus(sock, direction);
236  break;
238  status = x_RetryStatus(sock, direction);
239  break;
241  status = eIO_Timeout;
242  break;
243 #ifdef MBEDTLS_ERR_THREADING_FEATURE_UNAVAILABLE
244  case MBEDTLS_ERR_THREADING_FEATURE_UNAVAILABLE:
245 #endif
246 #ifdef MBEDTLS_ERR_SSL_NO_USABLE_CIPHERSUITE
247  case MBEDTLS_ERR_SSL_NO_USABLE_CIPHERSUITE:
248 #endif
251 #ifdef MBEDTLS_ERR_SSL_UNKNOWN_CIPHER
252  case MBEDTLS_ERR_SSL_UNKNOWN_CIPHER:
253 #endif
255 #ifdef MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED
257 #endif
258  status = eIO_NotSupported;
259  break;
262  status = eIO_InvalidArg;
263  break;
266  status = eIO_Closed;
267  break;
270  status = eIO_Unknown;
271  break;
273  if (sock->r_status != eIO_Success &&
274  sock->r_status != eIO_Closed) {
275  status = (EIO_Status) sock->r_status;
276  } else
277  status = eIO_Unknown;
278  break;
280  if (sock->w_status != eIO_Success)
281  status = (EIO_Status) sock->w_status;
282  else
283  status = eIO_Unknown;
284  break;
286  /*return eIO_Interrupt;*/
287  default:
288  status = eIO_Unknown;
289  break;
290  }
291 
294  status != eIO_Success);
296  CORE_TRACEF(("MBEDTLS error %d -> CONNECT MBEDTLS status %s",
297  error, IO_StatusStr(status)));
298  return status;
299 }
300 
301 
302 # ifdef __GNUC__
303 inline
304 # endif /*__GNUC__*/
305 static int x_StatusToError(EIO_Status status, SOCK sock, EIO_Event direction)
306 {
307  int error;
308 
309  assert(status != eIO_Success);
310  assert(direction == eIO_Read || direction == eIO_Write);
311 
312  switch (status) {
313  case eIO_Timeout:
314  error = EAGAIN;
315  break;
316  case eIO_Interrupt:
317  error = SOCK_EINTR;
318  break;
319  case eIO_NotSupported:
321  break;
322  case eIO_Unknown:
323  error = 0/*keep*/;
324  break;
325  case eIO_Closed:
327  break;
328  default:
329  /*NB:eIO_InvalidArg*/
330  error = EINVAL;
331  break;
332  }
333 
334  {{
335  int x_err = error ? error : errno;
337  CORE_TRACEF(("CONNECT MBEDTLS status %s -> %s %d",
338  IO_StatusStr(status),
339  error ? "error" : "errno", x_err));
340  if (!error)
341  errno = x_err; /* restore errno that might have been clobbered */
342  }}
343 
344  if (error)
345  errno = error;
346  else if (!(error = errno))
347  error = EINVAL;
348 
349  switch (error) {
350  case EAGAIN:
351  case SOCK_EINTR:
352  return direction == eIO_Read
355  case SOCK_ENOTCONN:
357  default:
358  break;
359  }
361 }
362 
363 
364 static void* s_MbedTlsCreate(ESOCK_Side side, SNcbiSSLctx* ctx, int* error)
365 {
366  int end = (side == eSOCK_Client
369  struct SNcbiMbedTlsCred* xcred;
370  mbedtls_ssl_context* session;
371  int err;
372 
374  CORE_TRACE("MbedTlsCreate(): Enter");
375 
376  if (end == MBEDTLS_SSL_IS_SERVER) {
378  "Server-side SSL not yet supported with MBEDTLS");
380  session = 0;
381  goto out;
382  }
383 
384  if (ctx->cred) {
385  if (ctx->cred->type != eNcbiCred_MbedTls || !ctx->cred->data) {
386  /*FIXME: there's a NULL(data)-terminated array of credentials */
388  ("%s credentials in MBEDTLS session",
389  ctx->cred->type != eNcbiCred_MbedTls
390  ? "Foreign"
391  : "Empty"));
392  *error = EINVAL;
393  session = 0;
394  goto out;
395  }
396  xcred = (struct SNcbiMbedTlsCred*) ctx->cred->data;
397  } else
398  xcred = 0;
399 
400  if (!(session = (mbedtls_ssl_context*) malloc(sizeof(*session)))) {
401  *error = errno;
402  goto out;
403  }
404  mbedtls_ssl_init(session);
405 
406  if ((err = mbedtls_ssl_setup(session, &s_MbedTlsConf)) != 0 ||
407  (ctx->host && *ctx->host
408  && (err = mbedtls_ssl_set_hostname(session, ctx->host)) != 0) ||
409  (xcred
411  (session, xcred->cert, xcred->pkey)) != 0)) {
412  mbedtls_ssl_free(session);
413  free(session);
414  *error = err;
415  session = 0;
416  goto out;
417  }
418 
420 
421 out:
423  CORE_TRACEF(("MbedTlsCreate(): Leave(%p)", session));
424 
425  return session;
426 }
427 
428 
429 static char* x_MbedTlsDesc(const mbedtls_ssl_context* session)
430 {
431  const char* alpn = mbedtls_ssl_get_alpn_protocol(session);
432  size_t alpn_len = alpn ? strlen(alpn) : 0;
433  const char* sslv = mbedtls_ssl_get_version(session);
434  size_t sslv_len = sslv ? strlen(sslv) : 0;
435  const char* ciph = mbedtls_ssl_get_ciphersuite(session);
436  size_t ciph_len = ciph ? strlen(ciph) : 0;
437  size_t len = alpn_len + sslv_len + ciph_len;
438  char* str;
439  if (!len || !(str = (char*) malloc(len + 3/*seps+EOL*/)))
440  return 0;
441  len = 0;
442  if (alpn_len) {
443  memcpy(str, alpn, alpn_len);
444  len = alpn_len;
445  }
446  if (sslv_len) {
447  if (len)
448  str[len++] = '/';
449  memcpy(str + len, sslv, sslv_len);
450  len += sslv_len;
451  }
452  if (ciph_len) {
453  if (len)
454  str[len++] = '/';
455  memcpy(str + len, ciph, ciph_len);
456  len += ciph_len;
457  }
458  str[len] = '\0';
459  return str;
460 }
461 
462 
463 static EIO_Status s_MbedTlsOpen(void* session, int* error, char** desc)
464 {
465  EIO_Status status;
466  int x_error;
467 
469  CORE_TRACEF(("MbedTlsOpen(%p): Enter", session));
470 
471  x_error = mbedtls_ssl_handshake((mbedtls_ssl_context*) session);
472 
473  if (x_error < 0) {
474  status = x_ErrorToStatus(x_error, (mbedtls_ssl_context*) session,
475  eIO_Open);
476  if (status == eIO_Success)
477  status = eIO_Unknown;
478  *error = x_error;
479  if (desc)
480  *desc = 0;
481  } else {
482  status = eIO_Success;
483  if (desc)
484  *desc = x_MbedTlsDesc((mbedtls_ssl_context*) session);
485  }
486 
488  CORE_TRACEF(("MbedTlsOpen(%p): Leave(%d)", session, status));
489 
490  return status;
491 }
492 
493 
494 #ifdef __GNUC__
495 inline
496 #endif /*__GNUC__*/
497 static int/*bool*/ x_IfToLog(void)
498 {
499  return 4 < s_MbedTlsLogLevel ? 1/*T*/ : 0/*F*/;
500 }
501 
502 
503 static int x_MbedTlsPull(void* ctx, unsigned char* buf, size_t size)
504 {
505  SOCK sock = ((SNcbiSSLctx*) ctx)->sock;
506  FSSLPull pull = s_Pull;
507  EIO_Status status;
508 
509  if (pull) {
510  size_t x_read = 0;
511  status = pull(sock, buf, size, &x_read, x_IfToLog());
512  if (x_read > 0 || status == eIO_Success/*&& x_read==0*/) {
513  assert(status == eIO_Success);
514  assert(x_read <= size);
515  return (int) x_read;
516  }
517  } else
518  status = eIO_NotSupported;
519 
520  return x_StatusToError(status, sock, eIO_Read);
521 }
522 
523 
524 static int x_MbedTlsPush(void* ctx, const unsigned char* data, size_t size)
525 {
526  SOCK sock = ((SNcbiSSLctx*) ctx)->sock;
527  FSSLPush push = s_Push;
528  EIO_Status status;
529 
530  if (push) {
531  ssize_t n_written = 0;
532  do {
533  size_t x_written = 0;
534  status = push(sock, data, size, &x_written, x_IfToLog());
535  if (!x_written) {
536  assert(!size || status != eIO_Success);
537  if (size || status != eIO_Success)
538  goto out;
539  } else {
540  assert(status == eIO_Success);
541  assert(x_written <= size);
542  n_written += (ssize_t) x_written;
543  size -= x_written;
544  data = data + x_written;
545  }
546  } while (size);
547  return (int) n_written;
548  } else
549  status = eIO_NotSupported;
550 
551  out:
552  return x_StatusToError(status, sock, eIO_Write);
553 }
554 
555 
556 static EIO_Status s_MbedTlsRead(void* session, void* buf, size_t n_todo,
557  size_t* n_done, int* error)
558 {
559  EIO_Status status;
560  int x_read;
561 
562  assert(session && buf && n_todo);
563 
564 again:
565  x_read = mbedtls_ssl_read((mbedtls_ssl_context*) session,
566  (unsigned char*) buf, n_todo);
567  assert(x_read < 0 || (size_t) x_read <= n_todo);
568 
569  if (x_read <= 0) {
570  status = x_ErrorToStatus(x_read, (mbedtls_ssl_context*) session,
571  eIO_Read);
572  if (status == eIO_Success && x_read == MBEDTLS_ERR_SSL_WANT_READ)
573  goto again;
574  *error = x_read;
575  x_read = 0;
576  } else
577  status = eIO_Success;
578 
579  *n_done = (size_t) x_read;
580  return status;
581 }
582 
583 
584 static EIO_Status x_MbedTlsWrite(void* session, const void* data,
585  size_t n_todo, size_t* n_done, int* error)
586 {
587  EIO_Status status;
588  int x_written;
589 
590  x_written = mbedtls_ssl_write((mbedtls_ssl_context*) session,
591  (const unsigned char*) data, n_todo);
592  assert(x_written < 0 || (size_t) x_written <= n_todo);
593 
594  if (x_written <= 0) {
595  status = x_ErrorToStatus(x_written, (mbedtls_ssl_context*) session,
596  eIO_Write);
597  if (status == eIO_Success)
598  status = eIO_Unknown;
599  *error = x_written;
600  x_written = 0;
601  } else
602  status = eIO_Success;
603 
604  *n_done = (size_t) x_written;
605  return status;
606 }
607 
608 
609 static EIO_Status s_MbedTlsWrite(void* session, const void* data,
610  size_t n_todo, size_t* n_done, int* error)
611 {
613  ((mbedtls_ssl_context*) session);
614  EIO_Status status;
615 
616  assert(session && data && n_todo);
617 
618  *n_done = 0;
619 
620  do {
621  size_t x_todo = n_todo > max_size ? max_size : n_todo;
622  size_t x_done;
623  status = x_MbedTlsWrite(session, data, x_todo, &x_done, error);
624  assert((status == eIO_Success) == (x_done > 0));
625  assert(status == eIO_Success || *error);
626  assert(x_done <= x_todo);
627  if (status != eIO_Success)
628  break;
629  *n_done += x_done;
630  if (x_todo != x_done)
631  break;
632  n_todo -= x_done;
633  data = (const char*) data + x_done;
634  } while (n_todo);
635 
636  return *n_done ? eIO_Success : status;
637 }
638 
639 
640 /*ARGSUSED*/
641 static EIO_Status s_MbedTlsClose(void* session, int how/*unused*/, int* error)
642 {
643  EIO_Status status;
644  int x_error;
645 
646  assert(session);
647 
649  CORE_TRACEF(("MbedTlsClose(%p): Enter", session));
650 
651  x_error = mbedtls_ssl_close_notify((mbedtls_ssl_context*) session);
652 
653  if (x_error) {
654  *error = x_error;
655  status = eIO_Unknown;
656  } else
657  status = eIO_Success;
658 
660  CORE_TRACEF(("MbedTlsClose(%p): Leave(%d)", session, status));
661 
662  return status;
663 }
664 
665 
666 static void s_MbedTlsDelete(void* session)
667 {
668  assert(session);
669 
671  CORE_TRACEF(("MbedTlsDelete(%p): Enter", session));
672 
674 
676  CORE_TRACEF(("MbedTlsDelete(%p): Leave", session));
677 
678  free(session);
679 }
680 
681 
683 {
684  EIO_Status status;
685 
686 # ifdef NCBI_THREADS
687  switch (mbedtls_version_check_feature("MBEDTLS_THREADING_C")) {
688  case 0:
689  break;
690  case -1:
691  return eIO_NotSupported;
692  case -2:
693  return eIO_InvalidArg;
694  default:
695  return eIO_Unknown;
696  }
697 # endif /*NCBI_THREADS*/
698 
699 # ifdef MBEDTLS_THREADING_PTHREAD
700  status = eIO_Success;
701 # elif defined(MBEDTLS_THREADING_ALT) && defined(NCBI_THREADS)
702  int locked;
703  MT_LOCK lock = CORE_GetLOCK();
704  if ((locked = MT_LOCK_Do(lock, eMT_Lock)) > 0) {
705  mbedtls_threading_set_alt(mbtls_user_mutex_init,
706  mbtls_user_mutex_deinit,
707  mbtls_user_mutex_lock,
708  mbtls_user_mutex_unlock);
709  MT_LOCK_Do(lock, eMT_Unlock);
710  status = eIO_Success;
711  } else
712  status = !locked ? eIO_Unknown : lock ? eIO_Success : eIO_NotSupported;
713 # elif !defined(NCBI_NO_THREADS) && defined(_MT)
715  "MBEDTLS locking uninited: Unknown threading model");
716  status = eIO_NotSupported;
717 # else
718  status = eIO_Success;
719 # endif
720 
721  return status;
722 }
723 
724 
725 /*ARGSUSED*/
726 static void x_MbedTlsExit(int/*bool*/ nopsa)
727 {
728  s_Push = 0;
729  s_Pull = 0;
730 
733 #ifdef MBEDTLS_PSA_CRYPTO_C
734  if (!nopsa)
736 #endif /*MBEDTLS_PSA_CRYPTO_C*/
739  memset(&s_MbedTlsCtrDrbg, 0, sizeof(s_MbedTlsCtrDrbg));
740  memset(&s_MbedTlsEntropy, 0, sizeof(s_MbedTlsEntropy));
741  memset(&s_MbedTlsConf, 0, sizeof(s_MbedTlsConf));
742 # if defined(MBEDTLS_THREADING_ALT) && defined(NCBI_THREADS)
744 # endif /*MBEDTLS_THREADING_ALT && NCBI_THREADS*/
745 }
746 
747 
748 /* NB: Called under a lock */
750 {
751  static const char kMbedTls[] =
752 # ifdef HAVE_LIBMBEDTLS
753  "External "
754 # else
755  "Embedded "
756 # endif /*HAVE_LIBMBEDTLS*/
757  "MBEDTLS";
758 #ifdef MBEDTLS_PSA_CRYPTO_C
759  psa_status_t psa_status;
760 #endif /*MBEDTLS_PSA_CRYPTO_C*/
761  EIO_Status status;
762  char version[80];
763  const char* val;
764  char buf[32];
765 
766  CORE_TRACE("MbedTlsInit(): Enter");
767 
771  ("%s version mismatch: %s headers vs. %s runtime",
772  kMbedTls, MBEDTLS_VERSION_STRING, version));
773  assert(0);
774  }
775 
776  if (!pull || !push) {
777  status = eIO_InvalidArg;
778  goto out;
779  }
780 
787 #if MBEDTLS_VERSION_NUMBER == 0x03060000
788  /* The above line can otherwise be ineffective. */
791 #endif
792 
793  /* Check CONN_[MBED]TLS_LOGLEVEL or [CONN][MBED]TLS_LOGLEVEL */
795  buf, sizeof(buf),
797  if (!val || !*val) {
799  buf, sizeof(buf),
801  }
802  if (val && *val) {
803  ELOG_Level level;
804  s_MbedTlsLogLevel = atoi(val);
805  if (s_MbedTlsLogLevel) {
808  level = eLOG_Note;
809  } else
810  level = eLOG_Trace;
811  CORE_LOGF_X(6, level, ("%s V%s (LogLevel=%d)",
812  kMbedTls, version, s_MbedTlsLogLevel));
813  }
814 
816  CORE_TRACE("MbedTlsInit(): Go-on");
817 
818  if ((status = x_InitLocking()) != eIO_Success) {
821  memset(&s_MbedTlsConf, 0, sizeof(s_MbedTlsConf));
822  goto out;
823  }
824 
827 
829  &s_MbedTlsEntropy, 0, 0) != 0) {
830  x_MbedTlsExit(1/*nopsa*/);
831  status = eIO_Unknown;
832  goto out;
833  }
836 
837 #ifdef MBEDTLS_PSA_CRYPTO_C
838  if ((psa_status = psa_crypto_init()) != PSA_SUCCESS) {
839  extern int psa_generic_status_to_mbedtls(psa_status_t status);
840  int err = psa_generic_status_to_mbedtls(psa_status);
841  char errbuf[80];
842  mbedtls_strerror(err, errbuf, sizeof(errbuf));
843  CORE_LOG_ERRNO_EXX(13, eLOG_Error, psa_status, errbuf,
844  "Platform Security Architecture (PSA) failed to initialize");
845  x_MbedTlsExit(1/*nopsa*/);
846  status = eIO_Unknown;
847  goto out;
848  }
849 #endif /*MBEDTLS_PSA_CRYPTO_C*/
850 
851  s_Pull = pull;
852  s_Push = push;
853  status = eIO_Success;
854 
855 out:
857  CORE_TRACEF(("MbedTlsInit(): Leave(%d)", status));
858 
859  return status;
860 }
861 
862 
863 /* NB: Called under a lock */
864 static void s_MbedTlsExit(void)
865 {
867  CORE_TRACE("MbedTlsExit(): Enter");
868 
869  x_MbedTlsExit(0/*psa as well*/);
870 
871  CORE_TRACE("MbedTlsExit(): Leave");
872 }
873 
874 
875 static const char* s_MbedTlsError(void* session/*unused*/, int error,
876  char* buf, size_t size)
877 {
879  return buf;
880 }
881 
882 #else
883 
884 /*ARGSUSED*/
885 static EIO_Status s_MbedTlsInit(FSSLPull unused_pull, FSSLPush unused_push)
886 {
887  CORE_LOG_X(7, eLOG_Critical, "Unavailable feature MBEDTLS");
888  return eIO_NotSupported;
889 }
890 
891 #endif /*HAVE_LIBMBEDTLS || NCBI_CXX_TOOLKIT*/
892 
893 
895 {
896  static const struct SOCKSSL_struct kMbedTlsOps = {
897  "MBEDTLS"
898  , s_MbedTlsInit
899 #if defined(HAVE_LIBMBEDTLS) || defined(NCBI_CXX_TOOLKIT)
901  , s_MbedTlsOpen
902  , s_MbedTlsRead
906  , s_MbedTlsExit
908 #endif /*HAVE_LIBMBEDTLS || NCBI_CXX_TOOLKIT*/
909  };
910 #if !defined(HAVE_LIBMBEDTLS) && !defined(NCBI_CXX_TOOLKIT)
911  CORE_LOG_X(8, eLOG_Warning, "Unavailable feature MBEDTLS");
912 #endif /*!HAVE_LIBMBEDTLS && !NCBI_CXX_TOOLKIT*/
913  return &kMbedTlsOps;
914 }
915 
916 
917 #define ALIGN2(s, a) ((((s) + ((a) - 1)) / (a)) * (a))
918 #define ALIGN(s) ALIGN2(s, sizeof(double))
919 
920 
921 extern NCBI_CRED NcbiCredMbedTls(void* xcert, void* xpkey)
922 {
923  struct SNcbiCred* cred;
924  struct SNcbiMbedTlsCred* xcred;
925  size_t size = ALIGN(sizeof(*cred));
926  if (xcert && xpkey) {
927  size <<= 1;
928  size += sizeof(*xcred);
929  }
930  cred = (NCBI_CRED) calloc(1, size);
931  if (cred) {
932  cred->type = eNcbiCred_MbedTls;
933  if (xcert && xpkey) {
934  xcred = (struct SNcbiMbedTlsCred*)
935  ((char*) cred + 2*ALIGN(sizeof(*cred)));
936  xcred->cert = (mbedtls_x509_crt*) xcert;
937  xcred->pkey = (mbedtls_pk_context*) xpkey;
938  cred->data = xcred;
939  }
940  }
941  return cred;
942 }
943 
944 
945 #if defined(HAVE_LIBMBEDTLS) || defined(NCBI_CXX_TOOLKIT)
946 
948 {
949  if (cred->type / 100 == eNcbiCred_MbedTls / 100 && !(cred->type % 100)) {
950  struct SNcbiMbedTlsCred* xcred = (struct SNcbiMbedTlsCred*) cred->data;
951  mbedtls_x509_crt_free(xcred->cert);
952  mbedtls_pk_free (xcred->pkey);
953  memset(xcred, 0, sizeof(*xcred));
954  } else {
955  char who[80];
956  switch (cred->type / 100) {
957  case eNcbiCred_GnuTls / 100:
958  strcpy(who, "GNUTLS");
959  break;
960  case eNcbiCred_MbedTls / 100:
961  strcpy(who, "MBEDTLS");
962  break;
963  default:
964  sprintf(who, "TLS 0x%08X", cred->type);
965  break;
966  }
968  ("Deleting unknown certificate credentials (%s/%u)",
969  who, cred->type % 100));
970  assert(0);
971  }
972  cred->type = (ENcbiCred) 0;
973  cred->data = 0;
974  free(cred);
975 }
976 
977 
979  size_t certsz,
980  const void* pkey,
981  size_t pkeysz)
982 {
983  struct SNcbiCred* ncbi_cred;
984  struct SNcbiMbedTlsCred* xcred;
985  const size_t size = (2*ALIGN(sizeof(*ncbi_cred))
986  + ALIGN(sizeof(*xcred))
987  + ALIGN(sizeof(*xcred->cert))
988  + sizeof(*xcred->pkey));
989  CORE_DEBUG_ARG(char tmp[1024];)
990  char errbuf[80];
991  int err;
992 
993  if (!(ncbi_cred = (NCBI_CRED) calloc(1, size))) {
994  CORE_LOGF_ERRNO_X(10, eLOG_Error, errno,
995  ("Cannot allocate NCBI_CRED (%lu bytes)",
996  (unsigned long) size));
997  return 0;
998  }
999 
1000  xcred = (struct SNcbiMbedTlsCred*)
1001  ((char*) ncbi_cred + 2*ALIGN(sizeof(*ncbi_cred)));
1002  xcred->cert = (mbedtls_x509_crt*)
1003  ((char*) xcred + ALIGN(sizeof(*xcred)));
1004  xcred->pkey = (mbedtls_pk_context*)
1005  ((char*) xcred->cert + ALIGN(sizeof(*xcred->cert)));
1006  ncbi_cred->type = eNcbiCred_MbedTls;
1007  ncbi_cred->data = xcred;
1008 
1009  /* these are not technically necessary as they just zero up the memory */
1010  mbedtls_x509_crt_init(xcred->cert);
1011  mbedtls_pk_init (xcred->pkey);
1012 
1013  err = mbedtls_x509_crt_parse(xcred->cert,
1014  (const unsigned char*) cert, certsz ? certsz
1015  : strlen((const char*) cert) + 1);
1016  if (err) {
1017  mbedtls_strerror(err, errbuf, sizeof(errbuf) - 1);
1018  CORE_LOG_ERRNO_EXX(11, eLOG_Error, err, errbuf,
1019  "mbedTLS cannot parse X.509 certificate");
1020  goto out;
1021  }
1023  "", xcred->cert));
1024  CORE_TRACEF(("Certificate loaded%s%s",
1025  err > 0 ? ":\n" : "",
1026  err > 0 ? tmp : ""));
1027 
1028  err = mbedtls_pk_parse_key(xcred->pkey,
1029  (const unsigned char*) pkey, pkeysz ? pkeysz
1030  : strlen((const char*) pkey) + 1, 0, 0
1031 #if MBEDTLS_VERSION_MAJOR >= 3
1033 #endif
1034  );
1035  if (err) {
1036  mbedtls_strerror(err, errbuf, sizeof(errbuf) - 1);
1037  CORE_LOG_ERRNO_EXX(12, eLOG_Error, err, errbuf,
1038  "mbedTLS cannot parse private key");
1039  goto out;
1040  }
1041  CORE_TRACEF(("Private key loaded: %s",
1042  mbedtls_pk_get_name(xcred->pkey)));
1043 
1044  return ncbi_cred;
1045 
1046  out:
1048  return 0;
1049 }
1050 
1051 #endif /*HAVE_LIBMBEDTLS || NCBI_CXX_TOOLKIT*/
#define MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE
The selected feature is not available.
Definition: cipher.h:38
Platform Security Architecture cryptography module.
void mbedtls_psa_crypto_free(void)
Library deinitialization.
This file contains definitions and functions for the CTR_DRBG pseudorandom generator.
void mbedtls_ctr_drbg_free(mbedtls_ctr_drbg_context *ctx)
This function resets CTR_DRBG context to the state immediately after initial call of mbedtls_ctr_drbg...
void mbedtls_ctr_drbg_init(mbedtls_ctr_drbg_context *ctx)
This function initializes the CTR_DRBG context, and prepares it for mbedtls_ctr_drbg_seed() or mbedtl...
int mbedtls_ctr_drbg_seed(mbedtls_ctr_drbg_context *ctx, int(*f_entropy)(void *, unsigned char *, size_t), void *p_entropy, const unsigned char *custom, size_t len)
This function seeds and sets up the CTR_DRBG entropy source for future reseeds.
int mbedtls_ctr_drbg_random(void *p_rng, unsigned char *output, size_t output_len)
This function uses CTR_DRBG to generate random data.
Functions for controlling and providing debug output from the library.
void mbedtls_debug_set_threshold(int threshold)
Set the threshold error level to handle globally all debug output.
Entropy accumulator implementation.
void mbedtls_entropy_free(mbedtls_entropy_context *ctx)
Free the data in the context.
int mbedtls_entropy_func(void *data, unsigned char *output, size_t len)
Retrieve entropy from the accumulator (Maximum length: MBEDTLS_ENTROPY_BLOCK_SIZE) (Thread-safe if MB...
void mbedtls_entropy_init(mbedtls_entropy_context *ctx)
Initialize the context.
std::ofstream out("events_result.xml")
main entry point for tests
CS_CONTEXT * ctx
Definition: t0006.c:12
static const char * str(char *buf, int n)
Definition: stats.c:84
static char tmp[3200]
Definition: utf8.c:42
char data[12]
Definition: iconv.c:80
SOCKSSL NcbiSetupMbedTls(void)
Explicitly setup mbedTLS library to support SSL in ncbi_socket.h[pp].
Definition: ncbi_mbedtls.c:894
#define DEF_CONN_TLS_LOGLEVEL
Definition: ncbi_tls.h:91
struct SNcbiCred * NCBI_CRED
Opaque type for credentials.
Definition: ncbi_socket.h:2303
#define REG_CONN_TLS_LOGLEVEL
Definition: ncbi_tls.h:90
EIO_Status SOCK_Status(SOCK sock, EIO_Event direction)
Return low-level socket I/O status of *last* socket operation.
Definition: ncbi_socket.c:7460
ESOCK_Side
Sides of socket.
Definition: ncbi_socket.h:210
NCBI_CRED NcbiCredMbedTls(void *xcert, void *xpkey)
Convert native mbedTLS certificate credentials' handles into an abstract toolkit handle.
Definition: ncbi_mbedtls.c:921
@ eSOCK_Client
Definition: ncbi_socket.h:212
MT_LOCK CORE_GetLOCK(void)
Get the lock handle that is to be used by the core internals.
Definition: ncbi_util.c:111
ELOG_Level
Log severity level.
Definition: ncbi_core.h:292
MT_LOCK MT_LOCK_AddRef(MT_LOCK lk)
Increment internal reference count by 1, then return "lk".
Definition: ncbi_core.c:217
EIO_Status
I/O status.
Definition: ncbi_core.h:132
const char * IO_StatusStr(EIO_Status status)
Get the text form of an enum status value.
Definition: ncbi_core.c:56
MT_LOCK MT_LOCK_Delete(MT_LOCK lk)
Decrement internal reference count by 1, and if it reaches 0, then destroy the handle,...
Definition: ncbi_core.c:234
EIO_Event
I/O event (or direction).
Definition: ncbi_core.h:118
#define MT_LOCK_Do(lk, how)
Call "lk->handler(lk->data, how)".
Definition: ncbi_core.h:270
@ eLOG_Critical
Definition: ncbi_core.h:298
@ eLOG_Error
Definition: ncbi_core.h:297
@ eLOG_Note
Definition: ncbi_core.h:294
@ eLOG_Warning
Definition: ncbi_core.h:296
@ eLOG_Trace
Definition: ncbi_core.h:293
@ eMT_Unlock
unlock critical section
Definition: ncbi_core.h:183
@ eMT_Lock
lock critical section
Definition: ncbi_core.h:181
@ eIO_Timeout
timeout expired before any I/O succeeded
Definition: ncbi_core.h:134
@ eIO_Interrupt
signal arrival prevented any I/O to succeed
Definition: ncbi_core.h:136
@ eIO_NotSupported
operation is not supported or is not available
Definition: ncbi_core.h:138
@ eIO_Success
everything is fine, no error occurred
Definition: ncbi_core.h:133
@ eIO_Unknown
unknown I/O error (likely fatal but can retry)
Definition: ncbi_core.h:139
@ eIO_InvalidArg
bad argument / parameter value(s) supplied
Definition: ncbi_core.h:137
@ eIO_Write
write
Definition: ncbi_core.h:121
@ eIO_Open
also serves as no-event indicator in SOCK_Poll
Definition: ncbi_core.h:119
@ eIO_Read
read
Definition: ncbi_core.h:120
int32_t psa_status_t
Function return status.
Definition: crypto_types.h:59
#define PSA_SUCCESS
The action was completed successfully.
Definition: crypto_values.h:57
psa_status_t psa_crypto_init(void)
Library initialization.
FILE * file
char * buf
int len
static const CS_INT unused
Definition: long_binary.c:20
#define MBEDTLS_VERSION_STRING
Definition: build_info.h:37
#define MBEDTLS_VERSION_MAJOR
The version number x.y.z is split into three parts.
Definition: build_info.h:27
list< Ts... > push
const string version
version string
Definition: variables.hpp:66
const struct ncbi::grid::netcache::search::fields::SIZE size
#define strcasecmp
EIO_Status(* FSSLPush)(SOCK sock, const void *data, size_t size, size_t *done, int logdata)
Definition: ncbi_connssl.h:81
EIO_Status(* FSSLPull)(SOCK sock, void *buf, size_t size, size_t *done, int logdata)
Definition: ncbi_connssl.h:69
ENcbiCred
Definition: ncbi_connssl.h:45
@ eNcbiCred_MbedTls
Definition: ncbi_connssl.h:48
@ eNcbiCred_GnuTls
Definition: ncbi_connssl.h:47
const char * ConnNetInfo_GetValueInternal(const char *service, const char *param, char *value, size_t value_size, const char *def_value)
static int x_StatusToError(EIO_Status status, SOCK sock, EIO_Event direction)
Definition: ncbi_mbedtls.c:305
void NcbiDeleteMbedTlsCertCredentials(NCBI_CRED cred)
Definition: ncbi_mbedtls.c:947
static void s_MbedTlsExit(void)
Definition: ncbi_mbedtls.c:864
static EIO_Status s_MbedTlsOpen(void *session, int *error, char **desc)
Definition: ncbi_mbedtls.c:463
NCBI_CRED NcbiCreateMbedTlsCertCredentials(const void *cert, size_t certsz, const void *pkey, size_t pkeysz)
Definition: ncbi_mbedtls.c:978
static char * x_MbedTlsDesc(const mbedtls_ssl_context *session)
Definition: ncbi_mbedtls.c:429
static EIO_Status x_MbedTlsWrite(void *session, const void *data, size_t n_todo, size_t *n_done, int *error)
Definition: ncbi_mbedtls.c:584
static EIO_Status s_MbedTlsRead(void *session, void *buf, size_t size, size_t *done, int *error)
Definition: ncbi_mbedtls.c:556
static int x_MbedTlsPull(void *, unsigned char *, size_t)
Definition: ncbi_mbedtls.c:503
static volatile int s_MbedTlsLogLevel
Definition: ncbi_mbedtls.c:173
static volatile FSSLPull s_Pull
Definition: ncbi_mbedtls.c:177
static EIO_Status s_MbedTlsInit(FSSLPull pull, FSSLPush push)
Definition: ncbi_mbedtls.c:749
static mbedtls_ssl_config s_MbedTlsConf
Definition: ncbi_mbedtls.c:176
static EIO_Status s_MbedTlsClose(void *session, int how, int *error)
Definition: ncbi_mbedtls.c:641
#define NCBI_NOTSUPPORTED
Definition: ncbi_mbedtls.c:64
static mbedtls_entropy_context s_MbedTlsEntropy
Definition: ncbi_mbedtls.c:174
static EIO_Status x_RetryStatus(SOCK sock, EIO_Event direction)
Definition: ncbi_mbedtls.c:200
static const char * s_MbedTlsError(void *session, int error, char *buf, size_t size)
Definition: ncbi_mbedtls.c:875
static int x_IfToLog(void)
Definition: ncbi_mbedtls.c:497
static void s_MbedTlsDelete(void *session)
Definition: ncbi_mbedtls.c:666
static volatile FSSLPush s_Push
Definition: ncbi_mbedtls.c:178
static void x_MbedTlsExit(int nopsa)
Definition: ncbi_mbedtls.c:726
static EIO_Status x_InitLocking(void)
Definition: ncbi_mbedtls.c:682
static EIO_Status x_ErrorToStatus(int error, mbedtls_ssl_context *session, EIO_Event direction)
Definition: ncbi_mbedtls.c:218
static EIO_Status s_MbedTlsWrite(void *session, const void *data, size_t size, size_t *done, int *error)
Definition: ncbi_mbedtls.c:609
static void x_MbedTlsLogger(void *data, int level, const char *file, int line, const char *message)
Definition: ncbi_mbedtls.c:182
static int x_MbedTlsPush(void *, const unsigned char *, size_t)
Definition: ncbi_mbedtls.c:524
static mbedtls_ctr_drbg_context s_MbedTlsCtrDrbg
Definition: ncbi_mbedtls.c:175
#define ALIGN(s)
Definition: ncbi_mbedtls.c:918
static void * s_MbedTlsCreate(ESOCK_Side side, SNcbiSSLctx *ctx, int *error)
Definition: ncbi_mbedtls.c:364
MT_LOCK g_CORE_MT_Lock
Definition: ncbi_priv.c:48
#define CORE_DEBUG_ARG(arg)
Definition: ncbi_priv.h:139
#define CORE_LOGF_X(subcode, level, fmt_args)
Definition: ncbi_priv.h:150
#define CORE_LOG_ERRNO_EXX(subcode, level, error, descr, message)
Definition: ncbi_priv.h:178
#define CORE_LOGF_ERRNO_X(subcode, level, error, fmt_args)
Definition: ncbi_priv.h:166
#define CORE_TRACEF(fmt_args)
Definition: ncbi_priv.h:138
#define CORE_TRACE(message)
Definition: ncbi_priv.h:137
#define CORE_LOG_X(subcode, level, message)
Definition: ncbi_priv.h:146
#define SOCK_ENOTCONN
Definition: ncbi_socketp.h:83
#define SOCK_EINTR
Definition: ncbi_socketp.h:75
int ssize_t
Definition: ncbiconf_msvc.h:93
#define mbedtls_version_get_string
#define mbedtls_pk_parse_key
#define mbedtls_ssl_set_hostname
#define psa_generic_status_to_mbedtls
#define mbedtls_x509_crt_init
#define mbedtls_version_check_feature
#define mbedtls_ssl_get_alpn_protocol
#define mbedtls_x509_crt_free
#define mbedtls_x509_crt_parse
#define mbedtls_x509_crt_info
#define mbedtls_ssl_set_hs_own_cert
#define mbedtls_threading_set_alt
#define mbedtls_threading_free_alt
Network sockets abstraction layer to integrate Mbed TLS into a BSD-style sockets API.
#define MBEDTLS_ERR_NET_RECV_FAILED
Reading information from the socket failed.
Definition: net_sockets.h:48
#define MBEDTLS_ERR_NET_CONN_RESET
Connection was reset by peer.
Definition: net_sockets.h:52
#define MBEDTLS_ERR_NET_SEND_FAILED
Sending information through the socket failed.
Definition: net_sockets.h:50
Public Key abstraction layer.
const char * mbedtls_pk_get_name(const mbedtls_pk_context *ctx)
Access the type name.
void mbedtls_pk_init(mbedtls_pk_context *ctx)
Initialize a mbedtls_pk_context (as NONE).
void mbedtls_pk_free(mbedtls_pk_context *ctx)
Free the components of a mbedtls_pk_context.
Error to string translation.
#define MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED
The requested feature is not supported by the platform.
Definition: error.h:105
void mbedtls_strerror(int errnum, char *buffer, size_t buflen)
Translate an Mbed TLS error code into a string representation.
Run-time version information.
#define assert(x)
Definition: srv_diag.hpp:58
SSL/TLS functions.
#define MBEDTLS_ERR_SSL_NON_FATAL
The alert message received indicates a non-fatal error.
Definition: ssl.h:146
const char * mbedtls_ssl_get_ciphersuite(const mbedtls_ssl_context *ssl)
Return the name of the current ciphersuite.
#define MBEDTLS_SSL_VERIFY_NONE
Definition: ssl.h:296
const char * mbedtls_ssl_get_version(const mbedtls_ssl_context *ssl)
Return the current TLS version.
#define MBEDTLS_SSL_IS_CLIENT
Definition: ssl.h:282
void mbedtls_ssl_free(mbedtls_ssl_context *ssl)
Free referenced items in an SSL context and clear memory.
#define MBEDTLS_ERR_SSL_TIMEOUT
The operation timed out.
Definition: ssl.h:140
@ MBEDTLS_SSL_VERSION_TLS1_2
Definition: ssl.h:1216
void mbedtls_ssl_conf_rng(mbedtls_ssl_config *conf, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
Set the random number generator callback.
int mbedtls_ssl_handshake(mbedtls_ssl_context *ssl)
Perform the SSL handshake.
void mbedtls_ssl_conf_authmode(mbedtls_ssl_config *conf, int authmode)
Set the certificate verification mode Default: NONE on server, REQUIRED on client.
int mbedtls_ssl_get_max_out_record_payload(const mbedtls_ssl_context *ssl)
Return the current maximum outgoing record payload in bytes.
int mbedtls_ssl_write(mbedtls_ssl_context *ssl, const unsigned char *buf, size_t len)
Try to write exactly 'len' application data bytes.
#define MBEDTLS_ERR_SSL_BAD_INPUT_DATA
Bad input parameters to function.
Definition: ssl.h:51
#define MBEDTLS_ERR_SSL_WANT_WRITE
Connection requires a write call.
Definition: ssl.h:138
#define MBEDTLS_ERR_SSL_WANT_READ
No data of requested type currently available on underlying transport.
Definition: ssl.h:136
#define MBEDTLS_SSL_IS_SERVER
Definition: ssl.h:283
void mbedtls_ssl_config_free(mbedtls_ssl_config *conf)
Free an SSL configuration context.
void mbedtls_ssl_init(mbedtls_ssl_context *ssl)
Initialize an SSL context Just makes the context ready for mbedtls_ssl_setup() or mbedtls_ssl_free()
void mbedtls_ssl_set_bio(mbedtls_ssl_context *ssl, void *p_bio, mbedtls_ssl_send_t *f_send, mbedtls_ssl_recv_t *f_recv, mbedtls_ssl_recv_timeout_t *f_recv_timeout)
Set the underlying BIO callbacks for write, read and read-with-timeout.
int mbedtls_ssl_config_defaults(mbedtls_ssl_config *conf, int endpoint, int transport, int preset)
Load reasonable default SSL configuration values.
int mbedtls_ssl_read(mbedtls_ssl_context *ssl, unsigned char *buf, size_t len)
Read at most 'len' application data bytes.
void mbedtls_ssl_conf_dbg(mbedtls_ssl_config *conf, void(*f_dbg)(void *, int, const char *, int, const char *), void *p_dbg)
Set the debug callback.
#define MBEDTLS_ERR_SSL_CONN_EOF
The connection indicated an EOF.
Definition: ssl.h:57
void mbedtls_ssl_config_init(mbedtls_ssl_config *conf)
Initialize an SSL configuration context Just makes the context ready for mbedtls_ssl_config_defaults(...
static void mbedtls_ssl_conf_max_tls_version(mbedtls_ssl_config *conf, mbedtls_ssl_protocol_version tls_version)
Set the maximum supported version sent from the client side and/or accepted at the server side.
Definition: ssl.h:4316
int mbedtls_ssl_close_notify(mbedtls_ssl_context *ssl)
Notify the peer that the connection is being closed.
#define MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY
The peer notified us that the connection is going to be closed.
Definition: ssl.h:80
#define MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE
A fatal alert message was received from our peer.
Definition: ssl.h:76
#define MBEDTLS_SSL_TRANSPORT_STREAM
Definition: ssl.h:265
#define MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE
The requested feature is not available.
Definition: ssl.h:49
#define MBEDTLS_ERR_SSL_INTERNAL_ERROR
Internal error (eg, unexpected failure in lower-level module)
Definition: ssl.h:125
int mbedtls_ssl_setup(mbedtls_ssl_context *ssl, const mbedtls_ssl_config *conf)
Set up an SSL context for use.
#define MBEDTLS_SSL_PRESET_DEFAULT
Definition: ssl.h:327
ENcbiCred type
Definition: ncbi_connssl.h:53
void * data
Definition: ncbi_connssl.h:54
mbedtls_x509_crt * cert
Definition: ncbi_mbedtls.c:76
mbedtls_pk_context * pkey
Definition: ncbi_mbedtls.c:77
TSOCK_Handle sock
Definition: ncbi_socketp.h:230
EBIO_Status w_status
Definition: ncbi_socketp.h:249
EBIO_Status r_status
Definition: ncbi_socketp.h:246
The CTR_DRBG context structure.
Definition: ctr_drbg.h:185
Entropy context structure.
Definition: entropy.h:105
Public key container.
Definition: pk.h:220
SSL/TLS configuration to be shared between mbedtls_ssl_context structures.
Definition: ssl.h:1411
const mbedtls_ssl_config * MBEDTLS_PRIVATE(conf)
Container for an X.509 certificate.
Definition: x509_crt.h:41
Threading abstraction layer.
#define MBEDTLS_ERR_THREADING_MUTEX_ERROR
Locking / unlocking / free failed with error code.
Definition: threading.h:25
#define MBEDTLS_ERR_THREADING_BAD_INPUT_DATA
Bad input parameters to function.
Definition: threading.h:23
done
Definition: token1.c:1
void free(voidpf ptr)
voidp malloc(uInt size)
voidp calloc(uInt items, uInt size)
Modified on Fri Sep 20 14:58:26 2024 by modify_doxy.py rev. 669887