github.com/eagleql/xray-core@v1.4.4/testing/scenarios/tls_test.go (about) 1 package scenarios 2 3 import ( 4 "crypto/x509" 5 "runtime" 6 "testing" 7 "time" 8 9 "golang.org/x/sync/errgroup" 10 11 "github.com/eagleql/xray-core/app/proxyman" 12 "github.com/eagleql/xray-core/common" 13 "github.com/eagleql/xray-core/common/net" 14 "github.com/eagleql/xray-core/common/protocol" 15 "github.com/eagleql/xray-core/common/protocol/tls/cert" 16 "github.com/eagleql/xray-core/common/serial" 17 "github.com/eagleql/xray-core/common/uuid" 18 core "github.com/eagleql/xray-core/core" 19 "github.com/eagleql/xray-core/proxy/dokodemo" 20 "github.com/eagleql/xray-core/proxy/freedom" 21 "github.com/eagleql/xray-core/proxy/vmess" 22 "github.com/eagleql/xray-core/proxy/vmess/inbound" 23 "github.com/eagleql/xray-core/proxy/vmess/outbound" 24 "github.com/eagleql/xray-core/testing/servers/tcp" 25 "github.com/eagleql/xray-core/testing/servers/udp" 26 "github.com/eagleql/xray-core/transport/internet" 27 "github.com/eagleql/xray-core/transport/internet/grpc" 28 "github.com/eagleql/xray-core/transport/internet/http" 29 "github.com/eagleql/xray-core/transport/internet/tls" 30 "github.com/eagleql/xray-core/transport/internet/websocket" 31 ) 32 33 func TestSimpleTLSConnection(t *testing.T) { 34 tcpServer := tcp.Server{ 35 MsgProcessor: xor, 36 } 37 dest, err := tcpServer.Start() 38 common.Must(err) 39 defer tcpServer.Close() 40 41 userID := protocol.NewID(uuid.New()) 42 serverPort := tcp.PickPort() 43 serverConfig := &core.Config{ 44 Inbound: []*core.InboundHandlerConfig{ 45 { 46 ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ 47 PortRange: net.SinglePortRange(serverPort), 48 Listen: net.NewIPOrDomain(net.LocalHostIP), 49 StreamSettings: &internet.StreamConfig{ 50 SecurityType: serial.GetMessageType(&tls.Config{}), 51 SecuritySettings: []*serial.TypedMessage{ 52 serial.ToTypedMessage(&tls.Config{ 53 Certificate: []*tls.Certificate{tls.ParseCertificate(cert.MustGenerate(nil))}, 54 }), 55 }, 56 }, 57 }), 58 ProxySettings: serial.ToTypedMessage(&inbound.Config{ 59 User: []*protocol.User{ 60 { 61 Account: serial.ToTypedMessage(&vmess.Account{ 62 Id: userID.String(), 63 }), 64 }, 65 }, 66 }), 67 }, 68 }, 69 Outbound: []*core.OutboundHandlerConfig{ 70 { 71 ProxySettings: serial.ToTypedMessage(&freedom.Config{}), 72 }, 73 }, 74 } 75 76 clientPort := tcp.PickPort() 77 clientConfig := &core.Config{ 78 Inbound: []*core.InboundHandlerConfig{ 79 { 80 ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ 81 PortRange: net.SinglePortRange(clientPort), 82 Listen: net.NewIPOrDomain(net.LocalHostIP), 83 }), 84 ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ 85 Address: net.NewIPOrDomain(dest.Address), 86 Port: uint32(dest.Port), 87 NetworkList: &net.NetworkList{ 88 Network: []net.Network{net.Network_TCP}, 89 }, 90 }), 91 }, 92 }, 93 Outbound: []*core.OutboundHandlerConfig{ 94 { 95 ProxySettings: serial.ToTypedMessage(&outbound.Config{ 96 Receiver: []*protocol.ServerEndpoint{ 97 { 98 Address: net.NewIPOrDomain(net.LocalHostIP), 99 Port: uint32(serverPort), 100 User: []*protocol.User{ 101 { 102 Account: serial.ToTypedMessage(&vmess.Account{ 103 Id: userID.String(), 104 }), 105 }, 106 }, 107 }, 108 }, 109 }), 110 SenderSettings: serial.ToTypedMessage(&proxyman.SenderConfig{ 111 StreamSettings: &internet.StreamConfig{ 112 SecurityType: serial.GetMessageType(&tls.Config{}), 113 SecuritySettings: []*serial.TypedMessage{ 114 serial.ToTypedMessage(&tls.Config{ 115 AllowInsecure: true, 116 }), 117 }, 118 }, 119 }), 120 }, 121 }, 122 } 123 124 servers, err := InitializeServerConfigs(serverConfig, clientConfig) 125 common.Must(err) 126 defer CloseAllServers(servers) 127 128 if err := testTCPConn(clientPort, 1024, time.Second*2)(); err != nil { 129 t.Fatal(err) 130 } 131 } 132 133 func TestAutoIssuingCertificate(t *testing.T) { 134 if runtime.GOOS == "windows" { 135 // Not supported on Windows yet. 136 return 137 } 138 139 if runtime.GOARCH == "arm64" { 140 return 141 } 142 143 tcpServer := tcp.Server{ 144 MsgProcessor: xor, 145 } 146 dest, err := tcpServer.Start() 147 common.Must(err) 148 defer tcpServer.Close() 149 150 caCert, err := cert.Generate(nil, cert.Authority(true), cert.KeyUsage(x509.KeyUsageDigitalSignature|x509.KeyUsageKeyEncipherment|x509.KeyUsageCertSign)) 151 common.Must(err) 152 certPEM, keyPEM := caCert.ToPEM() 153 154 userID := protocol.NewID(uuid.New()) 155 serverPort := tcp.PickPort() 156 serverConfig := &core.Config{ 157 Inbound: []*core.InboundHandlerConfig{ 158 { 159 ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ 160 PortRange: net.SinglePortRange(serverPort), 161 Listen: net.NewIPOrDomain(net.LocalHostIP), 162 StreamSettings: &internet.StreamConfig{ 163 SecurityType: serial.GetMessageType(&tls.Config{}), 164 SecuritySettings: []*serial.TypedMessage{ 165 serial.ToTypedMessage(&tls.Config{ 166 Certificate: []*tls.Certificate{{ 167 Certificate: certPEM, 168 Key: keyPEM, 169 Usage: tls.Certificate_AUTHORITY_ISSUE, 170 }}, 171 }), 172 }, 173 }, 174 }), 175 ProxySettings: serial.ToTypedMessage(&inbound.Config{ 176 User: []*protocol.User{ 177 { 178 Account: serial.ToTypedMessage(&vmess.Account{ 179 Id: userID.String(), 180 }), 181 }, 182 }, 183 }), 184 }, 185 }, 186 Outbound: []*core.OutboundHandlerConfig{ 187 { 188 ProxySettings: serial.ToTypedMessage(&freedom.Config{}), 189 }, 190 }, 191 } 192 193 clientPort := tcp.PickPort() 194 clientConfig := &core.Config{ 195 Inbound: []*core.InboundHandlerConfig{ 196 { 197 ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ 198 PortRange: net.SinglePortRange(clientPort), 199 Listen: net.NewIPOrDomain(net.LocalHostIP), 200 }), 201 ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ 202 Address: net.NewIPOrDomain(dest.Address), 203 Port: uint32(dest.Port), 204 NetworkList: &net.NetworkList{ 205 Network: []net.Network{net.Network_TCP}, 206 }, 207 }), 208 }, 209 }, 210 Outbound: []*core.OutboundHandlerConfig{ 211 { 212 ProxySettings: serial.ToTypedMessage(&outbound.Config{ 213 Receiver: []*protocol.ServerEndpoint{ 214 { 215 Address: net.NewIPOrDomain(net.LocalHostIP), 216 Port: uint32(serverPort), 217 User: []*protocol.User{ 218 { 219 Account: serial.ToTypedMessage(&vmess.Account{ 220 Id: userID.String(), 221 }), 222 }, 223 }, 224 }, 225 }, 226 }), 227 SenderSettings: serial.ToTypedMessage(&proxyman.SenderConfig{ 228 StreamSettings: &internet.StreamConfig{ 229 SecurityType: serial.GetMessageType(&tls.Config{}), 230 SecuritySettings: []*serial.TypedMessage{ 231 serial.ToTypedMessage(&tls.Config{ 232 ServerName: "example.com", 233 Certificate: []*tls.Certificate{{ 234 Certificate: certPEM, 235 Usage: tls.Certificate_AUTHORITY_VERIFY, 236 }}, 237 }), 238 }, 239 }, 240 }), 241 }, 242 }, 243 } 244 245 servers, err := InitializeServerConfigs(serverConfig, clientConfig) 246 common.Must(err) 247 defer CloseAllServers(servers) 248 249 for i := 0; i < 10; i++ { 250 if err := testTCPConn(clientPort, 1024, time.Second*2)(); err != nil { 251 t.Error(err) 252 } 253 } 254 } 255 256 func TestTLSOverKCP(t *testing.T) { 257 tcpServer := tcp.Server{ 258 MsgProcessor: xor, 259 } 260 dest, err := tcpServer.Start() 261 common.Must(err) 262 defer tcpServer.Close() 263 264 userID := protocol.NewID(uuid.New()) 265 serverPort := udp.PickPort() 266 serverConfig := &core.Config{ 267 Inbound: []*core.InboundHandlerConfig{ 268 { 269 ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ 270 PortRange: net.SinglePortRange(serverPort), 271 Listen: net.NewIPOrDomain(net.LocalHostIP), 272 StreamSettings: &internet.StreamConfig{ 273 Protocol: internet.TransportProtocol_MKCP, 274 SecurityType: serial.GetMessageType(&tls.Config{}), 275 SecuritySettings: []*serial.TypedMessage{ 276 serial.ToTypedMessage(&tls.Config{ 277 Certificate: []*tls.Certificate{tls.ParseCertificate(cert.MustGenerate(nil))}, 278 }), 279 }, 280 }, 281 }), 282 ProxySettings: serial.ToTypedMessage(&inbound.Config{ 283 User: []*protocol.User{ 284 { 285 Account: serial.ToTypedMessage(&vmess.Account{ 286 Id: userID.String(), 287 }), 288 }, 289 }, 290 }), 291 }, 292 }, 293 Outbound: []*core.OutboundHandlerConfig{ 294 { 295 ProxySettings: serial.ToTypedMessage(&freedom.Config{}), 296 }, 297 }, 298 } 299 300 clientPort := tcp.PickPort() 301 clientConfig := &core.Config{ 302 Inbound: []*core.InboundHandlerConfig{ 303 { 304 ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ 305 PortRange: net.SinglePortRange(clientPort), 306 Listen: net.NewIPOrDomain(net.LocalHostIP), 307 }), 308 ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ 309 Address: net.NewIPOrDomain(dest.Address), 310 Port: uint32(dest.Port), 311 NetworkList: &net.NetworkList{ 312 Network: []net.Network{net.Network_TCP}, 313 }, 314 }), 315 }, 316 }, 317 Outbound: []*core.OutboundHandlerConfig{ 318 { 319 ProxySettings: serial.ToTypedMessage(&outbound.Config{ 320 Receiver: []*protocol.ServerEndpoint{ 321 { 322 Address: net.NewIPOrDomain(net.LocalHostIP), 323 Port: uint32(serverPort), 324 User: []*protocol.User{ 325 { 326 Account: serial.ToTypedMessage(&vmess.Account{ 327 Id: userID.String(), 328 }), 329 }, 330 }, 331 }, 332 }, 333 }), 334 SenderSettings: serial.ToTypedMessage(&proxyman.SenderConfig{ 335 StreamSettings: &internet.StreamConfig{ 336 Protocol: internet.TransportProtocol_MKCP, 337 SecurityType: serial.GetMessageType(&tls.Config{}), 338 SecuritySettings: []*serial.TypedMessage{ 339 serial.ToTypedMessage(&tls.Config{ 340 AllowInsecure: true, 341 }), 342 }, 343 }, 344 }), 345 }, 346 }, 347 } 348 349 servers, err := InitializeServerConfigs(serverConfig, clientConfig) 350 common.Must(err) 351 defer CloseAllServers(servers) 352 353 if err := testTCPConn(clientPort, 1024, time.Second*2)(); err != nil { 354 t.Error(err) 355 } 356 } 357 358 func TestTLSOverWebSocket(t *testing.T) { 359 tcpServer := tcp.Server{ 360 MsgProcessor: xor, 361 } 362 dest, err := tcpServer.Start() 363 common.Must(err) 364 defer tcpServer.Close() 365 366 userID := protocol.NewID(uuid.New()) 367 serverPort := tcp.PickPort() 368 serverConfig := &core.Config{ 369 Inbound: []*core.InboundHandlerConfig{ 370 { 371 ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ 372 PortRange: net.SinglePortRange(serverPort), 373 Listen: net.NewIPOrDomain(net.LocalHostIP), 374 StreamSettings: &internet.StreamConfig{ 375 Protocol: internet.TransportProtocol_WebSocket, 376 SecurityType: serial.GetMessageType(&tls.Config{}), 377 SecuritySettings: []*serial.TypedMessage{ 378 serial.ToTypedMessage(&tls.Config{ 379 Certificate: []*tls.Certificate{tls.ParseCertificate(cert.MustGenerate(nil))}, 380 }), 381 }, 382 }, 383 }), 384 ProxySettings: serial.ToTypedMessage(&inbound.Config{ 385 User: []*protocol.User{ 386 { 387 Account: serial.ToTypedMessage(&vmess.Account{ 388 Id: userID.String(), 389 }), 390 }, 391 }, 392 }), 393 }, 394 }, 395 Outbound: []*core.OutboundHandlerConfig{ 396 { 397 ProxySettings: serial.ToTypedMessage(&freedom.Config{}), 398 }, 399 }, 400 } 401 402 clientPort := tcp.PickPort() 403 clientConfig := &core.Config{ 404 Inbound: []*core.InboundHandlerConfig{ 405 { 406 ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ 407 PortRange: net.SinglePortRange(clientPort), 408 Listen: net.NewIPOrDomain(net.LocalHostIP), 409 }), 410 ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ 411 Address: net.NewIPOrDomain(dest.Address), 412 Port: uint32(dest.Port), 413 NetworkList: &net.NetworkList{ 414 Network: []net.Network{net.Network_TCP}, 415 }, 416 }), 417 }, 418 }, 419 Outbound: []*core.OutboundHandlerConfig{ 420 { 421 ProxySettings: serial.ToTypedMessage(&outbound.Config{ 422 Receiver: []*protocol.ServerEndpoint{ 423 { 424 Address: net.NewIPOrDomain(net.LocalHostIP), 425 Port: uint32(serverPort), 426 User: []*protocol.User{ 427 { 428 Account: serial.ToTypedMessage(&vmess.Account{ 429 Id: userID.String(), 430 }), 431 }, 432 }, 433 }, 434 }, 435 }), 436 SenderSettings: serial.ToTypedMessage(&proxyman.SenderConfig{ 437 StreamSettings: &internet.StreamConfig{ 438 Protocol: internet.TransportProtocol_WebSocket, 439 TransportSettings: []*internet.TransportConfig{ 440 { 441 Protocol: internet.TransportProtocol_WebSocket, 442 Settings: serial.ToTypedMessage(&websocket.Config{}), 443 }, 444 }, 445 SecurityType: serial.GetMessageType(&tls.Config{}), 446 SecuritySettings: []*serial.TypedMessage{ 447 serial.ToTypedMessage(&tls.Config{ 448 AllowInsecure: true, 449 }), 450 }, 451 }, 452 }), 453 }, 454 }, 455 } 456 457 servers, err := InitializeServerConfigs(serverConfig, clientConfig) 458 common.Must(err) 459 defer CloseAllServers(servers) 460 461 var errg errgroup.Group 462 for i := 0; i < 10; i++ { 463 errg.Go(testTCPConn(clientPort, 10240*1024, time.Second*20)) 464 } 465 if err := errg.Wait(); err != nil { 466 t.Error(err) 467 } 468 } 469 470 func TestHTTP2(t *testing.T) { 471 tcpServer := tcp.Server{ 472 MsgProcessor: xor, 473 } 474 dest, err := tcpServer.Start() 475 common.Must(err) 476 defer tcpServer.Close() 477 478 userID := protocol.NewID(uuid.New()) 479 serverPort := tcp.PickPort() 480 serverConfig := &core.Config{ 481 Inbound: []*core.InboundHandlerConfig{ 482 { 483 ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ 484 PortRange: net.SinglePortRange(serverPort), 485 Listen: net.NewIPOrDomain(net.LocalHostIP), 486 StreamSettings: &internet.StreamConfig{ 487 Protocol: internet.TransportProtocol_HTTP, 488 TransportSettings: []*internet.TransportConfig{ 489 { 490 Protocol: internet.TransportProtocol_HTTP, 491 Settings: serial.ToTypedMessage(&http.Config{ 492 Host: []string{"example.com"}, 493 Path: "/testpath", 494 }), 495 }, 496 }, 497 SecurityType: serial.GetMessageType(&tls.Config{}), 498 SecuritySettings: []*serial.TypedMessage{ 499 serial.ToTypedMessage(&tls.Config{ 500 Certificate: []*tls.Certificate{tls.ParseCertificate(cert.MustGenerate(nil))}, 501 }), 502 }, 503 }, 504 }), 505 ProxySettings: serial.ToTypedMessage(&inbound.Config{ 506 User: []*protocol.User{ 507 { 508 Account: serial.ToTypedMessage(&vmess.Account{ 509 Id: userID.String(), 510 }), 511 }, 512 }, 513 }), 514 }, 515 }, 516 Outbound: []*core.OutboundHandlerConfig{ 517 { 518 ProxySettings: serial.ToTypedMessage(&freedom.Config{}), 519 }, 520 }, 521 } 522 523 clientPort := tcp.PickPort() 524 clientConfig := &core.Config{ 525 Inbound: []*core.InboundHandlerConfig{ 526 { 527 ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ 528 PortRange: net.SinglePortRange(clientPort), 529 Listen: net.NewIPOrDomain(net.LocalHostIP), 530 }), 531 ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ 532 Address: net.NewIPOrDomain(dest.Address), 533 Port: uint32(dest.Port), 534 NetworkList: &net.NetworkList{ 535 Network: []net.Network{net.Network_TCP}, 536 }, 537 }), 538 }, 539 }, 540 Outbound: []*core.OutboundHandlerConfig{ 541 { 542 ProxySettings: serial.ToTypedMessage(&outbound.Config{ 543 Receiver: []*protocol.ServerEndpoint{ 544 { 545 Address: net.NewIPOrDomain(net.LocalHostIP), 546 Port: uint32(serverPort), 547 User: []*protocol.User{ 548 { 549 Account: serial.ToTypedMessage(&vmess.Account{ 550 Id: userID.String(), 551 }), 552 }, 553 }, 554 }, 555 }, 556 }), 557 SenderSettings: serial.ToTypedMessage(&proxyman.SenderConfig{ 558 StreamSettings: &internet.StreamConfig{ 559 Protocol: internet.TransportProtocol_HTTP, 560 TransportSettings: []*internet.TransportConfig{ 561 { 562 Protocol: internet.TransportProtocol_HTTP, 563 Settings: serial.ToTypedMessage(&http.Config{ 564 Host: []string{"example.com"}, 565 Path: "/testpath", 566 }), 567 }, 568 }, 569 SecurityType: serial.GetMessageType(&tls.Config{}), 570 SecuritySettings: []*serial.TypedMessage{ 571 serial.ToTypedMessage(&tls.Config{ 572 AllowInsecure: true, 573 }), 574 }, 575 }, 576 }), 577 }, 578 }, 579 } 580 581 servers, err := InitializeServerConfigs(serverConfig, clientConfig) 582 common.Must(err) 583 defer CloseAllServers(servers) 584 585 var errg errgroup.Group 586 for i := 0; i < 10; i++ { 587 errg.Go(testTCPConn(clientPort, 1024*1024, time.Second*40)) 588 } 589 if err := errg.Wait(); err != nil { 590 t.Error(err) 591 } 592 } 593 594 func TestGRPC(t *testing.T) { 595 tcpServer := tcp.Server{ 596 MsgProcessor: xor, 597 } 598 dest, err := tcpServer.Start() 599 common.Must(err) 600 defer tcpServer.Close() 601 602 userID := protocol.NewID(uuid.New()) 603 serverPort := tcp.PickPort() 604 serverConfig := &core.Config{ 605 Inbound: []*core.InboundHandlerConfig{ 606 { 607 ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ 608 PortRange: net.SinglePortRange(serverPort), 609 Listen: net.NewIPOrDomain(net.LocalHostIP), 610 StreamSettings: &internet.StreamConfig{ 611 ProtocolName: "grpc", 612 TransportSettings: []*internet.TransportConfig{ 613 { 614 ProtocolName: "grpc", 615 Settings: serial.ToTypedMessage(&grpc.Config{ServiceName: "🍉"}), 616 }, 617 }, 618 SecurityType: serial.GetMessageType(&tls.Config{}), 619 SecuritySettings: []*serial.TypedMessage{ 620 serial.ToTypedMessage(&tls.Config{ 621 Certificate: []*tls.Certificate{tls.ParseCertificate(cert.MustGenerate(nil))}, 622 }), 623 }, 624 }, 625 }), 626 ProxySettings: serial.ToTypedMessage(&inbound.Config{ 627 User: []*protocol.User{ 628 { 629 Account: serial.ToTypedMessage(&vmess.Account{ 630 Id: userID.String(), 631 }), 632 }, 633 }, 634 }), 635 }, 636 }, 637 Outbound: []*core.OutboundHandlerConfig{ 638 { 639 ProxySettings: serial.ToTypedMessage(&freedom.Config{}), 640 }, 641 }, 642 } 643 644 clientPort := tcp.PickPort() 645 clientConfig := &core.Config{ 646 Inbound: []*core.InboundHandlerConfig{ 647 { 648 ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ 649 PortRange: net.SinglePortRange(clientPort), 650 Listen: net.NewIPOrDomain(net.LocalHostIP), 651 }), 652 ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ 653 Address: net.NewIPOrDomain(dest.Address), 654 Port: uint32(dest.Port), 655 NetworkList: &net.NetworkList{ 656 Network: []net.Network{net.Network_TCP}, 657 }, 658 }), 659 }, 660 }, 661 Outbound: []*core.OutboundHandlerConfig{ 662 { 663 ProxySettings: serial.ToTypedMessage(&outbound.Config{ 664 Receiver: []*protocol.ServerEndpoint{ 665 { 666 Address: net.NewIPOrDomain(net.LocalHostIP), 667 Port: uint32(serverPort), 668 User: []*protocol.User{ 669 { 670 Account: serial.ToTypedMessage(&vmess.Account{ 671 Id: userID.String(), 672 }), 673 }, 674 }, 675 }, 676 }, 677 }), 678 SenderSettings: serial.ToTypedMessage(&proxyman.SenderConfig{ 679 StreamSettings: &internet.StreamConfig{ 680 ProtocolName: "grpc", 681 TransportSettings: []*internet.TransportConfig{ 682 { 683 ProtocolName: "grpc", 684 Settings: serial.ToTypedMessage(&grpc.Config{ServiceName: "🍉"}), 685 }, 686 }, 687 SecurityType: serial.GetMessageType(&tls.Config{}), 688 SecuritySettings: []*serial.TypedMessage{ 689 serial.ToTypedMessage(&tls.Config{ 690 AllowInsecure: true, 691 }), 692 }, 693 }, 694 }), 695 }, 696 }, 697 } 698 699 servers, err := InitializeServerConfigs(serverConfig, clientConfig) 700 common.Must(err) 701 defer CloseAllServers(servers) 702 703 var errg errgroup.Group 704 for i := 0; i < 10; i++ { 705 errg.Go(testTCPConn(clientPort, 1024*10240, time.Second*40)) 706 } 707 if err := errg.Wait(); err != nil { 708 t.Error(err) 709 } 710 } 711 712 func TestGRPCMultiMode(t *testing.T) { 713 tcpServer := tcp.Server{ 714 MsgProcessor: xor, 715 } 716 dest, err := tcpServer.Start() 717 common.Must(err) 718 defer tcpServer.Close() 719 720 userID := protocol.NewID(uuid.New()) 721 serverPort := tcp.PickPort() 722 serverConfig := &core.Config{ 723 Inbound: []*core.InboundHandlerConfig{ 724 { 725 ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ 726 PortRange: net.SinglePortRange(serverPort), 727 Listen: net.NewIPOrDomain(net.LocalHostIP), 728 StreamSettings: &internet.StreamConfig{ 729 ProtocolName: "grpc", 730 TransportSettings: []*internet.TransportConfig{ 731 { 732 ProtocolName: "grpc", 733 Settings: serial.ToTypedMessage(&grpc.Config{ServiceName: "🍉"}), 734 }, 735 }, 736 SecurityType: serial.GetMessageType(&tls.Config{}), 737 SecuritySettings: []*serial.TypedMessage{ 738 serial.ToTypedMessage(&tls.Config{ 739 Certificate: []*tls.Certificate{tls.ParseCertificate(cert.MustGenerate(nil))}, 740 }), 741 }, 742 }, 743 }), 744 ProxySettings: serial.ToTypedMessage(&inbound.Config{ 745 User: []*protocol.User{ 746 { 747 Account: serial.ToTypedMessage(&vmess.Account{ 748 Id: userID.String(), 749 }), 750 }, 751 }, 752 }), 753 }, 754 }, 755 Outbound: []*core.OutboundHandlerConfig{ 756 { 757 ProxySettings: serial.ToTypedMessage(&freedom.Config{}), 758 }, 759 }, 760 } 761 762 clientPort := tcp.PickPort() 763 clientConfig := &core.Config{ 764 Inbound: []*core.InboundHandlerConfig{ 765 { 766 ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{ 767 PortRange: net.SinglePortRange(clientPort), 768 Listen: net.NewIPOrDomain(net.LocalHostIP), 769 }), 770 ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ 771 Address: net.NewIPOrDomain(dest.Address), 772 Port: uint32(dest.Port), 773 NetworkList: &net.NetworkList{ 774 Network: []net.Network{net.Network_TCP}, 775 }, 776 }), 777 }, 778 }, 779 Outbound: []*core.OutboundHandlerConfig{ 780 { 781 ProxySettings: serial.ToTypedMessage(&outbound.Config{ 782 Receiver: []*protocol.ServerEndpoint{ 783 { 784 Address: net.NewIPOrDomain(net.LocalHostIP), 785 Port: uint32(serverPort), 786 User: []*protocol.User{ 787 { 788 Account: serial.ToTypedMessage(&vmess.Account{ 789 Id: userID.String(), 790 }), 791 }, 792 }, 793 }, 794 }, 795 }), 796 SenderSettings: serial.ToTypedMessage(&proxyman.SenderConfig{ 797 StreamSettings: &internet.StreamConfig{ 798 ProtocolName: "grpc", 799 TransportSettings: []*internet.TransportConfig{ 800 { 801 ProtocolName: "grpc", 802 Settings: serial.ToTypedMessage(&grpc.Config{ServiceName: "🍉", MultiMode: true}), 803 }, 804 }, 805 SecurityType: serial.GetMessageType(&tls.Config{}), 806 SecuritySettings: []*serial.TypedMessage{ 807 serial.ToTypedMessage(&tls.Config{ 808 AllowInsecure: true, 809 }), 810 }, 811 }, 812 }), 813 }, 814 }, 815 } 816 817 servers, err := InitializeServerConfigs(serverConfig, clientConfig) 818 common.Must(err) 819 defer CloseAllServers(servers) 820 821 var errg errgroup.Group 822 for i := 0; i < 10; i++ { 823 errg.Go(testTCPConn(clientPort, 1024*10240, time.Second*40)) 824 } 825 if err := errg.Wait(); err != nil { 826 t.Error(err) 827 } 828 }