tls_test.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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.ListenAddress(netip.IPv4Unspecified()),
  18. ListenPort: clientPort,
  19. },
  20. },
  21. },
  22. {
  23. Type: C.TypeTrojan,
  24. TrojanOptions: option.TrojanInboundOptions{
  25. ListenOptions: option.ListenOptions{
  26. Listen: option.ListenAddress(netip.IPv4Unspecified()),
  27. ListenPort: serverPort,
  28. },
  29. Users: []option.TrojanUser{
  30. {
  31. Name: "sekai",
  32. Password: "password",
  33. },
  34. },
  35. TLS: &option.InboundTLSOptions{
  36. Enabled: true,
  37. ServerName: "example.org",
  38. CertificatePath: certPem,
  39. KeyPath: keyPem,
  40. },
  41. },
  42. },
  43. },
  44. Outbounds: []option.Outbound{
  45. {
  46. Type: C.TypeDirect,
  47. },
  48. {
  49. Type: C.TypeTrojan,
  50. Tag: "trojan-out",
  51. TrojanOptions: option.TrojanOutboundOptions{
  52. ServerOptions: option.ServerOptions{
  53. Server: "127.0.0.1",
  54. ServerPort: serverPort,
  55. },
  56. Password: "password",
  57. TLS: &option.OutboundTLSOptions{
  58. Enabled: true,
  59. ServerName: "example.org",
  60. CertificatePath: certPem,
  61. UTLS: &option.OutboundUTLSOptions{
  62. Enabled: true,
  63. Fingerprint: "chrome",
  64. },
  65. },
  66. },
  67. },
  68. },
  69. Route: &option.RouteOptions{
  70. Rules: []option.Rule{
  71. {
  72. DefaultOptions: option.DefaultRule{
  73. Inbound: []string{"mixed-in"},
  74. Outbound: "trojan-out",
  75. },
  76. },
  77. },
  78. },
  79. })
  80. testSuit(t, clientPort, testPort)
  81. }