|
1 | 1 | # Dinamo HSM KMS Implementation Documentation |
2 | 2 |
|
| 3 | +## ⚠️ Security Recommendation |
| 4 | + |
| 5 | +**For production KMS implementations, consider implementing the KMS-API in a C++ like language, or use typed arrays like Uint8Array for all sensitive data because JavaScript does not support secure memory management.** |
| 6 | + |
| 7 | +**Recommended Alternatives:** |
| 8 | +- **C++/Rust**: Languages with explicit memory management and secure allocation |
| 9 | +- **Node.js Typed Arrays**: Use `Uint8Array` for sensitive data with explicit zeroing |
| 10 | +- **Native Addons**: Implement cryptographic operations in native C++ modules |
| 11 | +- **Hardware Security**: Use HSM-backed secure memory when available |
| 12 | + |
3 | 13 | This document provides a reference implementation for integrating the 4 KMS API's with Dinamo HSM, covering the complete request-response flow from API handlers to HSM operations. |
4 | 14 |
|
5 | 15 | ## Demo Scripts |
@@ -153,41 +163,6 @@ async generateDataKey(rootKey: string, keySpec: DataKeyTypeType): Promise<Genera |
153 | 163 | 5. **Automatic Cleanup**: HSM deletes temporary key |
154 | 164 | 6. **⚠️ MEMORY SECURITY**: Plaintext key must be wiped from memory after use |
155 | 165 |
|
156 | | -### Memory Security Best Practices |
157 | | - |
158 | | -```typescript |
159 | | -// Example of secure memory handling (recommended for production) |
160 | | -async secureDataKeyGeneration(rootKey: string): Promise<GenerateDataKeyKmsRes> { |
161 | | - let plaintextKey: string | null = null; |
162 | | - |
163 | | - try { |
164 | | - const result = await this.generateDataKey(rootKey, 'AES-256'); |
165 | | - plaintextKey = result.plaintextKey; |
166 | | - |
167 | | - // Use the plaintext key immediately |
168 | | - const encryptedData = encrypt(plaintextKey, sensitiveData); |
169 | | - |
170 | | - return { |
171 | | - encryptedKey: result.encryptedKey, |
172 | | - encryptedData: encryptedData |
173 | | - }; |
174 | | - } finally { |
175 | | - // **CRITICAL**: Explicitly wipe plaintext key from memory |
176 | | - if (plaintextKey) { |
177 | | - // Overwrite with random data multiple times |
178 | | - for (let i = 0; i < 3; i++) { |
179 | | - plaintextKey = crypto.randomBytes(plaintextKey.length).toString('base64'); |
180 | | - } |
181 | | - plaintextKey = null; |
182 | | - } |
183 | | - |
184 | | - // Force garbage collection (if available) |
185 | | - if (global.gc) { |
186 | | - global.gc(); |
187 | | - } |
188 | | - } |
189 | | -} |
190 | | -``` |
191 | 166 |
|
192 | 167 | **Security Considerations:** |
193 | 168 | - **Immediate Use**: Plaintext keys should be used immediately after generation |
|
0 commit comments