Open gkc opened 4 months ago
Sample dart code for atkeys encryption atkeys_encryption.dart
@purnimavenkatasubbu Next steps:
For every task you've added, create a ticket and add the link to the task item
There's a reasonable amount of analysis to do here and a lot of admin / ticket creation; I'm going to estimate it as 8 SP
Since this has come up multiple times in conversations with customers, I've increase its priority to P1 and moved it into Triage for discussion at next sprint planning
@purnimavenkatasubbu What I described above is a broad-based bottom-up approach to getting this feature rolled out. A better approach is probably to first focus on getting this feature into all of the NoPorts distro's binaries (including at_activate) and treat all of the required work as P1; and then treat the remainder as P2
srvd.dart
, sshnp.dart
, sshnpd.dart
and npt.dart
files in noports/packages/dart/sshnoports/bin
folder which should propagate the password to the package which decrypts the password protected atKeys file : https://github.com/atsign-foundation/noports/issues/1465@gkc and @cpswan : Here are the proposed approaches for generating a hash from a passphrase to encrypt or decrypt the atKeys file. Kindly review these options and let us know which one would be the most suitable for our needs:
Approach 1: PBKDF2 with IV stored with the key file: PBKDF2
(Password-Based Key Derivation Function) uses HMAC to hash the password. With PBKDF2, we can specify the number of iterations the hash function should perform and provide a nonce, which strengthens the hash and reduces the risk of brute-force attacks.
However, one limitation of PBKDF2 is its susceptibility to brute-force attacks when executed on GPUs.
Approach 2: Argon2id with IV stored with the key file: Argon2id
is a more advanced alternative to PBKDF2 and is resistant to brute-force attacks even when executed on GPUs. Like PBKDF2, Argon2id allows us to specify the number of iterations and a nonce, but it also allows to define the amount of memory the algorithm can use. Allocating more memory makes the algorithm more resistant to brute-force attacks. Argon2id gives us the flexibility to adjust memory usage, iteration count, and the degree of parallelism, enabling us to balance performance and security based on your needs.
The Dart Cryptography package provides implementations of both algorithms: https://pub.dev/packages/cryptography .
For both approaches, an Initialization Vector (IV) must be provided to the encrypter. During encryption, a randomly generated IV of fixed length can be used, and this IV must be retained for decryption. One way to achieve this is by appending the IV to the encrypted atKeys content and storing them together in the atKeys file. During decryption, the IV and the encrypted atKeys are used to retrieve the decrypted version of atKeys. Through decrypting we get the atKeys file back
Example of the encrypted file: {"content":" < encrypted atKeys file content > ","IV":" < IV encoded to base64 > "}
Alternatively, in both approaches mentioned above, the IV for the encrypted atKeys file can be set to all zeros to avoid storing it within the file. However, this method provides weaker security.
I think argon2id is the way to go here. @cconstab any thoughts?
My first inclination is also towards argon2id, but we should check first how things look in C land given our progress with the SDK there.
We should also have a view on whether this is expected to be used primarily with clients (where the password can be entered interactively) or also on devices?
This GitHub repository includes Argon2id implementation in C-Language and provides an example demonstrating its usage.
@gkc @cpswan Please share your thoughts on how to go about managing the IV
@gkc @cpswan Please share your thoughts on how to go about managing the IV
Store in encrypted atKeys file as per @sitaram-kalluri's suggestion {"content":" < encrypted atKeys file content > ","IV":" < IV encoded to base64 > "}
The analysis is complete, and the below are the conclusions drawn for implementation:
Use the Argon2id algorithm for encryption and decryption of the atKeys file when a passphrase is provided.
The proposed structure for storing encrypted data in the atKeys file is as follows:
{
"content": "<encrypted atKeys content>",
"IV": "<IV encoded in base64>",
"Algorithm": "<Algorithm used for encryption>"
}
Including the encryption algorithm in the atKeys file allows for future flexibility, enabling the use of different algorithms or support for multiple algorithms. This information will help determine which algorithm to use for decryption.
Following are the tickets to track the implementation progress:
Spent 8SP in PR-98:
Pending work to do in PR: 99
Work accomplished in PR-99
Pending work in PR-100.
Work accomplished in PR-100.
Is your feature request related to a problem? Please describe.
atKeys
files are not encrypted, thus they need careful management; I'd like it not to be a security problem if my atKeys file is somehow leaked.Describe the solution you'd like
Support password-protected encryption of atKeys in the same way as for ssh private keys
Describe alternatives you've considered
No response
Additional context
This has come up multiple times in conversations with customers.