Securing Communications in Siemens TIA Portal using TLS Encryption
Introduction
This tutorial concludes the TIA Portal cybersecurity series. Check out the previous tutorials: Â Securing your Projects and Programs in Siemens TIA Portal, Securing your PLC Hardware in Siemens TIA Portal, and Securing your HMI in Siemens TIA Portal.
In the previous tutorials, we studied the three first layers of security available within the TIA Portal environment. The first was about software protection, the second was about PLC securing, and the last was about the HMI securing. In this tutorial, you will learn the final layer of protection which is securing communications.  Â
Many cyber attacks can take advantage of unsecured communications between a PLC and an external device (like a server for example). To ensure the integrity and authenticity of the data exchanged, we will use the TLS (Transport Layer Security) protocol, which is the most widely used security protocol. It consists of a key-based encryption algorithm (EC or RSA), each communication partner has its unique public and private key, and trusted devices share their relative keys using a certificate system. Each device generates a signed certificate that must be imported into all other partner devices. Certificates are used to identify upcoming communications and confirm their authenticity.
To illustrate how the configuration is done, we will use two different PLCs located in two different projects. Note that any of these two PLCs can be substituted with any other device supporting the TLS protocol. The principle of creating, exporting, and importing certificates will be the same.Â
Prerequisites:
To follow this tutorial, you will need an installation of TIA Portal. We will be using TIA Portal v17, but you can use any other version. No additional hardware or software is required.
Creating a secured project and generating TLS Certificates in TIA Portal
Let’s start by creating two different projects and adding the CPUs of your choice. I selected the simplest model of S7-1200.
![](https://cdn.prod.website-files.com/63dea6cb95e58cb38bb98cbd/6415da0da3139ec772d97623_635a4da57a09eb4e0f73fbb6_kjAX0iwlLLQMlU5g2ebrfA1OSZcJkDCPA9lv5Tbep3Xr3cCcE-JqY9XW6nSuC6PVKOPFdH9niizCBVo3xbBburgPcpGNrKjLlNa9c5t4Ji3W4wnzrsfr4y9MyFLtHFQoKOLC30eJLnCofbqQlR1PWliMixa5s-SsrIXh1SDHOetVaJ1Tt-oBTVnp-A.png)
![](https://cdn.prod.website-files.com/63dea6cb95e58cb38bb98cbd/6415da0ea3139edaf1d97628_635a4da5654996771806ce31_v-kparqM3idjd04v13twOHXODBMsTNm8oUh7yx9xCiSm8Tv0fu-PUhZ7Dg3RQN8Mkk-xyJcu-5ivWaFXl_as8LlQkm9Izoo8vebJHZvTT_G-w0XT7joQJrSG1m9ePpIMcJe6xRu1UFnBGYyVX1mjQm5nqCMXM1mbEzk9JhekgYQqXkKoh4S7Dhw1Qw.png)
Next, protect both projects by opening the “Security features” tab in the project tree. Then, click on settings followed by “protect this project. You can learn about this step in the Securing your Projects and Programs in Siemens TIA Portal tutorial.Â
![](https://cdn.prod.website-files.com/63dea6cb95e58cb38bb98cbd/6415da0da3139e9246d9761f_635a4da54b79fb528cd60836_BbGZxK3i2uayR0S-DjvX9T8jZfNQbE6VgJw07nL8yCX1vpVwYCM9tEML9hNhPJEte-M9eOxU5p3ReuSahtJeICdxHYi3STs43ojuQhfy0cPvAwrC8bBtcTB_4p16pfqB-eot5bPClLEc8dcMkloYo6bhzyZkeNHRrbIIeWXIUT4iTAfoVfxJ1AJ-Qw.png)
Once done, return to the first PLC project, and open the device configuration. In the properties tab, open the “Certificate manager” section and check “Use global security settings for certificate manager”. Using the global certificate manager is way more convenient and avoids mistakes when using local certificates.
![](https://cdn.prod.website-files.com/63dea6cb95e58cb38bb98cbd/6415da0da3139ee6b2d97622_635a4da5e448c90d789a3dc9_y-_2HA0fYhhhWW8LDdCkclQKRbaMWAdgg3IrHBbtOsUNu64nenoYdKye2be2am6ZCDKWLIE3L8dB2Dl4Znr_zzz02LtyxPGDBrBqhvgGEPFPpOrZMwab5bbC_N335y7lsfsAIJFso-ae4wj5EBT3ywoRpyteu4yFqOw2J-SvZsIYeJ7J3BrwD_pEng.png)
Now open the “Certificate manager” under the “Security features” in the project tree.
![](https://cdn.prod.website-files.com/63dea6cb95e58cb38bb98cbd/6415da0da3139e6d20d9761b_635a4da53f3edc685c946dd2_XPYANC-c3FJwfogaa7augUJDr6tHKmUgHtZn2bq8LzYTIVkb968zdkyB0vx3Id0chm7TWMbdC4Hq6rLFqWFzJl-NkVexm7dhCxn1nnz3h8jH8XZFutfIXoSuI8BuokDT_tWb4YhUIZ0_sXRTBTXNMra0zyTtjYLY72INy561ZctiJwQdlGqdkfCUdQ.png)
Once in the certificate manager, bring your attention to the two certificate authorities (CA) available in your software. TIA Portal includes two certified CAs you can use to sign your certificates. Always use certified CAs in your projects to ensure your secured communications' reliability.
![](https://cdn.prod.website-files.com/63dea6cb95e58cb38bb98cbd/6415da0da3139eb529d9761a_635a4da57a09eb465173fbb5_ft6nxn0K1n0S8WQjzvw8P4qwzMavkx7uCbTSmP3xDMLGR7x4rbXu2qPQCuV-fx4Q2P9xlzNZqe5XzoudN0xgAnLXc4wiKYgB3UPgoDI0tY01Vtzvt_zm4kUtUJRr3LMRV7LfnGMJ704X-KAzeE4x62skRctjQ5Qzxi2Jj9rlTanouL_fwnIiBcp0Jw.png)
Now, let’s create a signed certificate. Open the “Device Certificates” tab, right-click anywhere and click on “Create”
![](https://cdn.prod.website-files.com/63dea6cb95e58cb38bb98cbd/6415da0da3139edfa8d97618_635a4da5654996201206ce3a_fi6lMxClCK49bQbfmMibcSsX4Na-YiS1HAehJNAPDCcuM6Q3LjB7Ns6Ad6fxu73B0x3OqgcEC-jfhdYBaFX33cNGllfTvavfpBdAXFx0a5r82Zvz4W-RhbwaEzj00A4FhSXERyjeqhHWvvfAu6En5drVLz0s99x9i287fQj3reuJMujHNpWaLBzmBQ.png)
First, select the CA (from the CAs available in TIA or by importing a CA from a trusted source), then select the certificate parameters according to your application. There are 2 encryption types available; EC and RSA. You can define the type of encryption and hash algorithms in the “Encryption parameter” and “Hash algorithm” sections. You also have to specify the certificate's usage and the device's IP address.
![](https://cdn.prod.website-files.com/63dea6cb95e58cb38bb98cbd/6415da0da3139ea315d97617_635a4da5dd2872469a20f5ee_CdNhBFLxr6QCGIi898YleciCijOosPcRnm1ioATbHS1L1oTPBo7CLdyT1gWzi8aDYiQ-M1NufqhioPWEuNk1_W0krX8jplcm3frc_FBA0pINmOcKro-YRlMj2E1dmK1i1_DWvyaYq_s0f2acywp_LMTR5YoElkA1O9hpnpIIymKBYnQHpn8QADUZJw.png)
The certificate has been created and its ID number is 3. To use this certificate on another device, we must export it as a file. Right-click on the newly created certificate and click on “Export”.Â
![](https://cdn.prod.website-files.com/63dea6cb95e58cb38bb98cbd/6415da0da3139e2a6dd97619_635a4da6dfb493f6ad09d37b_v1dEvbE6Oo5aMEhUj9oeEzPFFU1Mpsakn9yKNGpcGpzZq_HttYKikTuIj1fPedQhLDXt59IKGlz0BSENj6WDSF4gVax-OZxvawlHkrwTX6Ub49uJQiWnvrcMJrN8IOxRvZeO2pV-Q63oCxi5IkEvKwzBlSl7mdP9qJOtD6xEXe5Vy9rM1iLqRrp7FQ.png)
An “Export Certificate” window will appear. Check the “Include the private key (in the export)” box. You must define a password to protect the certificate, if you don’t edit the password, the one defined for your project protection will be used. Â
![](https://cdn.prod.website-files.com/63dea6cb95e58cb38bb98cbd/6415da0da3139e3282d97621_635a4da67a09eb358573fbc1_m9UA-X0ru4YJxKrFjN18eBji_eiBs0jbdLh3cF660USLi3iIxbdBxAV6ewGskvoLs0fMuLRp0H9EL8Kb7Aya_e7kSbmk9S0CSpYak8f5sl98Gv8kv2FFvnoM9CjyPlUc_3xsaAa5Z_LHhvqx6ZV8XPnpXB768mZnaTiBZHLGDdUCc5BpYKUB7-4eJg.png)
Then, select the folder where you want to save your certificate file and the type of file. There are three main formats of certificate files :Â
- PEM based (.pem): Mainly used in Apache and Unix/Linux environments.
- DER based (.der/.cer): Mainly used in Java environments.
- P12 based (.p12): Mainly used in windows environments.
![](https://cdn.prod.website-files.com/63dea6cb95e58cb38bb98cbd/6415da0da3139e360ad9761c_635a4da67a09eb673c73fbc0_BjWrocT0mTOTmBEpazVI2AoLlEivGcwxjvFo3s4NW4BxiIMEobw7hStvE97fdxyF2f9WvOBcxjSXQMJJKjUnWtvfAAIhI-ORGbFnK-SU9Kk2g5PtLjvJtioTC8fP2hceqlr3AFWbnfRlRk34lglziRLjXcYFPAl6uFawGgKrGkKvY7m9lOwc2wxU6g.png)
Repeat all these last steps to create and export the signed certificate of the second PLC. Once done, you should have two certificate files, one for each PLC.
![](https://cdn.prod.website-files.com/63dea6cb95e58cb38bb98cbd/6415da0da3139e6a35d9761d_635a4da6f3c8a4c9fa4a33d9_JjW0NzjjJeOoZUQ90UrRt5cEfkV3RlNw8MkrUemnqJBi9YAdxeeDuNBn57b1v6KnrFfYPpn8_3W_ZJOenM6YXI73suSogleAkVfOC4iievjuisD2t284ASZTaIynrseoYGuWfhIG4k3GbqPyZWm2GHV0q7U40Mgb1mlE_ohWvkUbK6kqM0WBojrdeg.png)
The last step is to import each certificate to the other PLC. Go back to the Certificate manager of the first PLC, open the “Trusted certificates and root certificates” tab, and right-click anywhere. Then, click on “Import”.
![](https://cdn.prod.website-files.com/63dea6cb95e58cb38bb98cbd/6415da0da3139e4699d97620_635a4da671ea333e77b2811f_6U56cIR1c8AoujUU90Tco9mayvpEezGEZUIje24BLyZ46kspuVSmXGFZsjyEVgZdw5saoMq2FFLCSWgxURBXHkJLGqxcuVYxAcaMmEnB_ooR0ALlbXKpJt9g1TPq-4kGv0izV4gzkio2As3LnKtZ7EuaOPdI7SaSivroXUoQuZ42Dir78PVzZiUoWg.png)
Select the certificate of the second PLC and click on “Open”.
![](https://cdn.prod.website-files.com/63dea6cb95e58cb38bb98cbd/6415da0ea3139e5beed9762a_635a4da6befa0c54046f43bf_muntIlBgw-K7q-4RJ2Uu-OoULx5gkljJS-WEYz106plXsyBs9M_Eb3nihvph248aUJPPlhW6x4sDlf1mHcKXNSaj9IP7uyrgeSBuNDcY4NrPz1c4tJj7_9FQLHjxwGbupWiT9tfuNOK8yJsp_N4R3ksERZtHYrP9s-MMvmpn5Th0LhEj9XTuZ1yKig.png)
Enter the certificate’s protection password (If you didn’t modify it, it should be the same as your project password).
![](https://cdn.prod.website-files.com/63dea6cb95e58cb38bb98cbd/6415da0ea3139e5ce8d97626_635a4da604fcf64af7b66e24_KCjQVD1qnI2fMcVsngIZWsYuG7toJkqcDqJvj0TWSWzj80ZMhdvZrsRJnjwmon2x3ov8ODuv4fXY8MEWBh3iT04tHaENzr1DRRfmS0NqLIGnI5HK8fRuPN6Hz2Xw3CJ6YlhFWVwcJSxdm0Hx4ebxkultWJn1fN8MDb3jFi9nIuxB61VtqDBeHABpCw.png)
The PLC2 certificate has been added to the PLC1 project and has ID number 4.Â
![](https://cdn.prod.website-files.com/63dea6cb95e58cb38bb98cbd/6415da0da3139eae88d9761e_635a4da64bede02b540d0b4b_0XWlImdQBRgljpLzf2UcCH0_pnSpXoeLIq4ayL2_WuSTAvUw8zEMrh_tcpYUlCmIB_fU1njHxz-SEH461KrteZqxETOAXVQjtbagOLHno93Rg6evNdkjhTNbVCUwxUlRZzkY8HNT8urIzlmAGncVM-akfBTx7b2PRSgZJSwXJOS1LDCKy8S8brEnjQ.png)
Repeat these last steps to import the PLC1 certificate to the PLC2 project.
![](https://cdn.prod.website-files.com/63dea6cb95e58cb38bb98cbd/6415da0da3139ec146d97624_635a4da6654996abf306ce55_BhJpoHpXCHNiymIrZAtoT4Ct1OVqhmevW2Yh7Yp6aTAW9IC9WrWZOrBQiWWr8Pzp-eU1WUQdU_rEbKVc3eEd_Ve7I1Xu777iCt6XbV79JkEhJ97qS4NJfcqVaW4vNs_uju-pxQubwX2sO2qBmiTxeHbK3jwBxNgKTEkOWHuCLndSqP5tqLHdamsDXQ.png)
Establishing secured ProfiNet communications using TCON_IP_V4_SEC
Now that we’re done with the certificates, let’s program the communications. We’re going to use the Open User Communications instructions. You can refer to Open User Communication in Siemens TIA Portal tutorial for more details.Â
Instead of configuring the communication block in the instruction parameters, we have to manually create a DB (Data Block) and insert a certain data type called “TCON_IP_V4_SEC”. This data type contains all the parameters required to establish secure communications over IPv4.Â
First, we need to create the data block. Click on “Add new block” in the Project tree.
![](https://cdn.prod.website-files.com/63dea6cb95e58cb38bb98cbd/6415da0ea3139e6998d97629_635a4da6fd6f24d21381165a_3eEYCSdJb_NGRCk_HGk3yNe2gpxqvnJ6MwXMvbV2lRlpgHBxP90bVgbkL4ed6FuQYWAwg8jj3dEnpg0ONPT3Ij1wSqEP3OOSpr710J6qEgmyujhlkqIHhs6OH20jnpeJkpKerFT8qLJWRje2tVMd_Lw2_9ggDU-EoMKDE-kw4xxpz05wml2BEcTONg.png)
In the “Add new block” window, select “Data Block”, give it a name, and click on “OK”.
![](https://cdn.prod.website-files.com/63dea6cb95e58cb38bb98cbd/6415da0ea3139e19d4d9762b_635a4da6a34410e94a8f2e64_m_-hSHcFixGl0NqnH1eKkjE55cz9YPkRRnfvL1sWDNshCfRFnkmms4TE3vPm1RDM7oiza-CtG3N-e7S2p-s48CEn42W8c13vYyQu3XyvZYOst9ZM09Gz1obYCtI5iBDy01v66JqGMf0I0b8Mj_ddsl8hHxvFtzrB3vtL4rPgfTy9L4LObIC4vuC_qw.png)
Now open in the newly created DB by double-clicking on it in the Project tree.
![](https://cdn.prod.website-files.com/63dea6cb95e58cb38bb98cbd/6415da0ea3139e507ed97625_635a4da66f2b1e9863312315_X5d3gfH4g3kyoRxO9NvFK4CninKh0HUGPbkcT8Lkmxnmo8hv2oLEluszszvTu26ETDmPoy1jPDDaTaIqUS1doAuqhlXbhE31WGrBar7oudfuHC3mMNRMM1BZaJGZsVsNlmMCXi04xjNU3Yakj0TJ6xbygBEBGz-rAbt1M6JKHiqxW2mPQBebKagw.png)
Inside the DB, create a new variable, give it a name, and type “TCON_IP_V4_SEC” in the Data type section. Then, press “Enter”.
![](https://cdn.prod.website-files.com/63dea6cb95e58cb38bb98cbd/6415da0ea3139e15b5d97627_635a4da64bede0ba750d0b4c_7b5eU02FDiC-4g9PAU_M5r8NRAWU4btBjgLTA0o6-WJe5dgCiMliDtPSJjcmU87kRry0r4lccoOv5HwQd2fsfmgcSBT9m8EyJNLTilyJSat4--74-6S6dt635qN8Mgszq7lhSFOhSGhsI2eoVgjWkDRQYffx1OcndIhXOEBLu2Bp_i7aCBKvRZc4wg.png)
Open the content of the entire structure by clicking on the small black arrows. You will see all the parameters of the secured communication.Â
![](https://cdn.prod.website-files.com/63dea6cb95e58cb38bb98cbd/6415da0ea3139e3fe3d9762d_635a4da64bede061240d0b4d_reNHiZaYx8ahGOCe4OqIf0KOhMp4yxXNxYaLfut2BW-ScA3TKweR5cM1Oq2M0eMSWeS62MEvpgtkBE1J_ZR2Gkjhvnj23YmJFnMb9fBbXep0DJSvInN2a5E0sPq76EPnm0eAmD_Obkez-nPuGP3CY-e5Q4Sb3ML6_Cc6cJEw4RgZ47T940zzcniWUg.png)
The parameters we need to edit are:Â
- ID: Defines the Profinet ID of the communication.
- ActiveEstablishment: Defines if the device is a client or a server (False = Server / True = Client).
- ADDR 1 to 4: IPv4 Address over four bytes of the partner device.
- RemotePort: Port of the partner device. In the Siemens S7 PLCs, ports start at 2000.
- LocalPort: Port of the current device. In the Siemens S7 PLCs, ports start at 2000.
- TLSServerCerRef: ID of the server certificate (PLC2).
- TLSClientCerRef: ID of the client certificate (PLC1).
Edit the parameters (of PLC1) as follows.
![](https://cdn.prod.website-files.com/63dea6cb95e58cb38bb98cbd/6415da0ea3139efed6d9762c_635a4da66c1c8e8411c3b283_i2dl1Iu8nn_qNZMqCIo2yiZt75ExolwStxPnmTVjJpYyL5pkEN-3NQeMHQj0MqtYRzy84bHHqQrMTFADFicsWSadHPexzJaJ1n--1UKcJQvD6qE8iClRK57-7H52wW0xhn5KN7RqvE85JmXaeC1CMSi_CJjHq7on0pyro-lthHPGrHCwF3C2ZZPJIA.png)
Then, repeat these last steps for PLC2 and edit the parameters as follows.Â
![](https://cdn.prod.website-files.com/63dea6cb95e58cb38bb98cbd/6415da0ea3139e5f93d9762f_635a4da69c5314b414ef6848_pL6g3DyqPKBoUPBjywbNzOHFN0couPZz_7MylrWYN1Z15YL58-03a8ADygpLnzsAtA_gQr2cTnWE22M0tLcqN45cY1xOiF1CEGslljbefivEJkZWa8VU4mlYKBh7XtwSaEObBvLMC1lFQ5jrUOOuutBB8OfPYH7fESJAqNNDT1oDfxMkJFfFd33J9Q.png)
The final step is to program the communication. To do this, we’re going to use the compact communication instructions “TSEND_C” and “TRCV_C”. The following step applies to both PLC1 and PLC2.
Open the main program (OB1) and drag-and-drop TSEND_C and TRCV_C instructions. You can find these instructions in the Communication/Open User Communication folder. Then, edit the parameters as follows.
![](https://cdn.prod.website-files.com/63dea6cb95e58cb38bb98cbd/6415da0ea3139e7041d9762e_635a4da7fd6f242af9811675_hVtw2DTZyMF_DW09meKjtmbnEgSG2GKOReJa3vXZ9YQ4eCO_6OSOh6OCB62Y9xgn_sX0ItKS9aiYqZuG_bgtGVm8uS-qXhRlpthDH_egiK_qdQQFR5TVsP08kIU9WmHQFOOYl6a2qOn-2SN-8f-gFjO1htWzW8PLrUoWZ9dmiUv8MNAbVNyyBMKVKg.png)
- The CONNECT parameter must contain the TCON_IP_V4_SEC created in the DB (following this syntax “DBName”.StructureName).
- The DATA parameter contains the memory location you want to send or receive in.Â
Conclusion
In this tutorial, you learned how to secure your communications using the TLS protocol within TIA Portal.
By protecting your communications using an encryption-based protocol, you close the door to the majority of cyber attacks from external sources. In addition to the other three layers of security, your system should be safe from the most common threats.
To protect against more specific and targeted attacks, several other security tools such as firewalls and VPNs exist. To obtain total and reliable protection, it is possible to rely on the IEC 62443 standard which governs industrial cyber security. You will find more details on all the practices to adopt to certify a system against cyber threats.