mirror of
https://github.com/Hizenberg469/secure_mailer.git
synced 2026-04-20 01:02:23 +03:00
Project complete
This commit is contained in:
@@ -17,6 +17,7 @@ import javafx.application.Platform;
|
|||||||
import javafx.scene.control.Alert;
|
import javafx.scene.control.Alert;
|
||||||
import javafx.scene.control.Alert.AlertType;
|
import javafx.scene.control.Alert.AlertType;
|
||||||
import javafx.util.Duration;
|
import javafx.util.Duration;
|
||||||
|
import java.util.StringTokenizer;
|
||||||
|
|
||||||
public class ValidatorClient {
|
public class ValidatorClient {
|
||||||
|
|
||||||
@@ -154,7 +155,9 @@ public class ValidatorClient {
|
|||||||
String packet = formPacket(data);
|
String packet = formPacket(data);
|
||||||
|
|
||||||
//Packet ready.
|
//Packet ready.
|
||||||
packet = String.valueOf(1) + packet;
|
// packet = String.valueOf() + packet;
|
||||||
|
|
||||||
|
System.out.println("Packet for authentication : "+packet);
|
||||||
|
|
||||||
//Send the size of packet.
|
//Send the size of packet.
|
||||||
//ps.println(packet.length());
|
//ps.println(packet.length());
|
||||||
@@ -166,36 +169,69 @@ public class ValidatorClient {
|
|||||||
|
|
||||||
String msg = br.readLine();
|
String msg = br.readLine();
|
||||||
|
|
||||||
//Parse the packet.
|
StringTokenizer tokenizer = new StringTokenizer(msg, ":");
|
||||||
int i = 0;
|
this.timeStamp = tokenizer.nextToken();
|
||||||
String num = "";
|
this.authCode = tokenizer.nextToken();
|
||||||
for(; i < msg.length() ; i++ ) {
|
// //Parse the packet.
|
||||||
if( msg.charAt(i) != ':' )
|
// int i = 0;
|
||||||
num += Character.toString(msg.charAt(i));
|
// String num = "";
|
||||||
else
|
// for(; i < msg.length() ; i++ ) {
|
||||||
break;
|
// if( msg.charAt(i) != ':' )
|
||||||
}
|
// num += Character.toString(msg.charAt(i));
|
||||||
|
// else
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// num = num + "\0";
|
||||||
|
// if( num.equals("420") ) {
|
||||||
|
// Platform.runLater(() -> showAlert("Error", "Email record not found on server."));
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// this.timeStamp = num;
|
||||||
|
// i = i + 1;
|
||||||
|
// num = "";
|
||||||
|
// for(; i < msg.length() ; i++ ) {
|
||||||
|
// num += Character.toString(msg.charAt(i));
|
||||||
|
// }
|
||||||
|
//// num = num + "\0";
|
||||||
|
// this.authCode = num + "\0";
|
||||||
|
|
||||||
|
System.out.println("Size of timestamp : " + this.timeStamp.length());
|
||||||
if( num.equals("420") ) {
|
this.authCode = (this.authCode).substring(0, 6);
|
||||||
Platform.runLater(() -> showAlert("Error", "Email record not found on server."));
|
System.out.println("Size of authCode : " + this.authCode.length());
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.timeStamp = num;
|
|
||||||
i = i + 1;
|
|
||||||
num = "";
|
|
||||||
for(; i < msg.length() ; i++ ) {
|
|
||||||
num += Character.toString(msg.charAt(i));
|
|
||||||
}
|
|
||||||
this.authCode = num;
|
|
||||||
|
|
||||||
String secretKey = SecretCodeDAO.getSecretCode(fromEmailId);
|
String secretKey = SecretCodeDAO.getSecretCode(fromEmailId);
|
||||||
String totp = generateTOTP( secretKey, Long.parseLong(this.timeStamp));
|
String totp = generateTOTP( secretKey, Long.parseLong(this.timeStamp.trim()));
|
||||||
|
|
||||||
|
System.out.println("TimeStamp : "+this.timeStamp);
|
||||||
|
System.out.println("AuthCode : "+this.authCode);
|
||||||
|
|
||||||
|
System.out.println("TOTP : "+totp);
|
||||||
|
|
||||||
return (totp == this.authCode);
|
String temp = this.authCode;
|
||||||
|
int serverTOTP = -132;
|
||||||
|
try {
|
||||||
|
serverTOTP = Integer.parseInt(temp.trim());
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
System.err.println("Problem in serverTOTP");
|
||||||
|
}
|
||||||
|
|
||||||
|
int clientTOTP = 4324;
|
||||||
|
try {
|
||||||
|
clientTOTP = Integer.parseInt(totp.trim());
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
System.err.println("Problem in clientTOTP");
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("Server TOTP : "+serverTOTP);
|
||||||
|
System.out.println("Client TOTP : "+clientTOTP);
|
||||||
|
|
||||||
|
boolean result = (serverTOTP == clientTOTP);
|
||||||
|
|
||||||
|
System.out.println("Result : "+result);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
|
||||||
} catch(SQLException e) {
|
} catch(SQLException e) {
|
||||||
|
|
||||||
|
|||||||
@@ -299,6 +299,8 @@ public class MainWindowController extends BaseController implements Initializabl
|
|||||||
|
|
||||||
emailMessage.setIsAuthenticated(isAuthenticated);
|
emailMessage.setIsAuthenticated(isAuthenticated);
|
||||||
|
|
||||||
|
System.out.println("Is Authenticated : "+isAuthenticated);
|
||||||
|
|
||||||
if(emailMessage != null) {
|
if(emailMessage != null) {
|
||||||
if (isAuthenticated) {
|
if (isAuthenticated) {
|
||||||
emailManager.setSelectedMessage(emailMessage);
|
emailManager.setSelectedMessage(emailMessage);
|
||||||
|
|||||||
Reference in New Issue
Block a user