#include <wolfssl/options.h>#include <wolfssl/ssl.h>#include <wolfssl/test.h>#include <errno.h>#define MAX_LINE 4096int main(int argc, char** argv) {if (argv != 4) {printf("> server <cert> <key> <port>");exit(0);}int listenfd, connfd;WOLFSSL_CTX* ctx;WOLFSSL* ssl;int n;char buf[MAX_LINE];WOLFSSL_METHOD* method;/* Initialize wolfSSL library */wolfSSL_Init();/* Get encryption method */method = wolfTLSv1_2_server_method();/* Create wolfSSL_CTX */if ( (ctx = wolfSSL_CTX_new(method)) == NULL)err_sys("wolfSSL_CTX_new error");/* Load server certs into ctx */if (wolfSSL_CTX_use_certificate_file(ctx, argv[1], SSL_FILETYPE_PEM) != SSL_SUCCESS)err_sys("Error loading certs/server-cert.pem");/* Load server key into ctx */if (wolfSSL_CTX_use_PrivateKey_file(ctx, argv[2], SSL_FILETYPE_PEM) != SSL_SUCCESS)err_sys("Error loading certs/server-key.pem");tcp_accept(&listenfd, &connfd, NULL, atoi(argv[3]), 1, 0, 0, 0, 1);/* Create wolfSSL object */if ( (ssl = wolfSSL_new(ctx)) == NULL)err_sys("wolfSSL_new error");wolfSSL_set_fd(ssl, connfd);if ( (n = wolfSSL_read(ssl, buf, (sizeof(buf) -1))) > 0) {printf("%s\n", buf);if (wolfSSL_write(ssl, buf, n) != n)err_sys("wolfSSL_write error");}if (n <0)printf("wolfSSL_read error = %d\n", wolfSSL_get_error(ssl, n));else if (n == 0)printf("Connection close by peer\n");wolfSSL_free(ssl);close(connfd);wolfSSL_CTX_free(ctx);wolfSSL_Cleanup();exit(EXIT_SUCCESS);}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。