-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Implement reuse detection for cipher #165
Implement reuse detection for cipher #165
Conversation
573d00d
to
a8ad0a9
Compare
@riobard re-implement saltfilter and support change filter entries and FPS via |
pardon me, I should post the general purpose of this PR.
|
Please make |
@riobard How about create a |
I guess that's the way to do it. |
19b36d3
to
51544cd
Compare
internal/saltfilter.go
Outdated
|
||
func init() { | ||
var ( | ||
finalCapacity = DefaultBRCapacity |
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.
Is there anyway to change the value from the command line flags?
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.
Absolutely, but I thought about this: low-level flags maybe more suitable to expose to people who known this what to do and how to modify(to make it works as expect), and keep user-end flags as Shadowsocks well known provides.
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.
Makes sense. Maybe we could change it via environment variables?
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.
A good idea as well, with SHADOWSOCKS_
prefix or not?
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.
SHADOWSOCKS_SF_CAPACITY
SHADOWSOCKS_SF_FPR
SHADOWSOCKS_SF_SLOT
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.
Looks good to me. I'm debating if we should default the filter on or off. Maybe off by default?
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.
In my view, it's better to be enabled by default as it can 'protects' connection by withstand reuse detection.
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.
Makes sense.
51544cd
to
3e6e339
Compare
and also suppose public errors like |
What do you mean? It's already exported. |
errors declared both in aead and steam package, it’s not necessary and hard to handle outside as well |
We will remove shadowstream package soon (I've already removed it from my fork), so there's no need to worry about that. |
@riobard OK, then just keep those declaration |
3e6e339
to
5d517aa
Compare
We should add the necessary documentation. |
@riobard yep, I'll create a new PR about this soon. |
if finalCapacity <= 0 { | ||
return | ||
} | ||
saltfilter = NewBloomRing(int(finalSlot), int(finalCapacity), finalFPR) |
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.
Because this large allocation is done on init()
, anyone depending on go-shadowsocks2 will have this allocation done, even client code on memory constrained devices. This caused an issue on the Outline iOS client, where the VpnExtension has a very tight memory limit.
Instead, this could be done on main and injected into the code that needs it, or initialized on demand.
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.
Good point, client needs fewer capacity so maybe provide a manual initialization by giving two kind of capacity, slot and FPR which are identitified by running mode (client/server) to reduce large allocations is a good chooice.
What do you think? @riobard
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.
And on the other hand, saltfilter
provide enough ENV to let caller or executor to controll related args while initializing, it's another way to controll allocation directly.
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.
I sent #189 to fix it.
The ENV is not appropriate. Who sets it? Setting it on main leaks implementation details. Setting in a library is messy, since libraries can compete. For example, if client code disables it, we'll have a problem with an integration test that runs both the client and the server code.
The ideal solution would be to inject dependencies instead of using globals, but the code is not designed for injection (doesn't use classes). I implemented a compromise where I get a singleton object when needed. That can be injected later if wiring is made easier.
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.
…-filter Implement reuse detection for cipher
Use bloom filter to withstand reuse 'attack'.
Same implementation as https://github.com/shadowsocks/shadowsocks-libev/blob/v3.3.4/src/ppbloom.c