带有openSSL的libwebsocket服务器不接受连接
libwebsocket server with openSSL not accepting connection
我在(libwebsocket库(的帮助下编写了web套接字服务器,它接受非SSL的web套接字客户端连接。现在我想让它接受SSL连接,所以我生成了自签名证书和密钥,在创建web套接字上下文时,我还提供了密钥和证书路径以及选项LWS_SERVER_option_DO_SSL_GLOBAL_INIT。但是在使用进行https连接时wss://ip:7681我正在从中获取连接请求回调,即LWS_callback_SERVER_NEW_CLIENT_INSTANTIATED,之后LWS_callback_WSI_DESTROY和浏览器中获取关于无法连接的控制台错误。
Firefox can’t establish a connection to the server at wss://192.168.4.254:7681/.
请检查以下用于创建基于openSSL的web套接字服务器的服务器端代码。
struct lws_protocols WebSocketCommon::protocols[ 2 ] = { {"wss", WebSocketCommon::callback, 0, 0 },{ NULL, NULL, 0, 0 } };
int callback ( struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len ) {
switch ( reason ) {
case LWS_CALLBACK_SERVER_NEW_CLIENT_INSTANTIATED:
{
//code
break;
}
case LWS_CALLBACK_WSI_DESTROY:
{
//code
break;
}
case LWS_CALLBACK_OPENSSL_LOAD_EXTRA_SERVER_VERIFY_CERTS: {
Log::d( m_r_logger, TAG, "LWS_CALLBACK_OPENSSL_LOAD_EXTRA_SERVER_VERIFY_CERTSn");
SSL_CTX_load_verify_locations( (SSL_CTX*) user, NULL, getenv(SSL_CERT_FILE_PATH) );
break;
}
default: {
break;
}
}
return lws_callback_http_dummy(wsi, reason, user, in, len);
}
void createContext (bool useSSL) {
struct lws_context_creation_info info;
memset( &info, 0, sizeof(struct lws_context_creation_info) );
info.port = 7681;
info.uid = -1;
info.gid = -1;
info.protocols = protocols;
info.mounts = &mount;
info.extensions = exts;
info.timeout_secs = 5;
info.ip_limit_ah = 24; /* for testing */
info.ip_limit_wsi = 400; /* for testing */
// Following options for openSSL certificate
if(useSSL){
info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT | LWS_SERVER_OPTION_ALLOW_NON_SSL_ON_SSL_PORT | LWS_SERVER_OPTION_DISABLE_IPV6 | LWS_SERVER_OPTION_PEER_CERT_NOT_REQUIRED | LWS_SERVER_OPTION_IGNORE_MISSING_CERT;
info.ssl_cert_filepath = SSL_CERT_FILE_PATH;
info.ssl_private_key_filepath = SSL_PRIVATE_KEY_PATH;
}
fContext = lws_create_context( &info );
}
在创建web套接字上下文和接受wss连接时,我收到了以下日志。
WebSocket.cpp:638...... :createContext ( ) - begin
WebSocket.cpp:640...... : createContext - fReferenceCount = 0
WebSocket.cpp:324...... : Creating Vhost 'default' port 7681, 1 protocols, IPv6 off
WebSocket.cpp:324...... : Using SSL mode
WebSocket.cpp:324...... : SSL ECDH curve 'prime256v1'
WebSocket.cpp:612...... : LWS_CALLBACK_OPENSSL_LOAD_EXTRA_SERVER_VERIFY_CERTS
WebSocket.cpp:324...... : lws_tls_client_create_vhost_context: doing cert filepath /etc/nginx /ssl/mycert.crt
WebSocket.cpp:324...... : Loaded client cert /etc/nginx/ssl/mycert.crt
WebSocket.cpp:324...... : lws_tls_client_create_vhost_context: doing private key filepath
WebSocket.cpp:324...... : Loaded client cert private key /etc/nginx/ssl/mykey.key
WebSocket.cpp:324...... : created client ssl context for default
WebSocket.cpp:684...... : lws_create_context SUCCEEDED
WebSocket.cpp:759...... : start Starting Service Thread.
WebSocket.cpp:705...... : createContext - fReferenceCount = 1
WebSocket.cpp:706...... : createContext - end
以下是我正在使用的库版本。
libwebsocket.so 13
OpenSSL 1.0.2o 27 Mar 2018
请告诉我出了什么问题?
这个问题可能与libwebsocket无关,而是与Firefox对允许连接到具有自签名证书的WSS过于挑剔有关。尝试从其他程序连接到服务器,例如,一个简单的python程序。
相关:
Websocket和自签名SSL证书有什么问题
Firefox断开自签名证书的websockets连接
相关文章:
- 为什么线程不接受此输入?
- 函数不接受 X 参数,函数使用默认参数
- C++ boost::asio::ip::tcp::acceptor 有时不接受连接器?
- B不接受8作为输入的是什么?C++
- C++数组输入不接受一定数量的整数
- C++概念assignable_from不接受 const&-return 运算符=
- 斯堪夫不接受输入
- C++字符数组不接受超过 4 个字符的输入
- CIN不接受C++中带有空格的输入?
- 为什么C++ STL 哈希表 (unordered_map) 不接受向量作为键
- 带有openSSL的libwebsocket服务器不接受连接
- C 套接字服务器不接受任何客户端 /客户端无法连接
- C++ 套接字侦听器 accept() 在发布时不接受连接请求
- MySQL 服务器不接受远程连接
- boost::asio sync server 在第一个连接后不接受连接
- 套接字不接受连接
- 异步服务器不接受连接
- 在Linux上监听套接字连接而不接受调用
- 为什么这个简单的服务器不接受连接?
- DLib - 为什么 start_async() 不接受后台线程中的连接?