2

I am attempting to use the IoT SDK to communicate to DPS and then IoT Hub.

When I load a valid certificate PEM file, it looks correct in debug window shown below:

enter image description here

After loading the cert, I am unable to use it in the IoT SDK, getting the error below:

enter image description here

[note I have already configured DPS to trust the ca.cert.pem and have created an enrollment group.

My certificate is a v1, as shown below:

enter image description here

I am using a very simple CA from OpenSSL:

openssl genrsa -aes256 -out ca.key.pem 4096
openssl req -key ca.key.pem -new -x509 -days 3650 -sha256 -out ca.cert.pem 

openssl req -nodes -new -subj /CN=device4 -sha256 -out verify.csr -keyout private.pem
openssl x509 -req -in verify.csr -CA ca.cert.pem -CAkey ca.key.pem -CAcreateserial -out public.pem -days 180 -sha256

Here is the code I am using:

certificate = X509Certificate2.CreateFromPemFile(publicKeyFileName, privateKeyFileName);

SecurityProviderX509Certificate securityProvider = new SecurityProviderX509Certificate(certificate);
ProvisioningDeviceClient = ProvisioningDeviceClient.Create(DPSURL, DPSScopeId, securityProvider, provisioningTransportHandler);
DeviceRegistrationResult registrationResult = ProvisioningDeviceClient.RegisterAsync().Result;
Kevin Saye
  • 299
  • 1
  • 8

1 Answers1

0

There appears to be an issue in the SDK. There is a workaround if you export to PFX and then import the PFX. Submitted the Bug here: https://github.com/Azure/azure-iot-sdk-csharp/issues/2150

Kevin Saye
  • 299
  • 1
  • 8