Chinaunix首页 | 论坛 | 博客
  • 博客访问: 257602
  • 博文数量: 52
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 587
  • 用 户 组: 普通用户
  • 注册时间: 2017-03-09 09:24
个人简介

水滴

文章分类

全部博文(52)

文章存档

2021年(3)

2019年(8)

2018年(32)

2017年(9)

我的朋友

分类: LINUX

2021-12-27 10:21:57

Linux-实现链路加密


1 mbedtls

    mbedtls为嵌入式提供了最小化的链路加密方式,资源网站:tls.mbed.org

2 mbedtls交叉编译


1 在CMakeList.txt中添加 set(CMAKE_C_FLAGS "-std=c99") //mbedtls 3.0.0 以上需要
2 cmake -DUSE_SHARED_MBEDTLS_LIBRARY:Bool=ON -DENABLE_TESTING:Bool=OFF - DENABLE_PROGRAMS:Bool=ON -DCMAKE_C_COMPILER=arm-fsl-linux-gnueabi-gcc
3 make

3 证书生成方法

3.1 tls证书

3.1.1 正文

SSL证书通过在客户端浏览器和Web服务器之间建立一条SSL安全通道(Secure socketlayer(SSL),SSL安全协议主要用来提供对用户和服务器的认证;对传送的数据进行加密和隐藏;确保数据在传送中不被改变,即数据的完整性,现已成为该领域中全球化的标准。由于SSL技术已建立到所有主要的浏览器和WEB服务器程序中,因此,仅需安装服务器证书就可以激活该功能了)。即通过它可以激活SSL协议,实现数据信息在客户端和服务器之间的加密传输,可以防止数据信息的泄露。保证了双方传递信息的安全性,而且用户可以通过服务器证书验证他所访问的网站是否是真实可靠。    SSL网站不同于一般的Web站点,它使用的是“HTTPS”协议,而不是普通的“HTTP”协议。因此它的URL(统一资源定位器)格式为“”。

3.1.2 概念

    首先要有一个CA根证书,然后用CA根证书来签发用户证书。    用户进行证书申请:一般先生成一个私钥,然后用私钥生成证书请求(证书请求里应含有公钥信息),再利用证书服务器的CA根证书来签发证书。   
特别说明:(1)自签名证书(一般用于顶级证书、根证书): 证书的名称和认证机构的名称相同.(2)根证书:根证书是CA认证中心给自己颁发的证书,是信任链的起始点。任何安装CA根证书的服务器都意味着对这个CA认证中心是信任的。数字证书则是由证书认证机构(CA)对证书申请者真实身份验证之后,用CA的根证书对申请人的一些基本信息以及申请人的公钥进行签名(相当于加盖发证书机构的公章)后形成的一个数字文件。数字证书包含证书中所标识的实体的公钥(就是说你的证书里有你的公钥),由于证书将公钥与特定的个人匹配,并且该证书的真实性由颁发机构保证(就是说可以让大家相信你的证书是真的),因此,数字证书为如何找到用户的公钥并知道它是否有效这一问题提供了解决方案。
1 openssl中有如下后缀名的文件
.key格式:私有的密钥.csr格式:证书签名请求(证书请求文件),含有公钥信息,certificate signing request的缩写.crt格式:证书文件,certificate的缩写.crl格式:证书吊销列表,Certificate Revocation List的缩写.pem格式:用于导出,导入证书时候的证书的格式,有证书开头,结尾的格式
2 CA根证书的生成步骤
生成CA私钥(.key)-->生成CA证书请求(.csr)-->自签名得到根证书(.crt)(CA给自已颁发的证书)。
在实际的软件开发工作中,往往服务器就采用这种自签名的方式,因为毕竟找第三方签名机构是要给钱的,也是需要花时间的。
3 用户证书的生成步骤
生成私钥(.key)-->生成证书请求(.csr)-->用CA根证书签名得到证书(.crt)服务器端用户证书

3.2 根证书生成

1 openssl genrsa -out ca.key 2048

2 openssl req -new -key ca.key -out ca.csr
3 openssl x509 -req -days 3650 -in ca.csr -signkey ca.key -out ca.crt
4 openssl x509 -in ca.crt -text   //查看证书内容

3.3 服务器证书生成

1 openssl genrsa -out server.key 2048
2 openssl req -new -key server.key -out server.csr
3 openssl x509 -req -days 3650 -inserver.csr -CAkey ca.key -CA ca.crt -CAcreateserial -out server.crt
4  openssl x509 -in server.crt -text


3.4 客户端证书生成

1 openssl genrsa -out client.key 2048
2 openssl req -new -key client.key -out client.csr

3 openssl x509 -req -days 3650 -inclient.csr -CAkey ca.key -CA ca.crt -CAcreateserial -out client.crt

4  openssl x509 -in client.crt -text


4 利用mbedtls实现链路加密

4.2 服务端实现方式


点击(此处)折叠或打开

  1. #if !defined(MBEDTLS_CONFIG_FILE)
  2. #include "mbedtls/config.h"
  3. #else
  4. #include MBEDTLS_CONFIG_FILE
  5. #endif

  6. #if defined(MBEDTLS_PLATFORM_C)
  7. #include "mbedtls/platform.h"
  8. #else
  9. #include
  10. #include
  11. #define mbedtls_time time
  12. #define mbedtls_time_t time_t
  13. #define mbedtls_fprintf fprintf
  14. #define mbedtls_printf printf
  15. #endif

  16. #include "mbedtls/entropy.h"
  17. #include "mbedtls/ctr_drbg.h"
  18. #include "mbedtls/certs.h"
  19. #include "mbedtls/x509.h"
  20. #include "mbedtls/ssl.h"
  21. #include "mbedtls/net_sockets.h"
  22. #include "mbedtls/error.h"
  23. #include "mbedtls/debug.h"

  24. #if defined(MBEDTLS_SSL_CACHE_C)
  25. #include "mbedtls/ssl_cache.h"
  26. #endif

  27. #define HTTP_RESPONSE \
  28.     "HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n" \
  29.     "mbed TLS Test Server\r\n" \

  30.     "Successful connection using: %s\r\n"

  31. #define DEBUG_LEVEL 0

  32. static char *ca_path = "/root/openssl/ca.crt"; //根证书
  33. static char *cert_path = "/root/openssl/server.crt"; //服务器证书
  34. static char *key_path = "/root/openssl/server.key"; //证书密钥

  35. static void my_debug( void *ctx, int level,
  36.                       const char *file, int line,
  37.                       const char *str )
  38. {
  39.     ((void) level);
  40.     mbedtls_fprintf( (FILE *) ctx, "%s:%04d: %s", file, line, str );
  41.     fflush( (FILE *) ctx );
  42. }

  43. int main( void )
  44. {
  45.     int ret, len;
  46.     mbedtls_net_context listen_fd, client_fd;
  47.     unsigned char buf[1024];
  48.     const char *pers = "ssl_server";

  49.     mbedtls_entropy_context entropy;
  50.     mbedtls_ctr_drbg_context ctr_drbg;
  51.     mbedtls_ssl_context ssl;
  52.     mbedtls_ssl_config conf;
  53.     mbedtls_x509_crt srvcert;
  54.     mbedtls_x509_crt cacert;
  55.     mbedtls_pk_context pkey;
  56. #if defined(MBEDTLS_SSL_CACHE_C)
  57.     mbedtls_ssl_cache_context cache;
  58. #endif
  59.     mbedtls_net_init( &listen_fd );
  60.     mbedtls_net_init( &client_fd );
  61.     mbedtls_ssl_init( &ssl );
  62.     mbedtls_ssl_config_init( &conf );

  63. #if defined(MBEDTLS_SSL_CACHE_C)
  64.     mbedtls_ssl_cache_init( &cache );
  65. #endif

  66.     mbedtls_x509_crt_init( &srvcert );
  67.     mbedtls_x509_crt_init( &cacert );
  68.     mbedtls_pk_init( &pkey );
  69.     mbedtls_entropy_init( &entropy );
  70.     mbedtls_ctr_drbg_init( &ctr_drbg );

  71. #if defined(MBEDTLS_DEBUG_C)
  72.     mbedtls_debug_set_threshold( DEBUG_LEVEL );
  73. #endif
  74.     mbedtls_printf( "\n . Loading the server cert. and key..." );
  75.     fflush( stdout );

  76.     ret = mbedtls_x509_crt_parse_file(&(cacert), ca_path);
  77.     if( ret != 0 )
  78.     {
  79.         mbedtls_printf( " failed\n ! mbedtls_x509_crt_parse returned %d\n\n", ret );
  80.         goto exit;
  81.     }
  82.     ret = mbedtls_x509_crt_parse_file(&(srvcert), cert_path);
  83.     if( ret != 0 )
  84.     {
  85.         mbedtls_printf( " failed\n ! mbedtls_x509_crt_parse returned %d\n\n", ret );
  86.         goto exit;
  87.     }

  88.     ret = ret = mbedtls_pk_parse_keyfile(&pkey, key_path, "");
  89.     if( ret != 0 )
  90.     {
  91.         mbedtls_printf( " failed\n ! mbedtls_pk_parse_key returned %d\n\n", ret );
  92.         goto exit;
  93.     }

  94.     mbedtls_printf( " ok\n" );

  95.     mbedtls_printf( " . Bind on ..." );
  96.     fflush( stdout );

  97.     if( ( ret = mbedtls_net_bind( &listen_fd, NULL, "873", MBEDTLS_NET_PROTO_TCP ) ) != 0 )
  98.     {
  99.         mbedtls_printf( " failed\n ! mbedtls_net_bind returned %d\n\n", ret );
  100.         goto exit;
  101.     }

  102.     mbedtls_printf( " ok\n" );

  103.     mbedtls_printf( " . Seeding the random number generator..." );
  104.     fflush( stdout );

  105.     if( ( ret = mbedtls_ctr_drbg_seed( &ctr_drbg, mbedtls_entropy_func, &entropy,
  106.                                (const unsigned char *) pers,
  107.                                strlen( pers ) ) ) != 0 )
  108.     {
  109.         mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_seed returned %d\n", ret );
  110.         goto exit;
  111.     }

  112.     mbedtls_printf( " ok\n" );

  113.     mbedtls_printf( " . Setting up the SSL data...." );
  114.     fflush( stdout );

  115.     if( ( ret = mbedtls_ssl_config_defaults( &conf,
  116.                     MBEDTLS_SSL_IS_SERVER,
  117.                     MBEDTLS_SSL_TRANSPORT_STREAM,
  118.                     MBEDTLS_SSL_PRESET_DEFAULT ) ) != 0 )
  119.     {
  120.         mbedtls_printf( " failed\n ! mbedtls_ssl_config_defaults returned %d\n\n", ret );
  121.         goto exit;
  122.     }

  123.     mbedtls_ssl_conf_rng( &conf, mbedtls_ctr_drbg_random, &ctr_drbg );
  124.     mbedtls_ssl_conf_dbg( &conf, my_debug, stdout );

  125. #if defined(MBEDTLS_SSL_CACHE_C)
  126.     mbedtls_ssl_conf_session_cache( &conf, &cache,
  127.                                    mbedtls_ssl_cache_get,
  128.                                    mbedtls_ssl_cache_set );
  129. #endif

  130.     mbedtls_ssl_conf_ca_chain( &conf, &cacert, NULL );
  131.     if( ( ret = mbedtls_ssl_conf_own_cert( &conf, &srvcert, &pkey ) ) != 0 )
  132.     {
  133.         mbedtls_printf( " failed\n ! mbedtls_ssl_conf_own_cert returned %d\n\n", ret );
  134.         goto exit;
  135.     }

  136.     if( ( ret = mbedtls_ssl_setup( &ssl, &conf ) ) != 0 )
  137.     {
  138.         mbedtls_printf( " failed\n ! mbedtls_ssl_setup returned %d\n\n", ret );
  139.         goto exit;
  140.     }

  141.     ret = mbedtls_ssl_set_hostname(&(ssl), "sixents");
  142.     if(ret != 0)
  143.     {
  144.        printf("mbedtls_x509_crt_parse failed, returned %d", ret);
  145.        return -1;
  146.     }

  147.     mbedtls_printf( " ok\n" );

  148. reset:
  149. #ifdef MBEDTLS_ERROR_C
  150.     if( ret != 0 )
  151.     {
  152.         char error_buf[100];
  153.         mbedtls_strerror( ret, error_buf, 100 );
  154.         mbedtls_printf("Last error was: %d - %s\n\n", ret, error_buf );
  155.     }
  156. #endif

  157.     mbedtls_net_free( &client_fd );
  158.     mbedtls_ssl_session_reset( &ssl );

  159.     mbedtls_printf( " . Waiting for a remote connection ..." );
  160.     fflush( stdout );

  161.     if( ( ret = mbedtls_net_accept( &listen_fd, &client_fd,
  162.                                     NULL, 0, NULL ) ) != 0 )
  163.     {
  164.         mbedtls_printf( " failed\n ! mbedtls_net_accept returned %d\n\n", ret );
  165.         goto exit;
  166.     }

  167.     mbedtls_ssl_set_bio( &ssl, &client_fd, mbedtls_net_send, mbedtls_net_recv, NULL );

  168.     mbedtls_printf( " ok\n" );

  169.     mbedtls_printf( " . Performing the SSL/TLS handshake..." );
  170.     fflush( stdout );

  171.     while( ( ret = mbedtls_ssl_handshake( &ssl ) ) != 0 )
  172.     {
  173.         if( ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE )
  174.         {
  175.             mbedtls_printf( " failed\n ! mbedtls_ssl_handshake returned %d\n\n", ret );
  176.             goto reset;
  177.         }
  178.     }

  179.     mbedtls_printf( " ok\n" );

  180.     mbedtls_printf( " < Read from client:" );
  181.     fflush( stdout );

  182.     do
  183.     {
  184.         len = sizeof( buf ) - 1;
  185.         memset( buf, 0, sizeof( buf ) );
  186.         ret = mbedtls_ssl_read( &ssl, buf, len );

  187.         if( ret == MBEDTLS_ERR_SSL_WANT_READ || ret == MBEDTLS_ERR_SSL_WANT_WRITE )
  188.             continue;

  189.         if( ret <= 0 )
  190.         {
  191.             switch( ret )
  192.             {
  193.                 case MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY:
  194.                     mbedtls_printf( " connection was closed gracefully\n" );
  195.                     break;
  196.                 case MBEDTLS_ERR_NET_CONN_RESET:
  197.                     mbedtls_printf( " connection was reset by peer\n" );
  198.                     break;
  199.                 default:
  200.                     mbedtls_printf( " mbedtls_ssl_read returned -0x%x\n", -ret );
  201.                     break;
  202.             }
  203.             break;
  204.         }

  205.         len = ret;
  206.         mbedtls_printf( " %d bytes read\n\n%s", len, (char *) buf );

  207.         if( ret > 0 )
  208.             break;
  209.     }
  210.     while( 1 );

  211.     /*
  212.      * 7. Write the 200 Response
  213.      */
  214.     mbedtls_printf( " > Write to client:" );
  215.     fflush( stdout );

  216.     len = sprintf( (char *) buf, HTTP_RESPONSE,
  217.                    mbedtls_ssl_get_ciphersuite( &ssl ) );

  218.     while( ( ret = mbedtls_ssl_write( &ssl, buf, len ) ) <= 0 )
  219.     {
  220.         if( ret == MBEDTLS_ERR_NET_CONN_RESET )
  221.         {
  222.             mbedtls_printf( " failed\n ! peer closed the connection\n\n" );
  223.             goto reset;
  224.         }

  225.         if( ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE )
  226.         {
  227.             mbedtls_printf( " failed\n ! mbedtls_ssl_write returned %d\n\n", ret );
  228.             goto exit;
  229.         }
  230.     }

  231.     len = ret;
  232.     mbedtls_printf( " %d bytes written\n\n%s\n", len, (char *) buf );
  233.     mbedtls_printf( " . Closing the connection..." );

  234.     while( ( ret = mbedtls_ssl_close_notify( &ssl ) ) < 0 )
  235.     {
  236.         if( ret != MBEDTLS_ERR_SSL_WANT_READ &&
  237.             ret != MBEDTLS_ERR_SSL_WANT_WRITE )
  238.         {
  239.             mbedtls_printf( " failed\n ! mbedtls_ssl_close_notify returned %d\n\n", ret );
  240.             goto reset;
  241.         }
  242.     }
  243.     mbedtls_printf( " ok\n" );

  244.     ret = 0;
  245.     goto reset;

  246. exit:

  247. #ifdef MBEDTLS_ERROR_C
  248.     if( ret != 0 )
  249.     {
  250.         char error_buf[100];
  251.         mbedtls_strerror( ret, error_buf, 100 );
  252.         mbedtls_printf("Last error was: %d - %s\n\n", ret, error_buf );
  253.     }
  254. #endif

  255.     mbedtls_net_free( &client_fd );
  256.     mbedtls_net_free( &listen_fd );
  257.     mbedtls_x509_crt_free( &srvcert );
  258.     mbedtls_pk_free( &pkey );
  259.     mbedtls_ssl_free( &ssl );
  260.     mbedtls_ssl_config_free( &conf );
  261. #if defined(MBEDTLS_SSL_CACHE_C)
  262.     mbedtls_ssl_cache_free( &cache );
  263. #endif
  264.     mbedtls_ctr_drbg_free( &ctr_drbg );
  265.     mbedtls_entropy_free( &entropy );

  266. #if defined(_WIN32)
  267.     mbedtls_printf( " Press Enter to exit this program.\n" );
  268.     fflush( stdout ); getchar();
  269. #endif

  270.     return( ret );
  271. }

  272. 4.3 客户端实现方式
  273. typedef struct {
  274.   mbedtls_net_context net_context;
  275.   mbedtls_ssl_context ssl_context;
  276.   mbedtls_ssl_config conf;
  277.   mbedtls_x509_crt cacert;

  278.   mbedtls_x509_crt certchain;
  279.   mbedtls_pk_context pkey;
  280.   mbedtls_entropy_context entropy;
  281.   mbedtls_ctr_drbg_context ctr_drbg;
  282. } tls_parm_t;

  283. int tlscomm_init(tls_parm_t *tls_parm, tlsconf_t *tlsconf, const char *ser_addr, const char *ser_port)
  284. {
  285.   int ret = 0;
  286.   int force_ciphersuite;
  287.   int corebuf_len = 8*1024;
  288.   int get_corebuf_len;
  289.   int len = 0;


  290.   if(tls_parm == NULL || tlsconf == NULL || ser_addr == NULL || ser_port == NULL)
  291.   {
  292.     zlog_error(o, "input parameter error!");
  293.     return -1;
  294.   }
  295.   
  296.   len = sizeof(get_corebuf_len);
  297.   
  298.   mbedtls_debug_set_threshold(tlsconf->debuglevel);
  299.   zlog_info(o, "init environment.");
  300.   
  301.   mbedtls_net_init(&(tls_parm->net_context));
  302.   mbedtls_ssl_init(&(tls_parm->ssl_context));
  303.   mbedtls_ssl_config_init(&(tls_parm->conf));
  304.   mbedtls_x509_crt_init(&(tls_parm->cacert));
  305.   mbedtls_x509_crt_init(&(tls_parm->certchain));
  306.   mbedtls_pk_init(&(tls_parm->pkey));
  307.   mbedtls_entropy_init(&(tls_parm->entropy));
  308.   mbedtls_ctr_drbg_init(&(tls_parm->ctr_drbg));

  309.   ret = mbedtls_x509_crt_parse_file(&(tls_parm->cacert), tlsconf->cacert);
  310.   if(ret != 0)
  311.   {
  312.     mbedtls_strerror(ret, error_buf, 128);
  313.     zlog_error(o, "mbedtls_x509_crt_parse failed, returned %d - %s", ret, error_buf);
  314.     return -1;
  315.   }

  316.   ret = mbedtls_x509_crt_parse_file(&(tls_parm->certchain), tlsconf->cert);
  317.   if( ret != 0 )
  318.   {
  319.     mbedtls_strerror(ret, error_buf, 128);
  320.     zlog_error(o, "mbedtls_x509_crt_parse failed, returned %d - %s", ret, error_buf);
  321.     return -1;
  322.   }


  323.   ret = mbedtls_pk_parse_keyfile(&(tls_parm->pkey), tlsconf->key, "");
  324.   if(ret != 0)
  325.   {
  326.     mbedtls_strerror(ret, error_buf, 128);
  327.     zlog_error(o, "mbedtls_pk_parse_key failed, returned %d - %s", ret, error_buf);
  328.     return -1;
  329.   }

  330.   if((ret = mbedtls_ctr_drbg_seed(&(tls_parm->ctr_drbg), mbedtls_entropy_func, &(tls_parm->entropy),
  331.                                   (const unsigned char *)tlsconf->seed, tlsconf->seedlen)) != 0)
  332.   {
  333.     mbedtls_strerror(ret, error_buf, 128);
  334.     zlog_error(o, "mbedtls_ctr_drbg_seed failed, returned %d - %s", ret, error_buf);
  335.     return -1;
  336.   }

  337.   zlog_info(o, "config default environment.");
  338.   if((ret = mbedtls_ssl_config_defaults(&(tls_parm->conf),
  339.  MBEDTLS_SSL_IS_CLIENT, MBEDTLS_SSL_TRANSPORT_STREAM,MBEDTLS_SSL_PRESET_DEFAULT)) != 0)
  340.   {
  341.     mbedtls_strerror(ret, error_buf, 128);
  342.     zlog_error(o, "mbedtls_ssl_config_defaults failed, returned %d - %s", ret, error_buf);
  343.     return -1;
  344.   }
  345.    
  346.   force_ciphersuite = mbedtls_ssl_get_ciphersuite_id(tlsconf->ciphersuit);
  347.   mbedtls_ssl_conf_ciphersuites(&(tls_parm->conf), &force_ciphersuite);
  348.   mbedtls_ssl_conf_dbg(&(tls_parm->conf), my_debug, stdout);
  349.   mbedtls_ssl_conf_authmode(&(tls_parm->conf), MBEDTLS_SSL_VERIFY_REQUIRED);
  350.   mbedtls_ssl_conf_rng(&(tls_parm->conf), mbedtls_ctr_drbg_random, &(tls_parm->ctr_drbg));
  351.   mbedtls_ssl_conf_ca_chain(&(tls_parm->conf), &(tls_parm->cacert), NULL);
  352.   if((ret = mbedtls_ssl_conf_own_cert(&(tls_parm->conf), &(tls_parm->certchain), &(tls_parm->pkey))) != 0)
  353.   {
  354.     mbedtls_strerror(ret, error_buf, 128);
  355.     zlog_error(o, "mbedtls_ssl_conf_own_cert failed, returned %d - %s", ret, error_buf);
  356.     return -1;
  357.   }

  358.   if((ret = mbedtls_ssl_setup(&(tls_parm->ssl_context), &(tls_parm->conf))) != 0)
  359.   {
  360.     mbedtls_strerror(ret, error_buf, 128);
  361.     zlog_error(o, "mbedtls_ssl_setup failed, returned %d - %s", ret, error_buf);
  362.     return -1;
  363.   }

  364.   if((ret = tlscomm_connect(tls_parm, ser_addr, ser_port)) != 0)
  365.   {
  366.     zlog_error(o, "tlscomm_connect is error!");
  367.     return -1;
  368.   }

  369.   mbedtls_net_set_nonblock(&tls_parm->net_context);

  370.   setsockopt(tls_parm->net_context.fd, SOL_SOCKET, SO_SNDBUF, 
  371.                                            (const char *)&corebuf_len, sizeof(int));

  372.   getsockopt(tls_parm->net_context.fd, SOL_SOCKET, SO_SNDBUF, &get_corebuf_len, 
  373.                                             (socklen_t*)&len);
  374.  
  375.   if((ret = mbedtls_ssl_set_hostname(&(tls_parm->ssl_context), tlsconf->certcn)) != 0)
  376.   {
  377.     mbedtls_strerror(ret, error_buf, 128);
  378.     return -1;
  379.   }
  380.   mbedtls_ssl_set_bio(&(tls_parm->ssl_context), &(tls_parm->net_context), mbedtls_net_send, 
  381.                                       mbedtls_net_recv, mbedtls_net_recv_timeout);
  382.   mbedtls_ssl_conf_read_timeout(&(tls_parm->conf), 6000);

  383.   if((ret = mbedtls_ssl_handshake(&(tls_parm->ssl_context))) != 0)
  384.   {
  385.     mbedtls_strerror(ret, error_buf, 128);
  386.     zlog_error(o, "mbedtls_ssl_handshake failed, returned -0x%x - %s", -ret, error_buf);
  387.     if(ret == -0x6800)
  388.     {
  389.       tls_outtime_handle();
  390.     }
  391.     return -1;
  392.   }

  393.   if((ret = mbedtls_ssl_get_verify_result(&(tls_parm->ssl_context))) != 0)
  394.   {
  395.     char vrfy_buf[512];
  396.     mbedtls_x509_crt_verify_info(vrfy_buf, sizeof(vrfy_buf), " ! ", ret);
  397.     zlog_error(o, "mbedtls_ssl_get_verify_result failed, %s", vrfy_buf);
  398.     return -1;
  399.   }
  400.   return 0;
  401. }


阅读(444) | 评论(0) | 转发(0) |
0

上一篇:linux-环形队列

下一篇:没有了

给主人留下些什么吧!~~