how to close secure websocket properly

Discussion to talk about software related topics only.
RebootExpert
Posts: 78
Joined: Fri Oct 09, 2020 2:57 pm

how to close secure websocket properly

Post by RebootExpert »

I try to use the function close() to close a secure websocket and it will stop my app from working. but it runs fine with non secure websocket

Code: Select all

printf("closing wss_fd = %d\r\n", wss_fd);
close(wss_fd);
printf("wss_fd = %d closed\r\n", wss_fd);
the second print statement never execute.
User avatar
pbreed
Posts: 1080
Joined: Thu Apr 24, 2008 3:58 pm

Re: how to close secure websocket properly

Post by pbreed »

That should work...
What NNDK version are you running on what platform?
User avatar
pbreed
Posts: 1080
Joined: Thu Apr 24, 2008 3:58 pm

Re: how to close secure websocket properly

Post by pbreed »

I'd like to try to reproduce your issue....
Platform?
NNDK version?
RebootExpert
Posts: 78
Joined: Fri Oct 09, 2020 2:57 pm

Re: how to close secure websocket properly

Post by RebootExpert »

It's 2.9.3 and mod54415. The weird thing is that sometimes it prints out and sometimes it doesn't.
User avatar
pbreed
Posts: 1080
Joined: Thu Apr 24, 2008 3:58 pm

Re: how to close secure websocket properly

Post by pbreed »

Ok for close sometimes and not others, I might suspect some stack issues....
I'll see if we can recreate...

I've got a few things ahead of this on my plate, I'll see if the engineer working on TLS can take a look...
RebootExpert
Posts: 78
Joined: Fri Oct 09, 2020 2:57 pm

Re: how to close secure websocket properly

Post by RebootExpert »

I think close the ssl fd that associated with the secure websocket first solve the issue. Is there a function to get the ssl fd from a websocket fd? Like the function SSL_GetRawSocket(int sslSocketFd) return the tcp fd from a ssl fd. Right now I create a task monitor the state of all the ssl fd that associated with a websocket, but I don't want to have a task just for that.

I need something simple like this.

Code: Select all

if( websocket is closed remotely)
{
	fd = GetFdFromWS(ws_fd);
	if(IsSSLfd(fd)) 
		close(fd); 
	close(ws_fd);
}
User avatar
pbreed
Posts: 1080
Joined: Thu Apr 24, 2008 3:58 pm

Re: how to close secure websocket properly

Post by pbreed »

WE fixed some SSL/TLS close issues in rev 2.9.5.
Could you see if the problem exists under 2.9.5?
RebootExpert
Posts: 78
Joined: Fri Oct 09, 2020 2:57 pm

Re: how to close secure websocket properly

Post by RebootExpert »

When I rebuild all system files in 2.9.5, it gives me errors.
C:\nburn\gcc-m68k\msys\1.0\bin\sh.exe: *** Couldn't reserve space for cygwin's heap, Win32 error 0
make: *** [C:\nburn/make/librules.mak:48: extraio.o] Error 1
buffers.o userparam.o ftp.o arp.o md5c.o udpsocket.o tzsetchar.o aes.o system.o
0 [main] us 0 init_cheap: VirtualAlloc pointer is null, Win32 error 487
AllocationBase 0x0, BaseAddress 0x71110000, RegionSize 0x2E0000, State 0x10000
make: *** [C:\nburn/make/librules.mak:59: ftp.od] Error 1
update

follow the post by anguel in this thread, I rebase the msys-1.0.dll to 0x30000000 solve the problem
RebootExpert
Posts: 78
Joined: Fri Oct 09, 2020 2:57 pm

Re: how to close secure websocket properly

Post by RebootExpert »

regard to the secure websocket closure, issue still present in the app build by 2.9.5
User avatar
Jon
Posts: 79
Joined: Mon Feb 05, 2018 10:54 am

Re: how to close secure websocket properly

Post by Jon »

Hi RebootExpert,

It sounds like you had a working solution above, but wanted the SSL FD to close first. In this case, you can call:

int sslFd = 0;
WebSocket* ws = GetWebSocketRecord( webSocketFd );
if( ws != nullptr )
{
sslFd = ws->m_fd_tcp;
}

In this case, the TCP is actually the SSL fd, as it's assigned the return value of SSL_Connect(). You can then close this fd, and should be good to go.

Kind Regards,
Jon
Post Reply