Skip to content

Commit

Permalink
[feat] add reserved field.
Browse files Browse the repository at this point in the history
  • Loading branch information
peanut996 committed Dec 19, 2023
1 parent 8462e52 commit e554a8d
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 7 deletions.
44 changes: 37 additions & 7 deletions task/warping.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import (
"encoding/hex"
"errors"
"fmt"
"golang.org/x/crypto/blake2s"
"golang.org/x/crypto/poly1305"
"golang.zx2c4.com/wireguard/tai64n"
"log"
"math/rand"
"net"
Expand Down Expand Up @@ -43,17 +46,13 @@ var (

ScanAllPort = false

Reserved = [3]byte{0, 0, 0}

Routines = defaultRoutines

PingTimes = defaultPingTimes

commonIPv4Ports = []int{
500, 854, 859, 864, 878, 880, 890, 891, 894, 903,
908, 928, 934, 939, 942, 943, 945, 946, 955, 968,
987, 988, 1002, 1010, 1014, 1018, 1070, 1074, 1180, 1387,
1701, 1843, 2371, 2408, 2506, 3138, 3476, 3581, 3854, 4177,
4198, 4233, 4500, 5279, 5956, 7103, 7152, 7156, 7281, 7559, 8319, 8742, 8854, 8886,
}
commonIPv4Ports = []int{2408, 500, 1701, 4500}

commonIPv6Ports = []int{2408, 500, 1701, 4500}

Expand All @@ -77,6 +76,30 @@ var (
warpHandshakePacket, _ = hex.DecodeString("0100000030ec356d08af3939c1b09d3143c2e3773be539e4c7be2e2996e043f1871497be7ed28138b0473350f28647ca3013fe8de10f1ec7e448542c0ef0f0c5b2976455b6bc3f0224d06f14abfbabb7fc8753865f6dad38d7b1c2156c6cea13f57edc39c6627139659075a1c25d49743a86a40517ec45cf8e151bf0796b3f992070839600000000000000000000000000000000")
)

type MessageInitiation struct {
Type uint8
Reserved [3]byte
Sender uint32
Ephemeral device.NoisePublicKey
Static [device.NoisePublicKeySize + poly1305.TagSize]byte
Timestamp [tai64n.TimestampSize + poly1305.TagSize]byte
MAC1 [blake2s.Size128]byte
MAC2 [blake2s.Size128]byte
}

func NewMessageInitiation(msg *device.MessageInitiation) *MessageInitiation {
return &MessageInitiation{
Type: uint8(msg.Type),
Reserved: [3]byte{0, 0, 0},
Sender: msg.Sender,
Ephemeral: msg.Ephemeral,
Static: msg.Static,
Timestamp: msg.Timestamp,
MAC1: msg.MAC1,
MAC2: msg.MAC2,
}
}

type UDPAddr struct {
IP *net.IPAddr
Port int
Expand Down Expand Up @@ -307,15 +330,22 @@ func buildHandshakePacket(pri device.NoisePrivateKey, pub device.NoisePublicKey)

var buf [device.MessageInitiationSize]byte
writer := bytes.NewBuffer(buf[:0])

binary.Write(writer, binary.LittleEndian, msg)
packet := writer.Bytes()

generator := device.CookieGenerator{}
generator.Init(pub)
generator.AddMacs(packet)

AddReserved(packet)
return packet
}

func AddReserved(packet []byte) {
packet[1], packet[2], packet[3] = Reserved[0], Reserved[1], Reserved[2]
}

func getNoisePrivateKeyFromBase64(b string) (device.NoisePrivateKey, error) {
pk := device.NoisePrivateKey{}
h, err := encodeBase64ToHex(b)
Expand Down
29 changes: 29 additions & 0 deletions warp.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
### register new warp profile
POST https://api.cloudflareclient.com/v0i1909051800/reg
Content-Type: application/json
Authorization: Bearer
user-agent: okhttp/3.12.1

{
"install_id": "",
"tos": "2023-12-11T03:38:26.000Z",
"key": "{{pub}}",
"fcm_token": "",
"type": "ios",
"locale": "en_US"
}


### enable the warp
PATCH https://api.cloudflareclient.com/v0i1909051800/reg/{{regid}}
Authorization: Bearer {{token}}
Content-Type: application/json
User-Agent: okhttp/3.12.1

{"warp_enabled":true}

### get the profile
GET https://api.cloudflareclient.com/v0i1909051800/reg/{{regid}}
Authorization: Bearer {{token}}
Content-Type: application/json
User-Agent: okhttp/3.12.1

0 comments on commit e554a8d

Please sign in to comment.