Skip to content

Commit fce8ec0

Browse files
author
victorskl
committed
Implemented SSL, Added config directory and system wide properties file, Added initial auth server module
1 parent 75635aa commit fce8ec0

28 files changed

+537
-89
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
mvndeptree.txt
12
*.log
23
*.class
34

config/keystore/README.txt

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
Generated Using JDK Keytool
2+
---
3+
4+
keytool -genkey -keystore strike_keystore.jks -keyalg RSA
5+
6+
7+
8+
---
9+
Do I need to do it on my local:
10+
Nop. Just simply use this.
11+
12+
But, how to:
13+
Please read below.
14+
15+
Where to find keytool:
16+
Command line program 'keytool' comes with JDK installation.
17+
The complete path on Windows is:
18+
C:\Program Files\Java\jdk1.8.0_102\bin\keytool.exe
19+
20+
Screen capture:
21+
D:\Projects\unimelb\strike\config\keystore>keytool -genkey -keystore strike_keystore.jks -keyalg RSA
22+
Enter keystore password:
23+
Re-enter new password:
24+
What is your first and last name?
25+
[Unknown]: Strike
26+
What is the name of your organizational unit?
27+
[Unknown]: Strike
28+
What is the name of your organization?
29+
[Unknown]: Strike
30+
What is the name of your City or Locality?
31+
[Unknown]: Melbourne
32+
What is the name of your State or Province?
33+
[Unknown]: VIC
34+
What is the two-letter country code for this unit?
35+
[Unknown]: AU
36+
Is CN=Strike, OU=Strike, O=Strike, L=Melbourne, ST=VIC, C=AU correct?
37+
[no]: yes
38+
39+
Enter key password for <mykey>
40+
(RETURN if same as keystore password):

config/keystore/strike_keystore.jks

2.17 KB
Binary file not shown.
File renamed without changes.

config/system.properties

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#### Chat System wide properties
2+
#
3+
keystore=config/keystore/strike_keystore.jks
4+
####
5+
## Chat Client specific
6+
#
7+
client.string=string
8+
client.integer=1
9+
client.boolean=true
10+
####
11+
## Chat Server specific
12+
#
13+
server.string=string
14+
server.integer=1
15+
server.boolean=true
16+
####
17+
## Auth Server specific
18+
#
19+
auth.server.list=string
20+

mvndeptree.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
# Run this script to understand Maven dependency tree
3+
mvn dependency:tree > mvndeptree.txt

pom.xml

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<module>strike-common</module>
2121
<module>strike-server</module>
2222
<module>strike-client</module>
23+
<module>strike-auth-server</module>
2324
</modules>
2425

2526
<build>

strike-auth-server/pom.xml

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<parent>
6+
<artifactId>strike-parent-pom</artifactId>
7+
<groupId>strike</groupId>
8+
<version>1.0-SNAPSHOT</version>
9+
<relativePath>../strike-parent-pom/pom.xml</relativePath>
10+
</parent>
11+
12+
<artifactId>strike-auth-server</artifactId>
13+
<packaging>jar</packaging>
14+
15+
<properties>
16+
<shiro.version>1.3.2</shiro.version>
17+
</properties>
18+
19+
<dependencies>
20+
21+
<dependency>
22+
<groupId>strike</groupId>
23+
<artifactId>strike-common</artifactId>
24+
<version>1.0-SNAPSHOT</version>
25+
</dependency>
26+
27+
<dependency>
28+
<groupId>org.apache.shiro</groupId>
29+
<artifactId>shiro-core</artifactId>
30+
<version>${shiro.version}</version>
31+
</dependency>
32+
33+
</dependencies>
34+
35+
<build>
36+
<plugins>
37+
38+
<plugin>
39+
<groupId>org.apache.maven.plugins</groupId>
40+
<artifactId>maven-assembly-plugin</artifactId>
41+
<version>2.6</version>
42+
<configuration>
43+
<descriptorRefs>
44+
<descriptorRef>jar-with-dependencies</descriptorRef>
45+
</descriptorRefs>
46+
<archive>
47+
<manifest>
48+
<mainClass>strike.StrikeAuthServer</mainClass>
49+
</manifest>
50+
</archive>
51+
</configuration>
52+
<executions>
53+
<execution>
54+
<phase>package</phase>
55+
<goals>
56+
<goal>single</goal>
57+
</goals>
58+
</execution>
59+
</executions>
60+
</plugin>
61+
62+
<plugin>
63+
<artifactId>maven-resources-plugin</artifactId>
64+
<version>3.0.1</version>
65+
<executions>
66+
<execution>
67+
<id>copy-resources</id>
68+
<phase>package</phase>
69+
<goals>
70+
<goal>copy-resources</goal>
71+
</goals>
72+
<configuration>
73+
<outputDirectory>${project.build.directory}</outputDirectory>
74+
<resources>
75+
<resource>
76+
<directory>${basedir}</directory>
77+
<filtering>true</filtering>
78+
<includes>
79+
<include>auth-server.conf</include>
80+
</includes>
81+
</resource>
82+
</resources>
83+
</configuration>
84+
</execution>
85+
</executions>
86+
</plugin>
87+
88+
</plugins>
89+
</build>
90+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package strike;
2+
3+
import org.apache.logging.log4j.LogManager;
4+
import org.apache.logging.log4j.Logger;
5+
6+
public class StrikeAuthServer {
7+
8+
public static void main(String[] args) {
9+
new StrikeAuthServer(args);
10+
}
11+
12+
public StrikeAuthServer(String[] args) {
13+
14+
}
15+
16+
private static final Logger logger = LogManager.getLogger(StrikeAuthServer.class);
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package strike;
2+
3+
public class AppTest {
4+
5+
}

strike-client/src/main/java/au/edu/unimelb/tcp/client/Client.java

+28-24
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,51 @@
11
package au.edu.unimelb.tcp.client;
22

3+
import org.json.simple.parser.ParseException;
4+
5+
import javax.net.ssl.SSLSocket;
6+
import javax.net.ssl.SSLSocketFactory;
37
import java.io.IOException;
4-
import java.net.Socket;
58
import java.net.UnknownHostException;
6-
import java.util.ArrayList;
79
import java.util.HashMap;
8-
import java.util.Observable;
910
import java.util.Set;
1011

11-
import org.json.simple.parser.ParseException;
12-
import org.kohsuke.args4j.CmdLineException;
13-
import org.kohsuke.args4j.CmdLineParser;
14-
1512
public class Client {
1613

17-
String[] args;
14+
//String[] args;
15+
private ComLineValues values;
1816

1917
MessageSendThread messageSendThread;
2018

19+
/**
20+
* @deprecated use Client(ComLineValues values) constructor instead
21+
*/
22+
@Deprecated
2123
public Client(String[] args) {
22-
this.args = args;
24+
//this.args = args;
25+
throw new UnsupportedOperationException("move to: new Client(ComLineValues values)");
2326
}
2427

28+
public Client(ComLineValues values) {
29+
this.values = values;
30+
}
31+
2532
public void run() throws IOException, ParseException {
26-
Socket socket = null;
33+
SSLSocket socket = null;
2734
String identity = null;
2835
boolean debug = false;
2936
try {
3037
//load command line args
31-
ComLineValues values = new ComLineValues();
32-
CmdLineParser parser = new CmdLineParser(values);
33-
try {
34-
parser.parseArgument(args);
35-
String hostname = values.getHost();
36-
identity = values.getIdeneity();
37-
int port = values.getPort();
38-
debug = values.isDebug();
39-
socket = new Socket(hostname, port);
40-
} catch (CmdLineException e) {
41-
e.printStackTrace();
42-
}
43-
44-
State state = new State(identity, "");
38+
//ComLineValues values = new ComLineValues();
39+
//CmdLineParser parser = new CmdLineParser(values);
40+
//parser.parseArgument(args);
41+
String hostname = values.getHost();
42+
identity = values.getIdeneity();
43+
int port = values.getPort();
44+
debug = values.isDebug();
45+
SSLSocketFactory sslsocketfactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
46+
socket = (SSLSocket) sslsocketfactory.createSocket(hostname, port);
47+
48+
State state = new State(identity, "");
4549

4650
// start sending thread
4751
messageSendThread = new MessageSendThread(socket, state, debug);

strike-client/src/main/java/au/edu/unimelb/tcp/client/ComLineValues.java

+9
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
package au.edu.unimelb.tcp.client;
22
import org.kohsuke.args4j.Option;
33

4+
import java.io.File;
45

56
public class ComLineValues {
7+
8+
@Option(name = "-c", usage = "c=System Properties file")
9+
private File systemPropertiesFile = new File("./config/system.properties");
10+
611
@Option(required=true, name = "-h", aliases="--host", usage="Server host address")
712
private String host;
813

@@ -30,4 +35,8 @@ public String getIdeneity() {
3035
public boolean isDebug() {
3136
return debug;
3237
}
38+
39+
public File getSystemPropertiesFile() {
40+
return systemPropertiesFile;
41+
}
3342
}

strike-client/src/main/java/au/edu/unimelb/tcp/client/MessageReceiveThread.java

+14-12
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
package au.edu.unimelb.tcp.client;
22

3+
import org.json.simple.JSONArray;
4+
import org.json.simple.JSONObject;
5+
import org.json.simple.parser.JSONParser;
6+
import org.json.simple.parser.ParseException;
7+
8+
import javax.net.ssl.SSLSocket;
9+
import javax.net.ssl.SSLSocketFactory;
310
import java.io.BufferedReader;
411
import java.io.DataOutputStream;
512
import java.io.IOException;
613
import java.io.InputStreamReader;
7-
import java.net.Socket;
814
import java.util.HashSet;
915

10-
import org.json.simple.JSONArray;
11-
import org.json.simple.JSONObject;
12-
import org.json.simple.parser.JSONParser;
13-
import org.json.simple.parser.ParseException;
14-
1516
public class MessageReceiveThread implements Runnable {
1617

17-
private Socket socket;
18+
private SSLSocket socket;
1819
private State state;
1920
private boolean debug;
2021
private Client client;
@@ -27,7 +28,7 @@ public class MessageReceiveThread implements Runnable {
2728

2829
private MessageSendThread messageSendThread;
2930

30-
public MessageReceiveThread(Socket socket, State state, MessageSendThread messageSendThread, Client client, boolean debug) throws IOException {
31+
public MessageReceiveThread(SSLSocket socket, State state, MessageSendThread messageSendThread, Client client, boolean debug) throws IOException {
3132
this.socket = socket;
3233
this.state = state;
3334
this.messageSendThread = messageSendThread;
@@ -63,7 +64,7 @@ public void run() {
6364

6465
}
6566

66-
public void MessageReceive(Socket socket, JSONObject message)
67+
public void MessageReceive(SSLSocket socket, JSONObject message)
6768
throws IOException, ParseException {
6869
String type = (String) message.get("type");
6970

@@ -250,8 +251,9 @@ public void MessageReceive(Socket socket, JSONObject message)
250251
System.out.println("Connecting to server " + host + ":" + port);
251252
System.out.print("[" + state.getRoomId() + "] " + state.getIdentity() + "> ");
252253
}
253-
254-
Socket temp_socket = new Socket(host, port);
254+
255+
SSLSocketFactory sslsocketfactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
256+
SSLSocket temp_socket = (SSLSocket) sslsocketfactory.createSocket(host, port);
255257

256258
// send #movejoin
257259
DataOutputStream out = new DataOutputStream(temp_socket.getOutputStream());
@@ -296,7 +298,7 @@ public void MessageReceive(Socket socket, JSONObject message)
296298
}
297299
}
298300

299-
public void switchServer(Socket temp_socket, BufferedReader temp_in) throws IOException {
301+
public void switchServer(SSLSocket temp_socket, BufferedReader temp_in) throws IOException {
300302
in.close();
301303
in = temp_in;
302304
socket.close();

0 commit comments

Comments
 (0)