MCPcopy Index your code
hub / github.com/tailscale/tailscale / noiseExplorerServer

Function noiseExplorerServer

control/controlbase/interop_test.go:191–256  ·  view source on GitHub ↗
(conn net.Conn, controlKey key.MachinePrivate, wantMachineKey key.MachinePublic, payload []byte)

Source from the content-addressed store, hash-verified

189}
190
191func noiseExplorerServer(conn net.Conn, controlKey key.MachinePrivate, wantMachineKey key.MachinePublic, payload []byte) ([]byte, error) {
192 var mk keypair
193 copy(mk.private_key[:], controlKey.UntypedBytes())
194 copy(mk.public_key[:], controlKey.Public().UntypedBytes())
195 session := InitSession(false, protocolVersionPrologue(testProtocolVersion), mk, [32]byte{})
196
197 var buf [1024]byte
198 if _, err := io.ReadFull(conn, buf[:101]); err != nil {
199 return nil, err
200 }
201 // Ignore the header, we're just checking the noise implementation.
202 msg1 := messagebuffer{
203 ns: buf[37:85],
204 ciphertext: buf[85:101],
205 }
206 copy(msg1.ne[:], buf[5:37])
207 _, p, valid := RecvMessage(&session, &msg1)
208 if !valid {
209 return nil, errors.New("handshake failed")
210 }
211 if len(p) != 0 {
212 return nil, errors.New("non-empty payload")
213 }
214
215 _, msg2 := SendMessage(&session, nil)
216 var hdr [headerLen]byte
217 hdr[0] = msgTypeResponse
218 binary.BigEndian.PutUint16(hdr[1:3], 48)
219 if _, err := conn.Write(hdr[:]); err != nil {
220 return nil, err
221 }
222 if _, err := conn.Write(msg2.ne[:]); err != nil {
223 return nil, err
224 }
225 if _, err := conn.Write(msg2.ciphertext[:]); err != nil {
226 return nil, err
227 }
228
229 if _, err := io.ReadFull(conn, buf[:3]); err != nil {
230 return nil, err
231 }
232 plen := int(binary.BigEndian.Uint16(buf[1:3]))
233 if _, err := io.ReadFull(conn, buf[:plen]); err != nil {
234 return nil, err
235 }
236
237 msg3 := messagebuffer{
238 ciphertext: buf[:plen],
239 }
240 _, p, valid = RecvMessage(&session, &msg3)
241 if !valid {
242 return nil, errors.New("transport message decryption failed")
243 }
244
245 _, msg4 := SendMessage(&session, payload)
246 hdr[0] = msgTypeRecord
247 binary.BigEndian.PutUint16(hdr[1:3], uint16(len(msg4.ciphertext)))
248 if _, err := conn.Write(hdr[:]); err != nil {

Callers 1

TestInteropServerFunction · 0.85

Calls 8

InitSessionFunction · 0.85
protocolVersionPrologueFunction · 0.85
RecvMessageFunction · 0.85
SendMessageFunction · 0.85
WriteMethod · 0.65
UntypedBytesMethod · 0.45
PublicMethod · 0.45
NewMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…