Click here to Skip to main content
15,887,464 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I developed a client and server that use the OpenSSL to communicate using TLS via TCP, and it is working very well.

But I need to communicate via Namedpipe, and there is the question:
When I create a namedpipe, I call:
C++
HANDLE hPipe = CreateNamedPipe(...);
ConnectNamedPipe(hPipe, NULL);

After the Namedpipe is connected, I need call:
int SSL_set_fd(SSL *ssl, int fd);

As we can see, the "hPipe" is a HANDLE, but I need convert this HANDLE to int. So I tried to use the below to get a "int" then call SSL_set_fd(ssl, fd):
int fd = _open_osfhandle(reinterpret_cast<intptr_t>(hPipe), 0); 

The return of _open_osfhandle() will be "3", but OpenSSL isn't accepting when I try call "SSL_accept()".

Am I doing something wrong?
Is there other way to use OpenSSL with Namedpipe?
Note: I'm using the Microsoft Visual Studio, C++.

Thank you.
Posted
Comments
[no name] 1-Feb-14 14:11pm    
a.) why you need to convert to int?


b.) why in case it is need to convert, why you do not convert to a better matching type like e.g. DWORD
Haruks 1-Feb-14 14:24pm    
Because I need call "SSL_set_fd(SSL *ssl, int fd)" from OpenSSL. The second parameter is a "int" (the file descriptor) that will be associated with the "ssl" object.
[no name] 1-Feb-14 15:14pm    
Thanks for your feedback. Unfortunately I can't help you in this matter. But I think other members will help you ;)
Sergey Alexandrovich Kryukov 1-Feb-14 19:39pm    
Why named pipes, not sockets? Just to have some extra difficulties? :-)
—SA
Haruks 2-Feb-14 11:29am    
I need that two local process exchanges data (IPC), but it must be a exclusive communication channel (just two process can connect - just the server and one client). The use of TCP with loopback address is a option, but I wish to avoid problems with third-party firewall softwares.

1 solution

You are trying to convert a HANDLE into an FD.
Maybe open_osf_handle doesn't work as it should.

Try skipping that step.
In Unix named pipes are opened directly with fopen
FILE* fpwrite = fopen("\\\\.\\pipe\\SamplePipe", ....)

According to http://social.msdn.microsoft.com/Forums/vstudio/en-US/fc12d839-3358-4eca-ba15-893e146a5e7b/is-it-possible-to-open-named-pipes-on-windows-using-fopen-in-write-only?forum=vcgeneral[^] someone answered that it should be possible in Windows too.

I have never seen anyone run SSL over a named pipe.
I am not 100% sure it will work, but it is worth a try of course.
Good luck.
 
Share this answer
 
Comments
Haruks 5-Feb-14 20:55pm    
First of all, thank you by submit a solution.
Unfortunately, the fopen() can open a existing namedpipe (client side), but doesn't create the namedpipe (server side), it returns NULL.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900