Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSSE: add Host into HTTP GET in example ClientJSSE, used with -g #213

Merged
merged 1 commit into from
Aug 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 40 additions & 10 deletions examples/provider/ClientJSSE.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
Expand Down Expand Up @@ -64,9 +66,11 @@ public ClientJSSE() {

public void run(String[] args) throws Exception {
int ret = 0, input;
byte[] back = new byte[80];
byte[] back = new byte[1024];
String readString = null;
String msg = "Too legit to quit";
String httpGetMsg = "GET /index.html HTTP/1.0\r\n\r\n";
/* HTTP GET Host appended after command line args */
String httpGetMsg = "GET / HTTP/1.1";
String provider = "wolfJSSE";

KeyStore pKey, cert;
Expand All @@ -75,6 +79,8 @@ public void run(String[] args) throws Exception {
ServerSocketFactory srv;
ServerSocket tls;
SSLContext ctx;
BufferedReader inReader = null;
OutputStream outStream = null;

/* config info */
String version;
Expand Down Expand Up @@ -215,6 +221,9 @@ public void run(String[] args) throws Exception {
return;
}

/* Add host into HTTP GET */
httpGetMsg = String.format("%s\r\nHost: %s\r\n\r\n", httpGetMsg, host);

if (profileSleep) {
System.out.println(
"Sleeping 10 seconds to allow profiler to attach");
Expand Down Expand Up @@ -307,14 +316,25 @@ public java.security.cert.X509Certificate[] getAcceptedIssuers() {
sock.startHandshake();
firstSessionId = sock.getSession().getId();
showPeer(sock);

inReader = new BufferedReader(
new InputStreamReader(sock.getInputStream()));
outStream = sock.getOutputStream();

if (sendGET) {
sock.getOutputStream().write(httpGetMsg.getBytes());
outStream.write(httpGetMsg.getBytes());
}
else {
sock.getOutputStream().write(msg.getBytes());
outStream.write(msg.getBytes());
}

System.out.println("Server message : ");
while ((readString = inReader.readLine()) != null) {
System.out.println(readString);
}
sock.getInputStream().read(back);
System.out.println("Server message : " + new String(back));

inReader.close();
outStream.close();
sock.close();

if (resumeSession) {
Expand All @@ -336,20 +356,30 @@ public java.security.cert.X509Certificate[] getAcceptedIssuers() {
resumeSessionId = sock.getSession().getId();
showPeer(sock);

inReader = new BufferedReader(
new InputStreamReader(sock.getInputStream()));
outStream = sock.getOutputStream();

if (Arrays.equals(firstSessionId, resumeSessionId)) {
System.out.println("Session resumed");
} else {
System.out.println("Session NOT resumed");
}

if (sendGET) {
sock.getOutputStream().write(httpGetMsg.getBytes());
outStream.write(httpGetMsg.getBytes());
}
else {
sock.getOutputStream().write(msg.getBytes());
outStream.write(msg.getBytes());
}
sock.getInputStream().read(back);
System.out.println("Server message : " + new String(back));

System.out.println("Server message : ");
while ((readString = inReader.readLine()) != null) {
System.out.println(readString);
}

inReader.close();
outStream.close();
sock.close();
}

Expand Down