RE: Windows fd/socket problem with BIO: solved !

2004-04-27 Thread David Schwartz

 It's good. I have found a solution on msdn. I have to
 duplicate the socket handler ;

 DuplicateHandle(GetCurrentProcess(),(HANDLE)ctrl,
 GetCurrentProcess(),(HANDLE*)ctrl_dup,
 0, TRUE, /* inherit socket */
 DUPLICATE_SAME_ACCESS);

 Then put ctrl_dup on cmd_line args for
 CreateProcess();

 This value is retrieved easily parsing new process
 args. The retrieved handle could correctly be used as
 a socket with BIO_new_socket() and so on.

 I hope this could help somebody oneday.

It is an API violation to duplicate a socket via 'DuplicateHandle'. That
only duplicates the handle and could cause major problems by failing to
duplicate other structures associated with the socket but not the handle.
You should change your code immediately to use *socket* duplication
functions like 'WSADuplicateSocket'. Your code *will* break code that relies
upon such socket data structures.

DS

__
OpenSSL Project http://www.openssl.org
User Support Mailing List[EMAIL PROTECTED]
Automated List Manager   [EMAIL PROTECTED]


Windows fd/socket problem with BIO

2004-04-26 Thread stef duverger
Hi all,

I'm working on a multi-clients server under Windows2k.
My problem is about file descriptor / socket confusion
when creating a BIO.

In fact main code's jobe is to accept the socket in an
int variable, then CreateProcess(). This function is
called with newly accepted socket as argument, in
place of file descriptor number 0 (input).

ctrl = accept();
si.hStdInput  = ctrl;
si.hStdOutput = INVALID_HANDLE_VALUE;
si.hStdError  = INVALID_HANDLE_VALUE;
si.dwFlags = STARTF_USESTDHANDLES;

CreateProcess(..., si);

New process will inherit socket as file descriptor 0.
Then problems come :

I create a BIO with BIO_new_socket(); then the ssl
object and do the setbio() on this ssl object.

Then SSL_accept() is called and application fails with
memory could not be written message.

I've tryied to set the BIO using BIO_new_fd(). Since
windows has problems with file descriptor and socket
mixing. Damned, with this BIO it works strangely, in
fact my client dumps this error : 

SSL: error:140920F8:SSL
routines:SSL3_GET_SERVER_HELLO:unknown cipher returned

But i have no segfault.

I have also tryed to use: BIO_new(BIO_s_socket()) in
order to retrieve to right method. No success,
application segfaults too.

I really tought that with this BIO methods, the lib
will gives me the desired BIO to create my ssl object.

I think there is a problem with this file descriptor 0
used as a socket. In fact when i don't createProcess
and manage only one client, the socket is always the
descriptor retrieved from accept() call, and there is
no problem when i do a BIO_new_socket(), setbio() and
ssl_accept(). All works great.

Do you think i have to try to inherit socket in
another handler than stdin ? Or maybe it is a problem
in the openssl lib ?

Version used is: openssl-0.9.7d

thanks in advance

Regards,

NB: Same code (ssl context init, client verification
setting, calist loading ...) with fork() is used with
success under Unix. The only difference is that unix
handles sockets as well as file descriptors with no
difference. Write/send, read/recv could be used with
fd or socket, not under windows. Maybe the bio is not
able to be correctly set and leads to errors.






Yahoo! Mail : votre e-mail personnel et gratuit qui vous suit partout ! 
Créez votre Yahoo! Mail sur http://fr.benefits.yahoo.com/

Dialoguez en direct avec vos amis grâce à Yahoo! Messenger !Téléchargez Yahoo! 
Messenger sur http://fr.messenger.yahoo.com
__
OpenSSL Project http://www.openssl.org
User Support Mailing List[EMAIL PROTECTED]
Automated List Manager   [EMAIL PROTECTED]


Windows fd/socket problem with BIO: solved !

2004-04-26 Thread stef duverger
It's good. I have found a solution on msdn. I have to
duplicate the socket handler ;

DuplicateHandle(GetCurrentProcess(),(HANDLE)ctrl,
GetCurrentProcess(),(HANDLE*)ctrl_dup,
0, TRUE, /* inherit socket */   
DUPLICATE_SAME_ACCESS);

Then put ctrl_dup on cmd_line args for
CreateProcess();

This value is retrieved easily parsing new process
args. The retrieved handle could correctly be used as
a socket with BIO_new_socket() and so on.

I hope this could help somebody oneday.

bye

- previous message 

Hi all,

I'm working on a multi-clients server under Windows2k.
My problem is about file descriptor / socket confusion
when creating a BIO.

In fact main code's jobe is to accept the socket in an
int variable, then CreateProcess(). This function is
called with newly accepted socket as argument, in
place of file descriptor number 0 (input).

ctrl = accept();
si.hStdInput  = ctrl;
si.hStdOutput = INVALID_HANDLE_VALUE;
si.hStdError  = INVALID_HANDLE_VALUE;
si.dwFlags = STARTF_USESTDHANDLES;

CreateProcess(..., si);

New process will inherit socket as file descriptor 0.
Then problems come :

I create a BIO with BIO_new_socket(); then the ssl
object and do the setbio() on this ssl object.

Then SSL_accept() is called and application fails with
memory could not be written message.

I've tryied to set the BIO using BIO_new_fd(). Since
windows has problems with file descriptor and socket
mixing. Damned, with this BIO it works strangely, in
fact my client dumps this error : 

SSL: error:140920F8:SSL
routines:SSL3_GET_SERVER_HELLO:unknown cipher returned

But i have no segfault.

I have also tryed to use: BIO_new(BIO_s_socket()) in
order to retrieve to right method. No success,
application segfaults too.

I really tought that with this BIO methods, the lib
will gives me the desired BIO to create my ssl object.

I think there is a problem with this file descriptor 0
used as a socket. In fact when i don't createProcess
and manage only one client, the socket is always the
descriptor retrieved from accept() call, and there is
no problem when i do a BIO_new_socket(), setbio() and
ssl_accept(). All works great.

Do you think i have to try to inherit socket in
another handler than stdin ? Or maybe it is a problem
in the openssl lib ?

Version used is: openssl-0.9.7d

thanks in advance

Regards,

NB: Same code (ssl context init, client verification
setting, calist loading ...) with fork() is used with
success under Unix. The only difference is that unix
handles sockets as well as file descriptors with no
difference. Write/send, read/recv could be used with
fd or socket, not under windows. Maybe the bio is not
able to be correctly set and leads to errors.






Yahoo! Mail : votre e-mail personnel et gratuit qui vous suit partout ! 
Créez votre Yahoo! Mail sur http://fr.benefits.yahoo.com/

Dialoguez en direct avec vos amis grâce à Yahoo! Messenger !Téléchargez Yahoo! 
Messenger sur http://fr.messenger.yahoo.com
__
OpenSSL Project http://www.openssl.org
User Support Mailing List[EMAIL PROTECTED]
Automated List Manager   [EMAIL PROTECTED]