Authors: Atis Straujums Juris Olekss
Cryptographic keys are a foundational element of modern cybersecurity. They serve to keep data safely encrypted and help maintain secure networks for client-server communication. Unfortunately, this makes them a prime target for hackers. A single compromised key can unlock a treasure trove of personal data and valuable IP, or enable malicious activities like unauthorized system access and signing fake digital certificates. Yet, despite their importance, cryptographic key protection often remains an under-prioritized aspect of software development.
Recent cryptographic key attacks highlight the severity of the issue:
- SIM Card Breach: Hackers stole encryption keys from one of the world’s largest SIM card manufacturers, which produces over two billion cards annually. This could allow decryption of mobile device communications intended to be secure.
- Side-Channel Attacks: Researchers demonstrated a device capable of reading electromagnetic frequencies through hidden setups, such as embedding it in a piece of pita bread, to steal cryptographic keys..
- Bank Breach in South Africa: A bank stored its master encryption key in plain text at a data center. Employees exploited this lapse to commit fraud, leading to the replacement of 12 million bank cards.
- Marriott Hotel Hack: In a massive Marriott data breach, hackers stole both encrypted customer data and the cryptographic key stored on the same server, exacerbating the scale of damage.
Most of these attacks could have been mitigated by following basic cryptographic key protection strategies. Here are five essential best practices for development teams:
Cryptographic Key Protection Best Practices
1. Avoid Hardcoding Keys – Use White-Box Protection
Hardcoded cryptographic keys remain a widespread issue, even among cybersecurity vendors. This practice significantly increases the risk of encrypted data being compromised. Fixing such vulnerabilities often requires extensive patching, as one vendor discovered when it took 18 months to fully remediate hardcoded keys.
Additionally, secure coding practices recommend overwriting variables containing cryptographic keys after use to prevent exposure if memory is later accessed by untrusted code.
2. Assign Keys to Specific Purposes
Each cryptographic key should be used for one application and purpose only, whether that is encryption, authentication, key wrapping, random number generation or digital signature. Keys should be created with the appropriate key strength for their intended purpose—using it for a different process may weaken its effectiveness and increase the potential damage of a compromise. Reusing a key also can lead to greater damage in the event the key is compromised.
Special care is necessary for key-wrapping keys, or Key-Encryption-Keys (KEKs). KEKs are keys used to protect other cryptographic keys. KEKs must always have equal or greater strength than the cryptographic keys they are wrapping and should not be used for an additional purpose like encrypting data or communications.
3. Leverage Hardware-Backed Security
Hardware Security Modules (HSMs) are highly effective tools for cryptographic key protection and may be mandated in certain use cases, like securing root keys in PKI. This physical device can perform critical cryptographic functions such as encryption, decryption and key generation in a secure and isolated environment.. Using an HSM removes the burden of secure key storage from a software’s logic and reduces the chance that hackers will get access to data and the keys they need to decrypt it in one place. Other hardware-backed options include trusted platform modules (TPM) and trusted execution environments (TEE), which provide hardware isolated systems to perform cryptographic operations.
While these solutions reduce risk, they may be cost-prohibitive and susceptible to sidechannel attacks that exploit signals from physical devices (e.g. heat or timing).
4. Utilize White-Box Cryptography for Key Protection
For high-value applications and data, and when hardware-backed key security is unavailable or insufficient, include software-based key protection. White-box cryptography offers a robust alternative for protecting keys in software applications. White-box cryptography secures cryptographic operations and storage even in environments lacking hardware security features, such as mobile apps or web applications.
White-box cryptography uses multiple protection techniques to create a secure execution and storage environment for cryptographic functions in software and apps. zKeyBox, Zimperium’s industry-leading white-box cryptography solution, uses patented technology to protect major crypto algorithms (e.g. AES, RSA, ECDSA) without relying on hardware-based mechanisms like Keystore or Secure Enclave. Its single set of APIs, software-based key protection solutions provide identical functionality across devices, making them easier to implement than hardware alternatives. Especially in industries with strict security requirements, this becomes critical. Strong white-box cryptography has the added advantage of protecting applications from speculative execution and other side-channel attacks.
5. Implement Robust Key Management Policies
Key management involves creating a number of policies to ensure that cryptographic keys are not put in danger through ignorance or carelessness. Effective key management policies focus on:
- Lifecycle Management: Securely handle key generation, distribution, use, replacement, expiration, archival and destruction.
- Key Storage and Backup: Cryptographic key protection depends on secure storage, such as hardware-based security devices or using white-box cryptography. Keys stored in offline devices/databases should be encrypted using KEKs before exporting and storing. Applications must include the ability to securely backup keys as data encrypted with a lost cryptographic key cannot be recovered.
- Access Control: Restrict access to cryptographic keys and maintain accountability by tracking users and permissions. Such control is critical to both keep cryptographic keys safe and reduce the impact of any compromise that does occur.
How To Get Started
Cryptographic key protection doesn’t require reinventing the wheel. Established standards, like NIST SP 800-57, provide extensive guidelines on how to best protect secret keys and to what standard.
The OWASP Key Management Cheat Sheet is an excellent resource on cryptographic key protection and management for developers.