fix persisting keys

This commit is contained in:
2025-12-28 02:03:52 -07:00
parent 94d7cde6fa
commit be67bd0fb6
2 changed files with 38 additions and 0 deletions

View File

@@ -30,6 +30,9 @@ func InitDB() {
identity_key BLOB,
prekey BLOB,
prekey_signature BLOB,
enc_priv_key BLOB,
priv_key_salt BLOB,
priv_key_nonce BLOB,
created_at DATETIME
);
CREATE TABLE IF NOT EXISTS rooms (
@@ -97,6 +100,17 @@ func authorizeUser(pubkey, username string, identityKey, prekey, prekeySignature
return err
}
func storeUserEncryptedKey(username string, encKey, salt, nonce []byte) error {
_, err := db.Exec("UPDATE users SET enc_priv_key=?, priv_key_salt=?, priv_key_nonce=? WHERE username=?",
encKey, salt, nonce, username)
return err
}
func getUserEncryptedKey(username string) (encKey, salt, nonce []byte, err error) {
err = db.QueryRow("SELECT enc_priv_key, priv_key_salt, priv_key_nonce FROM users WHERE username = ?", username).Scan(&encKey, &salt, &nonce)
return
}
func getUsername(pubkey string) (string, error) {
var username string
err := db.QueryRow("SELECT username FROM users WHERE pubkey = ?", pubkey).Scan(&username)