@@ -17,9 +17,9 @@ package ipn
17
17
18
18
import (
19
19
"bufio"
20
- "bytes"
21
20
"context"
22
21
"encoding/base64"
22
+ "encoding/binary"
23
23
"fmt"
24
24
"net"
25
25
"net/netip"
@@ -77,7 +77,6 @@ type wgifopts struct {
77
77
peers map [string ]device.NoisePublicKey
78
78
dns , ep * multihost.MH
79
79
mtu int
80
- clientid [3 ]byte
81
80
amnezia * wg.Amnezia
82
81
}
83
82
@@ -91,7 +90,6 @@ type wgtun struct {
91
90
ingress chan * buffer.View // pipes ep writes to wg
92
91
events chan tun.Event // wg specific tun (interface) events
93
92
amnezia * wg.Amnezia // amnezia config, if any
94
- clientid [3 ]byte // client id; applicable only for warp
95
93
finalize chan struct {} // close signal for incomingPacket
96
94
once sync.Once // closer fn; exec exactly once
97
95
preferOffload bool // UDP GRO/GSO offloads
@@ -334,11 +332,6 @@ func (w *wgproxy) update(id, txt string) bool {
334
332
return anew
335
333
}
336
334
337
- if ! bytes .Equal (opts .clientid [:], w .clientid [:]) {
338
- log .D ("proxy: wg: !update(%s): clientid %v != %v" , w .id , opts .clientid , w .clientid )
339
- return anew
340
- }
341
-
342
335
if err := w .setRoutes (opts .ifaddrs ); err != nil {
343
336
log .W ("proxy: wg: !update(%s): setRoutes: %v" , w .id , err )
344
337
return anew
@@ -430,15 +423,6 @@ func wgIfConfigOf(id string, txtptr *string) (opts wgifopts, err error) {
430
423
if opts .mtu , err = strconv .Atoi (v ); err != nil {
431
424
return
432
425
}
433
- case "client_id" :
434
- // only for warp: blog.cloudflare.com/warp-technical-challenges
435
- // When we begin a WireGuard session we include our clientid field
436
- // which is provided by our authentication server which has to be
437
- // communicated with to begin a WARP session.
438
- if b , err := base64 .StdEncoding .DecodeString (v ); err == nil {
439
- n := copy (opts .clientid [:], b )
440
- log .D ("proxy: wg: %s ifconfig: clientid(%d) %v" , id , n , opts .clientid )
441
- }
442
426
case "allowed_ip" : // may exist more than once
443
427
if err = loadIPNets (& opts .allowed , v ); err != nil {
444
428
return
@@ -473,6 +457,31 @@ func wgIfConfigOf(id string, txtptr *string) (opts wgifopts, err error) {
473
457
// peer config: carry over public keys
474
458
log .D ("proxy: wg: %s ifconfig: processing key %q, err? %v" , id , k , exx )
475
459
pcfg .WriteString (line + "\n " )
460
+ case "client_id" :
461
+ // only for warp: blog.cloudflare.com/warp-technical-challenges
462
+ // When we begin a WireGuard session we include our clientid field
463
+ // which is provided by our authentication server which has to be
464
+ // communicated with to begin a WARP session.
465
+ // Though the open source Cloudflare WARP boring-tun impl does not do so:
466
+ // github.com/cloudflare/boringtun/blob/64a2fc7c63/boringtun/src/noise/handshake.rs#L734
467
+ if b , err := base64 .StdEncoding .DecodeString (v ); err == nil && len (b ) == 3 {
468
+ // github.com/WireGuard/wireguard-go/blob/12269c2761/device/send.go#L456
469
+ // github.com/WireGuard/wireguard-go/blob/12269c2761/device/noise-protocol.go#L56
470
+ h1 := append ([]byte {device .MessageInitiationType }, b ... )
471
+ h2 := append ([]byte {device .MessageResponseType }, b ... )
472
+ h3 := append ([]byte {device .MessageCookieReplyType }, b ... )
473
+ h4 := append ([]byte {device .MessageTransportType }, b ... )
474
+ // overwrite the 3 reserved bytes on all packets
475
+ // github.com/bepass-org/warp-plus/blob/19ac233cc6/wireguard/device/receive.go#L138
476
+ opts .amnezia .H1 = binary .LittleEndian .Uint32 (h1 )
477
+ opts .amnezia .H2 = binary .LittleEndian .Uint32 (h2 )
478
+ opts .amnezia .H3 = binary .LittleEndian .Uint32 (h3 )
479
+ opts .amnezia .H4 = binary .LittleEndian .Uint32 (h4 )
480
+ log .D ("proxy: wg: %s ifconfig: clientid(%d) %v" , id , len (b ), b )
481
+ } else {
482
+ log .W ("proxy: wg: %s ifconfig: clientid(%v) %d == 3?; err: %v" ,
483
+ id , v , len (b ), err )
484
+ }
476
485
case "jc" :
477
486
// github.com/amnezia-vpn/amneziawg-go/blob/2e3f7d122c/device/uapi.go#L286
478
487
jc , _ := strconv .Atoi (v )
@@ -506,9 +515,7 @@ func wgIfConfigOf(id string, txtptr *string) (opts wgifopts, err error) {
506
515
pcfg .WriteString (line + "\n " )
507
516
}
508
517
}
509
- if opts .amnezia .Set () {
510
- log .I ("proxy: wg: %s amnezia: %s" , id , opts .amnezia )
511
- }
518
+ log .D ("proxy: wg: %s amnezia: %s" , id , opts .amnezia )
512
519
* txtptr = pcfg .String ()
513
520
if err == nil && len (opts .ifaddrs ) <= 0 || opts .dns .Len () <= 0 || opts .mtu <= 0 {
514
521
err = errProxyConfig
@@ -574,7 +581,7 @@ func NewWgProxy(id string, ctl protect.Controller, rev netstack.GConnHandler, cf
574
581
// todo: use wgtun.serve fn instead of ctl
575
582
wgep = wg .NewEndpoint2 (id , ctl , opts .ep , wgtun .listener )
576
583
} else {
577
- wgep = wg .NewEndpoint (id , wgtun .serve , opts .ep , wgtun .listener , wgtun .amnezia , wgtun . clientid )
584
+ wgep = wg .NewEndpoint (id , wgtun .serve , opts .ep , wgtun .listener , wgtun .amnezia )
578
585
}
579
586
580
587
wgdev := device .NewDevice (wgtun , wgep , wglogger (id ))
@@ -648,7 +655,6 @@ func makeWgTun(id, cfg string, ctl protect.Controller, rev netstack.GConnHandler
648
655
rt : x .NewIpTree (), // must be set to allowedaddrs
649
656
ba : core.NewBarrier [[]netip.Addr ](wgbarrierttl ),
650
657
amnezia : ifopts .amnezia ,
651
- clientid : ifopts .clientid ,
652
658
status : core .NewVolatile (TUP ),
653
659
preferOffload : preferOffload (id ),
654
660
refreshBa : core.NewBarrier [bool ](2 * time .Minute ),
@@ -678,8 +684,8 @@ func makeWgTun(id, cfg string, ctl protect.Controller, rev netstack.GConnHandler
678
684
t .events <- tun .EventUp
679
685
680
686
if4 , if6 := netstack .StackAddrs (s , wgnic )
681
- log .I ("proxy: wg: %s tun: created; dns[%s]; dst[%s]; mtu[%d]; ifaddrs[%v / %v]; clientid[%v]; amnezia[%t]" ,
682
- t .id , ifopts .dns , ifopts .ep , tunmtu , if4 , if6 , ifopts .clientid , ifopts . amnezia .Set ())
687
+ log .I ("proxy: wg: %s tun: created; dns[%s]; dst[%s]; mtu[%d]; ifaddrs[%v / %v]; amnezia[%t]" ,
688
+ t .id , ifopts .dns , ifopts .ep , tunmtu , if4 , if6 , ifopts .amnezia .Set ())
683
689
684
690
return t , nil
685
691
}
0 commit comments