-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[server] Switch to native lib for results #7430
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
Conversation
Code Review - PR #7430: Switch to Native Lib for ResultsSummaryThis PR completes the migration from libsodium to native Go crypto libraries by switching the return values from comparison functions to use the native implementation. This is a critical step in eliminating the external libsodium dependency. ✅ Strengths
🐛 Critical BugLine if base64.StdEncoding.EncodeToString(nativeEnc.Cipher) != base64.StdEncoding.EncodeToString(encryptedEmailBytes) ||
base64.StdEncoding.EncodeToString(nativeEnc.Nonce) != base64.StdEncoding.EncodeToString(nonce) {
logrus.WithField("op", "crypto_compare").Error("encryption mismatch between libsodium and native implementation")
return ente.EncryptionResult{}, stacktrace.Propagate(err, "encryption mismatch") // ⚠️ BUG: 'err' is nil here
}Issue: The code tries to propagate Fix: Use return ente.EncryptionResult{}, stacktrace.NewError("encryption mismatch")This same pattern is correctly used on lines 67 and 87 for similar mismatch cases. 🔒 Security Considerations
⚡ Performance Considerations
📝 Recommendations
🎯 ConclusionThis is a well-structured PR that completes an important migration. The approach of validating native implementations against libsodium before switching is sound. The PR should not be merged until the critical bug on line 50 is fixed, but otherwise the changes are clean and follow good practices. Recommendation: Request changes to fix the error handling bug, then approve after fix. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
server/pkg/utils/crypto/crypto.go
Outdated
| if base64.StdEncoding.EncodeToString(nativeEnc.Cipher) != base64.StdEncoding.EncodeToString(encryptedEmailBytes) || | ||
| base64.StdEncoding.EncodeToString(nativeEnc.Nonce) != base64.StdEncoding.EncodeToString(nonce) { | ||
| logrus.WithField("op", "crypto_compare").Error("encryption mismatch between libsodium and native implementation") | ||
| return ente.EncryptionResult{}, stacktrace.Propagate(err, "encryption mismatch") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return error on native/libsodium encryption mismatch
When the libsodium and native encryption results differ, the code logs the mismatch and returns stacktrace.Propagate(err, "encryption mismatch"). At this point err is nil because the native call succeeded, so the propagated error is nil and callers see an empty EncryptionResult while thinking the operation succeeded. If the implementations ever diverge—the condition this check is trying to detect—upstream token generation will silently proceed with a zero-value cipher. Wrap a real error (e.g. stacktrace.NewError(...)) so mismatches surface as failures.
Useful? React with 👍 / 👎.
Code Review for PR #7430Thank you for this PR migrating to the native cryptographic implementation! This is an important step toward removing the libsodium dependency. ✅ Positive Aspects
🐛 Potential Issues1. Backward Compatibility Concerns (CRITICAL)The encryptWithNonce function now returns native encryption results instead of libsodium results. Questions to verify:
Recommendation: Add integration tests that verify old libsodium-encrypted data can be decrypted with native implementation. 2. Nonce Validation (Line 48)The nonce comparison check seems unnecessary since we pass the same nonce to both implementations. Consider removing or adding a comment explaining why it's necessary. 3. Error Messages (Lines 50, 67, 87)Minor issue: Extra space in error message and could be more actionable. ⚡ Performance ConsiderationsThe code still calls BOTH libsodium AND native implementations for every operation (2x computational cost). Recommendation:
🔒 Security ConcernsThis PR changes the cryptographic implementation used in production. The native implementation appears correct, but crypto changes deserve extra caution: Recommendations:
The code now returns errors instead of logging when native crypto fails. Add monitoring/alerting for these new error paths. 📝 Missing InformationPR description is minimal. Please add:
📋 SummarySeverity:
Recommendation: Approve with conditions - needs verification of backward compatibility testing, staging deployment plan, and monitoring for crypto failures. Great work on the native implementation! Code quality is good, but crypto changes deserve extra caution. 🔐 |
Pull Request Review: Switch to native lib for resultsSummaryThis PR completes the migration from libsodium to Go's native crypto libraries ( ✅ Strengths
🔍 Code Quality & Best PracticesGood:
Observations:
|
Description
Tests
go test ./pkg/utils/crypto -v