|
| 1 | +Generating certificates |
| 2 | +======================= |
| 3 | + |
| 4 | +With the release of Ansys product service packs adding enhanced security to |
| 5 | +gRPC communication, the PyAnsys ecosystem enables various transport modes for |
| 6 | +securing gRPC connections. Mutual TLS (mTLS) is one such mode that provides |
| 7 | +secure communication by requiring both the client and server to authenticate |
| 8 | +each other using digital certificates. |
| 9 | + |
| 10 | +.. important:: |
| 11 | + |
| 12 | + As a user,y ou are responsible for managing and securing your own certificates. |
| 13 | + |
| 14 | +`OpenSSL <https://www.openssl.org/>`__ can be used to generate the necessary |
| 15 | +certificates for mTLS. The following files are required for both the server and |
| 16 | +the client: |
| 17 | + |
| 18 | +.. table:: |
| 19 | + :widths: auto |
| 20 | + |
| 21 | + ====== ======================= ========================================== |
| 22 | + Side Required Files Purpose |
| 23 | + ====== ======================= ========================================== |
| 24 | + Server server.crt Server identity |
| 25 | + server.key Server private key |
| 26 | + ca.crt To verify client certificates |
| 27 | + Client client.crt Client identity |
| 28 | + client.key Client private key |
| 29 | + ca.crt To verify server certificates |
| 30 | + ====== ======================= ========================================== |
| 31 | + |
| 32 | +Generate a certificate authority |
| 33 | +-------------------------------- |
| 34 | + |
| 35 | +.. code-block:: bash |
| 36 | +
|
| 37 | + # Generate private key for CA |
| 38 | + openssl genrsa -out ca.key 4096 |
| 39 | +
|
| 40 | + # Generate self-signed CA certificate |
| 41 | + openssl req -x509 -new -nodes -key ca.key -sha256 -days 3650 -out ca.crt \ |
| 42 | + -subj "/CN=MyRootCA" |
| 43 | +
|
| 44 | +Generate the server certificate |
| 45 | +------------------------------- |
| 46 | + |
| 47 | +.. code-block:: bash |
| 48 | +
|
| 49 | + # Generate server private key |
| 50 | + openssl genrsa -out server.key 4096 |
| 51 | +
|
| 52 | + # Generate a certificate signing request (CSR) for the server |
| 53 | + openssl req -new -key server.key -out server.csr \ |
| 54 | + -subj "/CN=localhost" |
| 55 | +
|
| 56 | + # Generate server certificate signed by the CA |
| 57 | + openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial \ |
| 58 | + -out server.crt -days 365 -sha256 |
| 59 | +
|
| 60 | +Generate the client certificate |
| 61 | +------------------------------- |
| 62 | + |
| 63 | +.. code-block:: bash |
| 64 | +
|
| 65 | + # Generate client private key |
| 66 | + openssl genrsa -out client.key 4096 |
| 67 | +
|
| 68 | + # Generate a certificate signing request (CSR) for the client |
| 69 | + openssl req -new -key client.key -out client.csr \ |
| 70 | + -subj "/CN=grpc-client" |
| 71 | +
|
| 72 | + # Generate client certificate signed by the CA |
| 73 | + openssl x509 -req -in client.csr -CA ca.crt -CAkey ca.key -CAcreateserial \ |
| 74 | + -out client.crt -days 365 -sha256 |
| 75 | +
|
| 76 | +Verify certificates |
| 77 | +------------------- |
| 78 | + |
| 79 | +.. code-block:: bash |
| 80 | +
|
| 81 | + # Verify server certificate |
| 82 | + openssl verify -CAfile ca.crt server.crt |
| 83 | +
|
| 84 | + # Verify client certificate |
| 85 | + openssl verify -CAfile ca.crt client.crt |
0 commit comments