protocol.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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_UNFRONTED_MEEK_SESSION_TICKET = "UNFRONTED-MEEK-SESSION-TICKET-OSSH"
  29. TUNNEL_PROTOCOL_FRONTED_MEEK = "FRONTED-MEEK-OSSH"
  30. TUNNEL_PROTOCOL_FRONTED_MEEK_HTTP = "FRONTED-MEEK-HTTP-OSSH"
  31. SERVER_ENTRY_SOURCE_EMBEDDED = "EMBEDDED"
  32. SERVER_ENTRY_SOURCE_REMOTE = "REMOTE"
  33. SERVER_ENTRY_SOURCE_DISCOVERY = "DISCOVERY"
  34. SERVER_ENTRY_SOURCE_TARGET = "TARGET"
  35. CAPABILITY_SSH_API_REQUESTS = "ssh-api-requests"
  36. CAPABILITY_UNTUNNELED_WEB_API_REQUESTS = "handshake"
  37. CLIENT_CAPABILITY_SERVER_REQUESTS = "server-requests"
  38. PSIPHON_API_HANDSHAKE_REQUEST_NAME = "psiphon-handshake"
  39. PSIPHON_API_CONNECTED_REQUEST_NAME = "psiphon-connected"
  40. PSIPHON_API_STATUS_REQUEST_NAME = "psiphon-status"
  41. PSIPHON_API_CLIENT_VERIFICATION_REQUEST_NAME = "psiphon-client-verification"
  42. PSIPHON_API_OSL_REQUEST_NAME = "psiphon-osl"
  43. PSIPHON_API_CLIENT_SESSION_ID_LENGTH = 16
  44. PSIPHON_SSH_API_PROTOCOL = "ssh"
  45. PSIPHON_WEB_API_PROTOCOL = "web"
  46. )
  47. var SupportedTunnelProtocols = []string{
  48. TUNNEL_PROTOCOL_FRONTED_MEEK,
  49. TUNNEL_PROTOCOL_FRONTED_MEEK_HTTP,
  50. TUNNEL_PROTOCOL_UNFRONTED_MEEK,
  51. TUNNEL_PROTOCOL_UNFRONTED_MEEK_HTTPS,
  52. TUNNEL_PROTOCOL_UNFRONTED_MEEK_SESSION_TICKET,
  53. TUNNEL_PROTOCOL_OBFUSCATED_SSH,
  54. TUNNEL_PROTOCOL_SSH,
  55. }
  56. var SupportedServerEntrySources = []string{
  57. SERVER_ENTRY_SOURCE_EMBEDDED,
  58. SERVER_ENTRY_SOURCE_REMOTE,
  59. SERVER_ENTRY_SOURCE_DISCOVERY,
  60. SERVER_ENTRY_SOURCE_TARGET,
  61. }
  62. func TunnelProtocolUsesSSH(protocol string) bool {
  63. return true
  64. }
  65. func TunnelProtocolUsesObfuscatedSSH(protocol string) bool {
  66. return protocol != TUNNEL_PROTOCOL_SSH
  67. }
  68. func TunnelProtocolUsesMeekHTTP(protocol string) bool {
  69. return protocol == TUNNEL_PROTOCOL_UNFRONTED_MEEK ||
  70. protocol == TUNNEL_PROTOCOL_FRONTED_MEEK_HTTP
  71. }
  72. func TunnelProtocolUsesMeekHTTPS(protocol string) bool {
  73. return protocol == TUNNEL_PROTOCOL_FRONTED_MEEK ||
  74. protocol == TUNNEL_PROTOCOL_UNFRONTED_MEEK_HTTPS ||
  75. protocol == TUNNEL_PROTOCOL_UNFRONTED_MEEK_SESSION_TICKET
  76. }
  77. func TunnelProtocolUsesObfuscatedSessionTickets(protocol string) bool {
  78. return protocol == TUNNEL_PROTOCOL_UNFRONTED_MEEK_SESSION_TICKET
  79. }
  80. type HandshakeResponse struct {
  81. SSHSessionID string `json:"ssh_session_id"`
  82. Homepages []string `json:"homepages"`
  83. UpgradeClientVersion string `json:"upgrade_client_version"`
  84. PageViewRegexes []map[string]string `json:"page_view_regexes"`
  85. HttpsRequestRegexes []map[string]string `json:"https_request_regexes"`
  86. EncodedServerList []string `json:"encoded_server_list"`
  87. ClientRegion string `json:"client_region"`
  88. ServerTimestamp string `json:"server_timestamp"`
  89. }
  90. type ConnectedResponse struct {
  91. ConnectedTimestamp string `json:"connected_timestamp"`
  92. }
  93. type OSLRequest struct {
  94. ClearLocalSLOKs bool `json:"clear_local_sloks"`
  95. SeedPayload *osl.SeedPayload `json:"seed_payload"`
  96. }
  97. type SSHPasswordPayload struct {
  98. SessionId string `json:"SessionId"`
  99. SshPassword string `json:"SshPassword"`
  100. ClientCapabilities []string `json:"ClientCapabilities"`
  101. }