Skip to content

lib: Handle adding enc folders on an existing conn (fixes #7509) - #7510

Merged
calmh merged 3 commits into
syncthing:mainfrom
imsodin:lib/enc-without-conn-drop
Mar 22, 2021
Merged

calmh merged 3 commits into
syncthing:mainfrom
imsodin:lib/enc-without-conn-drop

Conversation

@imsodin

@imsodin imsodin commented Mar 21, 2021

Copy link
Copy Markdown
Member

Fixes #7509 by adding a method to the connection to set new folder passwords. This means that any connection may become (partly) encrypted. Thus there's no longer two separate factory methods, but every connection is a encryptedConnection.

The passwords on the connection are (re-)set when sending cluster-configs, meaning when a new connection is added, when a new folder is added or when a folder changes.

@calmh calmh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also fixes #7198 I think

Comment thread lib/model/model.go Resolved
Comment thread lib/protocol/encryption.go Resolved
Comment thread lib/protocol/encryption.go Outdated
Comment on lines +604 to +609
func newFolderKeyRegistry() *folderKeyRegistry {
return &folderKeyRegistry{
keys: make(map[string]*[keySize]byte),
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't really need a constructor for this one, nil map is fine until reset() happens

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really want a nil-check in folderKeyRegistry.get though.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would you need one?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd expect key, ok := r.keys[folder] to panic. And without checking I am not 100% that model.AddConnection is guaranteed to initialize the passwords before any message comes in from a remote. Expressing that thought makes it clear that I should keep initializing passwords when creating the connection. Likely it's all irrelevant practically, as the early messages aren't encrypted, but still.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't panic though, a nil map is equivalent to a non-nil but empty map when reading.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, wasn't aware of that. I didn't really internalize that aspect of go (treating nil as a valid state), I treat nil as "do not touch".
Any ways, it does now get initialized at connection construction time with a valid map of passwords.

Comment thread lib/protocol/encryption.go Resolved
Comment thread lib/protocol/protocol.go Resolved
@imsodin

imsodin commented Mar 21, 2021 •

Copy link
Copy Markdown
Member Author

Edit: I also have a fix for #7198. On top of this PR, thus filing afterwards to prevent merge conflicts.

#7198 sounds like the issue I am seeing when reproducing the issue here (having to pause/resume the folder before indexes get exchanged). And I am still seeing it with the PR applied.

@calmh
calmh merged commit 924b968 into syncthing:main Mar 22, 2021
@imsodin
imsodin deleted the lib/enc-without-conn-drop branch March 22, 2021 22:56
@calmh calmh added this to the v1.15.0 milestone Mar 23, 2021
calmh added a commit to calmh/syncthing that referenced this pull request Apr 5, 2021
* main: (36 commits)
  etc: Fix start-limit parameters location in systemd units (ref syncthing#7439) (syncthing#7529)
  gui: Add confirmation dialog for revert/override (fixes syncthing#7520) (syncthing#7522)
  readme: Larger link for Fitt's law, still semantic (syncthing#7523)
  gui, man, authors: Update docs, translations, and contributors
  lib/model: Reset conn when enc token is missing (fixes syncthing#7198) (syncthing#7518)
  lib: Handle adding enc folders on an existing conn (fixes syncthing#7509) (syncthing#7510)
  cmd/strelaysrv: Increase default strelaysrv network buffer size (fixes syncthing#7514) (syncthing#7517)
  lib/ur: Prevent panic when blocksResult is nil (ref syncthing#7495) (syncthing#7515)
  lib/model: Encrypted fileinfo trailer needs to be in wire format (syncthing#7505)
  lib/model: Error check in test (syncthing#7508)
  lib/osutil: Fix raising max FDs on macOS (syncthing#7507)
  lib/connections: Silence "connected to myself" messages. (syncthing#7500)
  lib/osutil: Remove unused code
  all: Simplify some method calls (syncthing#7499)
  cmd/uraggregate: Ignore errors harder (syncthing#7498)
  cmd/syncthing: Error handling on upgrade (syncthing#7497)
  Remove unnecessary guard around `delete` (syncthing#7496)
  all: Remove miscellaneous vestigial code (syncthing#7495)
  all: Remove crypto/md5 (syncthing#7493)
  lib/api: Missing error handling in API delete-device (syncthing#7494)
  ...
@calmh calmh added the frozen-due-to-age Issues closed and untouched for a long time, together with being locked for discussion label Aug 11, 2022
@syncthing syncthing locked and limited conversation to collaborators Aug 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

frozen-due-to-age Issues closed and untouched for a long time, together with being locked for discussion

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sharing the first folder to an untrusted device on an established connection sends plain-text

2 participants