tls_test.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. "github.com/sagernet/sing/common"
  8. "github.com/sagernet/sing/common/json/badoption"
  9. )
  10. func TestUTLS(t *testing.T) {
  11. _, certPem, keyPem := createSelfSignedCertificate(t, "example.org")
  12. startInstance(t, option.Options{
  13. Inbounds: []option.Inbound{
  14. {
  15. Type: C.TypeMixed,
  16. Tag: "mixed-in",
  17. Options: &option.HTTPMixedInboundOptions{
  18. ListenOptions: option.ListenOptions{
  19. Listen: common.Ptr(badoption.Addr(netip.IPv4Unspecified())),
  20. ListenPort: clientPort,
  21. },
  22. },
  23. },
  24. {
  25. Type: C.TypeTrojan,
  26. Options: &option.TrojanInboundOptions{
  27. ListenOptions: option.ListenOptions{
  28. Listen: common.Ptr(badoption.Addr(netip.IPv4Unspecified())),
  29. ListenPort: serverPort,
  30. },
  31. Users: []option.TrojanUser{
  32. {
  33. Name: "sekai",
  34. Password: "password",
  35. },
  36. },
  37. InboundTLSOptionsContainer: option.InboundTLSOptionsContainer{
  38. TLS: &option.InboundTLSOptions{
  39. Enabled: true,
  40. ServerName: "example.org",
  41. CertificatePath: certPem,
  42. KeyPath: keyPem,
  43. },
  44. },
  45. },
  46. },
  47. },
  48. Outbounds: []option.Outbound{
  49. {
  50. Type: C.TypeDirect,
  51. },
  52. {
  53. Type: C.TypeTrojan,
  54. Tag: "trojan-out",
  55. Options: &option.TrojanOutboundOptions{
  56. ServerOptions: option.ServerOptions{
  57. Server: "127.0.0.1",
  58. ServerPort: serverPort,
  59. },
  60. Password: "password",
  61. OutboundTLSOptionsContainer: option.OutboundTLSOptionsContainer{
  62. TLS: &option.OutboundTLSOptions{
  63. Enabled: true,
  64. ServerName: "example.org",
  65. CertificatePath: certPem,
  66. UTLS: &option.OutboundUTLSOptions{
  67. Enabled: true,
  68. Fingerprint: "chrome",
  69. },
  70. },
  71. },
  72. },
  73. },
  74. },
  75. Route: &option.RouteOptions{
  76. Rules: []option.Rule{
  77. {
  78. Type: C.RuleTypeDefault,
  79. DefaultOptions: option.DefaultRule{
  80. RawDefaultRule: option.RawDefaultRule{
  81. Inbound: []string{"mixed-in"},
  82. },
  83. RuleAction: option.RuleAction{
  84. Action: C.RuleActionTypeRoute,
  85. RouteOptions: option.RouteActionOptions{
  86. Outbound: "trojan-out",
  87. },
  88. },
  89. },
  90. },
  91. },
  92. },
  93. })
  94. testSuit(t, clientPort, testPort)
  95. }