Secure Client for exposing TLS (aka SSL) secured services as plain-text connections locally, and for multiplexing a single port with multiple protocols using SNI
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

83 lignes
1.6 KiB

  1. package main
  2. import (
  3. "flag"
  4. "fmt"
  5. "os"
  6. "strconv"
  7. "strings"
  8. )
  9. func usage() {
  10. fmt.Fprintf(os.Stderr, "\nusage: go run sclient*.go <remote> <local>\n"+
  11. "\n"+
  12. " ex: sclient example.com 3000\n"+
  13. " (sclient example.com:443 localhost:3000)\n"+
  14. "\n"+
  15. " ex: sclient example.com:8443 0.0.0.0:4080\n"+
  16. "\n")
  17. flag.PrintDefaults()
  18. fmt.Println()
  19. }
  20. func main() {
  21. flag.Usage = usage
  22. insecure := flag.Bool("k", false, "ignore bad TLS/SSL/HTTPS certificates")
  23. flag.BoolVar(insecure, "insecure", false, "ignore bad TLS/SSL/HTTPS certificates")
  24. flag.Parse()
  25. // NArg, Arg, Args
  26. i := flag.NArg()
  27. if 2 != i {
  28. usage()
  29. os.Exit(0)
  30. }
  31. opts := &SclientOpts{}
  32. opts.RemotePort = 443
  33. opts.LocalAddress = "localhost"
  34. opts.InsecureSkipVerify = *insecure
  35. remote := strings.Split(flag.Arg(0), ":")
  36. //remoteAddr, remotePort, err := net.SplitHostPort(flag.Arg(0))
  37. if 2 == len(remote) {
  38. rport, err := strconv.Atoi(remote[1])
  39. if nil != err {
  40. usage()
  41. os.Exit(0)
  42. }
  43. opts.RemotePort = rport
  44. } else if 1 != len(remote) {
  45. usage()
  46. os.Exit(0)
  47. }
  48. opts.RemoteAddress = remote[0]
  49. local := strings.Split(flag.Arg(1), ":")
  50. //localAddr, localPort, err := net.SplitHostPort(flag.Arg(0))
  51. if 1 == len(local) {
  52. lport, err := strconv.Atoi(local[0])
  53. if nil != err {
  54. usage()
  55. os.Exit(0)
  56. }
  57. opts.LocalPort = lport
  58. } else {
  59. lport, err := strconv.Atoi(local[1])
  60. if nil != err {
  61. usage()
  62. os.Exit(0)
  63. }
  64. opts.LocalAddress = local[0]
  65. opts.LocalPort = lport
  66. }
  67. sclient := &Sclient{}
  68. err := sclient.DialAndListen(opts)
  69. if nil != err {
  70. usage()
  71. os.Exit(0)
  72. }
  73. }