-
Notifications
You must be signed in to change notification settings - Fork 4
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
Encrypt and decrypt chat lsp communication #55
Conversation
101d41f
to
416b2cb
Compare
plugin/src/software/aws/toolkits/eclipse/amazonq/chat/ChatCommunicationManager.java
Outdated
Show resolved
Hide resolved
plugin/src/software/aws/toolkits/eclipse/amazonq/chat/ChatCommunicationManager.java
Outdated
Show resolved
Hide resolved
plugin/src/software/aws/toolkits/eclipse/amazonq/chat/ChatMessage.java
Outdated
Show resolved
Hide resolved
plugin/src/software/aws/toolkits/eclipse/amazonq/lsp/encryption/LspJsonWebToken.java
Show resolved
Hide resolved
plugin/src/software/aws/toolkits/eclipse/amazonq/lsp/encryption/LspEncryptionManager.java
Show resolved
Hide resolved
plugin/src/software/aws/toolkits/eclipse/amazonq/chat/models/EncryptedChatRequestParams.java
Outdated
Show resolved
Hide resolved
6d171d0
to
d3916ba
Compare
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
public record EncryptedChatParams( |
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.
It seems like both the encrypted classes have the same properties. Any reason we can't have a single class and use it for both use-cases?
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.
In order to best match the models provided in the Language Server Runtime types repo, I think it'd be best to continue with two separate classes
plugin/src/software/aws/toolkits/eclipse/amazonq/lsp/encryption/LspEncryptionKey.java
Show resolved
Hide resolved
plugin/src/software/aws/toolkits/eclipse/amazonq/lsp/encryption/LspEncryptionManager.java
Show resolved
Hide resolved
// The mapping entry no longer needs to be maintained once the final result is | ||
// retrieved. | ||
removePartialChatMessage(partialResultToken); | ||
|
||
String serializedData = lspEncryptionManager.decrypt(jwt); |
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.
I can't recall but do these calls get exception handled upstream from any calling code? Saw the throw calls within these decrypt/encrypt calls but don't rememeber if they should be caught or not to prevent any unexpected state to occur.
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.
These exceptions should be caught at the top-level in the Q Chat Part (See
amazon-q-eclipse/plugin/src/software/aws/toolkits/eclipse/amazonq/views/AmazonQChatWebview.java
Lines 73 to 75 in 49c450f
} catch (Exception e) { | |
PluginLogger.error("Error processing message from Browser", e); | |
} |
plugin/src/software/aws/toolkits/eclipse/amazonq/chat/ChatCommunicationManager.java
Outdated
Show resolved
Hide resolved
quickActionParams.setPartialResultToken(token); | ||
|
||
return chatMessageProvider.sendQuickAction(quickActionParams); | ||
}); | ||
String jwt = lspEncryptionManager.encrypt(quickActionParams); |
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.
Now that we are using encrypted params should L79 instead be changed to EncryptedQuickActionParams
for setting partial result token. Don't see the value in using that anymore
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.
Good question, the partialResultToken is an attribute in both the QuickActionParams
as well as EncryptedQuickActionParams
.
In QuickActionParams
, we have:
private final String tabId;
private final String quickAction;
private final String prompt;
private String partialResultToken;
In EncryptedQuickActionParams
, we have
@JsonProperty("message") String message, // Message as encrypted jwt
@JsonProperty("partialResultToken") String partialResultToken) {
Therefore the partialResultToken
is located in both the encrypted message attibute as well as a direct attribute under the EncryptedQuickActionParams
attribute.
After diving deeper into the EncryptedChat Communication, I see that the inner-most partialResultToken is being over written by the outer-most token (see https://github.com/aws/language-server-runtimes/blob/4bd707cb4220253620b5550e6dd48cd08a5350b3/runtimes/runtimes/chat/encryptedChat.ts#L76-L77)
To test my theory, I removed the line to set the partialResultToken
in the QuickActionPrams
and kept the partialResultToken
on the EncryptedQuickActionParams
- the partial results is continuing to work successfully. I am going to make the same change to ChatParams
and EncryptedChatParams
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.
Great digging! Please inform Flare team about this overriding behavior since it introduces risk. We wouldn't want to get in a scenario where there is change in this data contract on their end and we get impacted by it. i.e a scenario in future where they start honoring the decrypted partial token present in the innermost chat request param object
plugin/src/software/aws/toolkits/eclipse/amazonq/chat/ChatCommunicationManager.java
Outdated
Show resolved
Hide resolved
plugin/src/software/aws/toolkits/eclipse/amazonq/chat/ChatCommunicationManager.java
Outdated
Show resolved
Hide resolved
plugin/src/software/aws/toolkits/eclipse/amazonq/chat/ChatCommunicationManager.java
Outdated
Show resolved
Hide resolved
This reverts commit 9b6ea01.
d3916ba
to
011a650
Compare
Description
--set-credentials-encryption-key
flag in the start command)ChatRequestParams
into a jwtChatResult
ChatResult