Skip to content

Commit 5508eb4

Browse files
committed
Added Windows & Linux tabs for winpty support
1 parent 838089c commit 5508eb4

File tree

1 file changed

+93
-16
lines changed

1 file changed

+93
-16
lines changed

articles/iot-hub/tutorial-x509-test-certs.md

Lines changed: 93 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,15 @@ The following tutorial uses [OpenSSL](https://www.openssl.org/) and the [OpenSSL
3636
## Prerequisites
3737

3838
* 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+
3940
* 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.
4148
4249
## Create a root CA
4350

@@ -47,13 +54,13 @@ You must first create an internal root certificate authority (CA) and a self-sig
4754
- Create a configuration file used by OpenSSL to configure your root CA and certificates created with your root CA
4855
- Request and create a self-signed CA certificate that serves as your root CA certificate
4956

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.
5158

5259
```bash
5360
cd {base_dir}
5461
```
5562

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.
5764

5865
| Directory or file | Description |
5966
| --- | --- |
@@ -69,6 +76,7 @@ You must first create an internal root certificate authority (CA) and a self-sig
6976
mkdir rootca
7077
cd rootca
7178
mkdir certs db private
79+
chmod 700 private
7280
touch db/index
7381
openssl rand -hex 16 > db/serial
7482
echo 1001 > db/crlnumber
@@ -103,7 +111,7 @@ You must first create an internal root certificate authority (CA) and a self-sig
103111
commonName = "{rootca_common_name}"
104112
105113
[ca_default]
106-
home = .
114+
home = ../rootca
107115
database = $home/db/index
108116
serial = $home/db/serial
109117
crlnumber = $home/db/crlnumber
@@ -156,16 +164,27 @@ You must first create an internal root certificate authority (CA) and a self-sig
156164
subjectKeyIdentifier = hash
157165
```
158166

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.
160168

161169
> [!NOTE]
162170
> 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.
163171
172+
# [Windows](#tab/windows)
173+
174+
```bash
175+
winpty openssl req -new -config rootca.conf -out rootca.csr \
176+
-keyout private/rootca.key
177+
```
178+
179+
# [Linux](#tab/linux)
180+
164181
```bash
165182
openssl req -new -config rootca.conf -out rootca.csr \
166183
-keyout private/rootca.key
167184
```
168-
185+
186+
---
187+
169188
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.
170189

171190
```bash
@@ -176,13 +195,24 @@ You must first create an internal root certificate authority (CA) and a self-sig
176195

177196
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).
178197

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 for a 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 page in 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 for a 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 page in OpenSSL documentation.
199+
200+
# [Windows](#tab/windows)
201+
202+
```bash
203+
winpty openssl ca -selfsign -config rootca.conf -in rootca.csr -out rootca.crt \
204+
-extensions ca_ext
205+
```
206+
207+
# [Linux](#tab/linux)
180208

181209
```bash
182210
openssl ca -selfsign -config rootca.conf -in rootca.csr -out rootca.crt \
183211
-extensions ca_ext
184212
```
185213

214+
---
215+
186216
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.
187217
188218
```bash
@@ -214,13 +244,13 @@ Similar to your root CA, the files used to create and maintain your subordinate
214244
> * Create a configuration file used by OpenSSL to configure your subordinate CA and certificates created with your subordinate CA
215245
> * Request and create a CA certificate signed by your root CA that serves as your subordinate CA certificate
216246
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.
218248
219249
```bash
220250
cd {base_dir}
221251
```
222252
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.
224254
225255
| Placeholder | Description |
226256
| --- | --- |
@@ -232,6 +262,7 @@ Similar to your root CA, the files used to create and maintain your subordinate
232262
mkdir {subca_dir}
233263
cd {subca_dir}
234264
mkdir certs db private
265+
chmod 700 private
235266
touch db/index
236267
openssl rand -hex 16 > db/serial
237268
echo 1001 > db/crlnumber
@@ -262,7 +293,7 @@ Similar to your root CA, the files used to create and maintain your subordinate
262293
commonName = "{subca_common_name}"
263294
264295
[ca_default]
265-
home = .
296+
home = ../{subca_name}
266297
database = $home/db/index
267298
serial = $home/db/serial
268299
crlnumber = $home/db/crlnumber
@@ -315,13 +346,24 @@ Similar to your root CA, the files used to create and maintain your subordinate
315346
subjectKeyIdentifier = hash
316347
```
317348
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.
350+
351+
# [Windows](#tab/windows)
352+
353+
```bash
354+
winpty openssl req -new -config subca.conf -out subca.csr \
355+
-keyout private/subca.key
356+
```
357+
358+
# [Linux](#tab/linux)
319359
320360
```bash
321361
openssl req -new -config subca.conf -out subca.csr \
322362
-keyout private/subca.key
323363
```
324364
365+
---
366+
325367
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.
326368

327369
```bash
@@ -332,13 +374,24 @@ Similar to your root CA, the files used to create and maintain your subordinate
332374

333375
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).
334376

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)
336387
337388
```bash
338389
openssl ca -config ../rootca/rootca.conf -in subca.csr -out subca.crt \
339390
-extensions sub_ca_ext
340391
```
341392
393+
---
394+
342395
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.
343396

344397
```bash
@@ -391,13 +444,13 @@ Perform the following steps to:
391444
> * Create a private key and certificate signing request (CSR) for a client certificate
392445
> * Create a client certificate signed by your subordinate CA certificate
393446
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.
395448
396449
```bash
397450
cd {base_dir}
398451
```
399452
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.
401454
402455
| Placeholder | Description |
403456
| --- | --- |
@@ -406,13 +459,26 @@ Perform the following steps to:
406459
407460
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.
408461
462+
# [Windows](#tab/windows)
463+
464+
```bash
465+
cd {subca_dir}
466+
winpty openssl genpkey -out private/{device_name}.key -algorithm RSA \
467+
-pkeyopt rsa_keygen_bits:2048
468+
winpty openssl req -new -key private/{device_name}.key -out {device_name}.csr
469+
```
470+
471+
# [Linux](#tab/linux)
472+
409473
```bash
410474
cd {subca_dir}
411475
openssl genpkey -out private/{device_name}.key -algorithm RSA \
412476
-pkeyopt rsa_keygen_bits:2048
413477
openssl req -new -key private/{device_name}.key -out {device_name}.csr
414478
```
415479
480+
---
481+
416482
You're prompted to provide certificate details, as shown in the following example. Replace the following placeholders with the corresponding values.
417483
418484
| Placeholder | Description |
@@ -440,13 +506,24 @@ Perform the following steps to:
440506
441507
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).
442508
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)
444519
445520
```bash
446521
openssl ca -config subca.conf -in {device_name}.csr -out {device_name}.crt \
447522
-extensions client_ext
448523
```
449-
524+
525+
---
526+
450527
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.
451528
452529
```bash

0 commit comments

Comments
 (0)