HttpClientOptions hco = new HttpClientOptions();
hco.setProxyOptions(new ProxyOptions()
.setType(ProxyType.SOCKS5).setHost(PROXY_HOST).setPort(PROXY_PORT));
HttpClient httpclient = vertx.createHttpClient(hco);
WebClient client = WebClient.wrap(httpclient);
client.head(PORT, HOST, URI).send(ar -> {
if(ar.succeeded()) {
HttpResponse<Buffer> response = ar.result();
parseAuth(response.getHeader("WWW-Authenticate"));
client.get(PORT, HOST, URI)
.putHeader(HttpHeaders.AUTHORIZATION.toString(), getAuth())
.send(ar2 -> {
if (ar2.succeeded()) {
HttpResponse<Buffer> response2 = ar2.result();
System.out.println(response2.statusCode());
}
});
}
});
--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/829b28db-de01-4bad-bb4a-eec122d8a765%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/50a7e88e-7847-49ef-bb1e-1f7b4963e3d2%40googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/f2a5e039-5484-4b4b-a041-7e360d76d009%40googlegroups.com.
private String nonce;
private long nc;
private static final Pattern AUTH_PATTERN = Pattern.compile("Digest qop=\"auth\",algorithm=MD5,realm=\"monero-rpc\",nonce=\"(?<nonce>.+)\",stale=false");
private void parseAuth(String header) {
Matcher m = AUTH_PATTERN.matcher(header);
if(m.matches()) {
nc = 0;
nonce = m.group("nonce");
}
}
private String getAuth() {
if(nonce != null) {
final byte[] cnonceBytes = new byte[8];
RANDOM.nextBytes(cnonceBytes);
String clientNonce = bytesToHex(cnonceBytes);
String nonceCount = String.format("%08x", ++nc);
return getAuth(nonce, METHOD, clientNonce, nonceCount);
} else return null;
}
private String getAuth(String nonce, String method, String clientNonce, String nonceCount) {
String ha1 = md5(USER + ":" + REALM + ":" + PASSWORD);
String ha2 = md5(method + ":" + URI);
String response = md5(ha1 + ":" + nonce + ":" + nonceCount + ":" + clientNonce + ":" + QOP + ":" + ha2);
return "Digest username=\"" +
USER + "\", realm=\"" +
REALM + "\", nonce=\"" +
nonce + "\", uri=\"" +
URI + "\", algorithm=" +
ALGORITHM + ", response=\"" +
response + "\", qop=" +
QOP + ", nc=" +
nonceCount + ", cnonce=\"" +
clientNonce + "\"";
}
private MessageDigest md5;
private String md5(String payload) {
return md5(payload.getBytes());
}
private String md5(byte[] payload) {
md5.reset();
return bytesToHex(md5.digest(payload));
}
private static final char[] HEXADECIMAL = "0123456789abcdef".toCharArray();
private static String bytesToHex(byte[] bytes) {
char[] hexChars = new char[bytes.length * 2];
for ( int j = 0; j < bytes.length; j++ ) {
int v = bytes[j] & 0xFF;
hexChars[j * 2] = HEXADECIMAL[v >>> 4];
hexChars[j * 2 + 1] = HEXADECIMAL[v & 0x0F];
}
return new String(hexChars);
}
Frame 5869: 407 bytes on wire (3256 bits), 407 bytes captured (3256 bits) on interface 0
Ethernet II, Src: AsustekC_cc:74:ec (ac:22:0b:cc:74:ec), Dst: FreebsdF_00:75:97 (58:9c:fc:00:75:97)
Internet Protocol Version 4, Src: 192.168.1.33, Dst: 192.168.1.29
Transmission Control Protocol, Src Port: 57207, Dst Port: XXXXXX, Seq: 1, Ack: 1, Len: 341
Hypertext Transfer Protocol
GET /json_rpc HTTP/1.1\r\n
User-Agent: Vert.x-WebClient/3.4.2\r\n
[truncated]Authorization: Digest username="XXXXXXXXX", realm="monero-rpc", nonce="wJq8irY/W+OzkudqRavGUQ==", uri="/json_rpc", algorithm=MD5, response="0fb39587acb684f57d7b9afc1ee0d6f0", qop=auth, nc=00000
Host: docker:XXXXX\r\n
\r\n
[Full request URI: http://docker:XXXXX/json_rpc]
[HTTP request 1/1]
[Response in frame: 5875]
On 20 Oct 2017, at 17:53, Vincent Olivier <vncn...@gmail.com> wrote:
Hello !I tried directly through TCP without the proxy and I still had the problem. I looked at the raw request with Wireshark and I got this :
Frame 5869: 407 bytes on wire (3256 bits), 407 bytes captured (3256 bits)on interface 0
Ethernet II, Src: AsustekC_cc:74:ec (ac:22:0b:cc:74:ec), Dst:FreebsdF_00:75:97 (58:9c:fc:00:75:97)
Internet Protocol Version 4, Src: 192.168.1.33, Dst: 192.168.1.29
Transmission Control Protocol, Src Port: 57207, Dst Port: XXXXXX, Seq: 1,Ack: 1, Len: 341
Hypertext Transfer Protocol
GET /json_rpc HTTP/1.1\r\n
User-Agent: Vert.x-WebClient/3.4.2\r\n
[truncated]Authorization: Digest username="XXXXXXXXX", realm="monero-rpc", nonce="wJq8irY/W+OzkudqRavGUQ==", uri="/json_rpc", algorithm=MD5,response="0fb39587acb684f57d7b9afc1ee0d6f0", qop=auth, nc=00000
Host: docker:XXXXX\r\n
\r\n
[Full request URI: http://docker:XXXXX/json_rpc]
[HTTP request 1/1]
[Response in frame: 5875]
What is this "[truncated]" could it be that the header value is too long (the username is VERY long) an that it truncates the header ? Because what is sent from vert.x is clearly truncated indeed.
On Wednesday, October 18, 2017 at 8:25:22 PM UTC-4, Vincent Olivier wrote:
Hi ! Thanks for doing those tests! I will look into it (see what the server receives on the other end). The proxy is Tor and it works via the TorBrowser just fine. I'm using the alpha version for the new onion services (which I am using, so that is indeed something to investigate). I haven't tried another Java client yet, will do that too, if I can't find anything about Tor. Thanks. Will be back with results.
On Wednesday, October 18, 2017 at 6:53:12 PM UTC-4, Alexander Lehmann wrote:
When I configure apache with mod_auth_digest, the code can successfully authenticate with or without socks5 proxy, so I guess the error must happen somewhere.
It would probably be helpful to check the network traffic between the client and the proxy and if possible between the proxy and the server with wireshark or tcpdump.
On Wednesday, October 18, 2017 at 1:11:53 PM UTC+2, Alexander Lehmann wrote:
I will try to try your code this evening, it looks about right though.
Could you post an example request/response from curl -V, that would be helpful to mock a server that checks the authentication by setting all random values to fixed strings and run auth against this server.
On Tuesday, October 17, 2017 at 9:45:26 PM UTC+2, Vincent Olivier wrote:
Hi,Here is the code. I highly suspect a WebClient bug at this point because I can dump the raw request from Firefox and curl (also using the same SOCKS5 proxy) and for a given server nonce, they are identical.
private String nonce;
private long nc;
private static final Pattern AUTH_PATTERN =Pattern.compile("Digest qop=\"auth\",algorithm=MD5,realm=\"monero-rpc\",nonce=\"(?<nonce>.+)\",stale=false");
private void parseAuth(String header) {
Matcher m = AUTH_PATTERN.matcher(header);
if(m.matches()) {
nc = 0;
nonce = m.group("nonce");
}
}
private String getAuth() {
if(nonce != null) {
final byte[] cnonceBytes = new byte[8];
RANDOM.nextBytes(cnonceBytes);
String clientNonce = bytesToHex(cnonceBytes);
String nonceCount = String.format("%08x", ++nc);
return getAuth(nonce, METHOD, clientNonce,nonceCount);
} else return null;
}
private String getAuth(String nonce, String method, StringclientNonce, String nonceCount) {
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/c5e5b9a9-ecb3-40a9-9cb8-5c83dfbf5731%40googlegroups.com.
.setType(ProxyType.SOCKS5).setHost(PROXY_HOST).setPort<span style="margin:0px;padding:0px;
--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/482d6e5e-6abb-45f4-aea4-30fc4888d022%40googlegroups.com.
hco.setProxyOptions(new</span
--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/dba8efe2-b81a-4328-a98f-9e33dafc2b7f%40googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/18ea57e0-e00b-4be4-a911-074c9c28b789%40googlegroups.com.