-
Notifications
You must be signed in to change notification settings - Fork 2
feat: 🎸 Add support for decrypting messages from ios using v1 protocol #19
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -329,13 +329,51 @@ func (m *Manager) DecryptMessageV2(msg *line.Message) (string, error) { | |
| if err != nil { | ||
| return "", err | ||
| } | ||
|
|
||
| ver := 2 | ||
| if vStr, ok := msg.ContentMetadata["e2eeVersion"]; ok && vStr == "1" { | ||
| ver = 1 | ||
| } | ||
|
|
||
| if ver == 1 { | ||
| cipher, err := assembleCipherV1(msg.Chunks) | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
| pt, _, err := m.runner.ChannelDecryptV1(chanID, senderKeyID, receiverKeyID, base64.StdEncoding.EncodeToString(cipher)) | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
| return pt, nil | ||
| } | ||
|
|
||
| pt, _, err := m.runner.ChannelDecryptV2(chanID, msg.To, msg.From, senderKeyID, receiverKeyID, msg.ContentType, base64.StdEncoding.EncodeToString(cipher)) | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
| return pt, nil | ||
| } | ||
|
|
||
| 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 | ||
|
Comment on lines
+357
to
+374
|
||
| } | ||
|
|
||
| func (m *Manager) UnwrapGroupSharedKey(chatMid string, sharedKey *line.E2EEGroupSharedKey) (int, error) { | ||
| m.mu.Lock() | ||
| defer m.mu.Unlock() | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -398,6 +398,21 @@ async function run() { | |||||
| process.stdout.write( | ||||||
| JSON.stringify({ ciphertext: u8ToB64(ct) }) + "\n" | ||||||
| ); | ||||||
| } 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 | |
| } else if (type === "channel_decrypt_v1") { // messages sent from iOS LINE app use v1 |
Copilot
AI
Jan 20, 2026
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.
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.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -404,6 +404,28 @@ func (r *Runner) ChannelEncryptV2(channelID int, to, from string, senderKeyID, r | |||||
| return ct, nil | ||||||
| } | ||||||
|
|
||||||
| // decrypts ciphertext with channel v1 (ios) | ||||||
|
||||||
| // decrypts ciphertext with channel v1 (ios) | |
| // ChannelDecryptV1 decrypts ciphertext with channel v1 (iOS). |
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.
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.