π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[server] Use native crypto result
Neeraj Gupta71d4da435791
diff --git a/server/pkg/controller/user/twofactor.go b/server/pkg/controller/user/twofactor.goindex 388887ea50..bace007b22 100644--- a/server/pkg/controller/user/twofactor.go+++ b/server/pkg/controller/user/twofactor.go@@ -183,7 +183,7 @@ func (c *UserController) GetKeyAttributeAndToken(context *gin.Context, userID inif err != nil {return ente.TwoFactorAuthorizationResponse{}, stacktrace.Propagate(err, "")}- encryptedToken, err := crypto.GetEncryptedToken(token, keyAttributes.PublicKey)+ encryptedToken, err := crypto.GetEncryptedTokenNative(token, keyAttributes.PublicKey)if err != nil {return ente.TwoFactorAuthorizationResponse{}, stacktrace.Propagate(err, "")}diff --git a/server/pkg/controller/user/user_delete.go b/server/pkg/controller/user/user_delete.goindex a7257174a3..0601ebd9d5 100644--- a/server/pkg/controller/user/user_delete.go+++ b/server/pkg/controller/user/user_delete.go@@ -45,7 +45,7 @@ func (c *UserController) GetDeleteChallengeToken(ctx *gin.Context) (*ente.Deleteif err != nil {return nil, stacktrace.Propagate(err, "")}- encryptedToken, err := crypto.GetEncryptedToken(base64.StdEncoding.EncodeToString([]byte(token)), keyAttributes.PublicKey)+ encryptedToken, err := crypto.GetEncryptedTokenNative(base64.StdEncoding.EncodeToString([]byte(token)), keyAttributes.PublicKey)if err != nil {return nil, stacktrace.Propagate(err, "")}diff --git a/server/pkg/controller/user/userauth.go b/server/pkg/controller/user/userauth.goindex 54f30567df..a93db6536b 100644--- a/server/pkg/controller/user/userauth.go+++ b/server/pkg/controller/user/userauth.go@@ -484,13 +484,7 @@ func (c *UserController) onVerificationSuccess(context *gin.Context, email strin}}var encryptedToken string-- if strings.Contains(email, "@ente.io") {- log.Info("Using native encryption for ente.io email")- encryptedToken, err = crypto.GetEncryptedTokenNative(token, keyAttributes.PublicKey)- } else {- encryptedToken, err = crypto.GetEncryptedToken(token, keyAttributes.PublicKey)- }+ encryptedToken, err = crypto.GetEncryptedTokenNative(token, keyAttributes.PublicKey)if err != nil {return ente.EmailAuthorizationResponse{}, stacktrace.Propagate(err, "")}diff --git a/server/pkg/utils/crypto/crypto.go b/server/pkg/utils/crypto/crypto.goindex b1c66c172d..df225b16fe 100644--- a/server/pkg/utils/crypto/crypto.go+++ b/server/pkg/utils/crypto/crypto.go@@ -39,11 +39,13 @@ func encryptWithNonce(data string, encryptionKey []byte, nonce []byte) (ente.EncnativeEnc, err := encryptWithNonceNative(data, encryptionKey, nonce)if err != nil {logrus.WithField("op", "crypto_compare").WithError(err).Error("native encryption failed")+ return ente.EncryptionResult{}, stacktrace.Propagate(err, "native encryption failed")}if nativeEnc.Cipher != nil && base64.StdEncoding.EncodeToString(nativeEnc.Cipher) != base64.StdEncoding.EncodeToString(encryptedEmailBytes) {logrus.WithField("op", "crypto_compare").Error("encryption mismatch between libsodium and native implementation")+ return ente.EncryptionResult{}, stacktrace.Propagate(err, "encryption mismatch")}- return ente.EncryptionResult{Cipher: encryptedEmailBytes, Nonce: nonce}, nil+ return nativeEnc, nil}func Decrypt(cipher []byte, key []byte, nonce []byte) (string, error) {@@ -55,10 +57,12 @@ func Decrypt(cipher []byte, key []byte, nonce []byte) (string, error) {nativeResult, nativeErr := DecryptNative(cipher, key, nonce)if nativeErr != nil {logrus.WithField("op", "crypto_compare").WithError(nativeErr).Error("native decryption failed")+ return "", stacktrace.Propagate(nativeErr, "native decryption failed")} else if nativeResult != result {logrus.WithField("op", "crypto_compare").Error("decryption mismatch between libsodium and native implementation")+ return "", stacktrace.NewError("decryption mismatch")}- return result, nil+ return nativeResult, nil}func GetHash(data string, hashKey []byte) (string, error) {@@ -73,10 +77,12 @@ func GetHash(data string, hashKey []byte) (string, error) {nativeResult, nativeErr := GetHashNative(data, hashKey)if nativeErr != nil {logrus.WithField("op", "crypto_compare").WithError(nativeErr).Error("native hash failed")+ return "", stacktrace.Propagate(nativeErr, "native hash failed")} else if nativeResult != result {logrus.WithField("op", "crypto_compare").Error("hash mismatch between libsodium and native implementation")+ return "", stacktrace.NewError("hash mismatch")}- return result, nil+ return nativeResult, nil}func GetEncryptedToken(token string, publicKey string) (string, error) {