cancel
Showing results for 
Search instead for 
Did you mean: 

SSL issue

Tomás
New Contributor
Hi,

I'm having difficulty making a successful SSL connection to stream-api-integration.betfair.com:443.

hopen hsym `$"tcps://stream-api-integration.betfair.com:443"

I have OpenSsl installed and have a key and cert file specified in the Environment Variables. 

SSLEAY_VERSION OpenSSL 1.0.2r 26 Feb 2019
SSL_CERT_FILE C:\certs\client-2048.crt
SSL_CA_CERT_FILE C:\certs\cabundle.pem
SSL_CA_CERT_PATH C:\certs\
SSL_KEY_FILE C:\certs\client-2048.key
SSL_CIPHER_LIST ALL
SSL_VERIFY_CLIENT NO
SSL_VERIFY_SERVER NO   

If I override some of the .z methods, I never get a 'port open' message: just a close after a second or two. 

A simple TcpClient and SslStream C# app can connect to the socket straight away, so I suspect it has something to do with the OpenSSL version I have. I haven't had any problems making https GET and POST requests or connecting to WSS websockets with this config, so not sure how to diagnose what's going on here. 

Would appreciate any hints in the right direction. 
3 REPLIES 3

Kimmo_Linna
New Contributor II
Hi Tomás,

I had also some problems when I used a newer version. I installed 1.0.2h light (according documentation) and everything start to work.

Best regards,

Kimmo Linna
Nihtisalontie 3 as 1
02630 ESPOO
+358 40 590 1074
kimmo.linna@gmail.com

Tomás <tobriain@gmail.com> kirjoitti 10.11.2020 kello 7.50:

Hi,

I'm having difficulty making a successful SSL connection to stream-api-integration.betfair.com:443.

hopen hsym `$"tcps://stream-api-integration.betfair.com:443"

I have OpenSsl installed and have a key and cert file specified in the Environment Variables. 

SSLEAY_VERSION OpenSSL 1.0.2r 26 Feb 2019
SSL_CERT_FILE C:\certs\client-2048.crt
SSL_CA_CERT_FILE C:\certs\cabundle.pem
SSL_CA_CERT_PATH C:\certs\
SSL_KEY_FILE C:\certs\client-2048.key
SSL_CIPHER_LIST ALL
SSL_VERIFY_CLIENT NO
SSL_VERIFY_SERVER NO   

If I override some of the .z methods, I never get a 'port open' message: just a close after a second or two. 

A simple TcpClient and SslStream C# app can connect to the socket straight away, so I suspect it has something to do with the OpenSSL version I have. I haven't had any problems making https GET and POST requests or connecting to WSS websockets with this config, so not sure how to diagnose what's going on here. 

Would appreciate any hints in the right direction. 

--
You received this message because you are subscribed to the Google Groups "Kdb+ Personal Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to personal-kdbplus+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/personal-kdbplus/343f4c4e-5507-4010-965e-c44d16323d36n%40googlegro....

charlie
New Contributor II
New Contributor II
Hi Tomas,

you're opening a connection using the kdb+ ipc protocol, but betfair's service doesn't speak that. If I try to connect I observe

q).z.bm:0N! / print mad msg content
q)hopen hsym `$"tcps://stream-api-integration.betfair.com:443"
6i
q)(6i;"\"op\"oc\":")
'badmsg
\\

you can see that kdb+ detected the 8-byte msg header doesn't match the ipc expected format. You'll need a raw socket connection - there's likely some c-code lurking around on the forums that will do that. It's a shame that betfair don't appear to offer a websocket interface.

hth,
Charlie



Tomás
New Contributor
Hi Charles,

There is a thread entitled Basic Socket Communications in the forum with raw socket code in C, but it doesn't look like it links openssl anywhere and is written for Unix, so I'd need to port it to Windows. 

I've been reading through https://code.kx.com/q/interfaces/c-client-for-q/ and got the following shared library example to compile in Windows eventually using the 32-bit version of q.lib and some pre-processor code in Visual Studio: http://www.timestored.com/kdb-guides/compile-load-c-dll. I got a C class using winsock2.h called by q and it's attempting to connect to the socket, but incorporating all the SSL cert exchange etc in C is a bit beyond my grasp at the moment. 

I'll return to this if a websocket becomes an option, but it looks like I'll have to just stick to the C# client I have for now and send the data to q with qSharp. 

Thanks again for the help,

Tomas.