protocol.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * Copyright (c) 2016, Psiphon Inc.
  3. * All rights reserved.
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. */
  19. package protocol
  20. import (
  21. "github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/osl"
  22. )
  23. const (
  24. TUNNEL_PROTOCOL_SSH = "SSH"
  25. TUNNEL_PROTOCOL_OBFUSCATED_SSH = "OSSH"
  26. TUNNEL_PROTOCOL_UNFRONTED_MEEK = "UNFRONTED-MEEK-OSSH"
  27. TUNNEL_PROTOCOL_UNFRONTED_MEEK_HTTPS = "UNFRONTED-MEEK-HTTPS-OSSH"
  28. TUNNEL_PROTOCOL_FRONTED_MEEK = "FRONTED-MEEK-OSSH"
  29. TUNNEL_PROTOCOL_FRONTED_MEEK_HTTP = "FRONTED-MEEK-HTTP-OSSH"
  30. SERVER_ENTRY_SOURCE_EMBEDDED = "EMBEDDED"
  31. SERVER_ENTRY_SOURCE_REMOTE = "REMOTE"
  32. SERVER_ENTRY_SOURCE_DISCOVERY = "DISCOVERY"
  33. SERVER_ENTRY_SOURCE_TARGET = "TARGET"
  34. CAPABILITY_SSH_API_REQUESTS = "ssh-api-requests"
  35. CAPABILITY_UNTUNNELED_WEB_API_REQUESTS = "handshake"
  36. CLIENT_CAPABILITY_SERVER_REQUESTS = "server-requests"
  37. PSIPHON_API_HANDSHAKE_REQUEST_NAME = "psiphon-handshake"
  38. PSIPHON_API_CONNECTED_REQUEST_NAME = "psiphon-connected"
  39. PSIPHON_API_STATUS_REQUEST_NAME = "psiphon-status"
  40. PSIPHON_API_CLIENT_VERIFICATION_REQUEST_NAME = "psiphon-client-verification"
  41. PSIPHON_API_OSL_REQUEST_NAME = "psiphon-osl"
  42. PSIPHON_API_CLIENT_SESSION_ID_LENGTH = 16
  43. PSIPHON_SSH_API_PROTOCOL = "ssh"
  44. PSIPHON_WEB_API_PROTOCOL = "web"
  45. )
  46. var SupportedTunnelProtocols = []string{
  47. TUNNEL_PROTOCOL_FRONTED_MEEK,
  48. TUNNEL_PROTOCOL_FRONTED_MEEK_HTTP,
  49. TUNNEL_PROTOCOL_UNFRONTED_MEEK,
  50. TUNNEL_PROTOCOL_UNFRONTED_MEEK_HTTPS,
  51. TUNNEL_PROTOCOL_OBFUSCATED_SSH,
  52. TUNNEL_PROTOCOL_SSH,
  53. }
  54. var SupportedServerEntrySources = []string{
  55. SERVER_ENTRY_SOURCE_EMBEDDED,
  56. SERVER_ENTRY_SOURCE_REMOTE,
  57. SERVER_ENTRY_SOURCE_DISCOVERY,
  58. SERVER_ENTRY_SOURCE_TARGET,
  59. }
  60. func TunnelProtocolUsesSSH(protocol string) bool {
  61. return true
  62. }
  63. func TunnelProtocolUsesObfuscatedSSH(protocol string) bool {
  64. return protocol != TUNNEL_PROTOCOL_SSH
  65. }
  66. func TunnelProtocolUsesMeekHTTP(protocol string) bool {
  67. return protocol == TUNNEL_PROTOCOL_UNFRONTED_MEEK ||
  68. protocol == TUNNEL_PROTOCOL_FRONTED_MEEK_HTTP
  69. }
  70. func TunnelProtocolUsesMeekHTTPS(protocol string) bool {
  71. return protocol == TUNNEL_PROTOCOL_FRONTED_MEEK ||
  72. protocol == TUNNEL_PROTOCOL_UNFRONTED_MEEK_HTTPS
  73. }
  74. type HandshakeResponse struct {
  75. Homepages []string `json:"homepages"`
  76. UpgradeClientVersion string `json:"upgrade_client_version"`
  77. PageViewRegexes []map[string]string `json:"page_view_regexes"`
  78. HttpsRequestRegexes []map[string]string `json:"https_request_regexes"`
  79. EncodedServerList []string `json:"encoded_server_list"`
  80. ClientRegion string `json:"client_region"`
  81. ServerTimestamp string `json:"server_timestamp"`
  82. }
  83. type ConnectedResponse struct {
  84. ConnectedTimestamp string `json:"connected_timestamp"`
  85. }
  86. type OSLRequest struct {
  87. ClearLocalSLOKs bool `json:"clear_local_sloks"`
  88. SeedPayload *osl.SeedPayload `json:"seed_payload"`
  89. }
  90. type SSHPasswordPayload struct {
  91. SessionId string `json:"SessionId"`
  92. SshPassword string `json:"SshPassword"`
  93. ClientCapabilities []string `json:"ClientCapabilities"`
  94. }