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:
After loading the cert, I am unable to use it in the IoT SDK, getting the error below:
[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:
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;