Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Question about SSLSocket

Moderators: larsivi kris

Posted: 11/04/09 15:22:34

Hello. I'm writting framework to creating websites. Now, i encountered a strange situation.

module main;

private import tango.net.device.SSLSocket;
private import tango.net.device.Berkeley;
private import tango.net.util.PKI;

import tango.io.Stdout;
import tango.text.convert.Layout;
void main()
{

	SSLServerSocket server;
	SSLCtx ctx = new SSLCtx();
	Layout!(char) sprint = new Layout!(char);

	char[] key_data = 
`-----BEGIN RSA PRIVATE KEY-----
MIICWwIBAAKBgQDFNTsKFZrxvFGPZsrVRlndIYeIsWb7EAvrQxOOMySd9cmSUxyr
o6f4FB+VpGbkrf8xg9zhs5YjJr8Pbj0dyDZks2H2A8YCGSN0PQ/ZDG9+qVDrLvvu
WJDkBEdku6ycvoLh+S3XUGFmL2eSMj0m9YydugHu5u7DyMSfV28U/hLfAwIDAQAB
AoGAcHcl/19I6PmLzetCW5TuZNTdVZBOeXmyQm4TdfImvMrSNNefLyd7AFiBlraW
U24DbjqUOkdPpSZQqb0lr5lhotT27M6H0SQNEoziM6kQtFM584D6wGYtISlszPQk
zs9fbh7IbuuOE2f0Q9hg+IAnnjeajoB4voW7fXYgnHJR67ECQQD1xGnawhJAQB5g
uFtH8oO5/gKF+MdBJs64H89Vxp360+Dg0zzTkRqiXSjj79DHjJymUYrAv9z3LPWP
wBxUofeJAkEAzWs7jx3YDY8oZN/f8IcpqaDZ4uVLC4NgRm+AL36Wr13JUXYULsN+
YYArV0T0JFdmuNF6/DUyRP/iQ3sW3J4zKwJAcQ2H8BRkFuAn2TAU9VSumakp+fzF
k8fJQdOIKZny5AYBJQqmqV/PU67s92VCsfiRusQ5wo6/k4g/8X9ayOe0mQJAaaxK
XVtq8767dvk8SI4fvqWCsRhnvKp+8n0Volkqx1gl4oQt6cij0SCQKzrLpY5Yx6br
76amD5zbFv/RSPkRNQJAXnEu3OyK2HEznMDN37JC1MAdVePsqap+rGKiB3WUKDmI
ZUqM0Iy0kI48+ciQ8tkU2SXBPR4QDV8YTS2F+9RvCA==
-----END RSA PRIVATE KEY-----
`;

	char[] cer_data = 
`-----BEGIN CERTIFICATE-----
MIICTTCCAbYCCQC+cVlR7GlryDANBgkqhkiG9w0BAQUFADBrMQswCQYDVQQGEwJS
VTEPMA0GA1UECBMGTW9zY293MQ8wDQYDVQQHEwZNb3Njb3cxDzANBgNVBAoTBkRp
YURlbTEUMBIGA1UECxMLRGV2ZWxvcG1lbnQxEzARBgNVBAMTCmRpYS1kZW0ucnUw
HhcNMDkxMDIwMTExNDUxWhcNMTkxMDE4MTExNDUxWjBrMQswCQYDVQQGEwJSVTEP
MA0GA1UECBMGTW9zY293MQ8wDQYDVQQHEwZNb3Njb3cxDzANBgNVBAoTBkRpYURl
bTEUMBIGA1UECxMLRGV2ZWxvcG1lbnQxEzARBgNVBAMTCmRpYS1kZW0ucnUwgZ8w
DQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAMU1OwoVmvG8UY9mytVGWd0hh4ixZvsQ
C+tDE44zJJ31yZJTHKujp/gUH5WkZuSt/zGD3OGzliMmvw9uPR3INmSzYfYDxgIZ
I3Q9D9kMb36pUOsu++5YkOQER2S7rJy+guH5LddQYWYvZ5IyPSb1jJ26Ae7m7sPI
xJ9XbxT+Et8DAgMBAAEwDQYJKoZIhvcNAQEFBQADgYEAkF1Df1CZFyLbEaQgIExd
tCj8OIlFXXomHqruSGgIFBH2xshaiNAksjkbtDdlhtVYrzl0pJhowasdMlRCEOrR
0qSv1nhViVIyU7DbOOVdQKDeGCo2hvsAJXmPMbVqhtHaEuqb+LakWEJ8vdoYtkbV
50tB5DNk48lbNHI1ulT5rR4=
-----END CERTIFICATE-----
`;

	char[] o_data = "Hello, World.";
	char[] i_data = new char[512];

	PrivateKey key = new PrivateKey(key_data, "");
	Certificate certificate = new Certificate(cer_data);

	ctx.certificate = certificate;
	ctx.privateKey = key;

	server = new SSLServerSocket(443, ctx);
	Stdout("Reading...\n");

	SSLSocket request = server.accept;

	size_t size = request.read(i_data);
	Stdout.formatln(`{}`, size);
	if((size) && (size != size_t.max))
		i_data = i_data[0 .. size];
	else
		i_data = "";
	Stdout.formatln(`{}`, i_data.length);
		
	Stdout(i_data).flush;
	Stdout("write 0.\n");
	request.write("HTTP/1.1 200 OK\n");
	Stdout("write 1.\n");
	request.write("Content-type: text/html\n");
	Stdout("write 2.\n");
	request.write(sprint("Content-length: {}\n\n", o_data.length));
	Stdout("write 3.\n");
	request.write(o_data);
	Stdout("End work.\n");

}

When i open page in Firefox 3.5, i has read message from socket, write output, and has "segmentation fault", in browser i can see "Hello, World."

When i open page in Opera 10, or Internet Explorer 8 i has "segmentation fault" when i trying to read message from socket. It is my error, or bug?

Sorry for my bad English...

Author Message

Posted: 11/04/09 16:42:58

Since you get segmentation fault, I guess you run the server on Linux or some other Posix system? In that case, could you try running your application in gdb and use 'bt' to get a better view on where it crash?

Posted: 11/04/09 21:12:29 -- Modified: 11/04/09 21:24:27 by
Wazar -- Modified 2 Times

I tango.core.stacktrace.TraceExceptions? used and get the following result in Opera 10:

Segmentation fault encountered at:
[  b4ba0c]  ab4000+621068 EVP_DigestUpdate                 @b4b9f0+28 /lib/libcrypto.so.7:0
 Stacktrace:
[ 80776a8] 8048000+194215 tango_stacktrace_fault_handler   @8077578+303 ./DiaDaemon:0
[  a4940c]  a49000+1035 ???                                @0+0 :0
[  afc8ce]  ab4000+297165 HMAC_Update                      @afc8a0+45 /lib/libcrypto.so.7:0
[  c3ae53]  c1f000+114258 ???                              @0+0 /dmd/lib/libssl.so.0.9.8:0
[       0]       0+0   ???                                 @0+0 :0
Stacktrace singnal handler abort().
Aborted

In firefox 3.5 i get the following result:

Reading...
435
435
GET / HTTP/1.1
Host: dia-cms.ru:10443
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.1.4) Gecko/20091016 Firefox/3.5.4 (.NET CLR 3.5.30729)
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: ru,en-us;q=0.7,en;q=0.3
Accept-Encoding: gzip,deflate
Accept-Charset: windows-1251,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Cookie: ispmgr4=aqua:ru:1422640834

write 0.
write 1.
write 2.
write 3.
End work.
Segmentation fault encountered at:
[  cb463a]  c47000+448058 BN_BLINDING_free                           @cb4620+26 /lib/libcrypto.so.7:0
 Stacktrace:
[ 80776a8] 8048000+194215 tango_stacktrace_fault_handler             @8077578+303 ./DiaDaemon:0
[  f8440c]  f84000+1035 ???                                          @0+0 :0
[  cc1083]  c47000+499842 RSA_free                                   @cc0f60+290 /lib/libcrypto.so.7:0
[  ce459d]  c47000+644508 ???                                        @0+0 /lib/libcrypto.so.7:0
[  ce4627]  c47000+644646 EVP_PKEY_free                              @ce45c0+102 /lib/libcrypto.so.7:0
[  a577c1]  a36000+137152 ssl_cert_free                              @a57730+144 /dmd/lib/libssl.so.0.9.8:0
[  a54e7f]  a36000+126590 SSL_CTX_free                               @a54db0+206 /dmd/lib/libssl.so.0.9.8:0
[  a560fd]  a36000+131324 SSL_free                                   @a55fd0+300 /dmd/lib/libssl.so.0.9.8:0
[  a5f7a6]  a36000+169893 ???                                        @0+0 /dmd/lib/libssl.so.0.9.8:0
[ 1944acd] 18bc000+559820 BIO_free                                   @1944a10+188 /dmd/lib/libcrypto.so.0.9.7:0
[ 1944b24] 18bc000+559907 BIO_free_all                               @1944af0+51 /dmd/lib/libcrypto.so.0.9.7:0
[ 8053fd0] 8048000+49103 tango.net.device.SSLSocket.SSLSocket.detach @8053fac+35 ./DiaDaemon:0
[ 805a048] 8048000+73799 tango.io.device.Conduit.Conduit._dtor       @805a040+7 ./DiaDaemon:0
[ 80840f2] 8048000+246001 rt_finalize                                @8084088+105 ./DiaDaemon:0
[ 808b650] 8048000+276047 rt.basicgc.gcx.Gcx.fullcollect             @808b1d4+1147 ./DiaDaemon:0
[ 808b1c6] 8048000+274885 rt.basicgc.gcx.Gcx.fullcollectshell        @808b1a0+37 ./DiaDaemon:0
[ 808a480] 8048000+271487 rt.basicgc.gcx.GC.fullCollect              @808a460+31 ./DiaDaemon:0
[ 80888aa] 8048000+264361 gc_term                                    @8088848+97 ./DiaDaemon:0
[ 8083944] 8048000+244035 main                                       @80838bc+135 ./DiaDaemon:0
[  5f86e5]  5e2000+91876 __libc_start_main                           @5f8600+228 /lib/libc.so.6:0
[ 8049f21] 8048000+7968 ???                                          @0+0 ./DiaDaemon:0
Stacktrace singnal handler abort().
Aborted

As we can see the program with firefox 3.5 successfully read a headers, written response and broke down.

Sorry for my bad English...

Posted: 11/05/09 09:30:09

I'm wondering if the content being passed to BIO_freeall() is bogus? Please try closing the sockets manually, before exit, and see if that helps?

Posted: 11/06/09 08:54:34

Understand what it was. I stood in different versions of openssl at the same time. They conflicts. Anyway thanks.:-)

Sorry for my bad English...

Posted: 11/06/09 10:06:33

glad you got it resolved