Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit cc7f02d

Browse files
committedNov 22, 2024·
Support non-zero lowest frame offset
The lowest offset of CRYPTO frames in a QUIC packet does not necessarily start at zero, such as the second packet of a connection using Kyber key in the client hello. Also updates clienthellod to new repo.
1 parent cb2c7f1 commit cc7f02d

6 files changed

+71
-51
lines changed
 

‎README.md

+27-18
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
[![Go Build Status](https://github.com/refraction-networking/uquic/actions/workflows/go_build.yml/badge.svg?branch=master)](https://github.com/refraction-networking/uquic/actions/workflows/go_build.yml)
44
[![Ginkgo Test Status](https://github.com/refraction-networking/uquic/actions/workflows/ginkgo_test.yml/badge.svg?branch=master)](https://github.com/refraction-networking/uquic/actions/workflows/ginkgo_test.yml)
55
[![godoc](https://img.shields.io/badge/godoc-reference-blue.svg)](https://godoc.org/github.com/refraction-networking/uquic)
6+
67
---
7-
uQUIC is a fork of [quic-go](https://github.com/quic-go/quic-go), which provides Initial Packet fingerprinting resistance and other features. While the handshake is still performed by quic-go, this library provides interface to customize the unencrypted Initial Packet which may reveal fingerprint-able information.
8+
9+
uQUIC is a fork of [quic-go](https://github.com/quic-go/quic-go), which provides Initial Packet fingerprinting resistance and other features. While the handshake is still performed by quic-go, this library provides interface to customize the unencrypted Initial Packet which may reveal fingerprint-able information.
810

911
Golang 1.20+ is required.
1012

@@ -13,43 +15,50 @@ If you have any questions, bug reports or contributions, you are welcome to publ
1315
Development is still in progress and we welcome any contributions adding new features or fixing extant bugs.
1416

1517
# Disclaimer
16-
This repository belongs to a large research project on how to fingerprint QUIC clients and how to mitigate such fingerprinting. We do not encourage any malicious use of this project's output, including this repository, [uTLS](https://github.com/refraction-networking/utls), and [clienthellod](https://github.com/gaukas/clienthellod).
1718

18-
Our research paper is still yet to be published and therefore this repository is neither ready for production use nor peer-reviewed. And the scope of our research is limited that such mimicry backed by this library MAY NOT be realisticly indistinguishable from the real QUIC clients being mimicked, and some misuses of this library MAY lead to easier fingerprinting against the mimic. We welcome any contributions to improve the realism of the mimicry, as well as expanding the scope of this project.
19+
This repository belongs to a large research project on how to fingerprint QUIC clients and how to mitigate such fingerprinting. We do not encourage any malicious use of this project's output, including this repository, [uTLS](https://github.com/refraction-networking/utls), and [clienthellod](https://github.com/refraction-networking/clienthellod).
20+
21+
Our research paper is still yet to be published and therefore this repository is neither ready for production use nor peer-reviewed. And the scope of our research is limited that such mimicry backed by this library MAY NOT be realisticly indistinguishable from the real QUIC clients being mimicked, and some misuses of this library MAY lead to easier fingerprinting against the mimic. We welcome any contributions to improve the realism of the mimicry, as well as expanding the scope of this project.
1922

20-
For anyone intending to use this library for censorship circumvention, please be sure to understand the risks and limitations of this library.
23+
For anyone intending to use this library for censorship circumvention, please be sure to understand the risks and limitations of this library.
2124

2225
If you are interested in our research, please stay tuned for our paper.
2326

2427
# Development in Progress
28+
2529
## Development Roadmap
26-
- [ ] Customize Initial Packet
27-
- [x] QUIC Header
28-
- [x] QUIC Frame (~~[#3](https://github.com/refraction-networking/uquic/issues/3)~~)
29-
- [x] QUIC Crypto Frame
30-
- [x] QUIC Padding Frame
31-
- [x] QUIC Ping Frame
32-
- [ ] QUIC ACK Frame (on hold)
33-
- [x] TLS ClientHello Message (by [uTLS](https://github.com/refraction-networking/utls))
34-
- [x] QUIC Transport Parameters (in a uTLS extension)
30+
31+
- [ ] Customize Initial Packet
32+
- [x] QUIC Header
33+
- [x] QUIC Frame (~~[#3](https://github.com/refraction-networking/uquic/issues/3)~~)
34+
- [x] QUIC Crypto Frame
35+
- [x] QUIC Padding Frame
36+
- [x] QUIC Ping Frame
37+
- [ ] QUIC ACK Frame (on hold)
38+
- [x] TLS ClientHello Message (by [uTLS](https://github.com/refraction-networking/utls))
39+
- [x] QUIC Transport Parameters (in a uTLS extension)
3540
- [ ] Customize Initial ACK behavior ([#1](https://github.com/refraction-networking/uquic/issues/1), [quic-go#4007](https://github.com/quic-go/quic-go/issues/4007))
3641
- [ ] Customize Initial Retry behavior ([#2](https://github.com/refraction-networking/uquic/issues/2))
3742
- [ ] Add preset QUIC parrots
38-
- [x] Google Chrome parrot (call for parrots w/ `Token/PSK`)
39-
- [x] Mozilla Firefox parrot (call for parrots w/ `Token/PSK`)
40-
- [ ] Apple Safari parrot
41-
- [ ] Microsoft Edge parrot
43+
- [x] Google Chrome parrot (call for parrots w/ `Token/PSK`)
44+
- [x] Mozilla Firefox parrot (call for parrots w/ `Token/PSK`)
45+
- [ ] Apple Safari parrot
46+
- [ ] Microsoft Edge parrot
4247

4348
# Features
49+
4450
## Initial Packet fingerprinting resistance
51+
4552
uQUIC provides a mechanism to customize the Initial Packet, which is unencrypted and is almost unique to every QUIC client implementation. We provide an interface to customize the Initial Packet and makes the fingerprinting of QUIC clients harder.
4653

4754
### Build a QUIC Spec
48-
A QUIC Spec sets parameters and policies for uQUIC in establishing a QUIC connection.
55+
56+
A QUIC Spec sets parameters and policies for uQUIC in establishing a QUIC connection.
4957

5058
See `u_parrot.go` for examples of building a QUIC Spec (parrot).
5159

5260
### Use a preset QUIC Spec
61+
5362
We provide a few preset QUIC Specs (parrots) for popular QUIC clients in `u_parrot.go`.
5463

5564
To use one, simple invoke `QUICID2Spec(id)`. See below for a complete example of using a preset QUIC Spec in an HTTP3 client.

‎go.mod

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,35 @@
11
module github.com/refraction-networking/uquic
22

3-
go 1.21
3+
go 1.21.0
44

55
require (
66
github.com/francoispqt/gojay v1.2.13
7-
github.com/gaukas/clienthellod v0.4.2
87
github.com/onsi/ginkgo/v2 v2.17.2
98
github.com/onsi/gomega v1.33.1
109
github.com/quic-go/qpack v0.4.0
10+
github.com/refraction-networking/clienthellod v0.5.0-alpha2
1111
github.com/refraction-networking/utls v1.6.6
1212
go.uber.org/mock v0.4.0
13-
golang.org/x/crypto v0.22.0
14-
golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f
15-
golang.org/x/net v0.24.0
13+
golang.org/x/crypto v0.23.0
14+
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842
15+
golang.org/x/net v0.25.0
1616
golang.org/x/sync v0.7.0
17-
golang.org/x/sys v0.19.0
17+
golang.org/x/sys v0.20.0
1818
golang.org/x/time v0.5.0
1919
)
2020

2121
require (
2222
github.com/andybalholm/brotli v1.1.0 // indirect
2323
github.com/cloudflare/circl v1.3.8 // indirect
24-
github.com/gaukas/godicttls v0.0.4 // indirect
2524
github.com/go-logr/logr v1.4.1 // indirect
2625
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
2726
github.com/google/go-cmp v0.6.0 // indirect
2827
github.com/google/gopacket v1.1.19 // indirect
2928
github.com/google/pprof v0.0.0-20240430035430-e4905b036c4e // indirect
3029
github.com/klauspost/compress v1.17.8 // indirect
3130
golang.org/x/mod v0.17.0 // indirect
32-
golang.org/x/text v0.14.0 // indirect
33-
golang.org/x/tools v0.20.0 // indirect
31+
golang.org/x/text v0.15.0 // indirect
32+
golang.org/x/tools v0.21.0 // indirect
3433
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
3534
gopkg.in/yaml.v3 v3.0.1 // indirect
3635
)

‎go.sum

+16-18
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI
2525
github.com/francoispqt/gojay v1.2.13 h1:d2m3sFjloqoIUQU3TsHBgj6qg/BVGlTBeHDUmyJnXKk=
2626
github.com/francoispqt/gojay v1.2.13/go.mod h1:ehT5mTG4ua4581f1++1WLG0vPdaA9HaiDsoyrBGkyDY=
2727
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
28-
github.com/gaukas/clienthellod v0.4.2 h1:LPJ+LSeqt99pqeCV4C0cllk+pyWmERisP7w6qWr7eqE=
29-
github.com/gaukas/clienthellod v0.4.2/go.mod h1:M57+dsu0ZScvmdnNxaxsDPM46WhSEdPYAOdNgfL7IKA=
30-
github.com/gaukas/godicttls v0.0.4 h1:NlRaXb3J6hAnTmWdsEKb9bcSBD6BvcIjdGdeb0zfXbk=
31-
github.com/gaukas/godicttls v0.0.4/go.mod h1:l6EenT4TLWgTdwslVb4sEMOCf7Bv0JAK67deKr9/NCI=
3228
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
3329
github.com/gliderlabs/ssh v0.1.1/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0=
3430
github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q=
@@ -95,6 +91,8 @@ github.com/prometheus/common v0.0.0-20180801064454-c7de2306084e/go.mod h1:daVV7q
9591
github.com/prometheus/procfs v0.0.0-20180725123919-05ee40e3a273/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
9692
github.com/quic-go/qpack v0.4.0 h1:Cr9BXA1sQS2SmDUWjSofMPNKmvF6IiIfDRmgU0w1ZCo=
9793
github.com/quic-go/qpack v0.4.0/go.mod h1:UZVnYIfi5GRk+zI9UMaCPsmZ2xKJP7XBUvVyT1Knj9A=
94+
github.com/refraction-networking/clienthellod v0.5.0-alpha2 h1:h4y/a97p9EsxAdhXYCBcf8kGfroJ6sjTQ4F/yJyna4A=
95+
github.com/refraction-networking/clienthellod v0.5.0-alpha2/go.mod h1:4vN+Qh4x2TznUMsfw6N3ohGjwvfs6lnwwNPUn7zI9bQ=
9896
github.com/refraction-networking/utls v1.6.6 h1:igFsYBUJPYM8Rno9xUuDoM5GQrVEqY4llzEXOkL43Ig=
9997
github.com/refraction-networking/utls v1.6.6/go.mod h1:BC3O4vQzye5hqpmDTWUqi4P5DDhzJfkV1tdqtawQIH0=
10098
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
@@ -138,11 +136,11 @@ golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16/go.mod h1:6SG95UA2DQfeDnf
138136
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
139137
golang.org/x/crypto v0.0.0-20190313024323-a1f597ede03a/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
140138
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
141-
golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30=
142-
golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M=
139+
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
140+
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
143141
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
144-
golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f h1:99ci1mjWVBWwJiEKYY6jWa4d2nTQVIEhZIptnrVb1XY=
145-
golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f/go.mod h1:/lliqkxwWAhPjf5oSOIJup2XcqJaw8RGS6k3TGEc7GI=
142+
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 h1:vr/HnozRka3pE4EsMEg1lgkXJkTFJCVUX+S/ZT6wYzM=
143+
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842/go.mod h1:XtvwrStGgqGPLc4cjQfWqZHG1YFdYs6swckp8vpsjnc=
146144
golang.org/x/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
147145
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
148146
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
@@ -160,8 +158,8 @@ golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73r
160158
golang.org/x/net v0.0.0-20190313220215-9f648a60d977/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
161159
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
162160
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
163-
golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w=
164-
golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8=
161+
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
162+
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
165163
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
166164
golang.org/x/oauth2 v0.0.0-20181017192945-9dcd33a902f4/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
167165
golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
@@ -180,12 +178,12 @@ golang.org/x/sys v0.0.0-20181029174526-d69651ed3497/go.mod h1:STP8DvDyc/dI5b8T5h
180178
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
181179
golang.org/x/sys v0.0.0-20190316082340-a2f829d7f35f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
182180
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
183-
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
184-
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
181+
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
182+
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
185183
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
186184
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
187-
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
188-
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
185+
golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=
186+
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
189187
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
190188
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
191189
golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk=
@@ -195,8 +193,8 @@ golang.org/x/tools v0.0.0-20181030000716-a0a13e073c7b/go.mod h1:n7NCudcB/nEzxVGm
195193
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
196194
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
197195
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
198-
golang.org/x/tools v0.20.0 h1:hz/CVckiOxybQvFw6h7b/q80NTr9IUQb4s1IIzW7KNY=
199-
golang.org/x/tools v0.20.0/go.mod h1:WvitBU7JJf6A4jOdg4S1tviW9bhUxkgeCui/0JHctQg=
196+
golang.org/x/tools v0.21.0 h1:qc0xYgIbsSDt9EyWz05J5wfa7LOVW0YTLOXrqdLAWIw=
197+
golang.org/x/tools v0.21.0/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
200198
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
201199
google.golang.org/api v0.0.0-20180910000450-7ca32eb868bf/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0=
202200
google.golang.org/api v0.0.0-20181030000543-1d582fd0359e/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0=
@@ -214,8 +212,8 @@ google.golang.org/grpc v1.14.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmE
214212
google.golang.org/grpc v1.16.0/go.mod h1:0JHn/cJsOMiMfNA9+DeHDlAU7KAAB5GDlYFpa9MZMio=
215213
google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs=
216214
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
217-
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
218-
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
215+
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
216+
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
219217
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
220218
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
221219
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=

‎u_packet_packer.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"bytes"
55
"fmt"
66

7-
"github.com/gaukas/clienthellod"
7+
"github.com/refraction-networking/clienthellod"
88
"github.com/refraction-networking/uquic/internal/handshake"
99
"github.com/refraction-networking/uquic/internal/protocol"
1010
"github.com/refraction-networking/uquic/internal/wire"
@@ -250,8 +250,13 @@ func (p *uPacketPacker) MarshalInitialPacketPayload(pl payload, v protocol.Versi
250250
return nil, err
251251
}
252252

253-
if p.uSpec.InitialPacketSpec.FrameBuilder == nil {
253+
if p.uSpec.InitialPacketSpec.FrameBuilder == nil || len(p.uSpec.InitialPacketSpec.FrameBuilder.(QUICFrames)) == 0 {
254254
qfs := QUICFrames{}
255+
for _, frame := range qchframes {
256+
if cryptoFrame, ok := frame.(*clienthellod.CRYPTO); ok {
257+
qfs = append(qfs, QUICFrameCrypto{int(cryptoFrame.Offset), int(cryptoFrame.Length)})
258+
}
259+
}
255260
return qfs.Build(cryptoData)
256261
}
257262
return p.uSpec.InitialPacketSpec.FrameBuilder.Build(cryptoData)

‎u_quic_frames.go

+12-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import (
44
"bytes"
55
"crypto/rand"
66
"errors"
7+
"math"
78
"math/big"
89
mrand "math/rand"
910

10-
"github.com/gaukas/clienthellod"
11+
"github.com/refraction-networking/clienthellod"
1112
"github.com/refraction-networking/uquic/quicvarint"
1213
)
1314

@@ -30,18 +31,26 @@ func (qfs QUICFrames) Build(cryptoData []byte) (payload []byte, err error) {
3031
return qfsCryptoOnly.Build(cryptoData)
3132
}
3233

34+
lowestOffset := math.MaxUint16
35+
for _, frame := range qfs {
36+
if offset, _, _ := frame.CryptoFrameInfo(); offset < lowestOffset {
37+
lowestOffset = offset
38+
}
39+
}
40+
3341
for _, frame := range qfs {
3442
var frameBytes []byte
3543
if offset, length, cryptoOK := frame.CryptoFrameInfo(); cryptoOK {
44+
lengthOffset := offset - lowestOffset
3645
if length == 0 {
3746
// calculate length: from offset to the end of cryptoData
38-
length = len(cryptoData) - offset
47+
length = len(cryptoData) - lengthOffset
3948
}
4049
frameBytes = []byte{0x06} // CRYPTO frame type
4150
frameBytes = quicvarint.Append(frameBytes, uint64(offset))
4251
frameBytes = quicvarint.Append(frameBytes, uint64(length))
4352
frameCryptoData := make([]byte, length)
44-
copy(frameCryptoData, cryptoData[offset:]) // copy at most length bytes
53+
copy(frameCryptoData, cryptoData[lengthOffset:]) // copy at most length bytes
4554
frameBytes = append(frameBytes, frameCryptoData...)
4655
} else { // Handle none crypto frames: read and append to payload
4756
frameBytes, err = frame.Read()

‎u_quic_frames_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"bytes"
55
"testing"
66

7-
"github.com/gaukas/clienthellod"
7+
"github.com/refraction-networking/clienthellod"
88
)
99

1010
func TestQUICFrames(t *testing.T) {

0 commit comments

Comments
 (0)
Please sign in to comment.