# PyKX TLS Mode with company CA

**URL:** <https://forum.kx.com/t/pykx-tls-mode-with-company-ca/12996>\
**Category:** Community Support\
**Tags:** pykx\
**Created:** [September 1, 2023, 5:01pm UTC](https://forum.kx.com/t/pykx-tls-mode-with-company-ca/12996 "2023-09-01T17:01:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mauricemoore1](https://avatars.discourse-cdn.com/v4/letter/m/ccd318/32.png) [@mauricemoore1](https://forum.kx.com/u/mauricemoore1)\
**Post date:** [September 1, 2023, 5:01pm UTC](https://forum.kx.com/t/pykx-tls-mode-with-company-ca/12996/1 "2023-09-01T17:01:00Z")

</div>

Hi,

Is it possible to use an internal company CA file with PyKX?

From an ordinary q session, it’s possible to connect to a TLS enabled kdb server as long as env variable&nbsp;SSL\_CA\_CERT\_FILE is set, and an openssl library is accessible.;

h:hopen`$“:tcps://…”

I was hoping this would also work for PyKX IPC but I’ve had no luck so far.

&nbsp;

Thanks

---

<div class="post-metadata">

**Author:** ![cmccarthy11](https://avatars.discourse-cdn.com/v4/letter/c/58f4c7/32.png) [@cmccarthy11](https://forum.kx.com/u/cmccarthy11)\
**Post date:** [September 4, 2023, 2:24pm UTC](https://forum.kx.com/t/pykx-tls-mode-with-company-ca/12996/2 "2023-09-04T14:24:00Z")

</div>

Hi,

This should work, could you provide the error that you’re seeing when attempting to initialise the connection?

There are multiple IPC connection types with PyKX, my suggestion would be that for TLS enabled IPC you make use of the SecureQConnection class documented here

If this does not work a minimal code example would be extremely helpful.

---

<div class="post-metadata">

**Author:** ![mauricemoore1](https://avatars.discourse-cdn.com/v4/letter/m/ccd318/32.png) [@mauricemoore1](https://forum.kx.com/u/mauricemoore1)\
**Post date:** [September 6, 2023, 3:59pm UTC](https://forum.kx.com/t/pykx-tls-mode-with-company-ca/12996/3 "2023-09-06T15:59:00Z")

</div>

Hi,

Thanks for replying, I’m guessing it does not know where my company CA certificate is by default;

\>\>\> q = pykx.SecureQConnection(host = machineX, port = portX, username = userX, password = passwX, tls = True)  
Traceback (most recent call last):  
File “\<stdin\>”, line 1, in \<module\>  
File “C:\Users\mmoore\PycharmProjects\NodeJs\venv\lib\site-packages\pykx\ipc.py”, line 1971, in \_\_init\_\_  
self.\_init(host,  
File “C:\Users\mmoore\PycharmProjects\NodeJs\venv\lib\site-packages\pykx\ipc.py”, line 383, in \_init  
raise PyKXException(self.\_ipc\_errors.get(self.\_handle, ‘Unknown IPC error’))  
pykx.exceptions.PyKXException: OpenSSL initialization failed

---

<div class="post-metadata">

**Author:** ![rocuinneagain1](https://avatars.discourse-cdn.com/v4/letter/r/fbc32d/32.png) [@rocuinneagain1](https://forum.kx.com/u/rocuinneagain1)\
**Post date:** [September 7, 2023, 10:33am UTC](https://forum.kx.com/t/pykx-tls-mode-with-company-ca/12996/4 "2023-09-07T10:33:00Z")

</div>

If you have a q process which is able to use TLS then you can compare the output of it’s `-26![]` with the output of `pykx.ssl_info[]` in Python. This often shows what differences are causing the problems.

- https://code.kx.com/q/basics/internal/#-26x-ssl
- https://code.kx.com/pykx/1.6/changelog.html#pykx-140&nbsp;

&nbsp;

---

<div class="post-metadata">

**Author:** ![mauricemoore1](https://avatars.discourse-cdn.com/v4/letter/m/ccd318/32.png) [@mauricemoore1](https://forum.kx.com/u/mauricemoore1)\
**Post date:** [September 11, 2023, 5:43pm UTC](https://forum.kx.com/t/pykx-tls-mode-with-company-ca/12996/5 "2023-09-11T17:43:00Z")

</div>

Thanks for providing this command - pykx.ssl\_info()

It seems the issue is on my side and related to the openssl library

\>\>\> pykx.ssl\_info()  
Traceback (most recent call last):  
File “\<stdin\>”, line 1, in \<module\>  
File “pykx\_ipc.pyx”, line 74, in pykx.\_ipc.ssl\_info  
File “pykx\_ipc.pyx”, line 79, in pykx.\_ipc.ssl\_info  
File “pykx\_wrappers.pyx”, line 493, in pykx.\_wrappers.factory  
pykx.exceptions.QError: Could not initialize openssl. Error was The specified module could not be found.

&nbsp;

But it seems my openssl set up is okay;

\>\>\> os.system(‘openssl version’)  
OpenSSL 3.1.1 30 May 2023 (Library: OpenSSL 3.1.1 30 May 2023)  
0  
\>\>\>

&nbsp;

I’ll update the thread if I find the issue on my side.

Thanks.
