FreeOpcUa / opcua-asyncio

OPC UA library for python >= 3.7
GNU Lesser General Public License v3.0
1.12k stars 361 forks source link

sync wrapper: connecting with wrong certificate will lead to TimeoutError #1254

Open km-manzm opened 1 year ago

km-manzm commented 1 year ago

Describe the bug
I am using the sync wrapper. Whenever i try to connect to an OPC UA Server with a certificate that the server is not trusting the Exception exceptions.TimeoutError is being raised.

I expected that some better exception would be raised, e.g. BadCertificateUntrusted exception.

asyncua.uaprotocol log gives [WARNING] (asyncua.uaprotocol): Received an error: ErrorMessage(Error=StatusCode(value=2148728832), Reason=None)

The OPC UA Error Codes list says that 2148728832 is BadSecurityChecksFailed. So the library is identifying the issue correctly, but it seems that the sync wrapper is not passing this exception.

To Reproduce
try to connect to an OPC UA server whith an untrusted certificate.

from asyncua.sync import Client

opcua_client = Client(self.opcua_address)
opcua_client.set_security_string("Basic256Sha256,SignAndEncrypt,pubkey.der,privkey.pem")
opcua_client.connect()

Expected behavior
Not to raise TimeoutError but raise something like BadCertificateUntrusted

Version
Python-Version:3.8.12
opcua-asyncio Version master branch, 1.0.1

schroeder- commented 1 year ago

The problem is not exclusive to the sync layer, i think it's lost in the async connect. This is a open point.