Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Private key protection hardened WireGuard imple...

Private key protection hardened WireGuard implementation

I use WireGuard as a lightweight VPN.
I thought about how to safely deploy a relatively powerful Linux-powered device that can do a lot of processing such as sensors and cameras.

Kentaro Mitsuyasu

April 14, 2023
Tweet

More Decks by Kentaro Mitsuyasu

Other Decks in Technology

Transcript

  1. Agenda • Profile • About WireGuard • Secure Element in

    brief • WireGuard Security Enhancements • Prospect • Summary
  2. Profile I'm from infrastructure and work for a company in

    the security business. I've done a lot of things at home. Out-of-home DNS AD Construction (Samba4) Nextcloud server operation Home Gluster Distributed File System Construction (infiniband) Jupyter notebook GPU Machine Learning Server (nvidia Geforce RTX2070) Volumio Airplay Server SORACOM IoT Meetup - IoT Device Security Study session! Learning Secure Elements 2022/2/21
  3. About WireGuard WireGuard is a simple and fast VPN. It

    has been adopted as a standard module of Linux and is being used. Various security measures are considered on the edge device side such as sensors and cameras However, I wondered if it would be possible to use WireGuard for secure edge communication.
  4. How is the latest encryption technology adopted? Curve25519 ECDH Key

    Sharing HKDF Key Derivation ChaCha20-Poly1305 Authentication ciphers BLAKE2s hash About WireGuard
  5. Structure of WireGuard Linux kernel Network Interface eth0 wlan0 wireguard

    kernel module Linux userspace wireguard-tools rtnetlink kernel⇔network I/F communication netlink kernel⇔userspace I/F Interface config Transfer key pair Device creation, communication About WireGuard
  6. The latest cool encryption technology like Noise Protocol Framework: What

    is the Noise Protocol Framework? About WireGuard
  7. 2nd.DH calc. What is the Noise Protocol Framework? Static Secret

    Static Public Pub Pub Ephemeral Public Ephemeral Secret Handshake comm. Static Public Pub Get in advance Static Public for counterpart Pub Static Public for counterpart (get in advance) Pub Static Public for counterpart Pub Ephemeral Secret 3rd.DH calc. Static Public for counterpart Pub Static Secret 4th.DH calc. Static Secret Pub Ephemeral Secret Static Secret for counterpart Ephemeral Public Pub Ephemeral Public 1st.DH calc. Ephemeral Secret Pub Ephemeral Public About WireGuard
  8. Challenge: Where to Place a Static Private Key Can this

    be protected by Secure Element? [Interface] PrivateKey = FA2qtPQO3XsjOSR06Sx9Eg/rR8pw2B5cSgdOXKpa8Gs= Address = 10.0.0.112/32 [Peer] PublicKey = ty5vAuknCTspoVquXgHt1AR8sm05Jblrkv1bfGKfMBw= Endpoint = 111.109.67.21:51820 AllowedIPs = 10.0.0.0/24 PersistentKeepalive = 25 Static Secret Static Public for counterpart Pub About WireGuard
  9. Secure Element in brief ▪Secure Element features: I2C devices that

    hide private keys to prevent spoofing Basic features: ▪ There is no command to read the private key, and the public key can be read. There are only commands. ▪ Value (hash) to the secret key in the secure element There are commands that give and sign, perform DH calculations, etc. and return the results.
  10. Optiga Trust X SE050(C) ATECC608A Infineon NXP Microchip Vendor I2C

    interface Elliptic Cryptography (ECC) Elliptic Cryptography (ECC),RSA Elliptic Cryptography (ECC) Cryptographic operations NIST P-256, P-384 ECC NIST (192 to 521 bit) Brainpool (160 to 512 bit) Twisted Edwards Ed25519 Montgomery Curve25519 Koblitz (192 to 256 bit) Barreto-Naehrig Curve 256 bit NIST P-256 Elliptic cryptography - up to 4096 bit - RSA cryptography AES-128 AES 128, 192 and 256 bit and DES keys with single DES, 2K3DES and 3K3DES AES-128 Symmetric key cryptography SHA-256 SHA-224/256/384/512 SHA-256 Hash 10KB 50KB 1.1KB Storage area 2~3$ 5~6$ About 1$ Price (1 piece) 10pin DFN 20pin QFN 8pin SOIC,DFN Package Temperature-friendly products SE050(A), SE050(B) with limited functions only ATECC108A with limited functions only, etc. Product Family ー ー Google Coral SoM,Arduino MKR Wifi Amazon Dash Button 2nd gen.(ATECC108A) ZYMBIT security module NervesKey for NervesHub Adafruit ATECC608 Breakout Coldcard Bitcoin hardware wallet etc. Use cases Security certification CC EAL6+ Security certification CC EAL6+ (HW+JCOP) JavaCard version 3.0.5 GlobalPlatform specification version GP 3.0 ー Supported Standards Secure Element in brief
  11. ▪Raspberry Pi 3b+ bullseye environment available NXP SE050 C1 connected

    to I2C. (MIKROE Plug & Trust click is available as COTS) Enable I2C with $ sudo raspi-config $ i2cdetect –y 1 command to check 0x48 recognition WireGuard Security Enhancements
  12. ▪Image incorporating Secure Element WireGuard Security Enhancements Give the public

    key to the secure element DH calculation 2nd.DH calc. Static Secret Static Public Pub Pub Ephemeral Public Ephemeral Secret Handshake comm. Static Public Pub Get in advance Static Public for counterpart Pub Static Public for counterpart (get in advance) Pub Static Public for counterpart Pub Ephemeral Secret 3rd.DH calc. Static Public for counterpart Pub Static Secret 4th.DH calc. Static Secret Pub Ephemeral Secret Static Secret for counterpart Ephemeral Public Pub Ephemeral Public 1st.DH calc. Ephemeral Secret Pub Ephemeral Public
  13. WireGuard Security Enhancements ▪Key points of implementation Linux userspace wireguard-tools

    • wg genkey command In order to hide the output private key, it is the internal key storage number of the SE050. Output the object ID instead This value itself can be leaked. • wg pubkey command Using the object ID as an argument, the public key is output from the SE050.
  14. WireGuard Security Enhancements ▪Key points of implementation •noise.c In the

    code that performs the handshake, change the contents of the wg->static_identity.static_private structure to the object ID, which is the internal key storage number of SE050. Change and replace the function that calls it for ECDH calculations with the SE050 API. NXP's Plug & Trust middleware is for user space, so the kernel HAL (Hardware Abstraction Layer) must be created for the module. The code also needs to be rewritten for kernel space. Linux kernel WireGuard kernel module
  15. WireGuard Security Enhancements ▪wireguard-tools $ wg genkey 0x10000009 CQAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= $

    wg genkey 0x10000009 | wg pubkey Yh3rhVp7LfvPC4YWjB7L8mJO2hk2VXMh9sZ9B6tLm2c= The 0x10000009 became Base64, and the private key could be hidden. Output the public key of the object ID 0x10000009 of SE050. Register this with the counterpart.
  16. WireGuard Security Enhancements ▪wireguard $ sudo cat /etc/wireguard/wg0.conf [Interface] PrivateKey

    = CQAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= Address = 10.0.0.110/32 [Peer] PublicKey = XXXXX= Endpoint = XXX.XXX.XXX.XXX:XXXXX AllowedIPs = 10.0.0.0/24 PersistentKeepalive = 25 Register a number with the 0x10000009 set to Base64 as the secret key Register the counterpart public key
  17. WireGuard Security Enhancements ▪performance iperf3 5 runs average Standard wireguard

    39.28Mbit/sec Wireguard for Secure Element 39.38Mbit/sec No significant difference
  18. WireGuard Security Enhancements ▪Try key rotation. Create a private key,

    public key with a new key number on the client side. $ wg genkey 0x10000006 BgAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= $ wg genkey 0x10000006 | wg pubkey 9oGFAiGUSMIzg2gzwwEBasjfKxkULebTwzOEjn7K4Rk=
  19. WireGuard Security Enhancements ▪Try key rotation. On the server side:

    $ sudo wg set wg0 peer "9oGFAiGUSMIzg2gzwwEBasjfKxkULebTwzOEjn7K4Rk=" allowed- ips 10.0.0.111/32 The connection is lost when you do this. $ sudo wg set wg0 peer "ChgKBqwSnkov+rcC2KKUQKMgPH9pfrnWXzLpMzfKpg4=" remove IP is Current IP The public key of the currently connected peer
  20. WireGuard Security Enhancements ▪Try key rotation. On the client side:

    $ sudo wg-quick down /etc/wireguard/wg0.conf Change the following in $ sudo vi /etc/wireguard/wg0.conf ``` [Interface] PrivateKey = BgAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= Address = 10.0.0.111/32 ``` $ sudo wg-quick up /etc/wireguard/wg0.conf IP is Current IP Specify the key for the new 0x10000006
  21. Things to consider ▪SE050 write limit. “An exception in case

    the EC Montgomery curve 25519 is used: each shared secret generation will cause additional NVM write operations as well to store the external public key that is used in the shared secret generation.” It seems that internal flash writes occur every time ECDH calculation is performed on the SE050. Measurement: 4 runs in 5 minutes According to the data sheet, the number of times allowed to write is At worst, 20 million times, average 100 million times. If you assume that ECDH is calculated once a minute, it will be 38 years at worst.
  22. Prospect Intended use: IoT Device Maintenance Network Protocol protection such

    as existing MQTT The code I tested is below: https://github.com/kmwebnet/wireguard-se https://github.com/kmwebnet/wireguard-tools-se I write blogs related to IoT security. Any feedback would be appreciated. https://qiita.com/kmitsu76 https://medium.com/kmitsu-iot-security-tech-note/
  23. Summary The implementation of secure elements in IoT devices with

    increasing cloud connectivity will be more reliable in the network, data handled, and devices, and the range of applications will expand References: Make and understand WireGuard https://speakerdeck.com/fadis/zuo-tuteli-jie-suruwireguard