Skip to content

armgit / ente

Public Imported from GitHub
0

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

Use uint64 to gaurd from overflow

Mahmoud2791398159b5
diff --git a/server/ente/user.go b/server/ente/user.go
index 2b45d36bdb..961bca25af 100644
--- a/server/ente/user.go
+++ b/server/ente/user.go
@@ -12,7 +12,7 @@ const (
SignUpOTTPurpose = "signup"
LoginOTTPurpose = "login"
- ExpectedKDFStrength = 1073741824 * 4
+ ExpectedKDFStrength = uint64(1073741824 * 4)
)
// User represents a user in the system
@@ -80,8 +80,8 @@ type KeyAttributes struct {
PublicKey string `json:"publicKey" binding:"required"`
EncryptedSecretKey string `json:"encryptedSecretKey" binding:"required"`
SecretKeyDecryptionNonce string `json:"secretKeyDecryptionNonce" binding:"required"`
- MemLimit int `json:"memLimit" binding:"required"`
- OpsLimit int `json:"opsLimit" binding:"required"`
+ MemLimit uint64 `json:"memLimit" binding:"required"`
+ OpsLimit uint64 `json:"opsLimit" binding:"required"`
MasterKeyEncryptedWithRecoveryKey string `json:"masterKeyEncryptedWithRecoveryKey"`
MasterKeyDecryptionNonce string `json:"masterKeyDecryptionNonce"`
RecoveryKeyEncryptedWithMasterKey string `json:"recoveryKeyEncryptedWithMasterKey"`
@@ -114,8 +114,8 @@ type UpdateKeysRequest struct {
KEKSalt string `json:"kekSalt" binding:"required"`
EncryptedKey string `json:"encryptedKey" binding:"required"`
KeyDecryptionNonce string `json:"keyDecryptionNonce" binding:"required"`
- MemLimit int `json:"memLimit" binding:"required"`
- OpsLimit int `json:"opsLimit" binding:"required"`
+ MemLimit uint64 `json:"memLimit" binding:"required"`
+ OpsLimit uint64 `json:"opsLimit" binding:"required"`
}
func (u *UpdateKeysRequest) Validate() error {
diff --git a/server/ente/user_test.go b/server/ente/user_test.go
index 56562cacec..2b786ac37e 100644
--- a/server/ente/user_test.go
+++ b/server/ente/user_test.go
@@ -1,6 +1,10 @@
package ente
-import "testing"
+import (
+ "testing"
+
+ "github.com/stretchr/testify/require"
+)
const (
validArgonMemLimit = 128 * 1024 * 1024
@@ -18,6 +22,17 @@ func TestSetUserAttributesRequestValidate_RejectsUnexpectedKDFStrength(t *testin
assertBadRequestMessage(t, req.Validate(), "Unexpected KDF strength")
}
+func TestSetUserAttributesRequestValidate_AllowsMinimumMemory(t *testing.T) {
+ req := SetUserAttributesRequest{
+ KeyAttributes: KeyAttributes{
+ MemLimit: 128 * 1024 * 1024,
+ OpsLimit: validArgonOpsLimit,
+ },
+ }
+
+ require.NoError(t, req.Validate())
+}
+
func TestSetUserAttributesRequestValidate_RejectsLowMemoryLimit(t *testing.T) {
req := SetUserAttributesRequest{
KeyAttributes: KeyAttributes{
@@ -38,6 +53,15 @@ func TestUpdateKeysRequestValidate_RejectsUnexpectedKDFStrength(t *testing.T) {
assertBadRequestMessage(t, req.Validate(), "Unexpected KDF strength")
}
+func TestUpdateKeysRequestValidate_AllowsMinimumMemory(t *testing.T) {
+ req := UpdateKeysRequest{
+ MemLimit: 128 * 1024 * 1024,
+ OpsLimit: validArgonOpsLimit,
+ }
+
+ require.NoError(t, req.Validate())
+}
+
func TestUpdateKeysRequestValidate_RejectsLowMemoryLimit(t *testing.T) {
req := UpdateKeysRequest{
MemLimit: 64 * 1024 * 1024,