웹 소켓을 사용하는 응용 프로그램을 만들었습니다. 우리는 PHP로 자체 websocket 서버를 구축했으며 안전한 웹 소켓을 사용하기 위해 Stunnel을 사용합니다. Amazon EC2 Medium Server를 사용합니다Secure Websocket (wss) Stunnel을 사용하여 핸드 셰이크가 발생하지 않습니다.
지난 주 갑자기 Chrome 브라우저가 표시되기 시작했을 때까지 모든 것이 올바르게 작동했습니다. WebSocket 핸드 셰이크 중 오류 : net :: ERR_CONNECTION_RESET. Firefox에서도 연결이 끊어졌습니다.
그러나 시간에 wss 연결이 발생합니다. 우리가 페이지를 새로 고침 할 때 그 같은 것은 4 번 또는 5 번 이후일지도 모릅니다. wss 연결은 한 번 발생합니다. 되는 Stunnel에서
: 새로운 SSL 세션이 생성됩니다
이 모든 것이 잘 작동
우리는 아래의 문제를 분석하고있다
우리가 관찰 한 것들입니다. 아래는 세션이 재사용되는 경우에는, 연결이 PHP의 웹 소켓에서 닫힌 로그2014.12.05 05:56:08 LOG7[13990:140019053639616]: Service [websockets] accepted (FD=14) from 115.111.211.142:60018
2014.12.05 05:56:08 LOG7[13990:140019053496064]: Service [websockets] started
2014.12.05 05:56:08 LOG5[13990:140019053496064]: Service [websockets] accepted connection from 115.111.211.142:60018
2014.12.05 05:56:08 LOG7[13990:140019053496064]: SSL state (accept): before/accept initialization
2014.12.05 05:56:08 LOG7[13990:140019053496064]: SNI: no virtual services defined
2014.12.05 05:56:08 LOG7[13990:140019053496064]: SSL state (accept): SSLv3 read client hello B
2014.12.05 05:56:08 LOG7[13990:140019053496064]: SSL state (accept): SSLv3 write server hello A
2014.12.05 05:56:08 LOG7[13990:140019053496064]: SSL state (accept): SSLv3 write certificate A
2014.12.05 05:56:08 LOG7[13990:140019053496064]: SSL state (accept): SSLv3 write key exchange A
2014.12.05 05:56:08 LOG7[13990:140019053496064]: SSL state (accept): SSLv3 write server done A
2014.12.05 05:56:08 LOG7[13990:140019053496064]: SSL state (accept): SSLv3 flush data
2014.12.05 05:56:08 LOG7[13990:140019053496064]: SSL state (accept): SSLv3 read client key exchange A
2014.12.05 05:56:08 LOG7[13990:140019053496064]: SSL state (accept): SSLv3 read finished A
2014.12.05 05:56:08 LOG7[13990:140019053496064]: SSL state (accept): SSLv3 write session ticket A
2014.12.05 05:56:08 LOG7[13990:140019053496064]: SSL state (accept): SSLv3 write change cipher spec A
2014.12.05 05:56:08 LOG7[13990:140019053496064]: SSL state (accept): SSLv3 write finished A
2014.12.05 05:56:08 LOG7[13990:140019053496064]: SSL state (accept): SSLv3 flush data
2014.12.05 05:56:08 LOG7[13990:140019053496064]: 10 items in the session cache
2014.12.05 05:56:08 LOG7[13990:140019053496064]: 0 client connects (SSL_connect())
2014.12.05 05:56:08 LOG7[13990:140019053496064]: 0 client connects that finished
2014.12.05 05:56:08 LOG7[13990:140019053496064]: 0 client renegotiations requested
2014.12.05 05:56:08 LOG7[13990:140019053496064]: 1138 server connects (SSL_accept())
2014.12.05 05:56:08 LOG7[13990:140019053496064]: 1087 server connects that finished
2014.12.05 05:56:08 LOG7[13990:140019053496064]: 0 server renegotiations requested
2014.12.05 05:56:08 LOG7[13990:140019053496064]: 558 session cache hits
2014.12.05 05:56:08 LOG7[13990:140019053496064]: 0 external session cache hits
2014.12.05 05:56:08 LOG7[13990:140019053496064]: 0 session cache misses
2014.12.05 05:56:08 LOG7[13990:140019053496064]: 132 session cache timeouts
2014.12.05 05:56:08 LOG6[13990:140019053496064]: SSL accepted: new session negotiated
2014.12.05 05:56:08 LOG6[13990:140019053496064]: Negotiated TLSv1/SSLv3 ciphersuite: DHE-RSA-AES128-SHA (128-bit encryption)
2014.12.05 05:56:08 LOG6[13990:140019053496064]: Compression: null, expansion: null
2014.12.05 05:56:08 LOG6[13990:140019053496064]: connect_blocking: connecting 127.0.0.1:9000
2014.12.05 05:56:08 LOG7[13990:140019053496064]: connect_blocking: s_poll_wait 127.0.0.1:9000: waiting 10 seconds
2014.12.05 05:56:08 LOG5[13990:140019053496064]: connect_blocking: connected 127.0.0.1:9000
2014.12.05 05:56:08 LOG5[13990:140019053496064]: Service [websockets] connected remote server from 127.0.0.1:18479
입니다. 세션 재사용 그냥 데이터와 아무것도 그래서 핸드 셰이크가 실패로 문자열 'G'를 얻는 웹 소켓 서버를 발생
: 아래의 로그 우리의 PHP 웹 소켓 서버에서
2014.12.05 05:56:08 LOG7[13990:140019053496064]: Remote socket (FD=15) initialized
2014.12.05 05:56:39 LOG6[13990:140019053496064]: Read socket closed (readsocket)
2014.12.05 05:56:39 LOG7[13990:140019053496064]: Sending close_notify alert
2014.12.05 05:56:39 LOG7[13990:140019053496064]: SSL alert (write): warning: close notify
2014.12.05 05:56:39 LOG6[13990:140019053496064]: SSL_shutdown successfully sent close_notify alert
2014.12.05 05:56:39 LOG3[13990:140019053496064]: transfer: s_poll_wait: TIMEOUTclose exceeded: closing
2014.12.05 05:56:39 LOG5[13990:140019053496064]: Connection closed: 988 byte(s) sent to SSL, 873 byte(s) sent to socket
2014.12.05 05:56:39 LOG7[13990:140019053496064]: Remote socket (FD=15) closed
2014.12.05 05:56:39 LOG7[13990:140019053496064]: Local socket (FD=14) closed
2014.12.05 05:56:39 LOG7[13990:140019053496064]: Service [websockets] finished (3 left)
2014.12.05 05:56:43 LOG7[13990:140019053639616]: Service [websockets] accepted (FD=14) from 115.111.211.142:60045
2014.12.05 05:56:43 LOG7[13990:140019053496064]: Service [websockets] started
2014.12.05 05:56:43 LOG5[13990:140019053496064]: Service [websockets] accepted connection from 115.111.211.142:60045
2014.12.05 05:56:43 LOG7[13990:140019053496064]: SSL state (accept): before/accept initialization
2014.12.05 05:56:43 LOG7[13990:140019053496064]: SNI: no virtual services defined
2014.12.05 05:56:43 LOG7[13990:140019053496064]: SSL state (accept): SSLv3 read client hello B
2014.12.05 05:56:43 LOG7[13990:140019053496064]: SSL state (accept): SSLv3 write server hello A
2014.12.05 05:56:43 LOG7[13990:140019053496064]: SSL state (accept): SSLv3 write change cipher spec A
2014.12.05 05:56:43 LOG7[13990:140019053496064]: SSL state (accept): SSLv3 write finished A
2014.12.05 05:56:43 LOG7[13990:140019053496064]: SSL state (accept): SSLv3 flush data
2014.12.05 05:56:43 LOG7[13990:140019053496064]: SSL state (accept): SSLv3 read finished A
2014.12.05 05:56:43 LOG7[13990:140019053496064]: 10 items in the session cache
2014.12.05 05:56:43 LOG7[13990:140019053496064]: 0 client connects (SSL_connect())
2014.12.05 05:56:43 LOG7[13990:140019053496064]: 0 client connects that finished
2014.12.05 05:56:43 LOG7[13990:140019053496064]: 0 client renegotiations requested
2014.12.05 05:56:43 LOG7[13990:140019053496064]: 1139 server connects (SSL_accept())
2014.12.05 05:56:43 LOG7[13990:140019053496064]: 1088 server connects that finished
2014.12.05 05:56:43 LOG7[13990:140019053496064]: 0 server renegotiations requested
2014.12.05 05:56:43 LOG7[13990:140019053496064]: 559 session cache hits
2014.12.05 05:56:43 LOG7[13990:140019053496064]: 0 external session cache hits
2014.12.05 05:56:43 LOG7[13990:140019053496064]: 0 session cache misses
2014.12.05 05:56:43 LOG7[13990:140019053496064]: 132 session cache timeouts
2014.12.05 05:56:43 LOG6[13990:140019053496064]: SSL accepted: previous session reused
2014.12.05 05:56:43 LOG6[13990:140019053496064]: connect_blocking: connecting 127.0.0.1:9000
2014.12.05 05:56:43 LOG7[13990:140019053496064]: connect_blocking: s_poll_wait 127.0.0.1:9000: waiting 10 seconds
2014.12.05 05:56:43 LOG5[13990:140019053496064]: connect_blocking: connected 127.0.0.1:9000
2014.12.05 05:56:43 LOG5[13990:140019053496064]: Service [websockets] connected remote server from 127.0.0.1:18480
2014.12.05 05:56:43 LOG7[13990:140019053496064]: Remote socket (FD=15) initialized
2014.12.05 05:56:43 LOG6[13990:140019053496064]: Read socket closed (readsocket)
2014.12.05 05:56:43 LOG7[13990:140019053496064]: Sending close_notify alert
2014.12.05 05:56:43 LOG5[13990:140019053496064]: Read socket error: Broken pipe (32)
2014.12.05 05:56:43 LOG5[13990:140019053496064]: Connection reset: 0 byte(s) sent to SSL, 516 byte(s) sent to socket
2014.12.05 05:56:43 LOG7[13990:140019053496064]: Remote socket (FD=15) closed
2014.12.05 05:56:43 LOG7[13990:140019053496064]: Local socket (FD=14) closed
2014.12.05 05:56:43 LOG7[13990:140019053496064]: Service [websockets] finished (3 left)
입니다. 그러나 Stunnel에 새로운 세션이 생성되면 핸드 셰이크가 제대로 작동합니다.
누군가가 우리를 도울 수 있다면 좋을 것입니다. 우리는 지금까지이 문제를 해결하기 위해 수행 한 어떤
: 아파치
- 장애인 SSL 캐시. 문제가 계속 발생합니다.
- stunnel에서 사용 된 세션 캐시 설정입니다. 아직 문제가 있습니다. 또한 우리는 세션 캐시 설정과이를 비활성화하는 방법에 대해 명확하게 이해하지 못했습니다.
우리는 다음
다시 컴파일되는 Stunnel을하고 코드에서 SSL 캐시를 비활성화하려고 계획 무엇.
정지되는 Stunnel을 사용하여 PHP에서 SSL 연결을 설정하는 방법을 알아보십시오. 이러한 연결을 만들려면 stream_context_create과 같은 것을 얻습니다. 그러나 여전히 우리는 새로운 서버로 모든 이동과 장소 문제를 참조
stream_context_create
- 의 세부 정보를 볼 수 있습니다.
희망을 분명히했습니다. 답장을 기다리고 있습니다. 감사! 스트림 오프
스트림에서 1 바이트를 먼저 읽은 다음 전체 읽기 (1 바이트를 전체 읽기까지 연결)를 수행합니다. "G"는 "GET"의 첫 번째 바이트 일 가능성이 큽니다. 나는 그것이 무엇이 원인인지 모르겠다. 그러나 나는 이것을 최근에 경험했다. –
와우 :이 효과가 있습니다! 존, 고마워. 나는 그런 간단한 해결책에 놀란다! – yashair23
이것은 .NET에서 정상적인'SslStream'으로 나에게도 일어났다. 버퍼에는 TLS 협상에 대한 데이터도 포함되어 있기 때문에 실제 데이터의 첫 번째 바이트 만 버퍼에 들어갔 기 때문에 생각합니다. – vtortola