tls_test.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. package main
  2. import (
  3. "net/netip"
  4. "testing"
  5. C "github.com/sagernet/sing-box/constant"
  6. "github.com/sagernet/sing-box/option"
  7. )
  8. func TestUTLS(t *testing.T) {
  9. _, certPem, keyPem := createSelfSignedCertificate(t, "example.org")
  10. startInstance(t, option.Options{
  11. Inbounds: []option.Inbound{
  12. {
  13. Type: C.TypeMixed,
  14. Tag: "mixed-in",
  15. MixedOptions: option.HTTPMixedInboundOptions{
  16. ListenOptions: option.ListenOptions{
  17. Listen: option.NewListenAddress(netip.IPv4Unspecified()),
  18. ListenPort: clientPort,
  19. },
  20. },
  21. },
  22. {
  23. Type: C.TypeTrojan,
  24. TrojanOptions: option.TrojanInboundOptions{
  25. ListenOptions: option.ListenOptions{
  26. Listen: option.NewListenAddress(netip.IPv4Unspecified()),
  27. ListenPort: serverPort,
  28. },
  29. Users: []option.TrojanUser{
  30. {
  31. Name: "sekai",
  32. Password: "password",
  33. },
  34. },
  35. InboundTLSOptionsContainer: option.InboundTLSOptionsContainer{
  36. TLS: &option.InboundTLSOptions{
  37. Enabled: true,
  38. ServerName: "example.org",
  39. CertificatePath: certPem,
  40. KeyPath: keyPem,
  41. },
  42. },
  43. },
  44. },
  45. },
  46. Outbounds: []option.Outbound{
  47. {
  48. Type: C.TypeDirect,
  49. },
  50. {
  51. Type: C.TypeTrojan,
  52. Tag: "trojan-out",
  53. TrojanOptions: option.TrojanOutboundOptions{
  54. ServerOptions: option.ServerOptions{
  55. Server: "127.0.0.1",
  56. ServerPort: serverPort,
  57. },
  58. Password: "password",
  59. OutboundTLSOptionsContainer: option.OutboundTLSOptionsContainer{
  60. TLS: &option.OutboundTLSOptions{
  61. Enabled: true,
  62. ServerName: "example.org",
  63. CertificatePath: certPem,
  64. UTLS: &option.OutboundUTLSOptions{
  65. Enabled: true,
  66. Fingerprint: "chrome",
  67. },
  68. },
  69. },
  70. },
  71. },
  72. },
  73. Route: &option.RouteOptions{
  74. Rules: []option.Rule{
  75. {
  76. DefaultOptions: option.DefaultRule{
  77. Inbound: []string{"mixed-in"},
  78. Outbound: "trojan-out",
  79. },
  80. },
  81. },
  82. },
  83. })
  84. testSuit(t, clientPort, testPort)
  85. }