forked from Jigsaw-Code/outline-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Alim Shapiev
committed
Nov 3, 2024
1 parent
bf61e14
commit ed4022c
Showing
7 changed files
with
198 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,22 @@ | ||
// Copyright 2024 The Outline Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package configurl | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/Jigsaw-Code/outline-sdk/x/fake" | ||
"strconv" | ||
|
||
"github.com/Jigsaw-Code/outline-sdk/transport" | ||
"github.com/Jigsaw-Code/outline-sdk/x/fake" | ||
) | ||
|
||
// tls wikipedia request | ||
var tlsData = [517]byte{ | ||
0x16, 0x03, 0x01, 0x02, 0x00, 0x01, 0x00, 0x01, 0xfc, 0x03, 0x03, 0x03, 0x5f, | ||
0x6f, 0x2c, 0xed, 0x13, 0x22, 0xf8, 0xdc, 0xb2, 0xf2, 0x60, 0x48, 0x2d, 0x72, | ||
0x66, 0x6f, 0x57, 0xdd, 0x13, 0x9d, 0x1b, 0x37, 0xdc, 0xfa, 0x36, 0x2e, 0xba, | ||
0xf9, 0x92, 0x99, 0x3a, 0x20, 0xf9, 0xdf, 0x0c, 0x2e, 0x8a, 0x55, 0x89, 0x82, | ||
0x31, 0x63, 0x1a, 0xef, 0xa8, 0xbe, 0x08, 0x58, 0xa7, 0xa3, 0x5a, 0x18, 0xd3, | ||
0x96, 0x5f, 0x04, 0x5c, 0xb4, 0x62, 0xaf, 0x89, 0xd7, 0x0f, 0x8b, 0x00, 0x3e, | ||
0x13, 0x02, 0x13, 0x03, 0x13, 0x01, 0xc0, 0x2c, 0xc0, 0x30, 0x00, 0x9f, 0xcc, | ||
0xa9, 0xcc, 0xa8, 0xcc, 0xaa, 0xc0, 0x2b, 0xc0, 0x2f, 0x00, 0x9e, 0xc0, 0x24, | ||
0xc0, 0x28, 0x00, 0x6b, 0xc0, 0x23, 0xc0, 0x27, 0x00, 0x67, 0xc0, 0x0a, 0xc0, | ||
0x14, 0x00, 0x39, 0xc0, 0x09, 0xc0, 0x13, 0x00, 0x33, 0x00, 0x9d, 0x00, 0x9c, | ||
0x00, 0x3d, 0x00, 0x3c, 0x00, 0x35, 0x00, 0x2f, 0x00, 0xff, 0x01, 0x00, 0x01, | ||
0x75, 0x00, 0x00, 0x00, 0x16, 0x00, 0x14, 0x00, 0x00, 0x11, 0x77, 0x77, 0x77, | ||
0x2e, 0x77, 0x69, 0x6b, 0x69, 0x70, 0x65, 0x64, 0x69, 0x61, 0x2e, 0x6f, 0x72, | ||
0x67, 0x00, 0x0b, 0x00, 0x04, 0x03, 0x00, 0x01, 0x02, 0x00, 0x0a, 0x00, 0x16, | ||
0x00, 0x14, 0x00, 0x1d, 0x00, 0x17, 0x00, 0x1e, 0x00, 0x19, 0x00, 0x18, 0x01, | ||
0x00, 0x01, 0x01, 0x01, 0x02, 0x01, 0x03, 0x01, 0x04, 0x00, 0x10, 0x00, 0x0e, | ||
0x00, 0x0c, 0x02, 0x68, 0x32, 0x08, 0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, | ||
0x31, 0x00, 0x16, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x31, 0x00, 0x00, | ||
0x00, 0x0d, 0x00, 0x2a, 0x00, 0x28, 0x04, 0x03, 0x05, 0x03, 0x06, 0x03, 0x08, | ||
0x07, 0x08, 0x08, 0x08, 0x09, 0x08, 0x0a, 0x08, 0x0b, 0x08, 0x04, 0x08, 0x05, | ||
0x08, 0x06, 0x04, 0x01, 0x05, 0x01, 0x06, 0x01, 0x03, 0x03, 0x03, 0x01, 0x03, | ||
0x02, 0x04, 0x02, 0x05, 0x02, 0x06, 0x02, 0x00, 0x2b, 0x00, 0x09, 0x08, 0x03, | ||
0x04, 0x03, 0x03, 0x03, 0x02, 0x03, 0x01, 0x00, 0x2d, 0x00, 0x02, 0x01, 0x01, | ||
0x00, 0x33, 0x00, 0x26, 0x00, 0x24, 0x00, 0x1d, 0x00, 0x20, 0x11, 0x8c, 0xb8, | ||
0x8c, 0xe8, 0x8a, 0x08, 0x90, 0x1e, 0xee, 0x19, 0xd9, 0xdd, 0xe8, 0xd4, 0x06, | ||
0xb1, 0xd1, 0xe2, 0xab, 0xe0, 0x16, 0x63, 0xd6, 0xdc, 0xda, 0x84, 0xa4, 0xb8, | ||
0x4b, 0xfb, 0x0e, 0x00, 0x15, 0x00, 0xac, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
} | ||
var httpData = []byte("GET / HTTP/1.1\r\nHost: www.wikipedia.org\r\n\r\n") | ||
var udpData [64]byte | ||
|
||
func registerFakeStreamDialer(r TypeRegistry[transport.StreamDialer], typeID string, newSD BuildFunc[transport.StreamDialer]) { | ||
r.RegisterType(typeID, func(ctx context.Context, config *Config) (transport.StreamDialer, error) { | ||
sd, err := newSD(ctx, config.BaseConfig) | ||
if err != nil { | ||
return nil, err | ||
} | ||
prefixBytesStr := config.URL.Opaque | ||
prefixBytes, err := strconv.Atoi(prefixBytesStr) | ||
settings, err := fake.ParseSettings(config.URL.Opaque) | ||
if err != nil { | ||
return nil, fmt.Errorf("prefixBytes is not a number: %v. Fake config should be in fake:<number> format", prefixBytesStr) | ||
return nil, fmt.Errorf("failed to parse settings: %w", err) | ||
} | ||
// TODO: Read fake data from the CLI or use a default value (depending on the protocol). | ||
var fakeData []byte | ||
// TODO: Read fake offset from the CLI | ||
var fakeOffset int64 = 0 | ||
// TODO: Read fake TTL from the CLI or use a default value (8) | ||
var fakeTtl int = 8 | ||
// TODO: Read md5 signature from the CLI or use a default value (false). | ||
var md5Sig bool = false | ||
return fake.NewStreamDialer(sd, int64(prefixBytes), fakeData, fakeOffset, fakeTtl, md5Sig) | ||
return fake.NewStreamDialer(sd, settings.FakeData, settings.FakeOffset, settings.FakeBytes, settings.FakeTtl, settings.Md5Sig) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package fake | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
"strings" | ||
) | ||
|
||
const defaultTtl = 8 | ||
|
||
type Settings struct { | ||
FakeData []byte | ||
FakeOffset int64 | ||
FakeBytes int64 | ||
FakeTtl int | ||
Md5Sig bool | ||
} | ||
|
||
// ParseSettings expects the settings to be in the format "[data(str)]:<offset(int)>:<bytes(int)>:<ttl(int)>:<Md5Sig(int=0/1)>" | ||
func ParseSettings(raw string) (*Settings, error) { | ||
result := Settings{ | ||
FakeTtl: defaultTtl, | ||
} | ||
parts := strings.Split(raw, ":") | ||
if len(parts) > 0 && parts[0] != "" { | ||
result.FakeData = []byte(parts[0]) | ||
} | ||
if len(parts) > 1 && parts[1] != "" { | ||
offset, err := strconv.ParseInt(parts[1], 10, 64) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to parse offset: %w", err) | ||
} | ||
result.FakeOffset = offset | ||
} | ||
if len(parts) > 2 && parts[2] != "" { | ||
bytes, err := strconv.ParseInt(parts[2], 10, 64) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to parse bytes: %w", err) | ||
} | ||
result.FakeBytes = bytes | ||
} | ||
if len(parts) > 3 && parts[3] != "" { | ||
ttl, err := strconv.Atoi(parts[3]) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to parse TTL: %w", err) | ||
} | ||
result.FakeTtl = ttl | ||
} | ||
if len(parts) > 4 && parts[4] != "" { | ||
md5Sig, err := strconv.ParseBool(parts[4]) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to parse MD5 signature flag: %w", err) | ||
} | ||
result.Md5Sig = md5Sig | ||
} | ||
return &result, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.