Skip to content

Commit

Permalink
Merge pull request #213 from cconlon/ClientJSSEAddGETHost
Browse files Browse the repository at this point in the history
JSSE: add Host into HTTP GET in example ClientJSSE, used with -g
  • Loading branch information
dgarske authored Aug 1, 2024
2 parents 0361ce3 + 1abeaf1 commit 59aaba2
Showing 1 changed file with 40 additions and 10 deletions.
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

0 comments on commit 59aaba2

Please sign in to comment.