On Fri, Jan 19, 2001 at 04:05:19PM -0500, Jason Scharlach wrote:
> Has anyone else had any issues with SunOS and openSSL?
I don't have SunOS, but I also do not remember having seen reports about
special problems with SunOS...
Does the openssl application work? You can use "openssl s_client ..."
to perform the connection test.
> Any help/advice would be greatly appriciated!
Compile with "-g", call your favorite debugger and check out why the
segmentation fault occured.
Let's discuss your code:
> int main( void )
> {
> int sock;
> struct sockaddr_in sSockAddr;
> struct hostent *spHostEnt;
>
> SSL_CTX *ctx = NULL;
> SSL_METHOD *meth = NULL;
> SSL *ssl = NULL;
>
>
> sSockAddr.sin_family = AF_INET;
> sSockAddr.sin_port = htons( 443 );
>
> spHostEnt = gethostbyname( "www.csi.ca" );
Here you do not check the return value. gethostbyname might return NULL
because of a failure.
> memcpy( &(sSockAddr.sin_addr.s_addr),
> spHostEnt->h_addr_list[0],
> spHostEnt->h_length );
>
> sock = socket( AF_INET, SOCK_STREAM, 0 );
> connect( sock, (struct sockaddr *)&sSockAddr, sizeof( sSockAddr ));
Here you do not check sock [socket() might fail] and you do not check the
return value of connect() for failure.
> SSLeay_add_ssl_algorithms();
> meth = SSLv2_client_method();
> SSL_load_error_strings();
> ctx = SSL_CTX_new(meth);
>
> ssl = SSL_new( ctx );
>
> SSL_set_fd( ssl, sock );
> ERR_print_errors();
Of course, you did not check whether ctx and ssl have been successfully
created. You do not check whether SSL_set_fd() was successfull.
(I don't know whether this applies here, but at least some of the
OpenSSL functions are "NULL proof": they simply return 0 for failure
but do not set an error message because they suppose "nothing to be done".)
> printf( "SSL_connect: %d\n", SSL_connect( ssl ) );
> ERR_print_errors();
Aha, and here we go: ERR_print_errors() is actually called as:
void ERR_print_errors(BIO *bp);
with bp being the BIO to which the errors shall be reported. You do not
specify bp, so of course ERR_print_errors() will try to put the error message
to an undefined location.
Any good compiler should have warned you, that you did violate the function
prototype by not supplying "one argument of type BIO *".
(Actually the other ERR_print_errors() call only did not segfault because
nothing was to be reported.)
You probably want to use ERR_print_errors_fp(stderr) (or set up the BIO
for the error messages).
Best regards,
Lutz
--
Lutz Jaenicke [EMAIL PROTECTED]
BTU Cottbus http://www.aet.TU-Cottbus.DE/personen/jaenicke/
Lehrstuhl Allgemeine Elektrotechnik Tel. +49 355 69-4129
Universitaetsplatz 3-4, D-03044 Cottbus Fax. +49 355 69-4153
______________________________________________________________________
OpenSSL Project http://www.openssl.org
User Support Mailing List [EMAIL PROTECTED]
Automated List Manager [EMAIL PROTECTED]