feat: 🎸 Add support for decrypting messages from ios using v1 protocol#19
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds support for decrypting messages sent from the iOS LINE app using the v1 encryption protocol. The implementation detects the protocol version from message metadata and routes to the appropriate decryption method.
Changes:
- Added
ChannelDecryptV1function in the Go runner to handle v1 decryption - Implemented
channel_decrypt_v1handler in the JavaScript runner - Modified
DecryptMessageV2to detect v1 protocol version and route accordingly - Added
assembleCipherV1helper function to reconstruct ciphertext from message chunks
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| pkg/runner.go | Adds new ChannelDecryptV1 function to call the JavaScript v1 decryption handler |
| pkg/internal/runner.js | Implements channel_decrypt_v1 handler to perform actual v1 decryption using the channel's decryptV1 method |
| pkg/e2ee/manager.go | Adds version detection logic and assembleCipherV1 function; routes v1 messages to new decryption path |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const { | ||
| channelId, | ||
| ciphertext, | ||
| } = query; |
There was a problem hiding this comment.
The senderKeyId and receiverKeyId parameters are extracted from the query but never used. If these parameters are not needed for v1 decryption, they should be removed from the query destructuring. If they are needed, they should be passed to the decryptV1 method or validated.
| } | ||
|
|
||
| if ver == 1 { | ||
| cipher, err := assembleCipherV1(msg.Chunks) |
There was a problem hiding this comment.
The variable 'cipher' is assigned on line 324 from assembleCipher(msg.Chunks) but then shadowed on line 339 within the v1 block by declaring a new cipher variable with assembleCipherV1(msg.Chunks). This creates unnecessary confusion and wastes the initial computation. The first cipher assignment should be moved inside the 'else' or 'if ver == 2' block to avoid this shadowing and unnecessary computation when ver is 1.
| return ct, nil | ||
| } | ||
|
|
||
| // decrypts ciphertext with channel v1 (ios) |
There was a problem hiding this comment.
The comment should follow Go documentation conventions. It should start with the function name and use proper capitalization: "ChannelDecryptV1 decrypts ciphertext with channel v1 (iOS)." Note that "iOS" should be capitalized as it's a proper noun.
| // decrypts ciphertext with channel v1 (ios) | |
| // ChannelDecryptV1 decrypts ciphertext with channel v1 (iOS). |
| process.stdout.write( | ||
| JSON.stringify({ ciphertext: u8ToB64(ct) }) + "\n" | ||
| ); | ||
| } else if (type === "channel_decrypt_v1") { // messages sent from ios LINE app use v1 |
There was a problem hiding this comment.
The inline comment should capitalize "iOS" as it's a proper noun. It should read: "messages sent from iOS LINE app use v1"
| } else if (type === "channel_decrypt_v1") { // messages sent from ios LINE app use v1 | |
| } else if (type === "channel_decrypt_v1") { // messages sent from iOS LINE app use v1 |
| func assembleCipherV1(chunks []string) ([]byte, error) { | ||
| if len(chunks) < 3 { | ||
| return nil, fmt.Errorf("not enough chunks") | ||
| } | ||
| decode := func(s string) ([]byte, error) { return base64.StdEncoding.DecodeString(strings.TrimSpace(s)) } | ||
| b0, err := decode(chunks[0]) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| b1, err := decode(chunks[1]) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| b2, err := decode(chunks[2]) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return append(append(b0, b1...), b2...), nil |
There was a problem hiding this comment.
The assembleCipherV1 function concatenates chunks in the order [first, middle, tag] which differs from assembleCipher (v2) that reorders them to [first, tag, middle] as noted in its comment. Please verify that this difference in chunk ordering is intentional for the v1 protocol. If this is intentional, consider adding a comment explaining the chunk order for v1, similar to the comment in assembleCipher.
No description provided.