constants.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.SOCKS5_NO_ACCEPTABLE_AUTH = exports.SOCKS5_CUSTOM_AUTH_END = exports.SOCKS5_CUSTOM_AUTH_START = exports.SOCKS_INCOMING_PACKET_SIZES = exports.SocksClientState = exports.Socks5Response = exports.Socks5HostType = exports.Socks5Auth = exports.Socks4Response = exports.SocksCommand = exports.ERRORS = exports.DEFAULT_TIMEOUT = void 0;
  4. const DEFAULT_TIMEOUT = 30000;
  5. exports.DEFAULT_TIMEOUT = DEFAULT_TIMEOUT;
  6. // prettier-ignore
  7. const ERRORS = {
  8. InvalidSocksCommand: 'An invalid SOCKS command was provided. Valid options are connect, bind, and associate.',
  9. InvalidSocksCommandForOperation: 'An invalid SOCKS command was provided. Only a subset of commands are supported for this operation.',
  10. InvalidSocksCommandChain: 'An invalid SOCKS command was provided. Chaining currently only supports the connect command.',
  11. InvalidSocksClientOptionsDestination: 'An invalid destination host was provided.',
  12. InvalidSocksClientOptionsExistingSocket: 'An invalid existing socket was provided. This should be an instance of stream.Duplex.',
  13. InvalidSocksClientOptionsProxy: 'Invalid SOCKS proxy details were provided.',
  14. InvalidSocksClientOptionsTimeout: 'An invalid timeout value was provided. Please enter a value above 0 (in ms).',
  15. InvalidSocksClientOptionsProxiesLength: 'At least two socks proxies must be provided for chaining.',
  16. InvalidSocksClientOptionsCustomAuthRange: 'Custom auth must be a value between 0x80 and 0xFE.',
  17. InvalidSocksClientOptionsCustomAuthOptions: 'When a custom_auth_method is provided, custom_auth_request_handler, custom_auth_response_size, and custom_auth_response_handler must also be provided and valid.',
  18. NegotiationError: 'Negotiation error',
  19. SocketClosed: 'Socket closed',
  20. ProxyConnectionTimedOut: 'Proxy connection timed out',
  21. InternalError: 'SocksClient internal error (this should not happen)',
  22. InvalidSocks4HandshakeResponse: 'Received invalid Socks4 handshake response',
  23. Socks4ProxyRejectedConnection: 'Socks4 Proxy rejected connection',
  24. InvalidSocks4IncomingConnectionResponse: 'Socks4 invalid incoming connection response',
  25. Socks4ProxyRejectedIncomingBoundConnection: 'Socks4 Proxy rejected incoming bound connection',
  26. InvalidSocks5InitialHandshakeResponse: 'Received invalid Socks5 initial handshake response',
  27. InvalidSocks5IntiailHandshakeSocksVersion: 'Received invalid Socks5 initial handshake (invalid socks version)',
  28. InvalidSocks5InitialHandshakeNoAcceptedAuthType: 'Received invalid Socks5 initial handshake (no accepted authentication type)',
  29. InvalidSocks5InitialHandshakeUnknownAuthType: 'Received invalid Socks5 initial handshake (unknown authentication type)',
  30. Socks5AuthenticationFailed: 'Socks5 Authentication failed',
  31. InvalidSocks5FinalHandshake: 'Received invalid Socks5 final handshake response',
  32. InvalidSocks5FinalHandshakeRejected: 'Socks5 proxy rejected connection',
  33. InvalidSocks5IncomingConnectionResponse: 'Received invalid Socks5 incoming connection response',
  34. Socks5ProxyRejectedIncomingBoundConnection: 'Socks5 Proxy rejected incoming bound connection',
  35. };
  36. exports.ERRORS = ERRORS;
  37. const SOCKS_INCOMING_PACKET_SIZES = {
  38. Socks5InitialHandshakeResponse: 2,
  39. Socks5UserPassAuthenticationResponse: 2,
  40. // Command response + incoming connection (bind)
  41. Socks5ResponseHeader: 5,
  42. Socks5ResponseIPv4: 10,
  43. Socks5ResponseIPv6: 22,
  44. Socks5ResponseHostname: (hostNameLength) => hostNameLength + 7,
  45. // Command response + incoming connection (bind)
  46. Socks4Response: 8, // 2 header + 2 port + 4 ip
  47. };
  48. exports.SOCKS_INCOMING_PACKET_SIZES = SOCKS_INCOMING_PACKET_SIZES;
  49. var SocksCommand;
  50. (function (SocksCommand) {
  51. SocksCommand[SocksCommand["connect"] = 1] = "connect";
  52. SocksCommand[SocksCommand["bind"] = 2] = "bind";
  53. SocksCommand[SocksCommand["associate"] = 3] = "associate";
  54. })(SocksCommand || (SocksCommand = {}));
  55. exports.SocksCommand = SocksCommand;
  56. var Socks4Response;
  57. (function (Socks4Response) {
  58. Socks4Response[Socks4Response["Granted"] = 90] = "Granted";
  59. Socks4Response[Socks4Response["Failed"] = 91] = "Failed";
  60. Socks4Response[Socks4Response["Rejected"] = 92] = "Rejected";
  61. Socks4Response[Socks4Response["RejectedIdent"] = 93] = "RejectedIdent";
  62. })(Socks4Response || (Socks4Response = {}));
  63. exports.Socks4Response = Socks4Response;
  64. var Socks5Auth;
  65. (function (Socks5Auth) {
  66. Socks5Auth[Socks5Auth["NoAuth"] = 0] = "NoAuth";
  67. Socks5Auth[Socks5Auth["GSSApi"] = 1] = "GSSApi";
  68. Socks5Auth[Socks5Auth["UserPass"] = 2] = "UserPass";
  69. })(Socks5Auth || (Socks5Auth = {}));
  70. exports.Socks5Auth = Socks5Auth;
  71. const SOCKS5_CUSTOM_AUTH_START = 0x80;
  72. exports.SOCKS5_CUSTOM_AUTH_START = SOCKS5_CUSTOM_AUTH_START;
  73. const SOCKS5_CUSTOM_AUTH_END = 0xfe;
  74. exports.SOCKS5_CUSTOM_AUTH_END = SOCKS5_CUSTOM_AUTH_END;
  75. const SOCKS5_NO_ACCEPTABLE_AUTH = 0xff;
  76. exports.SOCKS5_NO_ACCEPTABLE_AUTH = SOCKS5_NO_ACCEPTABLE_AUTH;
  77. var Socks5Response;
  78. (function (Socks5Response) {
  79. Socks5Response[Socks5Response["Granted"] = 0] = "Granted";
  80. Socks5Response[Socks5Response["Failure"] = 1] = "Failure";
  81. Socks5Response[Socks5Response["NotAllowed"] = 2] = "NotAllowed";
  82. Socks5Response[Socks5Response["NetworkUnreachable"] = 3] = "NetworkUnreachable";
  83. Socks5Response[Socks5Response["HostUnreachable"] = 4] = "HostUnreachable";
  84. Socks5Response[Socks5Response["ConnectionRefused"] = 5] = "ConnectionRefused";
  85. Socks5Response[Socks5Response["TTLExpired"] = 6] = "TTLExpired";
  86. Socks5Response[Socks5Response["CommandNotSupported"] = 7] = "CommandNotSupported";
  87. Socks5Response[Socks5Response["AddressNotSupported"] = 8] = "AddressNotSupported";
  88. })(Socks5Response || (Socks5Response = {}));
  89. exports.Socks5Response = Socks5Response;
  90. var Socks5HostType;
  91. (function (Socks5HostType) {
  92. Socks5HostType[Socks5HostType["IPv4"] = 1] = "IPv4";
  93. Socks5HostType[Socks5HostType["Hostname"] = 3] = "Hostname";
  94. Socks5HostType[Socks5HostType["IPv6"] = 4] = "IPv6";
  95. })(Socks5HostType || (Socks5HostType = {}));
  96. exports.Socks5HostType = Socks5HostType;
  97. var SocksClientState;
  98. (function (SocksClientState) {
  99. SocksClientState[SocksClientState["Created"] = 0] = "Created";
  100. SocksClientState[SocksClientState["Connecting"] = 1] = "Connecting";
  101. SocksClientState[SocksClientState["Connected"] = 2] = "Connected";
  102. SocksClientState[SocksClientState["SentInitialHandshake"] = 3] = "SentInitialHandshake";
  103. SocksClientState[SocksClientState["ReceivedInitialHandshakeResponse"] = 4] = "ReceivedInitialHandshakeResponse";
  104. SocksClientState[SocksClientState["SentAuthentication"] = 5] = "SentAuthentication";
  105. SocksClientState[SocksClientState["ReceivedAuthenticationResponse"] = 6] = "ReceivedAuthenticationResponse";
  106. SocksClientState[SocksClientState["SentFinalHandshake"] = 7] = "SentFinalHandshake";
  107. SocksClientState[SocksClientState["ReceivedFinalResponse"] = 8] = "ReceivedFinalResponse";
  108. SocksClientState[SocksClientState["BoundWaitingForConnection"] = 9] = "BoundWaitingForConnection";
  109. SocksClientState[SocksClientState["Established"] = 10] = "Established";
  110. SocksClientState[SocksClientState["Disconnected"] = 11] = "Disconnected";
  111. SocksClientState[SocksClientState["Error"] = 99] = "Error";
  112. })(SocksClientState || (SocksClientState = {}));
  113. exports.SocksClientState = SocksClientState;
  114. //# sourceMappingURL=constants.js.map