问题
I've performed this example
https://docs.microsoft.com/en-us/azure/iot-dps/quick-enroll-device-x509-java
It does not appear under "registration records" under the enrolment group but it throws this error:
PROVISIONING_DEVICE_STATUS_FAILED, Exception: com.microsoft.azure.sdk.iot.provisioning.device.internal.exceptions.ProvisioningDeviceHubException: Signing certificate info did not match chain elements
Registration:
public class DeviceRegistration {
String idScope;
String globalEndpoint;
String clientCert;
String clientCertPrivateKey;
String signerCert;
public DeviceRegistration(String idScope, String globalEndpoint, String clientCert, String clientCertPrivateKey, String signerCert) {
this.idScope = idScope;
this.globalEndpoint = globalEndpoint;
this.clientCert = clientCert;
this.clientCertPrivateKey = clientCertPrivateKey;
this.signerCert = signerCert;
}
public void register(ProvisioningDeviceClientRegistrationCallback callback) throws Exception {
Collection<String> signerCertificates = new LinkedList<>();
signerCertificates.add(signerCert);
ProvisioningDeviceClient provisioningDeviceClient = null;
SecurityProvider securityProviderX509 = new SecurityProviderX509Cert(clientCert, clientCertPrivateKey, signerCertificates);
provisioningDeviceClient = ProvisioningDeviceClient.create(globalEndpoint, idScope, ProvisioningDeviceClientTransportProtocol.HTTPS,
securityProviderX509);
provisioningDeviceClient.registerDevice(callback, this);
}
private static String loadFile(String filename) throws Exception {
File f = new File(filename);
if (!f.exists())
throw new Exception("File not found: " + filename);
BufferedReader reader = new BufferedReader(new FileReader(f));
char[] buffer = new char[(int) f.length()];
reader.read(buffer);
reader.close();
return new String(buffer);
}
public static void main(String[] args){
try {
CountDownLatch countDownLatch = new CountDownLatch(1);
DeviceRegistration deviceRegistration = new DeviceRegistration(args[0], args[1], loadFile(args[2]), loadFile(args[3]), loadFile(args[4]));
deviceRegistration.register(new ProvisioningDeviceClientRegistrationCallback() {
@Override
public void run(ProvisioningDeviceClientRegistrationResult provisioningDeviceClientRegistrationResult, Exception e, Object context) {
if (provisioningDeviceClientRegistrationResult.getProvisioningDeviceClientStatus() == ProvisioningDeviceClientStatus.PROVISIONING_DEVICE_STATUS_ASSIGNED) {
System.out.println("IotHUb Uri : " + provisioningDeviceClientRegistrationResult.getIothubUri());
System.out.println("Device ID : " + provisioningDeviceClientRegistrationResult.getDeviceId());
countDownLatch.countDown();
} else {
System.out.println("Result: "+provisioningDeviceClientRegistrationResult.getProvisioningDeviceClientStatus()+", Exception: "+e);
}
}
});
countDownLatch.await();
} catch (Exception e) {
e.printStackTrace();
}
}}
回答1:
Delete the individual enrollment and make sure that you've gone through the verification of your X.509 signing cert (in the Certificates tab in the Azure portal). If you have both an enrollment group and an individual enrollment for a device, the individual enrollment takes precedence.
来源:https://stackoverflow.com/questions/50817794/auto-provisioning-device-under-an-enrolment-group-does-not-work-java-sdk