Skip to content
Snippets Groups Projects
Commit 0a87bda0 authored by Hai HoDac's avatar Hai HoDac
Browse files

Merged encryption function

parent 38aee1e5
No related branches found
No related tags found
1 merge request!34Added encryption
...@@ -11,11 +11,14 @@ import remote.IDrawingController; ...@@ -11,11 +11,14 @@ import remote.IDrawingController;
import java.rmi.RemoteException; import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry; import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry; import java.rmi.registry.Registry;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
public class Client public class Client
{ {
private final String DEFAULT_USERNAME = "Anonymous"; private final String DEFAULT_USERNAME = "Anonymous";
private final String DEFAULT_SERVER_ADDRESS = "localhost"; private final String DEFAULT_SERVER_ADDRESS = "localhost";
private final EncryptionUpdate encryptionUpdate;
private String userName; private String userName;
private String serverAddress; private String serverAddress;
...@@ -73,7 +76,7 @@ public class Client ...@@ -73,7 +76,7 @@ public class Client
public IDrawingController getDrawingController() { return drawingController; } public IDrawingController getDrawingController() { return drawingController; }
public Client(String username) throws RemoteException public Client(String username) throws RemoteException, NoSuchProviderException, NoSuchAlgorithmException
{ {
this.userName = username; this.userName = username;
this.clientUpdate = new ClientUpdate(this); this.clientUpdate = new ClientUpdate(this);
...@@ -81,6 +84,7 @@ public class Client ...@@ -81,6 +84,7 @@ public class Client
this.drawingUpdate = new DrawingUpdate(this); this.drawingUpdate = new DrawingUpdate(this);
this.startScreen = new StartScreen(this); this.startScreen = new StartScreen(this);
this.applicationMain = new ApplicationMain(this); this.applicationMain = new ApplicationMain(this);
this.encryptionUpdate = new EncryptionUpdate();
} }
public static void main(String[] args) public static void main(String[] args)
...@@ -143,7 +147,7 @@ public class Client ...@@ -143,7 +147,7 @@ public class Client
if( clientController.checkPassword(password) ) if( clientController.checkPassword(password) )
{ {
if( clientController.join(userName, this.chatUpdate, this.clientUpdate, this.drawingUpdate) ) if( clientController.join(userName, this.chatUpdate, this.clientUpdate, this.drawingUpdate, this.encryptionUpdate) )
{ {
System.out.println("Connected to server"); System.out.println("Connected to server");
......
...@@ -7,7 +7,7 @@ public interface IClientController extends Remote ...@@ -7,7 +7,7 @@ public interface IClientController extends Remote
{ {
enum Action {KICKOUT, ASSIGNADMIN}; enum Action {KICKOUT, ASSIGNADMIN};
boolean join(String username, IChatUpdate clientChat, IClientUpdate clientUpdate, IDrawingUpdate clientDrawing) throws RemoteException; boolean join(String username, IChatUpdate clientChat, IClientUpdate clientUpdate, IDrawingUpdate clientDrawing, IEncryptionUpdate encryptionUpdate) throws RemoteException;
void quit(String username) throws RemoteException; void quit(String username) throws RemoteException;
......
package server; package server;
import remote.IChatUpdate; import remote.*;
import remote.IClientUpdate;
import remote.IDrawingUpdate;
import remote.IClientController;
import java.io.Serializable; import java.io.Serializable;
import java.rmi.Remote; import java.rmi.Remote;
...@@ -20,13 +17,15 @@ public class ClientController extends UnicastRemoteObject implements IClientCont ...@@ -20,13 +17,15 @@ public class ClientController extends UnicastRemoteObject implements IClientCont
} }
@Override @Override
public boolean join(String username, IChatUpdate clientChat, IClientUpdate clientUpdate, IDrawingUpdate clientDrawing) throws RemoteException public boolean join(String username, IChatUpdate clientChat, IClientUpdate clientUpdate, IDrawingUpdate clientDrawing, IEncryptionUpdate encryptionUpdate) throws RemoteException
{ {
if( getUserIndex(username) < 0 ) if( getUserIndex(username) < 0 )
{ {
// user with same username is not connected // user with same username is not connected
server.chatController.broadcastMessageUserLogin(username); server.chatController.broadcastMessageUserLogin(username);
new MySharedKey(encryptionUpdate);
User newUser = new User(username, clientChat, clientUpdate, clientDrawing); User newUser = new User(username, clientChat, clientUpdate, clientDrawing);
server.users.add(newUser); server.users.add(newUser);
......
...@@ -4,6 +4,8 @@ import remote.IChatController; ...@@ -4,6 +4,8 @@ import remote.IChatController;
import remote.IClientController; import remote.IClientController;
import remote.IDrawingController; import remote.IDrawingController;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.rmi.RemoteException; import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry; import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry; import java.rmi.registry.Registry;
...@@ -54,7 +56,6 @@ public class Server ...@@ -54,7 +56,6 @@ public class Server
public void run() throws RemoteException public void run() throws RemoteException
{ {
LocateRegistry.createRegistry(1099); LocateRegistry.createRegistry(1099);
Registry registry = LocateRegistry.getRegistry(); Registry registry = LocateRegistry.getRegistry();
...@@ -71,5 +72,24 @@ public class Server ...@@ -71,5 +72,24 @@ public class Server
registry.rebind(drawingControllerName, drawingController); registry.rebind(drawingControllerName, drawingController);
System.out.println("Server is ready"); System.out.println("Server is ready");
printIP();
}
private void printIP()
{
InetAddress inetAddress = null;
try
{
inetAddress = InetAddress.getLocalHost();
}
catch (UnknownHostException e)
{
e.printStackTrace();
}
System.out.println("IP Address:- " + inetAddress.getHostAddress());
System.out.println("Host Name:- " + inetAddress.getHostName());
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment