-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.java
More file actions
86 lines (73 loc) · 3.03 KB
/
client.java
File metadata and controls
86 lines (73 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/**
* This class serves as an info collection client
* It contains code copyrighted to Tomas Vilda
* http://stilius.net/java/java_ssl.php
*
* Justin Fulner
*/
import javax.net.ssl.*;
import java.io.*;
public class client {
public static void main(String[] args) {
client c = new client();
String dns = "";
int port = 0;
if(args.length != 2) {
System.out.println("Usage: java client <ip/dns> <server port number>");
System.exit(-1);
}else {
dns = args[0];
port = Integer.parseInt(args[1]);
}
System.setProperty("javax.net.ssl.trustStore", "...");
System.setProperty("javax.net.ssl.trustStorePassword", "...");
try {
SSLSocketFactory sslsocketfactory =
(SSLSocketFactory) SSLSocketFactory.getDefault();
SSLSocket sslsocket =
(SSLSocket) sslsocketfactory.createSocket(dns, port);
InputStream inputstream = System.in;
InputStreamReader inputstreamreader = new InputStreamReader(inputstream);
BufferedReader in = new BufferedReader(inputstreamreader);
OutputStream outputstream = sslsocket.getOutputStream();
OutputStreamWriter outputstreamwriter = new OutputStreamWriter(outputstream);
BufferedWriter out = new BufferedWriter(outputstreamwriter);
InputStream sslssIN = sslsocket.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(sslssIN));
SSLSession session = sslsocket.getSession();
c.getSessionInfo(session);
System.out.println();
String string = null;
String servertoclient = null;
int count = 0;
do {
count++;
servertoclient = br.readLine();
System.out.println(servertoclient);
string = in.readLine();
out.write(string + '\n');
out.flush();
if (servertoclient.contains("Add new user?")
&& string.equalsIgnoreCase("yes")) {
count = 0;
}
}while(count < 6);
} catch (Exception exception) {
System.out.println("Something weird happened");
exception.printStackTrace();
}
}
private void getSessionInfo(SSLSession sesh) {
byte[] bytes = sesh.getId();
StringBuilder sb = new StringBuilder();
for (byte b: bytes)
sb.append(String.format("%02x", b));
String id = sb.toString();
System.out.println("Peer host is " + sesh.getPeerHost() + "\n" +
"Cipher suite is " + sesh.getCipherSuite() + "\n" +
"Protocol is " + sesh.getProtocol() + "\n" +
"Session ID is " + id + "\n" +
"The creation time of this session is " + sesh.getCreationTime() + "\n" +
"The last accessed time of this session is " + sesh.getLastAccessedTime());
}
}