Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance Local Password and Key Management Security #62

Open
fabohax opened this issue Dec 16, 2024 · 2 comments
Open

Enhance Local Password and Key Management Security #62

fabohax opened this issue Dec 16, 2024 · 2 comments

Comments

@fabohax
Copy link

fabohax commented Dec 16, 2024

The current implementation of password and private key handling stores decrypted private keys in localStorage, which poses a significant security risk:

auth.ts:

nuxtClientInit() {
  const decryptedPrivKey = ref<string | null>(localStorage.getItem(AUTH_LOCAL_STORAGE_DECRYPTED_KEY));
  if (decryptedPrivKey.value) {
    try {
      this.privKey = decryptedPrivKey.value;
      this.pubKey = getPublicKey(Buffer.from(this.privKey, 'hex'));
      this.authMethod = AuthMethod.LOCAL;
    } catch (err) {
      console.warn('Error setting local key from local storage: ', err);
      this.delete();
    }
  }
  watch(() => this.privKey, (newVal) => {
    localStorage.setItem(AUTH_LOCAL_STORAGE_DECRYPTED_KEY, newVal || '');
  });
},

Here are suggested fixes:

  1. Avoid storing decrypted private keys:

    • Keep decrypted keys in memory and never persist them to localStorage.
    • Use Vue's reactive state or composables to handle keys temporarily.
  2. Use Web Crypto API for Encryption:

    • Encrypt sensitive data before storing it.
    • Derive keys securely using a passphrase with PBKDF2 or Argon2.
  3. Implement a TTL (Time-to-Live):

    • Add an expiration mechanism for encrypted keys stored in localStorage.
@bilthon
Copy link
Collaborator

bilthon commented Dec 17, 2024

Keeping the unencrypted private key material in memory only is indeed a good idea. However take in consideration that a new private key management scheme will have to be introduced in the upcoming releases and the current one will be phased out. So I won't recommend putting too much time in modifying the current scheme for that.

You can more about the new scheme here: https://mostro.network/protocol/key_management.html

@fabohax
Copy link
Author

fabohax commented Dec 17, 2024

Ok. Gonna check in detail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants