Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions pkg/connector/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -906,12 +906,6 @@ func (lc *LineClient) tryLogin(ctx context.Context) error {
if mgr != nil {
lc.missingE2EEKeyMarked = false
}
if mgr != nil {
if err := mgr.SaveSecureDataToFile(loginSecureDataID(&staged, string(lc.UserLogin.ID)), map[string]any{"exportedKeyMap": exported}); err != nil {
lc.UserLogin.Bridge.Log.Warn().Err(err).Msg("Failed to save E2EE secure data after re-login")
}
}

lc.UserLogin.Bridge.Log.Info().Msg("Login successful!")
return nil
}
Expand Down Expand Up @@ -965,9 +959,6 @@ func (lc *LineClient) refreshLoginE2EEKeys(res *line.LoginResult, meta *UserLogi
return errLineClientSuperseded
}
lc.applyRefreshedLoginE2EEKeys(meta, res, exported)
if err := mgr.SaveSecureDataToFile(loginSecureDataID(meta, string(lc.UserLogin.ID)), map[string]any{"exportedKeyMap": exported}); err != nil {
return fmt.Errorf("save E2EE secure data after re-login: %w", err)
}
lc.UserLogin.Bridge.Log.Info().Int("keys", len(exported)).Msg("Refreshed E2EE keys after re-login")
return nil
}
Expand Down
13 changes: 0 additions & 13 deletions pkg/connector/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -828,12 +828,6 @@ func (ll *LineEmailLogin) finishLogin(ctx context.Context, res *line.LoginResult
retireLineLogin(ll.ExistingLogin)
}

if loginManager != nil {
if err := loginManager.SaveSecureDataToFile(loginSecureDataID(meta, string(ll.User.MXID)), map[string]any{"exportedKeyMap": meta.ExportedKeyMap}); err != nil {
ll.User.Bridge.Log.Warn().Err(err).Msg("Login: failed to save E2EE secure data")
}
}

go newClient.Connect(context.Background())

return &bridgev2.LoginStep{
Expand Down Expand Up @@ -946,13 +940,6 @@ func shouldPreserveExistingE2EEKeys(exportedKeys bool, existing *UserLoginMetada
return !exportedKeys && existing != nil && len(existing.ExportedKeyMap) > 0 && !existing.ForceFullE2EELogin
}

func loginSecureDataID(meta *UserLoginMetadata, fallback string) string {
if meta.Mid != "" {
return meta.Mid
}
return fallback
}

func (ll *LineEmailLogin) fetchLoginKeys(res *line.LoginResult, meta *UserLoginMetadata, client *line.Client) (*e2ee.Manager, error) {
if res.EncryptedKeyChain == "" || res.E2EEPublicKey == "" {
return nil, nil
Expand Down
12 changes: 0 additions & 12 deletions pkg/connector/login_keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,6 @@ func TestCopyLoginE2EEKeyMetadataClonesExportedKeyMap(t *testing.T) {
}
}

func TestLoginSecureDataIDPrefersLineMID(t *testing.T) {
meta := &UserLoginMetadata{Mid: "u-line-mid"}
if got := loginSecureDataID(meta, "@user:example.com"); got != "u-line-mid" {
t.Fatalf("loginSecureDataID = %q, want LINE MID", got)
}

meta.Mid = ""
if got := loginSecureDataID(meta, "@user:example.com"); got != "@user:example.com" {
t.Fatalf("loginSecureDataID fallback = %q, want Matrix fallback", got)
}
}

func TestStartWithOverrideForcesFullReconnectWithoutStoredE2EEKeys(t *testing.T) {
oldLogin := loginWithCredentials
var gotCertificate string
Expand Down
19 changes: 2 additions & 17 deletions pkg/e2ee/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,14 +258,8 @@ func (m *Manager) DecryptSecureBlob(b64Cipher string) (map[string]any, error) {
return out, nil
}

func (m *Manager) EncryptSecureBlob(data map[string]any) (string, error) {
buf, err := json.Marshal(data)
if err != nil {
return "", err
}
return m.runner.StorageEncrypt(string(buf))
}

// LoadSecureDataFromFile reads key files written by older bridge versions.
// New keys are only stored in the user login metadata.
func (m *Manager) LoadSecureDataFromFile(id string) (map[string]any, error) {
path := filepath.Join("data", fmt.Sprintf("lcs_secure_%s.json", id))
b, err := os.ReadFile(path)
Expand All @@ -275,15 +269,6 @@ func (m *Manager) LoadSecureDataFromFile(id string) (map[string]any, error) {
return m.DecryptSecureBlob(strings.TrimSpace(string(b)))
}

func (m *Manager) SaveSecureDataToFile(id string, data map[string]any) error {
ct, err := m.EncryptSecureBlob(data)
if err != nil {
return err
}
path := filepath.Join("data", fmt.Sprintf("lcs_secure_%s.json", id))
return os.WriteFile(path, []byte(ct), 0o600)
}

func (m *Manager) InitFromLoginKeyChain(serverPubB64, encryptedKeyChainB64 string) (map[string]string, error) {
keys, err := m.runner.LoginUnwrapKeyChain(serverPubB64, encryptedKeyChainB64)
if err != nil {
Expand Down
Loading