0
votes

With the now deprecated azure-iot-python-skd version 1 it was possible to connect a downstream device using X.509 authentication to a transparent iotedge enabled gateway by setting the connection string like this: HostName=<edge device hostname>;DeviceId=<device_id>;x509=true

And then set the certificates by using set_option("TrustedCerts" ...), set_option("x509certificate", ...) and set_option("x509privatekey", ...)

How can this be done with the new version 2 sdk?

I could not figure out how to do it using create_from_x509_certificate(...) or create_from_connection_string(...).

2

2 Answers

0
votes

please try the following where you pass in your root_ca_cert as a string:

Create instance of the device client using the connection string:

device_client = IoTHubDeviceClient.create_from_connection_string(connection_string=YOUR CONNECTION STRING,server_verification_cert=YOUR ROOT CA AS STRING)

await device_client.connect()

0
votes

create_from_connection_string will not work in this case. You need to use create_from_x509_certificate as below:-

self.device_client = IoTHubDeviceClient.create_from_x509_certificate(
           x509=x509, 
           hostname=hostname,
           device_id=device_id,
           server_verification_cert=root_ca_cert,
           gateway_hostname=gatewayHostname
)

Refer this ticket which is the bug fix done by MS team