Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
sendSocks5CommandRequest() {
const buff = new smart_buffer_1.SmartBuffer();
buff.writeUInt8(0x05);
buff.writeUInt8(constants_1.SocksCommand[this._options.command]);
buff.writeUInt8(0x00);
// ipv4, ipv6, domain?
if (net.isIPv4(this._options.destination.host)) {
buff.writeUInt8(constants_1.Socks5HostType.IPv4);
buff.writeBuffer(ip.toBuffer(this._options.destination.host));
}
else if (net.isIPv6(this._options.destination.host)) {
buff.writeUInt8(constants_1.Socks5HostType.IPv6);
buff.writeBuffer(ip.toBuffer(this._options.destination.host));
}
else {
buff.writeUInt8(constants_1.Socks5HostType.Hostname);
buff.writeUInt8(this._options.destination.host.length);
buff.writeString(this._options.destination.host);
sendSocks5InitialHandshake() {
const buff = new smart_buffer_1.SmartBuffer();
buff.writeUInt8(0x05);
// We should only tell the proxy we support user/pass auth if auth info is actually provided.
// Note: As of Tor v0.3.5.7+, if user/pass auth is an option from the client, by default it will always take priority.
if (this._options.proxy.userId || this._options.proxy.password) {
buff.writeUInt8(2);
buff.writeUInt8(constants_1.Socks5Auth.NoAuth);
buff.writeUInt8(constants_1.Socks5Auth.UserPass);
}
else {
buff.writeUInt8(1);
buff.writeUInt8(constants_1.Socks5Auth.NoAuth);
}
this._nextRequiredPacketBufferSize =
constants_1.SOCKS_INCOMING_PACKET_SIZES.Socks5InitialHandshakeResponse;
this._socket.write(buff.toBuffer());
this.state = constants_1.SocksClientState.SentInitialHandshake;
let xferBuffer: Buffer;
let remainingBuffer: SmartBuffer;
if (plainWriteBuffer.length <= this._getAvailableRemoteBufferSize()) {
// Send the whole buffer in one go.
xferBuffer = plainWriteBuffer;
remainingBuffer = new SmartBuffer();
} else {
// Cut the buffer into two.
xferBuffer = Buffer.alloc(this._getAvailableRemoteBufferSize());
plainWriteBuffer.copy(xferBuffer, 0, 0, this._getAvailableRemoteBufferSize());
const secondPartBuffer = Buffer.alloc(plainWriteBuffer.length - this._getAvailableRemoteBufferSize());
plainWriteBuffer.copy(secondPartBuffer, 0, this._getAvailableRemoteBufferSize());
remainingBuffer = new SmartBuffer();
remainingBuffer.writeBuffer(secondPartBuffer);
}
WebIpc.writeBulkFile(this._fileIdentifier, xferBuffer);
this._writeBuffer = remainingBuffer;
this._removeBufferDelta -= xferBuffer.length;
this._availableSize += xferBuffer.length;
this._onAvailableSizeChangeEventEmitter.fire(this._availableSize);
}
if (this._closePending && this._writeBuffer.length === 0) {
WebIpc.closeBulkFile(this._fileIdentifier, this._success);
this._isOpen = false;
this._closePending = false;
private sendSocks5CommandRequest() {
const buff = new SmartBuffer();
buff.writeUInt8(0x05);
buff.writeUInt8(SocksCommand[this._options.command]);
buff.writeUInt8(0x00);
// ipv4, ipv6, domain?
if (net.isIPv4(this._options.destination.host)) {
buff.writeUInt8(Socks5HostType.IPv4);
buff.writeBuffer(ip.toBuffer(this._options.destination.host));
} else if (net.isIPv6(this._options.destination.host)) {
buff.writeUInt8(Socks5HostType.IPv6);
buff.writeBuffer(ip.toBuffer(this._options.destination.host));
} else {
buff.writeUInt8(Socks5HostType.Hostname);
buff.writeUInt8(this._options.destination.host.length);
buff.writeString(this._options.destination.host);
private sendSocks4InitialHandshake() {
const userId = this._options.proxy.userId || '';
const buff = new SmartBuffer();
buff.writeUInt8(0x04);
buff.writeUInt8(SocksCommand[this._options.command]);
buff.writeUInt16BE(this._options.destination.port);
// Socks 4 (IPv4)
if (net.isIPv4(this._options.destination.host)) {
buff.writeBuffer(ip.toBuffer(this._options.destination.host));
buff.writeStringNT(userId);
// Socks 4a (hostname)
} else {
buff.writeUInt8(0x00);
buff.writeUInt8(0x00);
buff.writeUInt8(0x00);
buff.writeUInt8(0x01);
buff.writeStringNT(userId);
buff.writeStringNT(this._options.destination.host);
static createUDPFrame(options) {
const buff = new smart_buffer_1.SmartBuffer();
buff.writeUInt16BE(0);
buff.writeUInt8(options.frameNumber || 0);
// IPv4/IPv6/Hostname
if (net.isIPv4(options.remoteHost.host)) {
buff.writeUInt8(constants_1.Socks5HostType.IPv4);
buff.writeUInt32BE(ip.toLong(options.remoteHost.host));
}
else if (net.isIPv6(options.remoteHost.host)) {
buff.writeUInt8(constants_1.Socks5HostType.IPv6);
buff.writeBuffer(ip.toBuffer(options.remoteHost.host));
}
else {
buff.writeUInt8(constants_1.Socks5HostType.Hostname);
buff.writeUInt8(Buffer.byteLength(options.remoteHost.host));
buff.writeString(options.remoteHost.host);
}
private sendSocks5UserPassAuthentication() {
const userId = this._options.proxy.userId || '';
const password = this._options.proxy.password || '';
const buff = new SmartBuffer();
buff.writeUInt8(0x01);
buff.writeUInt8(Buffer.byteLength(userId));
buff.writeString(userId);
buff.writeUInt8(Buffer.byteLength(password));
buff.writeString(password);
this._nextRequiredPacketBufferSize =
SOCKS_INCOMING_PACKET_SIZES.Socks5UserPassAuthenticationResponse;
this._socket.write(buff.toBuffer());
this.state = SocksClientState.SentAuthentication;
}
public async load(oid: string): Promise {
const type = shell.exec(`git cat-file -t ${oid}`, { silent: true }).stdout.trim()
const size = shell.exec(`git cat-file -s ${oid}`, { silent: true }).stdout.trim()
const data = await git.binaryCatFile([type, oid])
const raw = new SmartBuffer()
raw.writeString(`${type} `)
raw.writeString(size)
raw.writeUInt8(0)
raw.writeBuffer(data)
return this.helper.ipld.deserialize(raw.toBuffer())
}