use of com.github.jh3nd3rs0n.jargyle.transport.socks5.Method in project jargyle by jh3nd3rs0n.
the class Socks5Client method negotiateMethod.
protected Method negotiateMethod(final Socket connectedInternalSocket) throws IOException {
Methods methods = this.getProperties().getValue(Socks5PropertySpecConstants.SOCKS5_METHODS);
ClientMethodSelectionMessage cmsm = ClientMethodSelectionMessage.newInstance(methods);
Method method = null;
try {
InputStream inputStream = connectedInternalSocket.getInputStream();
OutputStream outputStream = connectedInternalSocket.getOutputStream();
outputStream.write(cmsm.toByteArray());
outputStream.flush();
ServerMethodSelectionMessage smsm = ServerMethodSelectionMessage.newInstanceFrom(inputStream);
method = smsm.getMethod();
} catch (IOException e) {
SocksClientExceptionThrowingHelper.throwAsSocksClientException(e, this);
}
return method;
}
use of com.github.jh3nd3rs0n.jargyle.transport.socks5.Method in project jargyle by jh3nd3rs0n.
the class Socks5Client method doMethodSubnegotiation.
protected MethodEncapsulation doMethodSubnegotiation(final Method method, final Socket connectedInternalSocket) throws IOException {
MethodSubnegotiator methodSubnegotiator = MethodSubnegotiator.getInstance(method);
MethodEncapsulation methodEncapsulation = null;
try {
methodEncapsulation = methodSubnegotiator.subnegotiate(connectedInternalSocket, this);
} catch (IOException e) {
SocksClientExceptionThrowingHelper.throwAsSocksClientException(e, this);
}
return new SocksClientExceptionThrowingMethodEncapsulation(this, methodEncapsulation);
}
use of com.github.jh3nd3rs0n.jargyle.transport.socks5.Method in project jargyle by jh3nd3rs0n.
the class Socks5Worker method run.
public void run() throws IOException {
this.clientFacingInputStream = this.clientFacingSocket.getInputStream();
Method method = this.negotiateMethod();
if (method == null) {
return;
}
MethodSubnegotiationResults methodSubnegotiationResults = this.doMethodSubnegotiation(method);
if (methodSubnegotiationResults == null) {
return;
}
Socket socket = methodSubnegotiationResults.getSocket();
this.clientFacingInputStream = socket.getInputStream();
this.clientFacingSocket = socket;
this.socks5WorkerContext = new Socks5WorkerContext(new WorkerContext(this.clientFacingSocket, this.socks5WorkerContext.getConfiguration(), this.socks5WorkerContext.getRoute(), this.socks5WorkerContext.getRoutes(), this.socks5WorkerContext.getClientFacingDtlsDatagramSocketFactory()));
Socks5Request socks5Request = this.newSocks5Request();
if (socks5Request == null) {
return;
}
if (!this.canAllowSocks5Request(new Socks5RequestFirewallRule.Context(this.clientFacingSocket.getInetAddress().getHostAddress(), this.clientFacingSocket.getLocalAddress().getHostAddress(), methodSubnegotiationResults, socks5Request))) {
return;
}
Route route = this.selectRoute(new Socks5RequestRoutingRule.Context(this.clientFacingSocket.getInetAddress().getHostAddress(), this.clientFacingSocket.getLocalAddress().getHostAddress(), methodSubnegotiationResults, socks5Request, this.socks5WorkerContext.getRoutes()));
if (route == null) {
return;
}
this.socks5WorkerContext = new Socks5WorkerContext(new WorkerContext(this.socks5WorkerContext.getClientFacingSocket(), this.socks5WorkerContext.getConfiguration(), route, this.socks5WorkerContext.getRoutes(), this.socks5WorkerContext.getClientFacingDtlsDatagramSocketFactory()));
Socks5RequestWorkerContext socks5RequestWorkerContext = new Socks5RequestWorkerContext(this.socks5WorkerContext, methodSubnegotiationResults, socks5Request);
Socks5RequestWorker socks5RequestWorker = this.newSocks5RequestWorker(socks5RequestWorkerContext);
socks5RequestWorker.run();
}
use of com.github.jh3nd3rs0n.jargyle.transport.socks5.Method in project jargyle by jh3nd3rs0n.
the class Socks5Worker method negotiateMethod.
private Method negotiateMethod() {
InputStream in = new SequenceInputStream(new ByteArrayInputStream(new byte[] { Version.V5.byteValue() }), this.clientFacingInputStream);
ClientMethodSelectionMessage cmsm = null;
try {
cmsm = ClientMethodSelectionMessage.newInstanceFrom(in);
} catch (IOException e) {
ClientFacingIOExceptionLoggingHelper.log(LOGGER, ObjectLogMessageHelper.objectLogMessage(this, "Error in parsing the method selection message " + "from the client"), e);
return null;
}
LOGGER.debug(ObjectLogMessageHelper.objectLogMessage(this, "Received %s", cmsm.toString()));
Method method = null;
Methods methods = this.settings.getLastValue(Socks5SettingSpecConstants.SOCKS5_METHODS);
for (Method meth : methods.toList()) {
if (cmsm.getMethods().contains(meth)) {
method = meth;
break;
}
}
if (method == null) {
method = Method.NO_ACCEPTABLE_METHODS;
}
ServerMethodSelectionMessage smsm = ServerMethodSelectionMessage.newInstance(method);
LOGGER.debug(ObjectLogMessageHelper.objectLogMessage(this, "Sending %s", smsm.toString()));
try {
this.socks5WorkerContext.writeThenFlush(smsm.toByteArray());
} catch (IOException e) {
ClientFacingIOExceptionLoggingHelper.log(LOGGER, ObjectLogMessageHelper.objectLogMessage(this, "Error in writing the method selection message to " + "the client"), e);
return null;
}
return smsm.getMethod();
}
use of com.github.jh3nd3rs0n.jargyle.transport.socks5.Method in project java-storage by googleapis.
the class ITBlobWriteChannelTest method doJsonUnexpectedEOFTest.
private void doJsonUnexpectedEOFTest(int contentSize, int cappedByteCount) throws IOException {
String blobPath = String.format("%s/%s/blob", testName.getMethodName(), NOW_STRING);
BucketInfo bucketInfo = BucketInfo.of(dataGeneration.getBucketName());
BlobInfo blobInfoGen0 = BlobInfo.newBuilder(bucketInfo, blobPath, 0L).build();
RetryTestResource retryTestResource = RetryTestResource.newRetryTestResource(Method.newBuilder().setName("storage.objects.insert").build(), InstructionList.newBuilder().addInstructions(String.format("return-broken-stream-final-chunk-after-%dB", cappedByteCount)).build());
RetryTestResource retryTest = testBench.createRetryTest(retryTestResource);
StorageOptions baseOptions = StorageOptions.newBuilder().setCredentials(NoCredentials.getInstance()).setHost(testBench.getBaseUri()).setProjectId("project-id").build();
StorageRpc noHeader = (StorageRpc) baseOptions.getRpc();
StorageRpc yesHeader = (StorageRpc) baseOptions.toBuilder().setHeaderProvider(FixedHeaderProvider.create(ImmutableMap.of("x-retry-test-id", retryTest.id))).build().getRpc();
// noinspection UnstableApiUsage
StorageOptions storageOptions = baseOptions.toBuilder().setServiceRpcFactory(options -> Reflection.newProxy(StorageRpc.class, (proxy, method, args) -> {
try {
if ("writeWithResponse".equals(method.getName())) {
boolean lastChunk = (boolean) args[5];
LOGGER.info(String.format("writeWithResponse called. (lastChunk = %b)", lastChunk));
if (lastChunk) {
return method.invoke(yesHeader, args);
}
}
return method.invoke(noHeader, args);
} catch (Exception e) {
if (e.getCause() != null) {
throw e.getCause();
} else {
throw e;
}
}
})).build();
Storage testStorage = storageOptions.getService();
testStorage.create(bucketInfo);
ByteBuffer content = dataGeneration.randByteBuffer(contentSize);
// create a duplicate to preserve the initial offset and limit for assertion later
ByteBuffer expected = content.duplicate();
WriteChannel w = testStorage.writer(blobInfoGen0, BlobWriteOption.generationMatch());
w.write(content);
w.close();
RetryTestResource postRunState = testBench.getRetryTest(retryTest);
assertTrue(postRunState.completed);
Optional<StorageObject> optionalStorageObject = PackagePrivateMethodWorkarounds.maybeGetStorageObjectFunction().apply(w);
assertTrue(optionalStorageObject.isPresent());
StorageObject storageObject = optionalStorageObject.get();
assertThat(storageObject.getName()).isEqualTo(blobInfoGen0.getName());
// construct a new blob id, without a generation, so we get the latest when we perform a get
BlobId blobIdGen1 = BlobId.of(storageObject.getBucket(), storageObject.getName());
Blob blobGen2 = testStorage.get(blobIdGen1);
assertEquals(contentSize, (long) blobGen2.getSize());
assertNotEquals(blobInfoGen0.getGeneration(), blobGen2.getGeneration());
ByteArrayOutputStream actualData = new ByteArrayOutputStream();
blobGen2.downloadTo(actualData);
ByteBuffer actual = ByteBuffer.wrap(actualData.toByteArray());
assertEquals(expected, actual);
}
Aggregations