You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/iot-hub/tutorial-x509-test-certs.md
+93-16Lines changed: 93 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -36,8 +36,15 @@ The following tutorial uses [OpenSSL](https://www.openssl.org/) and the [OpenSSL
36
36
## Prerequisites
37
37
38
38
* An Azure subscription. If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F) before you begin.
39
+
39
40
* An IoT hub in your Azure subscription. If you don't have a hub yet, you can follow the steps in [Create an IoT hub](iot-hub-create-through-portal.md).
40
-
* An [OpenSSL](https://www.openssl.org/) installation. If you don't have OpenSSL installed, see the [Where can I get a compiled version of OpenSSL](https://www.openssl.org/docs/faq.html#MISC5) section of the [OpenSSL FAQ](https://www.openssl.org/docs/faq.html) for more information, or you can download and build OpenSSL from [https://www.openssl.org/source/](https://www.openssl.org/source/).
41
+
42
+
* The latest version of [Git](https://git-scm.com/download/). Make sure that Git is added to the environment variables accessible to the command window. See [Software Freedom Conservancy's Git client tools](https://git-scm.com/download/) for the latest version of `git` tools to install, which includes *Git Bash*, the command-line app that you can use to interact with your local Git repository.
43
+
44
+
* An [OpenSSL](https://www.openssl.org/) installation. On Windows, your installation of Git includes an installation of OpenSSL. You can access OpenSSL from the Git Bash prompt. To verify that OpenSSL is installed, open a Git Bash prompt and enter `openssl version`.
45
+
46
+
>[!NOTE]
47
+
> Unless you're familiar with OpenSSL and already have it installed on your Windows machine, we recommend using OpenSSL from the Git Bash prompt. Alternatively, you can choose to download the source code and build OpenSSL. To learn more, see the [OpenSSL Downloads](https://www.openssl.org/source/) page. Or, you can download OpenSSL pre-built from a third-party. To learn more, see the [OpenSSL wiki](https://wiki.openssl.org/index.php/Binaries). Microsoft makes no guarantees about the validity of packages downloaded from third-parties. If you do choose to build or download OpenSSL make sure that the OpenSSL binary is accessible in your path and that the `OPENSSL_CNF` environment variable is set to the path of your *openssl.cnf* file.
41
48
42
49
## Create a root CA
43
50
@@ -47,13 +54,13 @@ You must first create an internal root certificate authority (CA) and a self-sig
47
54
- Create a configuration file used by OpenSSL to configure your root CA and certificates created with your root CA
48
55
- Request and create a self-signed CA certificate that serves as your root CA certificate
49
56
50
-
1. Start a Bash window and run the following command, replacing *{base_dir}* with the desired directory in which to create the root CA.
57
+
1. Start a Git Bash window and run the following command, replacing *{base_dir}* with the desired directory in which to create the root CA.
51
58
52
59
```bash
53
60
cd {base_dir}
54
61
```
55
62
56
-
1. In the Bash window, run the following commands, one at a time. This step creates the following directory structure and support files for the root CA.
63
+
1. In the Git Bash window, run the following commands, one at a time. This step creates the following directory structure and support files for the root CA.
57
64
58
65
| Directory or file | Description |
59
66
| --- | --- |
@@ -69,6 +76,7 @@ You must first create an internal root certificate authority (CA) and a self-sig
69
76
mkdir rootca
70
77
cd rootca
71
78
mkdir certs db private
79
+
chmod 700 private
72
80
touch db/index
73
81
openssl rand -hex 16 > db/serial
74
82
echo 1001 > db/crlnumber
@@ -103,7 +111,7 @@ You must first create an internal root certificate authority (CA) and a self-sig
103
111
commonName = "{rootca_common_name}"
104
112
105
113
[ca_default]
106
-
home = .
114
+
home = ../rootca
107
115
database = $home/db/index
108
116
serial = $home/db/serial
109
117
crlnumber = $home/db/crlnumber
@@ -156,16 +164,27 @@ You must first create an internal root certificate authority (CA) and a self-sig
156
164
subjectKeyIdentifier = hash
157
165
```
158
166
159
-
1. In the Bash window, run the following command to generate a certificate signing request (CSR) in the *rootca* directory and a private key in the *rootca/private* directory. For more information about the OpenSSL `req` command, see the [openssl-req](https://www.openssl.org/docs/man3.1/man1/openssl-req.html) manual page in OpenSSL documentation.
167
+
1. In the Git Bash window, run the following command to generate a certificate signing request (CSR) in the *rootca* directory and a private key in the *rootca/private* directory. For more information about the OpenSSL `req` command, see the [openssl-req](https://www.openssl.org/docs/man3.1/man1/openssl-req.html) manual page in OpenSSL documentation.
160
168
161
169
> [!NOTE]
162
170
> Even though this root CA is for testing purposes and won't be exposed as part of a public key infrastructure (PKI), we recommend that you do not copy or share the private key.
You're prompted to enter a PEM pass phrase, as shown in the following example, for the private key file. Enter and confirm a pass phrase to generate your private key and CSR.
170
189
171
190
```bash
@@ -176,13 +195,24 @@ You must first create an internal root certificate authority (CA) and a self-sig
176
195
177
196
Confirm that the CSR file, *rootca.csr*, is present in the *rootca* directory and the private key file, *rootca.key*, is present in the *rootca/private* directory before continuing. For more information about the formats of the CSR and private key files, see [X.509 certificates](reference-x509-certificates.md#certificate-formats).
178
197
179
-
1. In the Bash window, run the following command to create a self-signed root CA certificate. The command applies the `ca_ext` configuration file extensions to the certificate. These extensions indicate that the certificate is fora root CA and can be used to sign certificates and certificate revocation lists (CRLs). For more information about the OpenSSL `ca` command, see the [openssl-ca](https://www.openssl.org/docs/man3.1/man1/openssl-ca.html) manual pagein OpenSSL documentation.
198
+
1. In the Git Bash window, run the following command to create a self-signed root CA certificate. The command applies the `ca_ext` configuration file extensions to the certificate. These extensions indicate that the certificate is fora root CA and can be used to sign certificates and certificate revocation lists (CRLs). For more information about the OpenSSL `ca` command, see the [openssl-ca](https://www.openssl.org/docs/man3.1/man1/openssl-ca.html) manual pagein OpenSSL documentation.
openssl ca -selfsign -config rootca.conf -in rootca.csr -out rootca.crt \
183
211
-extensions ca_ext
184
212
```
185
213
214
+
---
215
+
186
216
You're prompted to provide the PEM pass phrase, as shown in the following example, for the private key file. After providing the pass phrase, OpenSSL generates a certificate, then prompts you to sign and commit the certificate for your root CA. Specify *y* for both prompts to generate the self-signed certificate for your root CA.
187
217
188
218
```bash
@@ -214,13 +244,13 @@ Similar to your root CA, the files used to create and maintain your subordinate
214
244
> * Create a configuration file used by OpenSSL to configure your subordinate CA and certificates created with your subordinate CA
215
245
> * Request and create a CA certificate signed by your root CA that serves as your subordinate CA certificate
216
246
217
-
1. Start a Bash window and run the following command, replacing *{base_dir}* with the directory that contains your previously created root CA.
247
+
1. Start a Git Bash window and run the following command, replacing *{base_dir}* with the directory that contains your previously created root CA.
218
248
219
249
```bash
220
250
cd {base_dir}
221
251
```
222
252
223
-
1. In the Bash window, run the following commands, one at a time, replacing the following placeholders with their corresponding values.
253
+
1. In the Git Bash window, run the following commands, one at a time, replacing the following placeholders with their corresponding values.
224
254
225
255
| Placeholder | Description |
226
256
| --- | --- |
@@ -232,6 +262,7 @@ Similar to your root CA, the files used to create and maintain your subordinate
232
262
mkdir {subca_dir}
233
263
cd {subca_dir}
234
264
mkdir certs db private
265
+
chmod 700 private
235
266
touch db/index
236
267
openssl rand -hex 16 > db/serial
237
268
echo 1001 > db/crlnumber
@@ -262,7 +293,7 @@ Similar to your root CA, the files used to create and maintain your subordinate
262
293
commonName = "{subca_common_name}"
263
294
264
295
[ca_default]
265
-
home = .
296
+
home = ../{subca_name}
266
297
database = $home/db/index
267
298
serial = $home/db/serial
268
299
crlnumber = $home/db/crlnumber
@@ -315,13 +346,24 @@ Similar to your root CA, the files used to create and maintain your subordinate
315
346
subjectKeyIdentifier = hash
316
347
```
317
348
318
-
1. In the Bash window, run the following commands to generate a private key and a certificate signing request (CSR) in the subordinate CA directory.
349
+
1. In the Git Bash window, run the following commands to generate a private key and a certificate signing request (CSR) in the subordinate CA directory.
You're prompted to enter a PEM pass phrase, as shown in the following example, for the private key file. Enter and verify a pass phrase to generate your private key and CSR.
326
368
327
369
```bash
@@ -332,13 +374,24 @@ Similar to your root CA, the files used to create and maintain your subordinate
332
374
333
375
Confirm that the CSR file, *subca.csr*, is present in the subordinate CA directory and the private key file, *subca.key*, is present in the *private* subdirectory of the subordinate CA directory before continuing. For more information about the formats of the CSR and private key files, see [X.509 certificates](reference-x509-certificates.md#certificate-formats).
334
376
335
-
1. In the Bash window, run the following command to create a subordinate CA certificate in the subordinate CA directory. The command applies the `sub_ca_ext` configuration file extensions to the certificate. These extensions indicate that the certificate is for a subordinate CA and can also be used to sign certificates and certificate revocation lists (CRLs). Unlike the root CA certificate, this certificate isn't self-signed. Instead, the subordinate CA certificate is signed with the root CA certificate, establishing a certificate chain similar to what you would use for a public key infrastructure (PKI). The subordinate CA certificate is then used to sign client certificates for testing your devices.
377
+
1. In the Git Bash window, run the following command to create a subordinate CA certificate in the subordinate CA directory. The command applies the `sub_ca_ext` configuration file extensions to the certificate. These extensions indicate that the certificate is for a subordinate CA and can also be used to sign certificates and certificate revocation lists (CRLs). Unlike the root CA certificate, this certificate isn't self-signed. Instead, the subordinate CA certificate is signed with the root CA certificate, establishing a certificate chain similar to what you would use for a public key infrastructure (PKI). The subordinate CA certificate is then used to sign client certificates for testing your devices.
378
+
379
+
# [Windows](#tab/windows)
380
+
381
+
```bash
382
+
winpty openssl ca -config ../rootca/rootca.conf -in subca.csr -out subca.crt \
383
+
-extensions sub_ca_ext
384
+
```
385
+
386
+
# [Linux](#tab/linux)
336
387
337
388
```bash
338
389
openssl ca -config ../rootca/rootca.conf -in subca.csr -out subca.crt \
339
390
-extensions sub_ca_ext
340
391
```
341
392
393
+
---
394
+
342
395
You're prompted to enter the pass phrase, as shown in the following example, for the private key file of your root CA. After you enter the pass phrase, OpenSSL generates and displays the details of the certificate, then prompts you to sign and commit the certificate for your subordinate CA. Specify *y*for both prompts to generate the certificate for your subordinate CA.
343
396
344
397
```bash
@@ -391,13 +444,13 @@ Perform the following steps to:
391
444
> * Create a private key and certificate signing request (CSR) for a client certificate
392
445
> * Create a client certificate signed by your subordinate CA certificate
393
446
394
-
1. Start a Bash window and run the following command, replacing *{base_dir}* with the directory that contains your previously created root CA and subordinate CA.
447
+
1. Start a Git Bash window and run the following command, replacing *{base_dir}* with the directory that contains your previously created root CA and subordinate CA.
395
448
396
449
```bash
397
450
cd {base_dir}
398
451
```
399
452
400
-
1. In the Bash window, run the following commands, one at a time, replacing the following placeholders with their corresponding values. This step creates the private key and CSR for your client certificate.
453
+
1. In the Git Bash window, run the following commands, one at a time, replacing the following placeholders with their corresponding values. This step creates the private key and CSR for your client certificate.
401
454
402
455
| Placeholder | Description |
403
456
| --- | --- |
@@ -406,13 +459,26 @@ Perform the following steps to:
406
459
407
460
This step creates a 2048-bit RSA private key for your client certificate, and then generates a certificate signing request (CSR) using that private key.
You're prompted to provide certificate details, as shown in the following example. Replace the following placeholders with the corresponding values.
417
483
418
484
| Placeholder | Description |
@@ -440,13 +506,24 @@ Perform the following steps to:
440
506
441
507
Confirm that the CSR file is present in the subordinate CA directory and the private key file is present in the *private* subdirectory of the subordinate CA directory before continuing. For more information about the formats of the CSR and private key files, see [X.509 certificates](reference-x509-certificates.md#certificate-formats).
442
508
443
-
1. In the Bash window, run the following command, replacing the following placeholders with their corresponding values. This step creates a client certificate in the subordinate CA directory. The command applies the `client_ext` configuration file extensions to the certificate. These extensions indicate that the certificate is for a client certificate, which can't be used as a CA certificate. The client certificate is signed with the subordinate CA certificate.
509
+
1. In the Git Bash window, run the following command, replacing the following placeholders with their corresponding values. This step creates a client certificate in the subordinate CA directory. The command applies the `client_ext` configuration file extensions to the certificate. These extensions indicate that the certificate is for a client certificate, which can't be used as a CA certificate. The client certificate is signed with the subordinate CA certificate.
510
+
511
+
# [Windows](#tab/windows)
512
+
513
+
```bash
514
+
winpty openssl ca -config subca.conf -in {device_name}.csr -out {device_name}.crt \
515
+
-extensions client_ext
516
+
```
517
+
518
+
# [Linux](#tab/linux)
444
519
445
520
```bash
446
521
openssl ca -config subca.conf -in {device_name}.csr -out {device_name}.crt \
447
522
-extensions client_ext
448
523
```
449
-
524
+
525
+
---
526
+
450
527
You're prompted to enter the pass phrase, as shown in the following example, for the private key file of your subordinate CA. After you enter the pass phrase, OpenSSL generates and displays the details of the certificate, then prompts you to sign and commit the client certificate for your device. Specify *y* for both prompts to generate the client certificate.
0 commit comments