Hi! Thanks for checking out the proposal!
TL/DR: What’s stored on-chain are not the passwords themselves but the encrypted versions of them. Further, knowning the structure of the smart contract won’t help a hacker in deciphering the password from the encrypted text.
Longer version:
Let me answer 3 questions that you’re likely to ask:
- What is actually stored on-chain?
- What does a user need to decrypt/decipher the encrypted passwords stored on-chain?
- How easy is it for a hacker to decrypt an encrypted password without the master key?
1. What is actually stored on-chain?
The passwords themselves are not stored. Rather, it is the encrypted versions of the passwords. For example, suppose we have the following
{
"url": "google.com",
"username": "lousydropout@gmail.com",
"password": "this_is_not_my_actual_password_123",
"description": "password for personal gmail account",
"idx": "-1",
"timestamp": "2024-07-02T14:34:01Z",
"deleted": false
}
What ends up being stored on-chain is something like the following (btw, this is what I’m referring to as the “encrypted password” for simplicity):
(
'gaW9DL1Z4jzWpaSt',
'Y+3qYp3eru8UZMIUoli0OHHbYdX06NDJSnaTyRe5NgRj21T+VBhl++8ZAl6pB+OYebYD+qXbHoT7A91K6L9ok/9i6Ds/a0WEV4/H62uroS+LRT2nh46mcznhfKnY3YvNtominEurNZG2Cnx2sxfSJNCD6TY6xjEDuIwF5saWkv/q5039KGVlZx9BqkIvVBRq1hhvwb3rpttlDMw='
)
As you can see, the encrypted password that’s stored on-chain are 2 strings that look essentially like gibberish.
(Note: The encrypted password shown here contains my actual gmail username and password.)
2. What does a user need to decrypt/decipher the encrypted passwords stored on-chain?
In order to decrypt the encrypted text and get back the actual username and password, a user needs a “master key” of sorts. A “master key” looks like the following:
{
"alg": "A256GCM",
"ext": true,
"k": "MR9ioAcPn-zI_M5k8AfCCORnDw12AWZhLCM_um9jKAM",
"key_ops": ["encrypt", "decrypt"],
"kty": "oct"
}
The important thing to note here is the field k. k acts as the “master password” that lets you decrypt an encrypted text and, as you can see, k is a very long, random string (meaning, very difficult to crack or figure out).
3. How easy is it for a hacker to decrypt an encrypted password without the master key?
The encryption algorithm used here is called AES (Advanced Encryption Standard) and is generally considered to be the most secure form of encryption available.
Aside from certain rare and specific situations that are not applicable here, the only way to crack AES encryption is by brute force. And since keyvault uses 256-bit AES, it will take approximately 2^(256-1) = 2^255 attempts.
To give an idea as to how computationally intensive it’d be to make 2^255 attempts, please see a very nice and short video by 3Blue1Brown: https://www.youtube.com/watch?v=S9JGmA5_unY. (The video uses SHA-256 for its context, but the calculation is directly applicable to 256-bit AES encryption.)
Spoiler: An attacker can have a ridiculous number of Google supercomputers attempting to crack the encryption non-stop for billions of years and the attacker would still only have a 1 in 4 billion chance of succeeding.