Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Stop using legacy KEK hashes in server key attributes

Neeraj Guptaeda8a14548fb
diff --git a/cli/internal/api/login_type.go b/cli/internal/api/login_type.go
index 10a760f511..975d5cad04 100644
--- a/cli/internal/api/login_type.go
+++ b/cli/internal/api/login_type.go
@@ -23,7 +23,6 @@ type CreateSRPSessionResponse struct {
type KeyAttributes struct {
KEKSalt string `json:"kekSalt" binding:"required"`
- KEKHash string `json:"kekHash"`
EncryptedKey string `json:"encryptedKey" binding:"required"`
KeyDecryptionNonce string `json:"keyDecryptionNonce" binding:"required"`
PublicKey string `json:"publicKey" binding:"required"`
diff --git a/rust/apps/cli/src/api/models.rs b/rust/apps/cli/src/api/models.rs
index bc9546defb..9988f6f48e 100644
--- a/rust/apps/cli/src/api/models.rs
+++ b/rust/apps/cli/src/api/models.rs
@@ -59,7 +59,6 @@ pub struct VerifySrpSessionRequest {
#[serde(rename_all = "camelCase")]
pub struct KeyAttributes {
pub kek_salt: String,
- pub kek_hash: Option<String>,
pub encrypted_key: String,
pub key_decryption_nonce: String,
pub public_key: String,
diff --git a/rust/crates/accounts/src/auth/key_gen.rs b/rust/crates/accounts/src/auth/key_gen.rs
index 7a11083a2c..50f3013df9 100644
--- a/rust/crates/accounts/src/auth/key_gen.rs
+++ b/rust/crates/accounts/src/auth/key_gen.rs
@@ -47,7 +47,6 @@ pub fn generate_keys_with_strength(
let key_attributes = KeyAttributes {
kek_salt: b64::encode(derived.salt.as_bytes()),
- kek_hash: None,
encrypted_key: enc_key,
key_decryption_nonce: key_nonce,
public_key: b64::encode(public_key.as_bytes()),
@@ -105,7 +104,6 @@ pub fn generate_key_attributes_for_new_password_with_strength(
let key_attributes = KeyAttributes {
kek_salt: b64::encode(derived.salt.as_bytes()),
- kek_hash: None,
encrypted_key: enc_key,
key_decryption_nonce: key_nonce,
mem_limit: derived.params.mem_limit,
diff --git a/rust/crates/accounts/src/auth/types.rs b/rust/crates/accounts/src/auth/types.rs
index d513abb98d..029b7b608f 100644
--- a/rust/crates/accounts/src/auth/types.rs
+++ b/rust/crates/accounts/src/auth/types.rs
@@ -9,9 +9,6 @@ use ente_core::crypto::{SecretString, SecretVec};
#[serde(rename_all = "camelCase")]
pub struct KeyAttributes {
pub kek_salt: String,
- // Legacy KEK hash, present only on old accounts (base64).
- #[serde(skip_serializing_if = "Option::is_none")]
- pub kek_hash: Option<String>,
pub encrypted_key: String,
pub key_decryption_nonce: String,
pub public_key: String,
@@ -33,7 +30,6 @@ impl fmt::Debug for KeyAttributes {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("KeyAttributes")
.field("kek_salt", &"[REDACTED]")
- .field("kek_hash", &self.kek_hash.as_ref().map(|_| "[REDACTED]"))
.field("encrypted_key", &"[REDACTED]")
.field("key_decryption_nonce", &"[REDACTED]")
.field("public_key", &"[REDACTED]")
@@ -131,7 +127,6 @@ mod tests {
fn sample_key_attributes() -> KeyAttributes {
KeyAttributes {
kek_salt: "server-kek-salt".to_string(),
- kek_hash: Some("server-kek-hash".to_string()),
encrypted_key: "server-encrypted-key".to_string(),
key_decryption_nonce: "server-key-nonce".to_string(),
public_key: "server-public-key".to_string(),
@@ -153,7 +148,6 @@ mod tests {
let debug = format!("{attrs:?}");
assert!(debug.contains("[REDACTED]"));
assert!(!debug.contains("server-kek-salt"));
- assert!(!debug.contains("server-kek-hash"));
assert!(!debug.contains("server-encrypted-key"));
assert!(!debug.contains("server-key-nonce"));
assert!(!debug.contains("server-public-key"));
diff --git a/rust/crates/space/tests/support/auth.rs b/rust/crates/space/tests/support/auth.rs
index 03b09f4d24..3053728710 100644
--- a/rust/crates/space/tests/support/auth.rs
+++ b/rust/crates/space/tests/support/auth.rs
@@ -48,7 +48,6 @@ pub async fn create_account(endpoint: &str, email_prefix: &str) -> TestAccount {
let encrypted_recovery_with_master = secretbox::encrypt(recovery_key.as_bytes(), &master_key);
let key_attributes = KeyAttributes {
kek_salt: account_fixture::KEK_SALT.into(),
- kek_hash: None,
encrypted_key: b64::encode(&encrypted_master_key.encrypted_data),
key_decryption_nonce: b64::encode(encrypted_master_key.nonce.as_bytes()),
public_key: b64::encode(public_key.as_bytes()),
diff --git a/rust/crates/test-support/src/account_fixture.rs b/rust/crates/test-support/src/account_fixture.rs
index eacbea5868..9263d6e84f 100644
--- a/rust/crates/test-support/src/account_fixture.rs
+++ b/rust/crates/test-support/src/account_fixture.rs
@@ -53,7 +53,6 @@ pub async fn create_account(endpoint: &str, email_prefix: &str) -> TestResult<Te
let encrypted_recovery_with_master = secretbox::encrypt(recovery_key.as_bytes(), &master_key);
let key_attributes = KeyAttributes {
kek_salt: KEK_SALT.into(),
- kek_hash: None,
encrypted_key: b64::encode(&encrypted_master_key.encrypted_data),
key_decryption_nonce: b64::encode(encrypted_master_key.nonce.as_bytes()),
public_key: b64::encode(public_key.as_bytes()),
diff --git a/server/ente/user.go b/server/ente/user.go
index 43a6c56c60..0bb9fe901c 100644
--- a/server/ente/user.go
+++ b/server/ente/user.go
@@ -66,7 +66,6 @@ type EmailAuthorizationResponse struct {
type KeyAttributes struct {
KEKSalt string `json:"kekSalt" binding:"required"`
- KEKHash string `json:"kekHash"`
EncryptedKey string `json:"encryptedKey" binding:"required"`
KeyDecryptionNonce string `json:"keyDecryptionNonce" binding:"required"`
PublicKey string `json:"publicKey" binding:"required"`
diff --git a/server/pkg/api/user_test.go b/server/pkg/api/user_test.go
index a44d0821f7..ec48c6e50a 100644
--- a/server/pkg/api/user_test.go
+++ b/server/pkg/api/user_test.go
@@ -163,7 +163,6 @@ func setPublicKeyTestAttributes(t *testing.T, handler *UserHandler, userID int64
t.Helper()
keyAttributes := ente.KeyAttributes{
KEKSalt: "kek-salt",
- KEKHash: "kek-hash",
EncryptedKey: "encrypted-key",
KeyDecryptionNonce: "key-decryption-nonce",
PublicKey: "target-public-key",
diff --git a/server/pkg/controller/user/twofactor_session_test.go b/server/pkg/controller/user/twofactor_session_test.go
index 2c8cbfd713..3e92b47553 100644
--- a/server/pkg/controller/user/twofactor_session_test.go
+++ b/server/pkg/controller/user/twofactor_session_test.go
@@ -43,7 +43,7 @@ func TestTwoFactorSessionIsConsumedOnlyAfterSuccessfulAuthorization(t *testing.T
HashingKey: testutil.HashingKey(),
}
if err = userRepo.SetKeyAttributes(userID, ente.KeyAttributes{
- KEKSalt: "salt", KEKHash: "hash", EncryptedKey: "key", KeyDecryptionNonce: "nonce",
+ KEKSalt: "salt", EncryptedKey: "key", KeyDecryptionNonce: "nonce",
PublicKey: base64.StdEncoding.EncodeToString(publicKey[:]), EncryptedSecretKey: "secret-key",
SecretKeyDecryptionNonce: "secret-nonce", MemLimit: 1, OpsLimit: 1,
}); err != nil {
diff --git a/server/pkg/controller/user/user_recovery_test.go b/server/pkg/controller/user/user_recovery_test.go
index 3654c71442..2d6d57a17e 100644
--- a/server/pkg/controller/user/user_recovery_test.go
+++ b/server/pkg/controller/user/user_recovery_test.go
@@ -522,12 +522,11 @@ func insertKeyAttributes(t *testing.T, db *sql.DB, userID int64) {
t.Helper()
_, err := db.Exec(
`INSERT INTO key_attributes(
- user_id, kek_salt, kek_hash_bytes, encrypted_key, key_decryption_nonce,
+ user_id, kek_salt, encrypted_key, key_decryption_nonce,
public_key, encrypted_secret_key, secret_key_decryption_nonce, mem_limit, ops_limit
- ) VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)`,
+ ) VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9)`,
userID,
"kek-salt",
- []byte("kek-hash"),
"encrypted-key",
"key-nonce",
"public-key",
diff --git a/server/pkg/controller/user/userauth_send_ott_test.go b/server/pkg/controller/user/userauth_send_ott_test.go
index 6993b59332..9dcccb119a 100644
--- a/server/pkg/controller/user/userauth_send_ott_test.go
+++ b/server/pkg/controller/user/userauth_send_ott_test.go
@@ -412,7 +412,6 @@ func insertCompleteSendOTTTestUser(t *testing.T, db *sql.DB, userRepo *repo.User
func sendOTTTestKeyAttributes() ente.KeyAttributes {
return ente.KeyAttributes{
KEKSalt: "kek-salt",
- KEKHash: "kek-hash",
EncryptedKey: "encrypted-key",
KeyDecryptionNonce: "key-decryption-nonce",
PublicKey: "public-key",
diff --git a/server/pkg/repo/passkey/passkey_test.go b/server/pkg/repo/passkey/passkey_test.go
deleted file mode 100644
index 1bdfea3611..0000000000
--- a/server/pkg/repo/passkey/passkey_test.go
+++ /dev/null
@@ -1,54 +0,0 @@
-package passkey
-
-import (
- "testing"
-
- "github.com/ente/museum/ente"
- "github.com/ente/museum/internal/testutil"
-)
-
-func TestStoreTokenDataRoundTripsLegacyNULByte(t *testing.T) {
- testutil.WithServerRoot(t)
- db := testutil.RequireTestDB(t)
- testutil.ResetTables(t, db)
- t.Cleanup(func() { testutil.ResetTables(t, db) })
-
- userID := testutil.InsertUser(t, db, testutil.UserFixture{
- UserID: 1,
- Email: "[email protected]",
- CreationTime: 1,
- })
- const sessionID = "legacy-nul-byte-session"
- if _, err := db.Exec(`
- INSERT INTO passkey_login_sessions(user_id, session_id, creation_time, expiration_time)
- VALUES ($1, $2, $3, $4)
- `, userID, sessionID, 1, 2); err != nil {
- t.Fatalf("insert passkey login session: %v", err)
- }
-
- repo := &Repository{DB: db}
- want := ente.TwoFactorAuthorizationResponse{
- ID: userID,
- KeyAttributes: &ente.KeyAttributes{
- KEKHash: "\x00",
- },
- EncryptedToken: "encrypted-token",
- }
- if err := repo.StoreTokenData(sessionID, want); err != nil {
- t.Fatalf("store token data: %v", err)
- }
-
- got, err := repo.GetTokenData(sessionID)
- if err != nil {
- t.Fatalf("get token data: %v", err)
- }
- if got.ID != want.ID || got.EncryptedToken != want.EncryptedToken {
- t.Fatalf("token data = %+v, want %+v", got, want)
- }
- if got.KeyAttributes == nil {
- t.Fatal("token data is missing key attributes")
- }
- if got.KeyAttributes.KEKHash != want.KeyAttributes.KEKHash {
- t.Fatalf("kek hash = %q, want %q", got.KeyAttributes.KEKHash, want.KeyAttributes.KEKHash)
- }
-}
diff --git a/server/pkg/repo/user.go b/server/pkg/repo/user.go
index 6ff615df7e..3037134fa4 100644
--- a/server/pkg/repo/user.go
+++ b/server/pkg/repo/user.go
@@ -360,17 +360,15 @@ func (repo *UserRepository) GetUserIDWithEmailUnrestricted(email string) (int64,
}
func (repo *UserRepository) GetKeyAttributes(userID int64) (ente.KeyAttributes, error) {
- row := repo.DB.QueryRow(`SELECT kek_salt, kek_hash_bytes, encrypted_key, key_decryption_nonce, public_key, encrypted_secret_key, secret_key_decryption_nonce, mem_limit, ops_limit, master_key_encrypted_with_recovery_key, master_key_decryption_nonce, recovery_key_encrypted_with_master_key, recovery_key_decryption_nonce FROM key_attributes WHERE user_id = $1`, userID)
+ row := repo.DB.QueryRow(`SELECT kek_salt, encrypted_key, key_decryption_nonce, public_key, encrypted_secret_key, secret_key_decryption_nonce, mem_limit, ops_limit, master_key_encrypted_with_recovery_key, master_key_decryption_nonce, recovery_key_encrypted_with_master_key, recovery_key_decryption_nonce FROM key_attributes WHERE user_id = $1`, userID)
var (
keyAttributes ente.KeyAttributes
- kekHashBytes []byte
masterKeyEncryptedWithRecoveryKey sql.NullString
masterKeyDecryptionNonce sql.NullString
recoveryKeyEncryptedWithMasterKey sql.NullString
recoveryKeyDecryptionNonce sql.NullString
)
err := row.Scan(&keyAttributes.KEKSalt,
- &kekHashBytes,
&keyAttributes.EncryptedKey,
&keyAttributes.KeyDecryptionNonce,
&keyAttributes.PublicKey,
@@ -386,7 +384,6 @@ func (repo *UserRepository) GetKeyAttributes(userID int64) (ente.KeyAttributes,
if err != nil {
return ente.KeyAttributes{}, stacktrace.Propagate(err, "")
}
- keyAttributes.KEKHash = string(kekHashBytes)
if masterKeyEncryptedWithRecoveryKey.Valid {
keyAttributes.MasterKeyEncryptedWithRecoveryKey = masterKeyEncryptedWithRecoveryKey.String
}
@@ -404,8 +401,8 @@ func (repo *UserRepository) GetKeyAttributes(userID int64) (ente.KeyAttributes,
}
func (repo *UserRepository) SetKeyAttributes(userID int64, keyAttributes ente.KeyAttributes) error {
- _, err := repo.DB.Exec(`INSERT INTO key_attributes(user_id, kek_salt, kek_hash_bytes, encrypted_key, key_decryption_nonce, public_key, encrypted_secret_key, secret_key_decryption_nonce, mem_limit, ops_limit, master_key_encrypted_with_recovery_key, master_key_decryption_nonce, recovery_key_encrypted_with_master_key, recovery_key_decryption_nonce) VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)`,
- userID, keyAttributes.KEKSalt, []byte(keyAttributes.KEKHash),
+ _, err := repo.DB.Exec(`INSERT INTO key_attributes(user_id, kek_salt, encrypted_key, key_decryption_nonce, public_key, encrypted_secret_key, secret_key_decryption_nonce, mem_limit, ops_limit, master_key_encrypted_with_recovery_key, master_key_decryption_nonce, recovery_key_encrypted_with_master_key, recovery_key_decryption_nonce) VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)`,
+ userID, keyAttributes.KEKSalt,
keyAttributes.EncryptedKey, keyAttributes.KeyDecryptionNonce,
keyAttributes.PublicKey, keyAttributes.EncryptedSecretKey,
keyAttributes.SecretKeyDecryptionNonce, keyAttributes.MemLimit, keyAttributes.OpsLimit,
diff --git a/server/space/api/sessions_test.go b/server/space/api/sessions_test.go
index 8dc6dc086a..7a344aad13 100644
--- a/server/space/api/sessions_test.go
+++ b/server/space/api/sessions_test.go
@@ -55,10 +55,10 @@ func setupSpaceSessionAPITest(
})
_, err := db.Exec(`
INSERT INTO key_attributes (
- user_id, kek_salt, kek_hash_bytes, encrypted_key, key_decryption_nonce,
+ user_id, kek_salt, encrypted_key, key_decryption_nonce,
public_key, encrypted_secret_key, secret_key_decryption_nonce
- ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
- `, userID, "salt", []byte{1, 2, 3}, "encrypted-key", "nonce", "public-key", "encrypted-secret-key", "secret-nonce")
+ ) VALUES ($1, $2, $3, $4, $5, $6, $7)
+ `, userID, "salt", "encrypted-key", "nonce", "public-key", "encrypted-secret-key", "secret-nonce")
require.NoError(t, err)
return NewHandlers(controller.NewModule(
repos,
diff --git a/server/space/controller/test_helpers_test.go b/server/space/controller/test_helpers_test.go
index 3bcd59c4d8..f914db48a1 100644
--- a/server/space/controller/test_helpers_test.go
+++ b/server/space/controller/test_helpers_test.go
@@ -79,10 +79,10 @@ func insertSpaceControllerUser(t *testing.T, module *spacerepo.Module, email str
})
_, err := module.Spaces.DB.Exec(`
INSERT INTO key_attributes (
- user_id, kek_salt, kek_hash_bytes, encrypted_key, key_decryption_nonce,
+ user_id, kek_salt, encrypted_key, key_decryption_nonce,
public_key, encrypted_secret_key, secret_key_decryption_nonce
- ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
- `, userID, "salt", []byte{1, 2, 3}, "encrypted-key", "nonce", publicKey, "encrypted-secret-key", "secret-nonce")
+ ) VALUES ($1, $2, $3, $4, $5, $6, $7)
+ `, userID, "salt", "encrypted-key", "nonce", publicKey, "encrypted-secret-key", "secret-nonce")
require.NoError(t, err)
return userID
}
diff --git a/server/space/repo/module_test.go b/server/space/repo/module_test.go
index b28e313d9f..3f6b08d20a 100644
--- a/server/space/repo/module_test.go
+++ b/server/space/repo/module_test.go
@@ -525,10 +525,10 @@ func insertSpaceUser(t *testing.T, module *Module, email string, publicKey strin
})
_, err := module.Spaces.DB.Exec(`
INSERT INTO key_attributes (
- user_id, kek_salt, kek_hash_bytes, encrypted_key, key_decryption_nonce,
+ user_id, kek_salt, encrypted_key, key_decryption_nonce,
public_key, encrypted_secret_key, secret_key_decryption_nonce
- ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
- `, userID, "salt", []byte{1, 2, 3}, "encrypted-key", "nonce", publicKey, "encrypted-secret-key", "secret-nonce")
+ ) VALUES ($1, $2, $3, $4, $5, $6, $7)
+ `, userID, "salt", "encrypted-key", "nonce", publicKey, "encrypted-secret-key", "secret-nonce")
require.NoError(t, err)
return userID
}