Skip to content

Commit 593cd2d

Browse files
authored
Merge pull request #187 from beeper/highest/plat-37557
fix: more specific error message
2 parents 710e9e4 + f603f2f commit 593cd2d

2 files changed

Lines changed: 28 additions & 10 deletions

File tree

pkg/connector/connector.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,10 @@ func (ll *LineEmailLogin) SubmitUserInput(ctx context.Context, input map[string]
204204
}
205205

206206
func (ll *LineEmailLogin) loginErrorStep(message string) *bridgev2.LoginStep {
207-
instructions := fmt.Sprintf("Error when logging in: %s", message)
208207
return &bridgev2.LoginStep{
209208
Type: bridgev2.LoginStepTypeUserInput,
210209
StepID: "dev.highest.matrix.line.enter_creds",
211-
Instructions: instructions,
210+
Instructions: loginErrorInstructions(message),
212211
UserInputParams: &bridgev2.LoginUserInputParams{
213212
Fields: []bridgev2.LoginInputDataField{
214213
{
@@ -226,6 +225,17 @@ func (ll *LineEmailLogin) loginErrorStep(message string) *bridgev2.LoginStep {
226225
}
227226
}
228227

228+
func loginErrorInstructions(message string) string {
229+
message = strings.TrimSpace(message)
230+
if message == "" {
231+
return "Could not log in to LINE. Please check your email and password and try again."
232+
}
233+
if strings.EqualFold(message, "Account ID or password is invalid") {
234+
return "LINE rejected the email or password. Make sure you used the email from LINE Settings -> Account -> Email Address, then try again."
235+
}
236+
return fmt.Sprintf("Could not log in to LINE: %s", message)
237+
}
238+
229239
func loginErrorReason(err error) string {
230240
if err == nil {
231241
return ""

pkg/line/password/password.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package password
22

33
import (
4+
"bytes"
45
"crypto/rand"
56
"crypto/rsa"
67
"encoding/hex"
@@ -11,7 +12,10 @@ import (
1112
// EncryptPassword constructs the payload and encrypts it using RSA-PKCS1v15.
1213
func EncryptPassword(email, password, sessionKey, nHex, eHex string) (string, error) {
1314
// 1. Construct the payload: [len + val]...
14-
payload := createPayload(email, password, sessionKey)
15+
payload, err := createPayload(email, password, sessionKey)
16+
if err != nil {
17+
return "", fmt.Errorf("failed to create password payload: %w", err)
18+
}
1519

1620
// 2. Parse Public Key from Hex
1721
pubKey, err := parseRSAPublicKey(nHex, eHex)
@@ -20,7 +24,7 @@ func EncryptPassword(email, password, sessionKey, nHex, eHex string) (string, er
2024
}
2125

2226
// 3. Encrypt using RSA-PKCS1-v1.5
23-
encryptedBytes, err := rsa.EncryptPKCS1v15(rand.Reader, pubKey, []byte(payload))
27+
encryptedBytes, err := rsa.EncryptPKCS1v15(rand.Reader, pubKey, payload)
2428
if err != nil {
2529
return "", fmt.Errorf("failed to encrypt payload: %w", err)
2630
}
@@ -30,12 +34,16 @@ func EncryptPassword(email, password, sessionKey, nHex, eHex string) (string, er
3034
}
3135

3236
// Format: [len(sessionKey) + sessionKey + len(email) + email + len(password) + password]
33-
func createPayload(email, password, sessionKey string) string {
34-
return fmt.Sprintf("%c%s%c%s%c%s",
35-
len(sessionKey), sessionKey,
36-
len(email), email,
37-
len(password), password,
38-
)
37+
func createPayload(email, password, sessionKey string) ([]byte, error) {
38+
var payload bytes.Buffer
39+
for _, field := range []string{sessionKey, email, password} {
40+
if len(field) > 255 {
41+
return nil, fmt.Errorf("field is too long: %d bytes", len(field))
42+
}
43+
payload.WriteByte(byte(len(field)))
44+
payload.WriteString(field)
45+
}
46+
return payload.Bytes(), nil
3947
}
4048

4149
// parseRSAPublicKey converts hex modulus and exponent into *rsa.PublicKey.

0 commit comments

Comments
 (0)