Debian Codegraph @

transports/scramblesuit/conn.go

raw symbols SCIP
1 /*
2 * Copyright (c) 2015, Yawning Angel <yawning at schwanenlied dot me>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * * Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 *
11 * * Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 package scramblesuitscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/
29
30 import (
31 "bytesscip-go gomod github.com/golang/go/src go1.22.0 bytes/"
32 "crypto/aesscip-go gomod github.com/golang/go/src go1.22.0 `crypto/aes`/"
33 "crypto/cipherscip-go gomod github.com/golang/go/src go1.22.0 `crypto/cipher`/"
34 "crypto/hmacscip-go gomod github.com/golang/go/src go1.22.0 `crypto/hmac`/"
35 "crypto/sha256scip-go gomod github.com/golang/go/src go1.22.0 `crypto/sha256`/"
36 "encoding/base32scip-go gomod github.com/golang/go/src go1.22.0 `encoding/base32`/"
37 "encoding/binaryscip-go gomod github.com/golang/go/src go1.22.0 `encoding/binary`/"
38 "errorsscip-go gomod github.com/golang/go/src go1.22.0 errors/"
39 "fmtscip-go gomod github.com/golang/go/src go1.22.0 fmt/"
40 "hashscip-go gomod github.com/golang/go/src go1.22.0 hash/"
41 "ioscip-go gomod github.com/golang/go/src go1.22.0 io/"
42 "netscip-go gomod github.com/golang/go/src go1.22.0 net/"
43 "timescip-go gomod github.com/golang/go/src go1.22.0 time/"
44
45 "gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/goptlibscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/goptlib v1.6.0 `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/goptlib`/"
46 "gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/csrandscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/csrand`/"
47 "gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/drbgscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/drbg`/"
48 "gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/probdistscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/probdist`/"
49 "gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdhscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/"
50 )
51
52 const (
53 passwordArgscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/passwordArg. = "password"
54
55 maxSegmentLengthscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/maxSegmentLength. = 1448
56 maxPayloadLengthscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/maxPayloadLength. = 1427
57 sharedSecretLengthscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/sharedSecretLength. = 160 / 8 // k_B
58 clientHandshakeTimeoutscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/clientHandshakeTimeout. = timescip-go gomod github.com/golang/go/src go1.22.0 time/.Durationscip-go gomod github.com/golang/go/src go1.22.0 time/Duration#(60) * timescip-go gomod github.com/golang/go/src go1.22.0 time/.Secondscip-go gomod github.com/golang/go/src go1.22.0 time/Second.
59
60 minLenDistLengthscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/minLenDistLength. = 21
61 maxLenDistLengthscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/maxLenDistLength. = maxSegmentLengthscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/maxSegmentLength.
62
63 keyLengthscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/keyLength. = 32 + 8 + 32
64
65 pktPrngSeedLengthscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/pktPrngSeedLength. = 32
66 pktOverheadscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/pktOverhead. = macLengthscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/macLength. + pktHdrLengthscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/pktHdrLength.
67 pktHdrLengthscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/pktHdrLength. = 2 + 2 + 1
68 pktPayloadscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/pktPayload. = 1
69 pktNewTicketscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/pktNewTicket. = 1 << 1
70 pktPrngSeedscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/pktPrngSeed. = 1 << 2
71 )
72
73 var (
74 // ErrNotSupported is the error returned for a unsupported operation.
75 ErrNotSupportedscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ErrNotSupported. = errorsscip-go gomod github.com/golang/go/src go1.22.0 errors/.Newscip-go gomod github.com/golang/go/src go1.22.0 errors/New().("scramblesuit: operation not supported")
76
77 // ErrInvalidPacket is the error returned when a invalid packet is received.
78 ErrInvalidPacketscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ErrInvalidPacket. = errorsscip-go gomod github.com/golang/go/src go1.22.0 errors/.Newscip-go gomod github.com/golang/go/src go1.22.0 errors/New().("scramblesuit: invalid packet")
79
80 zeroPadBytesscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/zeroPadBytes. [maxPayloadLengthscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/maxPayloadLength.]byte
81 )
82
83 type ssSharedSecretscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssSharedSecret# [sharedSecretLengthscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/sharedSecretLength.]byte
84
85 type ssClientArgsscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssClientArgs# struct {
86 kBscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssClientArgs#kB. *ssSharedSecretscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssSharedSecret#
87 sessionKeyscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssClientArgs#sessionKey. *uniformdhscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/.PrivateKeyscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/PrivateKey#
88 }
89
90 func newClientArgsscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/newClientArgs().(args *ptscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/goptlib v1.6.0 `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/goptlib`/.Argsscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/goptlib v1.6.0 `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/goptlib`/Args#) (ca *ssClientArgsscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssClientArgs#, err error) {
91 ca = &ssClientArgsscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssClientArgs#{}
92 if ca.kBscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssClientArgs#kB., err = parsePasswordArgscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/parsePasswordArg().(args); err != nil {
93 return nil, err
94 }
95
96 // Generate the client keypair before opening a connection since the time
97 // taken is visible to an adversary. This key might not end up being used
98 // if a session ticket is present, but this doesn't take that long.
99 if ca.sessionKeyscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssClientArgs#sessionKey., err = uniformdhscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/.GenerateKeyscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/GenerateKey().(csrandscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/csrand`/.Readerscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/csrand`/Reader.); err != nil {
100 return nil, err
101 }
102 return
103 }
104
105 func parsePasswordArgscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/parsePasswordArg().(args *ptscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/goptlib v1.6.0 `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/goptlib`/.Argsscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/goptlib v1.6.0 `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/goptlib`/Args#) (*ssSharedSecretscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssSharedSecret#, error) {
106 str, ok := args.Getscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/goptlib v1.6.0 `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/goptlib`/Args#Get().(passwordArgscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/passwordArg.)
107 if !ok {
108 return nil, fmtscip-go gomod github.com/golang/go/src go1.22.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.22.0 fmt/Errorf().("missing argument '%s'", passwordArgscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/passwordArg.)
109 }
110
111 // To match the obfsproxy behavior, 'str' should contain a Base32 encoded
112 // shared secret (k_B) used for handshaking.
113 decoded, err := base32scip-go gomod github.com/golang/go/src go1.22.0 `encoding/base32`/.StdEncodingscip-go gomod github.com/golang/go/src go1.22.0 `encoding/base32`/StdEncoding..DecodeStringscip-go gomod github.com/golang/go/src go1.22.0 `encoding/base32`/Encoding#DecodeString().(str)
114 if err != nil {
115 return nil, fmtscip-go gomod github.com/golang/go/src go1.22.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.22.0 fmt/Errorf().("failed to decode password: %s", err)
116 }
117 if len(decoded) != sharedSecretLengthscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/sharedSecretLength. {
118 return nil, fmtscip-go gomod github.com/golang/go/src go1.22.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.22.0 fmt/Errorf().("password length %d is invalid", len(decoded))
119 }
120 ss := new(ssSharedSecretscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssSharedSecret#)
121 copy(ss[:], decoded)
122 return ss, nil
123 }
124
125 type ssCryptoStatescip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssCryptoState# struct {
126 sscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssCryptoState#s. cipherscip-go gomod github.com/golang/go/src go1.22.0 `crypto/cipher`/.Streamscip-go gomod github.com/golang/go/src go1.22.0 `crypto/cipher`/Stream#
127 macscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssCryptoState#mac. hashscip-go gomod github.com/golang/go/src go1.22.0 hash/.Hashscip-go gomod github.com/golang/go/src go1.22.0 hash/Hash#
128 }
129
130 func newCryptoStatescip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/newCryptoState().(aesKey []byte, ivPrefix []byte, macKey []byte) (*ssCryptoStatescip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssCryptoState#, error) {
131 // The ScrambleSuit CTR-AES256 link crypto uses an 8 byte prefix from the
132 // KDF, and a 64 bit counter initialized to 1 as the IV. The initial value
133 // of the counter isn't documented in the spec either.
134 var initialCtr = []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}
135 iv := make([]byte, 0, aesscip-go gomod github.com/golang/go/src go1.22.0 `crypto/aes`/.BlockSizescip-go gomod github.com/golang/go/src go1.22.0 `crypto/aes`/BlockSize.)
136 iv = append(iv, ivPrefix...)
137 iv = append(iv, initialCtr...)
138 b, err := aesscip-go gomod github.com/golang/go/src go1.22.0 `crypto/aes`/.NewCipherscip-go gomod github.com/golang/go/src go1.22.0 `crypto/aes`/NewCipher().(aesKey)
139 if err != nil {
140 return nil, err
141 }
142 s := cipherscip-go gomod github.com/golang/go/src go1.22.0 `crypto/cipher`/.NewCTRscip-go gomod github.com/golang/go/src go1.22.0 `crypto/cipher`/NewCTR().(b, iv)
143 mac := hmacscip-go gomod github.com/golang/go/src go1.22.0 `crypto/hmac`/.Newscip-go gomod github.com/golang/go/src go1.22.0 `crypto/hmac`/New().(sha256scip-go gomod github.com/golang/go/src go1.22.0 `crypto/sha256`/.Newscip-go gomod github.com/golang/go/src go1.22.0 `crypto/sha256`/New()., macKey)
144 return &ssCryptoStatescip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssCryptoState#{sscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssCryptoState#s.: s, macscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssCryptoState#mac.: mac}, nil
145 }
146
147 type ssConnscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn# struct {
148 netscip-go gomod github.com/golang/go/src go1.22.0 net/.Connscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#Conn.
149
150 isServerscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#isServer. bool
151
152 lenDistscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#lenDist. *probdistscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/probdist`/.WeightedDistscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/probdist`/WeightedDist#
153 receiveBufferscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#receiveBuffer. *bytesscip-go gomod github.com/golang/go/src go1.22.0 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.22.0 bytes/Buffer#
154 receiveDecodedBufferscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#receiveDecodedBuffer. *bytesscip-go gomod github.com/golang/go/src go1.22.0 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.22.0 bytes/Buffer#
155 receiveStatescip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#receiveState. ssRxStatescip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssRxState#
156
157 txCryptoscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#txCrypto. *ssCryptoStatescip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssCryptoState#
158 rxCryptoscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#rxCrypto. *ssCryptoStatescip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssCryptoState#
159
160 ticketStorescip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#ticketStore. *ssTicketStorescip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssTicketStore#
161 }
162
163 type ssRxStatescip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssRxState# struct {
164 macscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssRxState#mac. []byte
165 hdrscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssRxState#hdr. []byte
166
167 totalLenscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssRxState#totalLen. int
168 payloadLenscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssRxState#payloadLen. int
169 }
170
171 func (conn *ssConnscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#) Readscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#Read().(b []byte) (n int, err error) {
172 // If the receive payload buffer is empty, consume data off the network.
173 for conn.receiveDecodedBufferscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#receiveDecodedBuffer..Lenscip-go gomod github.com/golang/go/src go1.22.0 bytes/Buffer#Len().() == 0 {
174 if err = conn.readPacketsscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#readPackets().(); err != nil {
175 break
176 }
177 }
178
179 // Service the read request using buffered payload.
180 if conn.receiveDecodedBufferscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#receiveDecodedBuffer..Lenscip-go gomod github.com/golang/go/src go1.22.0 bytes/Buffer#Len().() > 0 {
181 n, _ = conn.receiveDecodedBufferscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#receiveDecodedBuffer..Readscip-go gomod github.com/golang/go/src go1.22.0 bytes/Buffer#Read().(b)
182 }
183 return
184 }
185
186 func (conn *ssConnscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#) Writescip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#Write().(b []byte) (n int, err error) {
187 var frameBuf bytesscip-go gomod github.com/golang/go/src go1.22.0 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.22.0 bytes/Buffer#
188 p := b
189 toSend := len(p)
190
191 for toSend > 0 {
192 // Send as much payload as will fit into each frame as possible.
193 wrLen := len(p)
194 if wrLen > maxPayloadLengthscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/maxPayloadLength. {
195 wrLen = maxPayloadLengthscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/maxPayloadLength.
196 }
197 payload := p[:wrLen]
198 if err = conn.makePacketscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#makePacket().(&frameBuf, pktPayloadscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/pktPayload., payload, 0); err != nil {
199 return 0, err
200 }
201
202 toSend -= wrLen
203 p = p[wrLen:]
204 n += wrLen
205 }
206
207 // Pad out the burst as appropriate.
208 if err = conn.padBurstscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#padBurst().(&frameBuf, conn.lenDistscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#lenDist..Samplescip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/probdist`/WeightedDist#Sample().()); err != nil {
209 return 0, err
210 }
211
212 // Write and return.
213 _, err = conn.Connscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#Conn..Writescip-go gomod github.com/golang/go/src go1.22.0 net/Conn#Write().(frameBuf.Bytesscip-go gomod github.com/golang/go/src go1.22.0 bytes/Buffer#Bytes().())
214 return
215 }
216
217 func (conn *ssConnscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#) SetDeadlinescip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#SetDeadline().(t timescip-go gomod github.com/golang/go/src go1.22.0 time/.Timescip-go gomod github.com/golang/go/src go1.22.0 time/Time#) error {
218 return ErrNotSupportedscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ErrNotSupported.
219 }
220
221 func (conn *ssConnscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#) SetReadDeadlinescip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#SetReadDeadline().(t timescip-go gomod github.com/golang/go/src go1.22.0 time/.Timescip-go gomod github.com/golang/go/src go1.22.0 time/Time#) error {
222 return ErrNotSupportedscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ErrNotSupported.
223 }
224
225 func (conn *ssConnscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#) SetWriteDeadlinescip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#SetWriteDeadline().(t timescip-go gomod github.com/golang/go/src go1.22.0 time/.Timescip-go gomod github.com/golang/go/src go1.22.0 time/Time#) error {
226 return ErrNotSupportedscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ErrNotSupported.
227 }
228
229 func (conn *ssConnscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#) makePacketscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#makePacket().(w ioscip-go gomod github.com/golang/go/src go1.22.0 io/.Writerscip-go gomod github.com/golang/go/src go1.22.0 io/Writer#, pktType byte, data []byte, padLen int) error {
230 payloadLen := len(data)
231 totalLen := payloadLen + padLen
232 if totalLen > maxPayloadLengthscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/maxPayloadLength. {
233 panic(fmtscip-go gomod github.com/golang/go/src go1.22.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.22.0 fmt/Sprintf().("BUG: makePacket() len(data) + padLen > maxPayloadLength: %d + %d > %d", len(data), padLen, maxPayloadLengthscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/maxPayloadLength.))
234 }
235
236 // Build the packet header (total length, payload length, flags),
237 // and append the payload and padding.
238 pkt := make([]byte, pktHdrLengthscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/pktHdrLength., pktHdrLengthscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/pktHdrLength.+payloadLen+padLen)
239 binaryscip-go gomod github.com/golang/go/src go1.22.0 `encoding/binary`/.BigEndianscip-go gomod github.com/golang/go/src go1.22.0 `encoding/binary`/BigEndian..PutUint16scip-go gomod github.com/golang/go/src go1.22.0 `encoding/binary`/bigEndian#PutUint16().(pkt[0:], uint16(totalLen))
240 binaryscip-go gomod github.com/golang/go/src go1.22.0 `encoding/binary`/.BigEndianscip-go gomod github.com/golang/go/src go1.22.0 `encoding/binary`/BigEndian..PutUint16scip-go gomod github.com/golang/go/src go1.22.0 `encoding/binary`/bigEndian#PutUint16().(pkt[2:], uint16(payloadLen))
241 pkt[4] = pktType
242 pkt = append(pkt, data...)
243 pkt = append(pkt, zeroPadBytesscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/zeroPadBytes.[:padLen]...)
244
245 // Encrypt the packet, and calculate the MAC.
246 conn.txCryptoscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#txCrypto..sscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssCryptoState#s..XORKeyStreamscip-go gomod github.com/golang/go/src go1.22.0 `crypto/cipher`/Stream#XORKeyStream().(pkt, pkt)
247 conn.txCryptoscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#txCrypto..macscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssCryptoState#mac..Resetscip-go gomod github.com/golang/go/src go1.22.0 hash/Hash#Reset().()
248 _, _ = conn.txCryptoscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#txCrypto..macscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssCryptoState#mac..Writescip-go gomod github.com/golang/go/src go1.22.0 io/Writer#Write().(pkt)
249 mac := conn.txCryptoscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#txCrypto..macscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssCryptoState#mac..Sumscip-go gomod github.com/golang/go/src go1.22.0 hash/Hash#Sum().(nil)[:macLengthscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/macLength.]
250
251 // Write out MAC | Packet. Note that this does not go onto the network
252 // yet, as w is a byte.Buffer (This is done so each call to conn.Write()
253 // gets padding added).
254 if _, err := w.Writescip-go gomod github.com/golang/go/src go1.22.0 io/Writer#Write().(mac); err != nil {
255 return err
256 }
257 _, err := w.Writescip-go gomod github.com/golang/go/src go1.22.0 io/Writer#Write().(pkt)
258 return err
259 }
260
261 func (conn *ssConnscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#) readPacketsscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#readPackets().() error {
262 // Consume and buffer up to 1 MSS worth of data.
263 var buf [maxSegmentLengthscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/maxSegmentLength.]byte
264 rdLen, rdErr := conn.Connscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#Conn..Readscip-go gomod github.com/golang/go/src go1.22.0 net/Conn#Read().(buf[:])
265 conn.receiveBufferscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#receiveBuffer..Writescip-go gomod github.com/golang/go/src go1.22.0 bytes/Buffer#Write().(buf[:rdLen])
266
267 // Process incoming packets incrementally. conn.receiveState stores
268 // the results of partial processing.
269 for conn.receiveBufferscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#receiveBuffer..Lenscip-go gomod github.com/golang/go/src go1.22.0 bytes/Buffer#Len().() > 0 {
270 if conn.receiveStatescip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#receiveState..macscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssRxState#mac. == nil {
271 // Read and store the packet MAC.
272 if conn.receiveBufferscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#receiveBuffer..Lenscip-go gomod github.com/golang/go/src go1.22.0 bytes/Buffer#Len().() < macLengthscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/macLength. {
273 break
274 }
275 mac := make([]byte, macLengthscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/macLength.)
276 _, _ = conn.receiveBufferscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#receiveBuffer..Readscip-go gomod github.com/golang/go/src go1.22.0 bytes/Buffer#Read().(mac)
277 conn.receiveStatescip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#receiveState..macscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssRxState#mac. = mac
278 }
279
280 if conn.receiveStatescip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#receiveState..hdrscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssRxState#hdr. == nil {
281 // Read and store the packet header.
282 if conn.receiveBufferscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#receiveBuffer..Lenscip-go gomod github.com/golang/go/src go1.22.0 bytes/Buffer#Len().() < pktHdrLengthscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/pktHdrLength. {
283 break
284 }
285 hdr := make([]byte, pktHdrLengthscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/pktHdrLength.)
286 _, _ = conn.receiveBufferscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#receiveBuffer..Readscip-go gomod github.com/golang/go/src go1.22.0 bytes/Buffer#Read().(hdr)
287
288 // Add the encrypted packet header to the HMAC instance, and then
289 // decrypt it so that the length of the packet can be determined.
290 conn.rxCryptoscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#rxCrypto..macscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssCryptoState#mac..Resetscip-go gomod github.com/golang/go/src go1.22.0 hash/Hash#Reset().()
291 _, _ = conn.rxCryptoscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#rxCrypto..macscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssCryptoState#mac..Writescip-go gomod github.com/golang/go/src go1.22.0 io/Writer#Write().(hdr)
292 conn.rxCryptoscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#rxCrypto..sscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssCryptoState#s..XORKeyStreamscip-go gomod github.com/golang/go/src go1.22.0 `crypto/cipher`/Stream#XORKeyStream().(hdr, hdr)
293
294 // Store the plaintext packet header, and host byte order length
295 // values.
296 totalLen := int(binaryscip-go gomod github.com/golang/go/src go1.22.0 `encoding/binary`/.BigEndianscip-go gomod github.com/golang/go/src go1.22.0 `encoding/binary`/BigEndian..Uint16scip-go gomod github.com/golang/go/src go1.22.0 `encoding/binary`/bigEndian#Uint16().(hdr[0:]))
297 payloadLen := int(binaryscip-go gomod github.com/golang/go/src go1.22.0 `encoding/binary`/.BigEndianscip-go gomod github.com/golang/go/src go1.22.0 `encoding/binary`/BigEndian..Uint16scip-go gomod github.com/golang/go/src go1.22.0 `encoding/binary`/bigEndian#Uint16().(hdr[2:]))
298 if payloadLen > totalLen || totalLen > maxPayloadLengthscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/maxPayloadLength. {
299 return ErrInvalidPacketscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ErrInvalidPacket.
300 }
301 conn.receiveStatescip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#receiveState..hdrscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssRxState#hdr. = hdr
302 conn.receiveStatescip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#receiveState..totalLenscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssRxState#totalLen. = totalLen
303 conn.receiveStatescip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#receiveState..payloadLenscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssRxState#payloadLen. = payloadLen
304 }
305
306 var data []byte
307 if conn.receiveStatescip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#receiveState..totalLenscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssRxState#totalLen. > 0 {
308 // If the packet actually has payload (including padding), read,
309 // digest and decrypt it.
310 if conn.receiveBufferscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#receiveBuffer..Lenscip-go gomod github.com/golang/go/src go1.22.0 bytes/Buffer#Len().() < conn.receiveStatescip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#receiveState..totalLenscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssRxState#totalLen. {
311 break
312 }
313 data = make([]byte, conn.receiveStatescip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#receiveState..totalLenscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssRxState#totalLen.)
314 _, _ = conn.receiveBufferscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#receiveBuffer..Readscip-go gomod github.com/golang/go/src go1.22.0 bytes/Buffer#Read().(data)
315 _, _ = conn.rxCryptoscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#rxCrypto..macscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssCryptoState#mac..Writescip-go gomod github.com/golang/go/src go1.22.0 io/Writer#Write().(data)
316 conn.rxCryptoscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#rxCrypto..sscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssCryptoState#s..XORKeyStreamscip-go gomod github.com/golang/go/src go1.22.0 `crypto/cipher`/Stream#XORKeyStream().(data, data)
317 }
318
319 // Authenticate the packet, by comparing the received MAC with the one
320 // calculated over the ciphertext consumed off the network.
321 cmpMAC := conn.rxCryptoscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#rxCrypto..macscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssCryptoState#mac..Sumscip-go gomod github.com/golang/go/src go1.22.0 hash/Hash#Sum().(nil)[:macLengthscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/macLength.]
322 if !hmacscip-go gomod github.com/golang/go/src go1.22.0 `crypto/hmac`/.Equalscip-go gomod github.com/golang/go/src go1.22.0 `crypto/hmac`/Equal().(cmpMAC, conn.receiveStatescip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#receiveState..macscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssRxState#mac.[:]) {
323 return ErrInvalidPacketscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ErrInvalidPacket.
324 }
325
326 // Based on the packet flags, do something useful with the payload.
327 data = data[:conn.receiveStatescip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#receiveState..payloadLenscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssRxState#payloadLen.]
328 switch conn.receiveStatescip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#receiveState..hdrscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssRxState#hdr.[4] {
329 case pktPayloadscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/pktPayload.:
330 // User data, write it into the decoded payload buffer so that Read
331 // calls can be serviced.
332 conn.receiveDecodedBufferscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#receiveDecodedBuffer..Writescip-go gomod github.com/golang/go/src go1.22.0 bytes/Buffer#Write().(data)
333 case pktNewTicketscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/pktNewTicket.:
334 // New Session Ticket to be used for future handshakes, store it in
335 // the Session Ticket store.
336 if conn.isServerscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#isServer. || len(data) != ticketKeyLengthscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ticketKeyLength.+ticketLengthscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ticketLength. {
337 return ErrInvalidPacketscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ErrInvalidPacket.
338 }
339 conn.ticketStorescip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#ticketStore..storeTicketscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssTicketStore#storeTicket().(conn.RemoteAddrscip-go gomod github.com/golang/go/src go1.22.0 net/Conn#RemoteAddr().(), data)
340 case pktPrngSeedscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/pktPrngSeed.:
341 // New PRNG_SEED for the protocol polymorphism. Regenerate the
342 // length obfuscation probability distribution.
343 if conn.isServerscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#isServer. || len(data) != pktPrngSeedLengthscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/pktPrngSeedLength. {
344 return ErrInvalidPacketscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ErrInvalidPacket.
345 }
346 seed, err := drbgscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/drbg`/.SeedFromBytesscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/drbg`/SeedFromBytes().(data)
347 if err != nil {
348 return ErrInvalidPacketscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ErrInvalidPacket.
349 }
350 conn.lenDistscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#lenDist..Resetscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/probdist`/WeightedDist#Reset().(seed)
351 default:
352 return ErrInvalidPacketscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ErrInvalidPacket.
353 }
354
355 // Done processing a packet, clear the partial state.
356 conn.receiveStatescip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#receiveState..macscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssRxState#mac. = nil
357 conn.receiveStatescip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#receiveState..hdrscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssRxState#hdr. = nil
358 conn.receiveStatescip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#receiveState..totalLenscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssRxState#totalLen. = 0
359 conn.receiveStatescip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#receiveState..payloadLenscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssRxState#payloadLen. = 0
360 }
361 return rdErr
362 }
363
364 func (conn *ssConnscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#) clientHandshakescip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#clientHandshake().(kB *ssSharedSecretscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssSharedSecret#, sessionKey *uniformdhscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/.PrivateKeyscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/PrivateKey#) error {
365 if conn.isServerscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#isServer. {
366 return fmtscip-go gomod github.com/golang/go/src go1.22.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.22.0 fmt/Errorf().("clientHandshake called on server connection")
367 }
368
369 // Query the Session Ticket store to see if there is a stored session
370 // ticket.
371 ticket, err := conn.ticketStorescip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#ticketStore..getTicketscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssTicketStore#getTicket().(conn.RemoteAddrscip-go gomod github.com/golang/go/src go1.22.0 net/Conn#RemoteAddr().())
372 if err != nil {
373 return err
374 } else if ticket != nil {
375 // Ok, there is an existing ticket, so attempt to do a Session Ticket
376 // handshake. Until we write to the network, failures are non-fatal as
377 // we can transition gracefully into doing a UniformDH handshake.
378
379 // Derive the keys from the prestored master key received with the
380 // ticket. This is done before the actual handshake since the
381 // handshake uses the outgoing HMAC-SHA256-128 key for authentication.
382 if err = conn.initCryptoscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#initCrypto().(ticket.keyscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssTicket#key.[:]); err != nil {
383 goto handshakeUDH
384 }
385
386 // Generate and send the ticket handshake. There is no response, since
387 // both sides have the keying material.
388 hs := newTicketClientHandshakescip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/newTicketClientHandshake().(conn.txCryptoscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#txCrypto..macscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssCryptoState#mac., ticket)
389 blob, err := hs.generateHandshakescip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssTicketClientHandshake#generateHandshake().()
390 if err != nil {
391 goto handshakeUDH
392 }
393 if _, err = conn.Connscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#Conn..Writescip-go gomod github.com/golang/go/src go1.22.0 net/Conn#Write().(blob); err != nil {
394 return err
395 }
396 return nil
397 }
398
399 handshakeUDH:
400 // No session ticket, so take the slow path and do a UniformDH based
401 // handshake.
402
403 // Generate and send the client handshake.
404 hs := newDHClientHandshakescip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/newDHClientHandshake().(kB, sessionKey)
405 blob, err := hs.generateHandshakescip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssDHClientHandshake#generateHandshake().()
406 if err != nil {
407 return err
408 }
409 if _, err = conn.Connscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#Conn..Writescip-go gomod github.com/golang/go/src go1.22.0 net/Conn#Write().(blob); err != nil {
410 return err
411 }
412
413 // Consume the server handshake. Since we don't actually know the length
414 // of the respose, we need to consume data off the network till we either
415 // find the tail marker + MAC digest indicating that a handshake response
416 // has been received, or the maximum handshake size passes without a valid
417 // response.
418 var hsBuf [maxHandshakeLengthscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/maxHandshakeLength.]byte
419 for {
420 var n int
421 if n, err = conn.Connscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#Conn..Readscip-go gomod github.com/golang/go/src go1.22.0 net/Conn#Read().(hsBuf[:]); err != nil {
422 return err
423 }
424 conn.receiveBufferscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#receiveBuffer..Writescip-go gomod github.com/golang/go/src go1.22.0 bytes/Buffer#Write().(hsBuf[:n])
425
426 // Attempt to process all the data seen so far as a response.
427 var seed []byte
428 n, seed, err = hs.parseServerHandshakescip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssDHClientHandshake#parseServerHandshake().(conn.receiveBufferscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#receiveBuffer..Bytesscip-go gomod github.com/golang/go/src go1.22.0 bytes/Buffer#Bytes().())
429 if err == errMarkNotFoundYetscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/errMarkNotFoundYet. {
430 // No response found yet, keep trying.
431 continue
432 } else if err != nil {
433 return err
434 }
435
436 // Ok, done processing the handshake, discard the response, and do the
437 // key derivation based off the calculated shared secret.
438 _ = conn.receiveBufferscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#receiveBuffer..Nextscip-go gomod github.com/golang/go/src go1.22.0 bytes/Buffer#Next().(n)
439 err = conn.initCryptoscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#initCrypto().(seed)
440 return err
441 }
442 }
443
444 func (conn *ssConnscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#) initCryptoscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#initCrypto().(seed []byte) error {
445 // Use HKDF-SHA256 (Expand only, no Extract) to generate session keys from
446 // initial keying material.
447 okm := hkdfExpandscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/hkdfExpand().(sha256scip-go gomod github.com/golang/go/src go1.22.0 `crypto/sha256`/.Newscip-go gomod github.com/golang/go/src go1.22.0 `crypto/sha256`/New()., seed, nil, kdfSecretLengthscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/kdfSecretLength.)
448 var err error
449 conn.txCryptoscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#txCrypto., err = newCryptoStatescip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/newCryptoState().(okm[0:32], okm[32:40], okm[80:112])
450 if err != nil {
451 return err
452 }
453 conn.rxCryptoscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#rxCrypto., err = newCryptoStatescip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/newCryptoState().(okm[40:72], okm[72:80], okm[112:144])
454 if err != nil {
455 return err
456 }
457 return nil
458 }
459
460 func (conn *ssConnscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#) padBurstscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#padBurst().(burst *bytesscip-go gomod github.com/golang/go/src go1.22.0 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.22.0 bytes/Buffer#, sampleLen int) error {
461 // Burst contains the fully encrypted+MACed outgoing payload that will be
462 // written to the network. Pad it out so that the last segment (based on
463 // the ScrambleSuit MTU) is sampleLen bytes.
464
465 dataLen := burst.Lenscip-go gomod github.com/golang/go/src go1.22.0 bytes/Buffer#Len().() % maxSegmentLengthscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/maxSegmentLength.
466 padLen := 0
467 if sampleLen >= dataLen {
468 padLen = sampleLen - dataLen
469 } else {
470 padLen = (maxSegmentLengthscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/maxSegmentLength. - dataLen) + sampleLen
471 }
472 if padLen < pktOverheadscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/pktOverhead. {
473 // The padLen is less than the MAC + packet header in length, so
474 // two packets are required.
475 padLen += maxSegmentLengthscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/maxSegmentLength.
476 }
477
478 if padLen == 0 {
479 return nil
480 }
481 if padLen > maxSegmentLengthscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/maxSegmentLength. {
482 // Note: packetmorpher.py: getPadding is slightly wrong and only
483 // accounts for one of the two packet headers.
484 if err := conn.makePacketscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#makePacket().(burst, pktPayloadscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/pktPayload., nil, 700-pktOverheadscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/pktOverhead.); err != nil {
485 return err
486 }
487 return conn.makePacketscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#makePacket().(burst, pktPayloadscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/pktPayload., nil, padLen-(700+2*pktOverheadscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/pktOverhead.))
488 }
489 return conn.makePacketscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#makePacket().(burst, pktPayloadscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/pktPayload., nil, padLen-pktOverheadscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/pktOverhead.)
490 }
491
492 func newScrambleSuitClientConnscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/newScrambleSuitClientConn().(conn netscip-go gomod github.com/golang/go/src go1.22.0 net/.Connscip-go gomod github.com/golang/go/src go1.22.0 net/Conn#, tStore *ssTicketStorescip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssTicketStore#, ca *ssClientArgsscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssClientArgs#) (netscip-go gomod github.com/golang/go/src go1.22.0 net/.Connscip-go gomod github.com/golang/go/src go1.22.0 net/Conn#, error) {
493 // At this point we have kB and our session key, so we can directly
494 // start handshaking and seeing what happens.
495
496 // Seed the initial polymorphism distribution.
497 seed, err := drbgscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/drbg`/.NewSeedscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/drbg`/NewSeed().()
498 if err != nil {
499 return nil, err
500 }
501 dist := probdistscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/probdist`/.Newscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/probdist`/New().(seed, minLenDistLengthscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/minLenDistLength., maxLenDistLengthscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/maxLenDistLength., true)
502
503 // Allocate the client structure.
504 c := &ssConnscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#{conn, false, dist, bytesscip-go gomod github.com/golang/go/src go1.22.0 bytes/.NewBufferscip-go gomod github.com/golang/go/src go1.22.0 bytes/NewBuffer().(nil), bytesscip-go gomod github.com/golang/go/src go1.22.0 bytes/.NewBufferscip-go gomod github.com/golang/go/src go1.22.0 bytes/NewBuffer().(nil), ssRxStatescip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssRxState#{}, nil, nil, tStore}
505
506 // Start the handshake timeout.
507 deadline := timescip-go gomod github.com/golang/go/src go1.22.0 time/.Nowscip-go gomod github.com/golang/go/src go1.22.0 time/Now().().Addscip-go gomod github.com/golang/go/src go1.22.0 time/Time#Add().(clientHandshakeTimeoutscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/clientHandshakeTimeout.)
508 if err := conn.SetDeadlinescip-go gomod github.com/golang/go/src go1.22.0 net/Conn#SetDeadline().(deadline); err != nil {
509 return nil, err
510 }
511
512 // Attempt to handshake.
513 if err := c.clientHandshakescip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssConn#clientHandshake().(ca.kBscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssClientArgs#kB., ca.sessionKeyscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/transports/scramblesuit`/ssClientArgs#sessionKey.); err != nil {
514 return nil, err
515 }
516
517 // Stop the handshake timeout.
518 if err := conn.SetDeadlinescip-go gomod github.com/golang/go/src go1.22.0 net/Conn#SetDeadline().(timescip-go gomod github.com/golang/go/src go1.22.0 time/.Timescip-go gomod github.com/golang/go/src go1.22.0 time/Time#{}); err != nil {
519 return nil, err
520 }
521
522 return c, nil
523 }