-
Notifications
You must be signed in to change notification settings - Fork 24
Implement encryptor in keystore library #1587
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
base: main
Are you sure you want to change the base?
Conversation
✅ API Diff Results - No breaking changes |
} | ||
return EncryptResponse{EncryptedData: encrypted}, nil | ||
default: | ||
return EncryptResponse{}, ErrEncryptionFailed |
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.
Should these ErrEncryptionFailed
errors be wrapped with more context? Currently there is no difference between too long, unknown type, name not found, etc.
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.
yeah thats intentional - most encrypt/decrypt libs operate that way since sometimes leaking info like "bad padding" can lead to attacks. That being said probably less important if the code is OS, not sure can ask sec what they think
} | ||
sharedSecret, err := curve25519.X25519(internal.Bytes(key.privateKey), req.RemotePubKey) | ||
if err != nil { | ||
return DeriveSharedSecretResponse{}, ErrSharedSecretFailed |
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.
We should include the original error, no? Or at least log it if we don't want to expose something?
* Wip * Basic signer test * Errors new * Fix merge * Remove unnecessary lock
const ( | ||
// Maximum payload size for encrypt/decrypt operations (100kb) | ||
// Note just an initial limit, we may want to increase this in the future. | ||
MaxEncryptionPayloadSize = 100 * 1024 |
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.
Do we allow users to pass in a limit when creating the keystore? Agree this is fine for now, but since we're going to be trusting clients to use this correctly, it would make sense for them to be able to provide the limit. (Maybe we can follow the OCR model of having a MaxMax limit)
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.
We don't yet but yep we can add a user facing limit with an underlying MaxMax
k.mu.RLock() | ||
defer k.mu.RUnlock() | ||
|
||
if len(req.EncryptedData) == 0 || len(req.EncryptedData) > MaxEncryptionPayloadSize*2 { |
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.
Is this potentially brittle? Can we document how we got to this number and under what circumstances it would change
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.
yeah I think it'd be possible in principle that we introduce some new scheme which has enormous overhead/envelope size (more than 2x), but exceedingly unlikely. Perhaps better to have explicit envelope sizes per type (at least the existing ones so far are fixed so we can start with that). Can do in a follow up
Note signer impl already reviewed.