Skip to content

Commit 5598dc8

Browse files
committed
Updated steps and code samples
1 parent dedd6b7 commit 5598dc8

4 files changed

+16
-21
lines changed

includes/iot-hub-howto-auth-device-cert-dotnet.md

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,22 @@ ms.service: iot-hub
88
ms.devlang: csharp
99
ms.topic: include
1010
ms.manager: lizross
11-
ms.date: 11/19/2024
11+
ms.date: 12/12/2024
1212
ms.custom: mqtt, devx-track-csharp, devx-track-dotnet
1313
---
1414

1515
To connect a device to IoT Hub using an X.509 certificate:
1616

17-
1. Use [DeviceAuthenticationWithX509Certificate](/dotnet/api/microsoft.azure.devices.client.deviceauthenticationwithx509certificate) to create an object that contains certificate information that is passed to `Create` (step 2).
17+
1. Use [DeviceAuthenticationWithX509Certificate](/dotnet/api/microsoft.azure.devices.client.deviceauthenticationwithx509certificate) to create an object that contains device and certificate information that is passed as the second parameter to `DeviceClient.Create` (step 2).
1818

19-
2. Use [Create](/dotnet/api/microsoft.azure.devices.client.deviceclient.create?#microsoft-azure-devices-client-deviceclient-create(system-string-microsoft-azure-devices-client-iauthenticationmethod)) to connect the device to IoT Hub using an X.509 certificate.
19+
1. Use [DeviceClient.Create](/dotnet/api/microsoft.azure.devices.client.deviceclient.create?#microsoft-azure-devices-client-deviceclient-create(system-string-microsoft-azure-devices-client-iauthenticationmethod)) to connect the device to IoT Hub using an X.509 certificate.
2020

2121
This example shows certificate input parameter values as local variables for clarity. In a production system, store sensitive input parameters in environment variables or another more secure storage location. For example, use `Environment.GetEnvironmentVariable("HOSTNAME")` to read the host name environment variable.
2222

23+
In this example, the `auth` `DeviceAuthenticationWithX509Certificate` object has been populated with device and certificate information and is passed as to `DeviceClient.Create`. An example of `DeviceAuthenticationWithX509Certificate` information population has been omitted because of the flexible nature of how the certificate information can be added.
24+
2325
```csharp
24-
RootCertPath = "~/certificates/certs/sensor-thl-001-device.cert.cer";
25-
Intermediate1CertPath = "";
26-
Intermediate2CertPath = "";
27-
DevicePfxPath = "~/certificates/certs/sensor-thl-001-device.cert.pfx";
28-
DevicePfxPassword = "1234";
29-
DeviceName = "MyDevice";
3026
HostName = "xxxxx.azure-devices.net";
31-
32-
var chainCerts = new X509Certificate2Collection();
33-
chainCerts.Add(new X509Certificate2(RootCertPath));
34-
chainCerts.Add(new X509Certificate2(Intermediate1CertPath));
35-
chainCerts.Add(new X509Certificate2(Intermediate2CertPath));
36-
using var deviceCert = new X509Certificate2(DevicePfxPath, DevicePfxPassword);
37-
using var auth = new DeviceAuthenticationWithX509Certificate(DeviceName, deviceCert, chainCerts);
38-
3927
using var deviceClient = DeviceClient.Create(
4028
HostName,
4129
auth,
@@ -46,7 +34,14 @@ For more information about certificate authentication, see:
4634

4735
* [Authenticate identities with X.509 certificates](/azure/iot-hub/authenticate-authorize-x509)
4836
* [Create and upload certificates for testing](/azure/iot-hub/tutorial-x509-test-certs)
37+
* [X509Certificate2Collection](/dotnet/api/system.security.cryptography.x509certificates.x509certificate2collection)
38+
* [X509Certificate2](/dotnet/api/system.security.cryptography.x509certificates.x509certificate2)
39+
* [Tutorial: Provision multiple X.509 devices using enrollment groups](/azure/iot-dps/tutorial-custom-hsm-enrollment-group-x509?pivots=programming-language-java)
4940

5041
##### Code samples
5142

52-
For a working sample of device X.509 certificate authentication, see [Connect with X.509 certificate](https://github.com/Azure/azure-iot-sdk-csharp/tree/main/iothub/device/samples/how%20to%20guides/X509DeviceCertWithChainSample).
43+
For working samples of device X.509 certificate authentication, see:
44+
45+
* [Connect with X.509 certificate](https://github.com/Azure/azure-iot-sdk-csharp/tree/main/iothub/device/samples/how%20to%20guides/X509DeviceCertWithChainSample)
46+
* [DeviceClientX509AuthenticationE2ETests](https://github.com/Azure/azure-iot-sdk-csharp/blob/main/e2e/test/iothub/DeviceClientX509AuthenticationE2ETests.cs)
47+
* [Guided project - Provision IoT devices securely and at scale with IoT Hub Device Provisioning Service](https://learn.microsoft.com/en-us/training/modules/provision-iot-devices-secure-scale-with-iot-hub-dps/)

includes/iot-hub-howto-auth-device-cert-java.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ms.service: iot-hub
88
ms.devlang: java
99
ms.topic: include
1010
ms.manager: lizross
11-
ms.date: 11/19/2024
11+
ms.date: 12/12/2024
1212
---
1313

1414
To connect a device to IoT Hub using an X.509 certificate:

includes/iot-hub-howto-auth-device-cert-node.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ms.service: iot-hub
88
ms.devlang: python
99
ms.topic: include
1010
ms.manager: lizross
11-
ms.date: 12/06/2024
11+
ms.date: 12/12/2024
1212
---
1313

1414
The X.509 certificate is attached to the device-to-IoT Hub connection transport.

includes/iot-hub-howto-file-upload-dotnet.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ms.author: kgremban
77
ms.service: azure-iot-hub
88
ms.devlang: csharp
99
ms.topic: include
10-
ms.date: 07/01/2024
10+
ms.date: 12/12/2024
1111
ms.custom: mqtt, devx-track-csharp, devx-track-dotnet
1212
---
1313

0 commit comments

Comments
 (0)