Skip to content
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

Shadowsocks2022 Client Support #2767

Merged
merged 4 commits into from Nov 19, 2023
Merged

Conversation

xiaokangwang
Copy link
Contributor

This merge request adds shadowsocks2022 client support to V2Ray. It is current implementation lacks check against UDP duplicate packets.

@xiaokangwang
Copy link
Contributor Author

Example config:

{
  "log": {
    "error": {
      "level": "Debug",
      "type": "Console"
    },
    "access": {
      "type": "None"
    }
  },
  "outbounds": [
    {
      "protocol": "shadowsocks2022",
      "settings": {
        "address": "127.0.0.1",
        "port": 20220,
        "method": "2022-blake3-aes-128-gcm",
        "psk": "oE/s2z9Q8EWORAB8B3UCxw==",
        "ipsk": [
          "qQln3GlVCZi5iJUObJVNCw=="
        ]
      }
    }
  ],
  "inbounds": [
    {
      "protocol": "socks",
      "settings": {
        "udpEnabled": true,
        "address": "127.0.0.1",
        "packetEncoding": "Packet"
      },
      "port": 11099
    }
  ]
}

@codecov-commenter
Copy link

codecov-commenter commented Nov 18, 2023

Codecov Report

Attention: 770 lines in your changes are missing coverage. Please review.

Comparison is base (bacdf98) 37.65% compared to head (7511c91) 36.97%.
Report is 4 commits behind head on master.

Files Patch % Lines
proxy/shadowsocks2022/client.go 0.66% 148 Missing and 1 partial ⚠️
proxy/shadowsocks2022/encoding.go 0.00% 146 Missing ⚠️
proxy/shadowsocks2022/client_session.go 0.00% 97 Missing ⚠️
proxy/shadowsocks2022/udp_aes.go 0.00% 79 Missing ⚠️
proxy/shadowsocks2022/eih_aes.go 0.00% 62 Missing ⚠️
proxy/shadowsocks2022/config.pb.go 25.97% 55 Missing and 2 partials ⚠️
proxy/shadowsocks2022/method_aes128gcm.go 0.00% 45 Missing ⚠️
proxy/shadowsocks2022/method_aes256gcm.go 0.00% 45 Missing ⚠️
proxy/shadowsocks2022/requestsalt.go 0.00% 28 Missing ⚠️
transport/internet/udp/monodest.go 0.00% 25 Missing ⚠️
... and 4 more

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2767      +/-   ##
==========================================
- Coverage   37.65%   36.97%   -0.69%     
==========================================
  Files         659      671      +12     
  Lines       38894    39685     +791     
==========================================
+ Hits        14647    14675      +28     
- Misses      22631    23390     +759     
- Partials     1616     1620       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@xiaokangwang xiaokangwang merged commit 39851b3 into v2fly:master Nov 19, 2023
39 of 40 checks passed
Copy link
Contributor

@database64128 database64128 left a comment

Choose a reason for hiding this comment

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

Thanks for taking the time to read the spec and test against our implementations. While the implementation in this PR is correct overall, I have found a few problems.

Based on the severity of these problems, my recommendation is to pull the release, or at least update the release notes to say that the current implementation MUST NOT be used. I know the release is a user preview, but the lack of basic security guarantees should not make into any kind of release.

paddingLength := TCPMinPaddingLength
if initialPayload == nil {
initialPayload = []byte{}
paddingLength += rand.Intn(TCPMaxPaddingLength) // TODO INSECURE RANDOM USED
Copy link
Contributor

Choose a reason for hiding this comment

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

In section 3.1.3 of the spec:

When making a request header, if payload is not available, add non-zero random length padding.

It's fine to use simple RNGs. But sending a request with no initial payload and no padding will get yourself rejected by spec-compliant servers.

Suggested change
paddingLength += rand.Intn(TCPMaxPaddingLength) // TODO INSECURE RANDOM USED
paddingLength += 1 + rand.Intn(TCPMaxPaddingLength)

}
timeDifference := int64(fixedLengthHeader.Timestamp) - time.Now().Unix()
if timeDifference < -30 || timeDifference > 30 {
return newError("timestamp is too far away")
Copy link
Contributor

Choose a reason for hiding this comment

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

It can be useful to include the exact time difference in the error.

{
timeDifference := int64(udpResp.TimeStamp) - time.Now().Unix()
if timeDifference < -30 || timeDifference > 30 {
newError("udp packet timestamp difference too large, packet discarded").WriteToLog()
Copy link
Contributor

Choose a reason for hiding this comment

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

It can be useful to include the exact time difference in the error.

resp.PacketID = separateHeaderStruct.PacketID
resp.SessionID = separateHeaderStruct.SessionID
{
mainPacketAEADMaterialized := p.mainPacketAEAD(separateHeaderBuffer.Bytes()[0:8])
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks to me that you derive keys and create a new cipher instance on every new packet. This is extremely inefficient.

Maintaining server-to-client session state is mandatory on the client side, because it is crucial that each server-to-client session has its own sliding window filter for protecting against replay attacks. Please fix this and cache the AEAD cipher in the state.

@xiaokangwang
Copy link
Contributor Author

Thanks for your review. The sliding window filter will be considered a stable release block and will be fixed before any release is marked as stable. Other suggestions will be applied in a less urgent manner.

Do you consider this client implementation spec confirming, after all suggestions are implemented?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants