- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我知道还有很多其他类似的问题,但经过几天的尝试,我没有更多的想法来解决这个问题。
我是第一次体验 Websocket 连接,我需要构建一个简单的聊天,为此我正在尝试 PHPWebSocketServer ( https://github.com/ghedipunk/PHP-WebSockets ),所以我测试了这个聊天示例 ( https://github.com/Flynsarmy/PHPWebSocket-Chat ) 和一切正常,直到我使用 ws 连接(这是一个已知的故事)。
对于 wss,我已经使用 pem 签名的 OpenSSL 证书设置了 Stunnel,服务已启动,端口 (9040 - 9000) 已打开并且 websocket 服务器正在正确监听端口 9000 (php ./server.php ), 但我不明白为什么在 stunnel.log 中每次浏览器客户端调用中总是出现“证书错误”错误。
下面是所有可能有用的文件和日志。从 Websocket php 服务器文件开始:
服务器.php
<?php
// prevent the server from timing out
set_time_limit(0);
// include the web sockets server script (the server is started at the far bottom of this file)
require 'class.PHPWebSocket.php';
// when a client sends data to the server
function wsOnMessage($clientID, $message, $messageLength, $binary) {
global $Server;
$ip = long2ip( $Server->wsClients[$clientID][6] );
// check if message length is 0
if ($messageLength == 0) {
$Server->wsClose($clientID);
return;
}
//The speaker is the only person in the room. Don't let them feel lonely.
if ( sizeof($Server->wsClients) == 1 )
$Server->wsSend($clientID, "There isn't anyone else in the room, but I'll still listen to you. --Your Trusty Server");
else
//Send the message to everyone but the person who said it
foreach ( $Server->wsClients as $id => $client )
if ( $id != $clientID )
$Server->wsSend($id, "Visitor $clientID ($ip) said \"$message\"");
}
// when a client connects
function wsOnOpen($clientID)
{
global $Server;
$ip = long2ip( $Server->wsClients[$clientID][6] );
$Server->log( "$ip ($clientID) has connected." );
//Send a join notice to everyone but the person who joined
foreach ( $Server->wsClients as $id => $client )
if ( $id != $clientID )
$Server->wsSend($id, "Visitor $clientID ($ip) has joined the room.");
}
// when a client closes or lost connection
function wsOnClose($clientID, $status) {
global $Server;
$ip = long2ip( $Server->wsClients[$clientID][6] );
$Server->log( "$ip ($clientID) has disconnected." );
//Send a user left notice to everyone in the room
foreach ( $Server->wsClients as $id => $client )
$Server->wsSend($id, "Visitor $clientID ($ip) has left the room.");
}
// start the server
$Server = new PHPWebSocket();
$Server->bind('message', 'wsOnMessage');
$Server->bind('open', 'wsOnOpen');
$Server->bind('close', 'wsOnClose');
// for other computers to connect, you will probably need to change this to your LAN IP or external IP,
// alternatively use: gethostbyaddr(gethostbyname($_SERVER['SERVER_NAME']))
$Server->wsStartServer('0.0.0.0', 9000);
?>
客户端聊天.php
<html>
<head>
<meta charset='UTF-8' />
<style>
input, textarea {border:1px solid #CCC;margin:0px;padding:0px}
#body {max-width:800px;margin:auto}
#log {width:100%;height:400px}
#message {width:100%;line-height:20px}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="fancywebsocket.js"></script>
<script>
var Server;
function log( text ) {
$log = $('#log');
//Add text to log
$log.append(($log.val()?"\n":'')+text);
//Autoscroll
$log[0].scrollTop = $log[0].scrollHeight - $log[0].clientHeight;
}
function send( text ) {
Server.send( 'message', text );
}
$(document).ready(function() {
log('Connecting...');
Server = new FancyWebSocket('wss://xx.xx.xx.xx:9040');
$('#message').keypress(function(e) {
if ( e.keyCode == 13 && this.value ) {
log( 'You: ' + this.value );
send( this.value );
$(this).val('');
}
});
//Let the user know we're connected
Server.bind('open', function() {
log( "Connected." );
});
//OH NOES! Disconnection occurred.
Server.bind('close', function( data ) {
log( "Disconnected." );
});
//Log any messages sent from server
Server.bind('message', function( payload ) {
log( payload );
});
Server.connect();
});
</script>
</head>
<body>
<div id='body'>
<textarea id='log' name='log' readonly='readonly'></textarea><br/>
<input type='text' id='message' name='message' />
</div>
</body>
</html>
stunnel.conf
cert = /home/myuser/ssl-cert/ssl/stunnel.pem
key = /home/myuser/ssl-cert/mykey.key
chroot = /var/run/stunnel
pid = /stunnel.pid
client = no
fips = no
sslVersion = all
options = NO_SSLv2 ;also commented but same result
options = NO_SSLv3 ;also commented but same result
accept = foobar
socket = l:TCP_NODELAY=1
socket = r:TCP_NODELAY=1
debug = 7
output = /var/log/stunnel/stunnel.log
[stunnel]
accept = 0.0.0.0:9040
connect = 127.0.0.1:9000
我的 OpenSSL 签名证书来自 ssls (COMODO) CA,正如 stunnel howto 中所建议的,我使用服务器机器的主机名作为通用名称,我们称之为 (mydomain.com),但我还有另一个以我网站的域名作为https模式(www.mydomain.com)的通用名称的OpenSSL证书,我都用过,但错误仍然相同。
无论如何,COMODO 向我发送了 4 个不同的文件,mydomain_com.crt、COMODORSADomainValidationSecureServerCA.crt、COMODORSAAddTrustCA.crt、AddTrustExternalCARoot.crt,我已经按照这种方式将它们分类到 stunnel.pem 文件中。
stunnel.log(服务启动时)
2015.04.24 17:39:30 LOG7[13406:139929686013888]: Snagged 64 random bytes from /dev/urandom
2015.04.24 17:39:30 LOG7[13406:139929686013888]: RAND_status claims sufficient entropy for the PRNG
2015.04.24 17:39:30 LOG7[13406:139929686013888]: PRNG seeded successfully
2015.04.24 17:39:30 LOG7[13406:139929686013888]: Configuration SSL options: 0x03000000
2015.04.24 17:39:30 LOG7[13406:139929686013888]: SSL options set: 0x03000004
2015.04.24 17:39:30 LOG7[13406:139929686013888]: Certificate: /home/myuser/ssl-cert/ssl/stunnel.pem
2015.04.24 17:39:30 LOG7[13406:139929686013888]: Certificate loaded
2015.04.24 17:39:30 LOG7[13406:139929686013888]: Key file: /home/myuser/ssl-cert/mykey.key
2015.04.24 17:39:30 LOG7[13406:139929686013888]: Private key loaded
2015.04.24 17:39:30 LOG7[13406:139929686013888]: SSL context initialized for service stunnel
2015.04.24 17:39:30 LOG7[13406:139929686013888]: FIPS mode disabled
2015.04.24 17:39:31 LOG5[13406:139929686013888]: stunnel 4.29 on x86_64-redhat-linux-gnu with OpenSSL 1.0.1e-fips 11 Feb 2013
2015.04.24 17:39:31 LOG5[13406:139929686013888]: Threading:PTHREAD SSL:ENGINE,FIPS Sockets:POLL,IPv6 Auth:LIBWRAP
2015.04.24 17:39:31 LOG6[13406:139929686013888]: file ulimit = 1024 (can be changed with 'ulimit -n')
2015.04.24 17:39:31 LOG6[13406:139929686013888]: poll() used - no FD_SETSIZE limit for file descriptors
2015.04.24 17:39:31 LOG5[13406:139929686013888]: 500 clients allowed
2015.04.24 17:39:31 LOG7[13406:139929686013888]: FD 10 in non-blocking mode
2015.04.24 17:39:31 LOG7[13406:139929686013888]: FD 11 in non-blocking mode
2015.04.24 17:39:31 LOG7[13406:139929686013888]: FD 12 in non-blocking mode
2015.04.24 17:39:31 LOG7[13406:139929686013888]: SO_REUSEADDR option set on accept socket
2015.04.24 17:39:31 LOG7[13406:139929686013888]: stunnel bound to 0.0.0.0:9040
2015.04.24 17:39:31 LOG7[13412:139929686013888]: Created pid file /stunnel.pid
stunnel.log(客户端wss调用)
2015.04.24 17:45:10 LOG7[13412:139929686013888]: stunnel accepted FD=13 from xx.xx.xx.xx:62481
2015.04.24 17:45:10 LOG7[13412:139929686116096]: stunnel started
2015.04.24 17:45:10 LOG7[13412:139929686116096]: FD 13 in non-blocking mode
2015.04.24 17:45:10 LOG7[13412:139929686116096]: TCP_NODELAY option set on local socket
2015.04.24 17:45:10 LOG7[13412:139929686116096]: Waiting for a libwrap process
2015.04.24 17:45:10 LOG7[13412:139929686116096]: Acquired libwrap process #0
2015.04.24 17:45:10 LOG7[13412:139929686116096]: Releasing libwrap process #0
2015.04.24 17:45:10 LOG7[13412:139929686116096]: Released libwrap process #0
2015.04.24 17:45:10 LOG7[13412:139929686116096]: stunnel permitted by libwrap from xx.xx.xx.xx:62481
2015.04.24 17:45:10 LOG5[13412:139929686116096]: stunnel accepted connection from xx.xx.xx.xx:62481
2015.04.24 17:45:10 LOG7[13412:139929686116096]: SSL state (accept): before/accept initialization
2015.04.24 17:45:10 LOG7[13412:139929686116096]: SSL state (accept): SSLv3 read client hello A
2015.04.24 17:45:10 LOG7[13412:139929686116096]: SSL state (accept): SSLv3 write server hello A
2015.04.24 17:45:10 LOG7[13412:139929686116096]: SSL state (accept): SSLv3 write certificate A
2015.04.24 17:45:10 LOG7[13412:139929686116096]: SSL state (accept): SSLv3 write server done A
2015.04.24 17:45:10 LOG7[13412:139929686116096]: SSL state (accept): SSLv3 flush data
2015.04.24 17:45:10 LOG7[13412:139929686116096]: SSL state (accept): SSLv3 read client key exchange A
2015.04.24 17:45:10 LOG7[13412:139929686116096]: SSL state (accept): SSLv3 read finished A
2015.04.24 17:45:10 LOG7[13412:139929686116096]: SSL state (accept): SSLv3 write session ticket A
2015.04.24 17:45:10 LOG7[13412:139929686116096]: SSL state (accept): SSLv3 write change cipher spec A
2015.04.24 17:45:10 LOG7[13412:139929686116096]: SSL state (accept): SSLv3 write finished A
2015.04.24 17:45:10 LOG7[13412:139929686116096]: SSL state (accept): SSLv3 flush data
2015.04.24 17:45:10 LOG7[13412:139929686116096]: 0 items in the session cache
2015.04.24 17:45:10 LOG7[13412:139929686116096]: 0 client connects (SSL_connect())
2015.04.24 17:45:10 LOG7[13412:139929686116096]: 0 client connects that finished
2015.04.24 17:45:10 LOG7[13412:139929686116096]: 0 client renegotiations requested
2015.04.24 17:45:10 LOG7[13412:139929686116096]: 1 server connects (SSL_accept())
2015.04.24 17:45:10 LOG7[13412:139929686116096]: 1 server connects that finished
2015.04.24 17:45:10 LOG7[13412:139929686116096]: 0 server renegotiations requested
2015.04.24 17:45:10 LOG7[13412:139929686116096]: 0 session cache hits
2015.04.24 17:45:10 LOG7[13412:139929686116096]: 0 external session cache hits
2015.04.24 17:45:10 LOG7[13412:139929686116096]: 0 session cache misses
2015.04.24 17:45:10 LOG7[13412:139929686116096]: 0 session cache timeouts
2015.04.24 17:45:10 LOG6[13412:139929686116096]: SSL accepted: new session negotiated
2015.04.24 17:45:10 LOG6[13412:139929686116096]: Negotiated ciphers: AES128-SHA SSLv3 Kx=RSA Au=RSA Enc=AES(128) Mac=SHA1
2015.04.24 17:45:10 LOG7[13412:139929686116096]: FD 14 in non-blocking mode
2015.04.24 17:45:10 LOG6[13412:139929686116096]: connect_blocking: connecting 127.0.0.1:9000
2015.04.24 17:45:10 LOG7[13412:139929686116096]: connect_blocking: s_poll_wait 127.0.0.1:9000: waiting 10 seconds
2015.04.24 17:45:10 LOG5[13412:139929686116096]: connect_blocking: connected 127.0.0.1:9000
2015.04.24 17:45:10 LOG5[13412:139929686116096]: stunnel connected remote server from 127.0.0.1:50258
2015.04.24 17:45:10 LOG7[13412:139929686116096]: Remote FD=14 initialized
2015.04.24 17:45:10 LOG7[13412:139929686116096]: TCP_NODELAY option set on remote socket
2015.04.24 17:45:10 LOG7[13412:139929686116096]: SSL alert (read): fatal: bad certificate
2015.04.24 17:45:10 LOG3[13412:139929686116096]: SSL_read: 14094412: error:14094412:SSL routines:SSL3_READ_BYTES:sslv3 alert bad certificate
2015.04.24 17:45:10 LOG5[13412:139929686116096]: Connection reset: 0 bytes sent to SSL, 0 bytes sent to socket
2015.04.24 17:45:10 LOG7[13412:139929686116096]: stunnel finished (0 left)
我也试过openssl客户端连接
openssl s_client -connect xx.xx.xx.xx:9040
而且有效!
请帮忙!
最佳答案
i've also tried the openssl client connection ... and it works!
尚不清楚什么在起作用:可能是连接和 SSL 握手在起作用。如果信任链对您有效,您将得到 Verify return code: 0 (ok)
。但是 openssl s_client
不做任何主机名检查,而浏览器会做。
Server = new FancyWebSocket('wss://xx.xx.xx.xx:9040');
这仅在您的证书确实适用于给定 IP 时才有效。但我怀疑您是否为特定 IP 购买了证书,因为人们通常为主机名购买证书。由于您不通过证书中包含的名称访问服务器,因此主机名验证将失败。
关于带有 OpenSSL 签名证书的 PHP Websocket SSL Stunnel "bad certificate",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29852209/
我已经创建了一个 conf 文件,用于连接到位于/usr/local/etc/stunnel/中的 stunnel 的地址和端口,并启动了 stunnel 服务。 我已经把地址绑定(bind)到我的本
我有运行 stunnel 的机器 A。我正在从机器 B 的机器 A 的端口上发送数据,但是当请求来自不同的机器时,stunnel 没有监听这个端口。当我从本地计算机在同一端口上发送请求时,它工作正常。
我正在尝试了解用于在 stunnel 上到期时更换证书的程序。所以我在 Windows 上安装了一个简单配置的 stunnel: [test1] accept = 127.0.0.1:21234 co
1 个关于 Stunnel 的问题。我想将 Stunnel 用作互联网的 FIX(金融信息交换)网关,以支持 SSL 和非 SSL 连接。 Stunnel 是否可以在没有任何加密的情况下运行?我刚刚尝
我正在尝试在 Windows 中使用 REDIS 设置 stunnel。安装 stunnel 和 redis 后,我在服务器和客户端模式下进行了以下配置: 客户端机器配置: [redis-stunne
我知道 STunnel 可以通过配置文件中的“client = no”或“client = yes”行设置为服务器或客户端。有没有办法让一台机器既是服务器又是客户端? 最佳答案 这样就容易多了您只需在
我正在尝试更正 CentOS 6.x 的以下 stunnel 语法: stunnel -c -f -d 1143 -r imap.foo.tld:993 -P '' 建议的语法不起作用: -c: No
我使用 stunnel 版本 4.29 连接到服务,该服务的提供者禁用了通过 stunnel 4.29 的连接。这现在需要我从 WHM 更新我的 stunnel。 我更新使用 yum update
我有 Ratchet webSocket 服务器在运行并且运行良好。问题是某些连接在握手后立即关闭。 在搜索 stackOverflow 和 google 之后我发现我应该使用 wss,因为使用 ss
有人可以向我解释使用一种优于另一种的好处吗?它们具有可比性吗? 我知道 sshuttle 充当出站通信的代理,但是它也可以用于转发连接吗? 例如,stunnel 可以用作在我的网络之外传输数据的反向代
我有一个完全可操作的系统,其中基于 openssl 的客户端与 openssl 服务器交互。每个客户端都有自己的证书,由服务器验证。已使用 openssl(X509、pem)生成证书。它们是自签名的。
我有一个监听端口 8081 的 Web 服务(它是一个在单声道上运行的 ServiceStack REST Web 服务,如果有帮助的话)。我正在尝试使用 stunnel 保护它,但问题是一旦我连接到
寻求一些帮助,以通过 FIX4.4 协议(protocol)使用 stunnel 和 quickfix python 与我的经纪人 DUKASCOPY 建立连接。 这是我的 channel 配置: c
一段时间以来,我一直在启用 SSL 的页面上使用 stunnel 进行本地 Django 开发,但是自从升级到 Yosemite 之后它似乎停止工作了: $ sudo stunnel stunnel/
在 CentOS 7 上运行 Apache v2.4、PHP v5.6 w/php-fpm 所以我正在尝试让 wss 与 stunnel & Ratchet 一起工作。我有 Ratchet 的 Hel
我需要连接的服务为我提供了三个文件,我正在尝试弄清楚我需要什么来创建 STUNNEL 需要的 Cert=xxx.PEM 文件 我有一个“keystore.jks”文件。用 keytool 转储说这是一
我正在尝试通过 stunnel 实现 TCP 套接字,但不确定如何捕获服务器响应。我的stunnel配置文件是这样的: [Coinbase] client = yes accept = 127.0.0
我正在尝试使用 stunnel 将 wss 连接转换为 ws 连接,因为 wsServer不支持wss。服务器运行的是 Ubuntu,而我使用的客户端是 Chrome,如果重要的话。 这是我的stun
我在 Ubuntu 14.04 上使用 stunnel4 安全地将连接转发到远程连接。我重新启动了 stunnel 服务,它似乎正在正常运行,但我无法打开与 127.0.0.1:8888 的连接。 $
SSL 保护 Redis 集群的正确方法是什么? (客户端-服务器、节点-节点通信)。 如 Redis 集群规范中所述,集群上的每个节点都监听 2 个端口:用于“外部”通信的端口和用于集群总线的端口。
我是一名优秀的程序员,十分优秀!