protocol.go 4.3 KB

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