MCPcopy Create free account
hub / github.com/nodejs/node / sendAuthRequest

Method sendAuthRequest

deps/undici/src/lib/core/socks5-client.js:214–244  ·  view source on GitHub ↗

* Send username/password authentication request

()

Source from the content-addressed store, hash-verified

212 * Send username/password authentication request
213 */
214 sendAuthRequest () {
215 const { username, password } = this.options
216
217 if (!username || !password) {
218 throw new InvalidArgumentError('Username and password required for authentication')
219 }
220
221 debug('sending username/password auth')
222
223 // Username/Password authentication request (RFC 1929)
224 // +----+------+----------+------+----------+
225 // |VER | ULEN | UNAME | PLEN | PASSWD |
226 // +----+------+----------+------+----------+
227 // | 1 | 1 | 1 to 255 | 1 | 1 to 255 |
228 // +----+------+----------+------+----------+
229 const usernameBuffer = Buffer.from(username)
230 const passwordBuffer = Buffer.from(password)
231
232 if (usernameBuffer.length > 255 || passwordBuffer.length > 255) {
233 throw new InvalidArgumentError('Username or password too long')
234 }
235
236 const request = Buffer.alloc(3 + usernameBuffer.length + passwordBuffer.length)
237 request[0] = 0x01 // Sub-negotiation version
238 request[1] = usernameBuffer.length
239 usernameBuffer.copy(request, 2)
240 request[2 + usernameBuffer.length] = passwordBuffer.length
241 passwordBuffer.copy(request, 3 + usernameBuffer.length)
242
243 this.socket.write(request)
244 }
245
246 /**
247 * Handle authentication response

Callers 1

Calls 5

allocMethod · 0.80
copyMethod · 0.65
debugFunction · 0.50
fromMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected